summaryrefslogtreecommitdiffstats
path: root/man2/clock_getres.2
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--man2/clock_getres.285
1 files changed, 50 insertions, 35 deletions
diff --git a/man2/clock_getres.2 b/man2/clock_getres.2
index 170215d..ec1e327 100644
--- a/man2/clock_getres.2
+++ b/man2/clock_getres.2
@@ -9,32 +9,32 @@
.\" 2003-08-24 aeb, large parts rewritten
.\" 2004-08-06 Christoph Lameter <clameter@sgi.com>, SMP note
.\"
-.TH clock_getres 2 2023-07-20 "Linux man-pages 6.05.01"
+.TH clock_getres 2 2024-03-05 "Linux man-pages 6.7"
.SH NAME
clock_getres, clock_gettime, clock_settime \- clock and time functions
.SH LIBRARY
Standard C library
.RI ( libc ", " \-lc ),
since glibc 2.17
-.PP
+.P
Before glibc 2.17,
Real-time library
.RI ( librt ", " \-lrt )
.SH SYNOPSIS
.nf
.B #include <time.h>
-.PP
+.P
.BI "int clock_getres(clockid_t " clockid ", struct timespec *_Nullable " res );
-.PP
+.P
.BI "int clock_gettime(clockid_t " clockid ", struct timespec *" tp );
.BI "int clock_settime(clockid_t " clockid ", const struct timespec *" tp );
.fi
-.PP
+.P
.RS -4
Feature Test Macro Requirements for glibc (see
.BR feature_test_macros (7)):
.RE
-.PP
+.P
.BR clock_getres (),
.BR clock_gettime (),
.BR clock_settime ():
@@ -60,14 +60,14 @@ is not a multiple of
.IR res ,
then it is truncated to a multiple of
.IR res .
-.PP
+.P
The functions
.BR clock_gettime ()
and
.BR clock_settime ()
retrieve and set the time of the specified clock
.IR clockid .
-.PP
+.P
The
.I res
and
@@ -75,24 +75,24 @@ and
arguments are
.BR timespec (3)
structures.
-.PP
+.P
The
.I clockid
argument is the identifier of the particular clock on which to act.
A clock may be system-wide and hence visible for all processes, or
per-process if it measures time only within a single process.
-.PP
+.P
All implementations support the system-wide real-time clock,
which is identified by
.BR CLOCK_REALTIME .
Its time represents seconds and nanoseconds since the Epoch.
When its time is changed, timers for a relative interval are
unaffected, but timers for an absolute point in time are affected.
-.PP
+.P
More clocks may be implemented.
The interpretation of the
corresponding time values and the effect on timers is unspecified.
-.PP
+.P
Sufficiently recent versions of glibc and the Linux kernel
support the following clocks:
.TP
@@ -101,9 +101,17 @@ A settable system-wide clock that measures real (i.e., wall-clock) time.
Setting this clock requires appropriate privileges.
This clock is affected by discontinuous jumps in the system time
(e.g., if the system administrator manually changes the clock),
-and by the incremental adjustments performed by
-.BR adjtime (3)
-and NTP.
+and by frequency adjustments performed by NTP and similar applications via
+.BR adjtime (3),
+.BR adjtimex (2),
+.BR clock_adjtime (2),
+and
+.BR ntp_adjtime (3).
+This clock normally counts the number of seconds since
+1970-01-01 00:00:00 Coordinated Universal Time (UTC)
+except that it ignores leap seconds;
+near a leap second it is typically adjusted by NTP
+to stay roughly in sync with UTC.
.TP
.BR CLOCK_REALTIME_ALARM " (since Linux 3.0; Linux-specific)"
Like
@@ -126,9 +134,9 @@ and probably also architecture support for this flag in the
.BR CLOCK_TAI " (since Linux 3.10; Linux-specific)"
.\" commit 1ff3c9677bff7e468e0c487d0ffefe4e901d33f4
A nonsettable system-wide clock derived from wall-clock time
-but ignoring leap seconds.
+but counting leap seconds.
This clock does
-not experience discontinuities and backwards jumps caused by NTP
+not experience discontinuities or frequency adjustments caused by
inserting leap seconds as
.B CLOCK_REALTIME
does.
@@ -146,9 +154,7 @@ The
.B CLOCK_MONOTONIC
clock is not affected by discontinuous jumps in the system time
(e.g., if the system administrator manually changes the clock),
-but is affected by the incremental adjustments performed by
-.BR adjtime (3)
-and NTP.
+but is affected by frequency adjustments.
This clock does not count time that the system is suspended.
All
.B CLOCK_MONOTONIC
@@ -170,9 +176,7 @@ and probably also architecture support for this flag in the
Similar to
.BR CLOCK_MONOTONIC ,
but provides access to a raw hardware-based time
-that is not subject to NTP adjustments or
-the incremental adjustments performed by
-.BR adjtime (3).
+that is not subject to frequency adjustments.
This clock does not count time that the system is suspended.
.TP
.BR CLOCK_BOOTTIME " (since Linux 2.6.39; Linux-specific)"
@@ -203,7 +207,7 @@ On Linux, this clock is not settable.
.BR CLOCK_THREAD_CPUTIME_ID " (since Linux 2.6.12)"
This is a clock that measures CPU time consumed by this thread.
On Linux, this clock is not settable.
-.PP
+.P
Linux also implements dynamic clock instances as described below.
.SS Dynamic clocks
In addition to the hard-coded System-V style clock IDs described above,
@@ -211,7 +215,7 @@ Linux also supports
POSIX clock operations on certain character devices.
Such devices are
called "dynamic" clocks, and are supported since Linux 2.6.39.
-.PP
+.P
Using the appropriate macros, open file
descriptors may be converted into clock IDs and passed to
.BR clock_gettime (),
@@ -220,7 +224,7 @@ and
.BR clock_adjtime (2).
The following example shows how to convert a file descriptor into a
dynamic clock ID.
-.PP
+.P
.in +4n
.EX
#define CLOCKFD 3
@@ -304,6 +308,17 @@ has disappeared after its character device was opened.
The operation is not supported by the dynamic POSIX clock device
specified.
.TP
+.B EOVERFLOW
+The timestamp would not fit in
+.I time_t
+range.
+This can happen if an executable with 32-bit
+.I time_t
+is run on a 64-bit kernel when the time is 2038-01-19 03:14:08 UTC or later.
+However, when the system time is out of
+.I time_t
+range in other situations, the behavior is undefined.
+.TP
.B EPERM
.BR clock_settime ()
does not have permission to set the clock indicated.
@@ -323,11 +338,10 @@ T{
.BR clock_settime ()
T} Thread safety MT-Safe
.TE
-.sp 1
.SH VERSIONS
POSIX.1 specifies the following:
.RS
-.PP
+.P
Setting the value of the
.B CLOCK_REALTIME
clock via
@@ -339,7 +353,7 @@ function; nor on the expiration of relative timers based upon this clock.
Consequently, these time services shall expire when the requested relative
interval elapses, independently of the new or old value of the clock.
.RE
-.PP
+.P
According to POSIX.1-2001, a process with "appropriate privileges" may set the
.B CLOCK_PROCESS_CPUTIME_ID
and
@@ -359,10 +373,12 @@ POSIX.1-2008.
.SH HISTORY
POSIX.1-2001, SUSv2.
Linux 2.6.
-.PP
+.P
On POSIX systems on which these functions are available, the symbol
.B _POSIX_TIMERS
is defined in \fI<unistd.h>\fP to a value greater than 0.
+POSIX.1-2008 makes these functions mandatory.
+.P
The symbols
.BR _POSIX_MONOTONIC_CLOCK ,
.BR _POSIX_CPUTIME ,
@@ -374,7 +390,6 @@ indicate that
are available.
(See also
.BR sysconf (3).)
-POSIX.1-2008 makes these APIs mandatory.
.\"
.SS Historical note for SMP systems
Before Linux added kernel support for
@@ -388,7 +403,7 @@ These registers may differ between CPUs and as a consequence
these clocks may return
.B bogus results
if a process is migrated to another CPU.
-.PP
+.P
If the CPUs in an SMP system have different clock sources, then
there is no way to maintain a correlation between the timer registers since
each CPU will run at a slightly different frequency.
@@ -399,7 +414,7 @@ will return
to signify this condition.
The two clocks will then be useful only if it
can be ensured that a process stays on a certain CPU.
-.PP
+.P
The processors in an SMP system do not start all at exactly the same
time and therefore the timer registers are typically running at an offset.
Some architectures include code that attempts to limit these offsets on bootup.
@@ -408,7 +423,7 @@ glibc contains no provisions to deal with these offsets (unlike the Linux
Kernel).
Typically these offsets are small and therefore the effects may be
negligible in most cases.
-.PP
+.P
Since glibc 2.4,
the wrapper functions for the system calls described in this page avoid
the abovementioned problems by employing the kernel implementation of
@@ -424,7 +439,7 @@ and
.BR clock_getres ()
with various clocks.
This is an example of what we might see when running the program:
-.PP
+.P
.in +4n
.EX
$ \fB./clock_times x\fP