From: Richard Cochran <richardcochran-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Michael Kerrisk <mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>,
John Stultz <john.stultz-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
Stephen Boyd <sboyd-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>,
Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>,
linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH man-pages 1/2] clock_getres.2: Explain dynamic clocks.
Date: Sun, 31 Dec 2017 22:28:51 -0800 [thread overview]
Message-ID: <f85030cb44354de97f3b7822b23ec34fd21d1f28.1514787752.git.richardcochran@gmail.com> (raw)
In-Reply-To: <20171219165811.6ahuquuf5hq74zg3@localhost>
Linux has allowed passing open file descriptors to clock_gettime() and
friends since v2.6.39. This patch documents these "dynamic" clocks
and adds a brief example of how to use them.
Signed-off-by: Richard Cochran <richardcochran-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
man2/clock_getres.2 | 39 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
diff --git a/man2/clock_getres.2 b/man2/clock_getres.2
index 0812d159a..30cbfe46a 100644
--- a/man2/clock_getres.2
+++ b/man2/clock_getres.2
@@ -183,6 +183,35 @@ Per-process CPU-time clock
.TP
.BR CLOCK_THREAD_CPUTIME_ID " (since Linux 2.6.12)"
Thread-specific CPU-time clock.
+.PP
+Linux also implements dynamic clock instances as described below.
+.SH DYNAMIC CLOCKS " (since Linux 2.6.39)"
+In addition to hard coded SYS-V style clock ids, Linux also supports
+POSIX clock operations on certain character devices. Such devices are
+called "dynamic" clocks. Using the appropriate macros, open file
+descriptors may be converted into clock ids and passed to
+.BR clock_gettime (),
+.BR clock_settime (),
+and
+.BR clock_adj (2).
+The follow example shows how to convert a file descriptor into a
+dynamic clock id.
+.PP
+.in +4n
+.EX
+#define CLOCKFD 3
+#define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD)
+#define CLOCKID_TO_FD(clk) ((unsigned int) ~((clk) >> 3))
+
+struct timeval tv;
+clockid_t clkid;
+int fd;
+
+fd = open("/dev/ptp0", O_RDWR);
+clkid = FD_TO_CLOCKID(fd);
+clock_gettime(clkid, &tv);
+.EE
+.in
.SH RETURN VALUE
.BR clock_gettime (),
.BR clock_settime (),
@@ -200,11 +229,19 @@ points outside the accessible address space.
.B EINVAL
The
.I clk_id
-specified is not supported on this system.
+specified is invalid for one of two reasons. Either the SYS-V style
+hard coded positive value is out of range, or the dynamic clock id
+does not refer to a valid instance of a clock object.
.\" Linux also gives this error on attempts to set CLOCK_PROCESS_CPUTIME_ID
.\" and CLOCK_THREAD_CPUTIME_ID, when probably the proper error should be
.\" EPERM.
.TP
+.B ENODEV
+The hot-plugable device (like USB for example) represented by a
+dynamic
+.I clk_id
+has disappeared after its character device was opened.
+.TP
.B EPERM
.BR clock_settime ()
does not have permission to set the clock indicated.
--
2.11.0
next prev parent reply other threads:[~2018-01-01 6:28 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-20 22:53 [PATCH] [man-pages] adjtimex.2: document clock_adjtime Arnd Bergmann
2017-11-21 3:05 ` Richard Cochran
2017-11-21 8:06 ` Arnd Bergmann
2017-11-21 16:06 ` Richard Cochran
2017-11-21 22:09 ` Arnd Bergmann
2017-12-18 19:19 ` Michael Kerrisk (man-pages)
[not found] ` <436eb61b-0fe2-41c8-0992-e21614fd3657-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-12-19 16:58 ` Richard Cochran
2018-01-01 6:28 ` Richard Cochran [this message]
2018-01-01 6:28 ` [PATCH man-pages 2/2] " Richard Cochran
2020-04-20 11:14 ` Michael Kerrisk (man-pages)
2020-04-20 11:13 ` [PATCH man-pages 1/2] clock_getres.2: Explain dynamic clocks Michael Kerrisk (man-pages)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f85030cb44354de97f3b7822b23ec34fd21d1f28.1514787752.git.richardcochran@gmail.com \
--to=richardcochran-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=arnd-r2nGTMty4D4@public.gmane.org \
--cc=john.stultz-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=sboyd-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
--cc=tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).