linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>
To: Richard Cochran <richardcochran@gmail.com>
Cc: mtk.manpages@gmail.com, Arnd Bergmann <arnd@arndb.de>,
	John Stultz <john.stultz@linaro.org>,
	Stephen Boyd <sboyd@codeaurora.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	linux-api@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH man-pages 1/2] clock_getres.2: Explain dynamic clocks.
Date: Mon, 20 Apr 2020 13:13:57 +0200	[thread overview]
Message-ID: <aba829df-3da2-dd9e-dd19-808a46e09035@gmail.com> (raw)
In-Reply-To: <f85030cb44354de97f3b7822b23ec34fd21d1f28.1514787752.git.richardcochran@gmail.com>

Hello Richard,

On 1/1/18 7:28 AM, Richard Cochran wrote:
> 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.

This fell on the floor, I'm sorry. It's applied now.

Thanks you!

Michael

> Signed-off-by: Richard Cochran <richardcochran@gmail.com>
> ---
>  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.
> 


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/

      parent reply	other threads:[~2020-04-20 11:14 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             ` [PATCH man-pages 1/2] clock_getres.2: Explain dynamic clocks Richard Cochran
2018-01-01  6:28               ` [PATCH man-pages 2/2] adjtimex.2: document clock_adjtime Richard Cochran
2020-04-20 11:14                 ` Michael Kerrisk (man-pages)
2020-04-20 11:13               ` Michael Kerrisk (man-pages) [this message]

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=aba829df-3da2-dd9e-dd19-808a46e09035@gmail.com \
    --to=mtk.manpages@gmail.com \
    --cc=arnd@arndb.de \
    --cc=john.stultz@linaro.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=richardcochran@gmail.com \
    --cc=sboyd@codeaurora.org \
    --cc=tglx@linutronix.de \
    /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).