I was experimenting with some possible changes to adjtimex(2) and
clock_adjtime(2) and tried to look up the man page to see what the
documented behavior is when I noticed that clock_adjtime() appears
to be the only system call that is currently undocumented.
Before I do any changes to it, this tries to document what I
understand it currently does.
Signed-off-by: Arnd Bergmann <redacted>
---
This is my first patch to man-pages, I'm just guessing about
what should be in there and how to format it, please reword
or reformat as necessary.
---
man2/adjtimex.2 | 25 +++++++++++++++++++++++--
man2/clock_adjtime.2 | 1 +
2 files changed, 24 insertions(+), 2 deletions(-)
create mode 100644 man2/clock_adjtime.2
@@ -344,6 +346,12 @@ Attempts to set read-only .Istatus bits are silently ignored..\"+.SSclock_adjtime()+The+.BRclock_adjtime()+system call (added in Linux 2.6.39) behaves like adjtimex() but takes an additional+.IRclk_id+argument to specify the particular clock on which to act. .SSntp_adjtime() The .BRntp_adjtime()
@@ -472,6 +480,11 @@ An attempt was made to set to a value other than those listed above. .TP .BEINVAL+The+.Iclk_id+specified is not supported on this system.+.TP+.BEINVAL An attempt was made to set .Ibuf.tick to a value outside the range
@@ -482,6 +495,10 @@ where .BHZ is the system timer interrupt frequency. .TP+.BEOPNOTSUPP+.Iclk_id+does not support adjustment+.TP .BEPERM .Ibuf.modes is neither 0 nor
@@ -503,10 +520,12 @@ T{ T} Thread safety MT-Safe .TE .SHCONFORMINGTO-Neither of these interfaces is described in POSIX.1+None of these interfaces is described in POSIX.1 .PP .BRadjtimex()-is Linux-specific and should not be used in programs+and+.BRclock_adjtimex()+are Linux-specific and should not be used in programs intended to be portable. .PP The preferred API for the NTP daemon is
@@ -533,6 +552,8 @@ is done by the kernel in timer context Thus, it will take one tick into the second for the leap second to be inserted or deleted. .SHSEEALSO+.BRclock_gettime(2)+.BRclock_settime(2) .BRsettimeofday(2), .BRadjtime(3), .BRntp_gettime(3),
From: Richard Cochran <richardcochran@gmail.com> Date: 2017-11-21 03:05:05
On Mon, Nov 20, 2017 at 11:53:02PM +0100, Arnd Bergmann wrote:
.B EINVAL
+The
+.I clk_id
+specified is not supported on this system.
We return EINVAL when the clockid is not valid. That can mean two
things. Either the SYS-V style hard coded positive clockid is out of
range, or the dynamic negative clockid does not refer to a valid
instance of a clock object.
Dynamic clocks might also return ENODEV in case a hot-plugable device
(like USB) has disappeared after its character device was opened.
Thanks,
Richard
On Tue, Nov 21, 2017 at 4:05 AM, Richard Cochran
[off-list ref] wrote:
On Mon, Nov 20, 2017 at 11:53:02PM +0100, Arnd Bergmann wrote:
quoted
.B EINVAL
+The
+.I clk_id
+specified is not supported on this system.
We return EINVAL when the clockid is not valid. That can mean two
things. Either the SYS-V style hard coded positive clockid is out of
range, or the dynamic negative clockid does not refer to a valid
instance of a clock object.
Dynamic clocks might also return ENODEV in case a hot-plugable device
(like USB) has disappeared after its character device was opened.
I copied that line from clock_gettime() man page. I suppose we want to
fix change this in both pages, right? Any suggestions for a good way to
express your explanation in the man page? I suppose we don't want to
go into details of the implementation there but still capture the possible
corner cases.
Arnd
From: Richard Cochran <richardcochran@gmail.com> Date: 2017-11-21 16:06:07
On Tue, Nov 21, 2017 at 09:06:37AM +0100, Arnd Bergmann wrote:
I copied that line from clock_gettime() man page. I suppose we want to
fix change this in both pages, right? Any suggestions for a good way to
express your explanation in the man page? I suppose we don't want to
go into details of the implementation there but still capture the possible
corner cases.
Dynamic clockids are a Linux specific extension. This should be
explained with a paragraph or two on the gettime man page, along with
an example using the macros.
#define CLOCKFD 3
#define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD)
#define CLOCKID_TO_FD(clk) ((unsigned int) ~((clk) >> 3))
Then, the adjtimex page can say, see gettime.
Let me try to come up with a text over the (USA) holiday weekend.
Thanks,
Richard
On Tue, Nov 21, 2017 at 5:06 PM, Richard Cochran
[off-list ref] wrote:
On Tue, Nov 21, 2017 at 09:06:37AM +0100, Arnd Bergmann wrote:
quoted
I copied that line from clock_gettime() man page. I suppose we want to
fix change this in both pages, right? Any suggestions for a good way to
express your explanation in the man page? I suppose we don't want to
go into details of the implementation there but still capture the possible
corner cases.
Dynamic clockids are a Linux specific extension. This should be
explained with a paragraph or two on the gettime man page, along with
an example using the macros.
#define CLOCKFD 3
#define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD)
#define CLOCKID_TO_FD(clk) ((unsigned int) ~((clk) >> 3))
Then, the adjtimex page can say, see gettime.
Let me try to come up with a text over the (USA) holiday weekend.
Thanks! There is no rush here, take your time. One more question:
I see that ptp_clock_adjtime doesn't call timekeeping_validate_timex(),
so a number of the error conditions are not caught there. Should we
document that as intended, or change it to behave the same way
as do_adjtimex()?
I also see that ptp_clock_adjtime() ignores all other flags whenever
ADJ_SETOFFSET is set, while __do_adjtimex() can do ADJ_SETOFFSET
and ADJ_FREQUENCY (or any other combination) in a single syscall,
which matches what is documented in the man page.
Arnd
From: Michael Kerrisk (man-pages) <hidden> Date: 2017-12-18 19:19:50
Hi Richard,
On 11/21/2017 05:06 PM, Richard Cochran wrote:
On Tue, Nov 21, 2017 at 09:06:37AM +0100, Arnd Bergmann wrote:
quoted
I copied that line from clock_gettime() man page. I suppose we want to
fix change this in both pages, right? Any suggestions for a good way to
express your explanation in the man page? I suppose we don't want to
go into details of the implementation there but still capture the possible
corner cases.
Dynamic clockids are a Linux specific extension. This should be
explained with a paragraph or two on the gettime man page, along with
an example using the macros.
#define CLOCKFD 3
#define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD)
#define CLOCKID_TO_FD(clk) ((unsigned int) ~((clk) >> 3))
Then, the adjtimex page can say, see gettime.
Let me try to come up with a text over the (USA) holiday weekend.
From: Richard Cochran <richardcochran@gmail.com> Date: 2018-01-01 06:28:58
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 <redacted>
---
man2/clock_getres.2 | 39 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
@@ -183,6 +183,35 @@ Per-process CPU-time clock .TP .BRCLOCK_THREAD_CPUTIME_ID" (since Linux 2.6.12)" Thread-specific CPU-time clock.+.PP+Linux also implements dynamic clock instances as described below.+.SHDYNAMICCLOCKS" (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+.BRclock_gettime(),+.BRclock_settime(),+and+.BRclock_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 .SHRETURNVALUE .BRclock_gettime(), .BRclock_settime(),
@@ -200,11 +229,19 @@ points outside the accessible address space. .BEINVAL The .Iclk_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+.BENODEV+The hot-plugable device (like USB for example) represented by a+dynamic+.Iclk_id+has disappeared after its character device was opened.+.TP .BEPERM .BRclock_settime() does not have permission to set the clock indicated.
From: Richard Cochran <richardcochran@gmail.com> Date: 2018-01-01 06:29:10
From: Arnd Bergmann <arnd@arndb.de>
I was experimenting with some possible changes to adjtimex(2) and
clock_adjtime(2) and tried to look up the man page to see what the
documented behavior is when I noticed that clock_adjtime() appears
to be the only system call that is currently undocumented.
Before I do any changes to it, this tries to document what I
understand it currently does.
[ RC: Add better explanations of the usage and error codes
and correct some typographical mistakes. ]
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
---
man2/adjtimex.2 | 63 +++++++++++++++++++++++++++++++++++++++++++++++++---
man2/clock_adjtime.2 | 1 +
2 files changed, 61 insertions(+), 3 deletions(-)
create mode 100644 man2/clock_adjtime.2
@@ -158,8 +160,26 @@ includes the .BADJ_NANO flag, then .Ibuf.time.tv_usec-is interpreted as a nanosecond value;+is interpreted as a nanosecond value, otherwise it is interpreted as microseconds.+.IP+The value of+.Ibuf.time+is the sum of its two fields, but the+field+.Ibuf.time.tv_usec+must always be non-negative. The following example shows how to+normalize a timeval with nanosecond resolution.+.PP+.in+12n+.EX+while (buf.time.tv_usec < 0) {+ buf.time.tv_sec -= 1;+ buf.time.tv_usec += 1000000000;+}+.EE+.in+.PP .TP .BRADJ_MICRO" (since Linux 2.6.26)".\" commit eea83d896e318bda54be2d2770d2c5d6668d11db
@@ -344,6 +364,12 @@ Attempts to set read-only .Istatus bits are silently ignored..\"+.SSclock_adjtime()+The+.BRclock_adjtime()+system call (added in Linux 2.6.39) behaves like adjtimex() but takes an additional+.IRclk_id+argument to specify the particular clock on which to act. .SSntp_adjtime() The .BRntp_adjtime()
@@ -472,6 +498,19 @@ An attempt was made to set to a value other than those listed above. .TP .BEINVAL+The+.Iclk_id+given to+.BRclock_adjtime()+is invalid for one of two reasons. Either the SYS-V style hard coded+positive value is out of range, or the dynamic+.Iclk_id+does not refer to a valid instance of a clock object.+See+.BRclock_gettime(2)+for a discussion of dynamic clocks.+.TP+.BEINVAL An attempt was made to set .Ibuf.tick to a value outside the range
@@ -482,6 +521,20 @@ where .BHZ is the system timer interrupt frequency. .TP+.BENODEV+The hot-plugable device (like USB for example) represented by a+dynamic+.Iclk_id+has disappeared after its character device was opened.+See+.BRclock_gettime(2)+for a discussion of dynamic clocks.+.TP+.BEOPNOTSUPP+The given+.Iclk_id+does not support adjustment.+.TP .BEPERM .Ibuf.modes is neither 0 nor
@@ -503,10 +556,12 @@ T{ T} Thread safety MT-Safe .TE .SHCONFORMINGTO-Neither of these interfaces is described in POSIX.1+None of these interfaces is described in POSIX.1 .PP .BRadjtimex()-is Linux-specific and should not be used in programs+and+.BRclock_adjtime()+are Linux-specific and should not be used in programs intended to be portable. .PP The preferred API for the NTP daemon is
@@ -533,6 +588,8 @@ is done by the kernel in timer context Thus, it will take one tick into the second for the leap second to be inserted or deleted. .SHSEEALSO+.BRclock_gettime(2)+.BRclock_settime(2) .BRsettimeofday(2), .BRadjtime(3), .BRntp_gettime(3),
From: Michael Kerrisk (man-pages) <hidden> Date: 2020-04-20 11:14:05
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
@@ -183,6 +183,35 @@ Per-process CPU-time clock .TP .BRCLOCK_THREAD_CPUTIME_ID" (since Linux 2.6.12)" Thread-specific CPU-time clock.+.PP+Linux also implements dynamic clock instances as described below.+.SHDYNAMICCLOCKS" (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+.BRclock_gettime(),+.BRclock_settime(),+and+.BRclock_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 .SHRETURNVALUE .BRclock_gettime(), .BRclock_settime(),
@@ -200,11 +229,19 @@ points outside the accessible address space. .BEINVAL The .Iclk_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+.BENODEV+The hot-plugable device (like USB for example) represented by a+dynamic+.Iclk_id+has disappeared after its character device was opened.+.TP .BEPERM .BRclock_settime() does not have permission to set the clock indicated.
From: Michael Kerrisk (man-pages) <hidden> Date: 2020-04-20 11:14:16
Hello Richard, Arnd,
On 1/1/18 7:28 AM, Richard Cochran wrote:
From: Arnd Bergmann <arnd@arndb.de>
I was experimenting with some possible changes to adjtimex(2) and
clock_adjtime(2) and tried to look up the man page to see what the
documented behavior is when I noticed that clock_adjtime() appears
to be the only system call that is currently undocumented.
Before I do any changes to it, this tries to document what I
understand it currently does.
[ RC: Add better explanations of the usage and error codes
and correct some typographical mistakes. ]
And this patch too is now applied.
Thank you!
Cheers,
Michael
@@ -158,8 +160,26 @@ includes the .BADJ_NANO flag, then .Ibuf.time.tv_usec-is interpreted as a nanosecond value;+is interpreted as a nanosecond value, otherwise it is interpreted as microseconds.+.IP+The value of+.Ibuf.time+is the sum of its two fields, but the+field+.Ibuf.time.tv_usec+must always be non-negative. The following example shows how to+normalize a timeval with nanosecond resolution.+.PP+.in+12n+.EX+while (buf.time.tv_usec < 0) {+ buf.time.tv_sec -= 1;+ buf.time.tv_usec += 1000000000;+}+.EE+.in+.PP .TP .BRADJ_MICRO" (since Linux 2.6.26)".\" commit eea83d896e318bda54be2d2770d2c5d6668d11db
@@ -344,6 +364,12 @@ Attempts to set read-only .Istatus bits are silently ignored..\"+.SSclock_adjtime()+The+.BRclock_adjtime()+system call (added in Linux 2.6.39) behaves like adjtimex() but takes an additional+.IRclk_id+argument to specify the particular clock on which to act. .SSntp_adjtime() The .BRntp_adjtime()
@@ -472,6 +498,19 @@ An attempt was made to set to a value other than those listed above. .TP .BEINVAL+The+.Iclk_id+given to+.BRclock_adjtime()+is invalid for one of two reasons. Either the SYS-V style hard coded+positive value is out of range, or the dynamic+.Iclk_id+does not refer to a valid instance of a clock object.+See+.BRclock_gettime(2)+for a discussion of dynamic clocks.+.TP+.BEINVAL An attempt was made to set .Ibuf.tick to a value outside the range
@@ -482,6 +521,20 @@ where .BHZ is the system timer interrupt frequency. .TP+.BENODEV+The hot-plugable device (like USB for example) represented by a+dynamic+.Iclk_id+has disappeared after its character device was opened.+See+.BRclock_gettime(2)+for a discussion of dynamic clocks.+.TP+.BEOPNOTSUPP+The given+.Iclk_id+does not support adjustment.+.TP .BEPERM .Ibuf.modes is neither 0 nor
@@ -503,10 +556,12 @@ T{ T} Thread safety MT-Safe .TE .SHCONFORMINGTO-Neither of these interfaces is described in POSIX.1+None of these interfaces is described in POSIX.1 .PP .BRadjtimex()-is Linux-specific and should not be used in programs+and+.BRclock_adjtime()+are Linux-specific and should not be used in programs intended to be portable. .PP The preferred API for the NTP daemon is
@@ -533,6 +588,8 @@ is done by the kernel in timer context Thus, it will take one tick into the second for the leap second to be inserted or deleted. .SHSEEALSO+.BRclock_gettime(2)+.BRclock_settime(2) .BRsettimeofday(2), .BRadjtime(3), .BRntp_gettime(3),