]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/clock_getres.2
ioctl_userfaultfd.2: Document replacement of ENOSPC with ESRCH
[thirdparty/man-pages.git] / man2 / clock_getres.2
CommitLineData
fea681da
MK
1.\" Copyright (c) 2003 Nick Clifford (zaf@nrc.co.nz), Jan 25, 2003
2.\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl), Aug 24, 2003
3.\"
93015253 4.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
5.\" Permission is granted to make and distribute verbatim copies of this
6.\" manual provided the copyright notice and this permission notice are
7.\" preserved on all copies.
8.\"
9.\" Permission is granted to copy and distribute modified versions of this
10.\" manual under the conditions for verbatim copying, provided that the
11.\" entire resulting derived work is distributed under the terms of a
12.\" permission notice identical to this one.
c13182ef 13.\"
fea681da
MK
14.\" Since the Linux kernel and libraries are constantly changing, this
15.\" manual page may be incorrect or out-of-date. The author(s) assume no
16.\" responsibility for errors or omissions, or for damages resulting from
17.\" the use of the information contained herein. The author(s) may not
18.\" have taken the same level of care in the production of this manual,
19.\" which is licensed free of charge, as they might when working
20.\" professionally.
c13182ef 21.\"
fea681da
MK
22.\" Formatted or processed versions of this manual, if unaccompanied by
23.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 24.\" %%%LICENSE_END
fea681da
MK
25.\"
26.\" 2003-08-23 Martin Schulze <joey@infodrom.org> improvements
27.\" 2003-08-24 aeb, large parts rewritten
28.\" 2004-08-06 Christoph Lameter <clameter@sgi.com>, SMP note
29.\"
35deeb87 30.TH CLOCK_GETRES 2 2016-12-12 "" "Linux Programmer's Manual"
fea681da
MK
31.SH NAME
32clock_getres, clock_gettime, clock_settime \- clock and time functions
33.SH SYNOPSIS
34.B #include <time.h>
68e4db0a 35.PP
fea681da 36.BI "int clock_getres(clockid_t " clk_id ", struct timespec *" res );
dbfe9c70 37.PP
fea681da 38.BI "int clock_gettime(clockid_t " clk_id ", struct timespec *" tp );
dbfe9c70 39.PP
fea681da 40.BI "int clock_settime(clockid_t " clk_id ", const struct timespec *" tp );
68e4db0a 41.PP
02959991 42Link with \fI\-lrt\fP (only for glibc versions before 2.17).
68e4db0a 43.PP
cc4615cc
MK
44.in -4n
45Feature Test Macro Requirements for glibc (see
46.BR feature_test_macros (7)):
47.in
68e4db0a 48.PP
cc4615cc
MK
49.ad l
50.BR clock_getres (),
51.BR clock_gettime (),
52.BR clock_settime ():
8260c01f 53.RS
cc4615cc 54_POSIX_C_SOURCE\ >=\ 199309L
8260c01f 55.RE
cc4615cc 56.ad b
fea681da
MK
57.SH DESCRIPTION
58The function
59.BR clock_getres ()
60finds the resolution (precision) of the specified clock
61.IR clk_id ,
62and, if
63.I res
0c2ec4f1 64is non-NULL, stores it in the \fIstruct timespec\fP pointed to by
fea681da
MK
65.IR res .
66The resolution of clocks depends on the implementation and cannot be
67configured by a particular process.
68If the time value pointed to by the argument
69.I tp
70of
71.BR clock_settime ()
72is not a multiple of
73.IR res ,
74then it is truncated to a multiple of
75.IR res .
76.PP
77The functions
78.BR clock_gettime ()
79and
80.BR clock_settime ()
81retrieve and set the time of the specified clock
82.IR clk_id .
83.PP
84The
85.I res
86and
87.I tp
88arguments are
f19a0f03 89.I timespec
4e836144 90structures, as specified in
c13182ef 91.IR <time.h> :
fea681da 92.sp
3ad4ddcd 93.in +4n
fea681da
MK
94.nf
95struct timespec {
cc4615cc
MK
96 time_t tv_sec; /* seconds */
97 long tv_nsec; /* nanoseconds */
fea681da
MK
98};
99.fi
3ad4ddcd 100.in
fea681da 101.PP
c13182ef 102The
fea681da
MK
103.I clk_id
104argument is the identifier of the particular clock on which to act.
105A clock may be system-wide and hence visible for all processes, or
106per-process if it measures time only within a single process.
107.LP
6f36deb4 108All implementations support the system-wide real-time clock,
fea681da
MK
109which is identified by
110.BR CLOCK_REALTIME .
111Its time represents seconds and nanoseconds since the Epoch.
112When its time is changed, timers for a relative interval are
113unaffected, but timers for an absolute point in time are affected.
114.LP
c13182ef
MK
115More clocks may be implemented.
116The interpretation of the
fea681da
MK
117corresponding time values and the effect on timers is unspecified.
118.LP
5260fe08 119Sufficiently recent versions of glibc and the Linux kernel
fea681da
MK
120support the following clocks:
121.TP
122.B CLOCK_REALTIME
22594a3c 123System-wide clock that measures real (i.e., wall-clock) time.
fea681da 124Setting this clock requires appropriate privileges.
22594a3c
MK
125This clock is affected by discontinuous jumps in the system time
126(e.g., if the system administrator manually changes the clock),
127and by the incremental adjustments performed by
65a0c012 128.BR adjtime (3)
22594a3c 129and NTP.
f5546fcd 130.TP
55f749ae
CH
131.BR CLOCK_REALTIME_COARSE " (since Linux 2.6.32; Linux-specific)"
132.\" Added in commit da15cfdae03351c689736f8d142618592e3cebc3
1d33f7d7
MK
133A faster but less precise version of
134.BR CLOCK_REALTIME .
55f749ae 135Use when you need very fast, but not fine-grained timestamps.
c74bc519
MK
136Requires per-architecture support,
137and probably also architecture support for this flag in the
138.BR vdso (7).
55f749ae 139.TP
fea681da
MK
140.B CLOCK_MONOTONIC
141Clock that cannot be set and represents monotonic time since
142some unspecified starting point.
63f0f3d9
MK
143This clock is not affected by discontinuous jumps in the system time
144(e.g., if the system administrator manually changes the clock),
145but is affected by the incremental adjustments performed by
65a0c012 146.BR adjtime (3)
63f0f3d9 147and NTP.
f5546fcd 148.TP
55f749ae
CH
149.BR CLOCK_MONOTONIC_COARSE " (since Linux 2.6.32; Linux-specific)"
150.\" Added in commit da15cfdae03351c689736f8d142618592e3cebc3
1d33f7d7
MK
151A faster but less precise version of
152.BR CLOCK_MONOTONIC .
55f749ae 153Use when you need very fast, but not fine-grained timestamps.
c74bc519
MK
154Requires per-architecture support,
155and probably also architecture support for this flag in the
156.BR vdso (7).
fea681da 157.TP
1ba3fba8
MK
158.BR CLOCK_MONOTONIC_RAW " (since Linux 2.6.28; Linux-specific)"
159.\" Added in commit 2d42244ae71d6c7b0884b5664cf2eda30fb2ae68, John Stultz
160Similar to
161.BR CLOCK_MONOTONIC ,
162but provides access to a raw hardware-based time
63f0f3d9
MK
163that is not subject to NTP adjustments or
164the incremental adjustments performed by
65a0c012 165.BR adjtime (3).
1ba3fba8 166.TP
b28712e1 167.BR CLOCK_BOOTTIME " (since Linux 2.6.39; Linux-specific)"
a5d9ce65
MK
168.\" commit 7fdd7f89006dd5a4c702fa0ce0c272345fa44ae0
169.\" commit 70a08cca1227dc31c784ec930099a4417a06e7d0
b28712e1
CH
170Identical to
171.BR CLOCK_MONOTONIC ,
a5d9ce65
MK
172except it also includes any time that the system is suspended.
173This allows applications to get a suspend-aware monotonic clock
174without having to deal with the complications of
175.BR CLOCK_REALTIME ,
176which may have discontinuities if the time is changed using
0bbe872f
MK
177.BR settimeofday (2)
178or similar.
b28712e1 179.TP
783d6cb4 180.BR CLOCK_PROCESS_CPUTIME_ID " (since Linux 2.6.12)"
2fd2c35c
MK
181Per-process CPU-time clock
182(measures CPU time consumed by all threads in the process).
fea681da 183.TP
783d6cb4 184.BR CLOCK_THREAD_CPUTIME_ID " (since Linux 2.6.12)"
fea681da 185Thread-specific CPU-time clock.
47297adb 186.SH RETURN VALUE
e1d6264d 187.BR clock_gettime (),
cc83f4d1 188.BR clock_settime (),
fea681da
MK
189and
190.BR clock_getres ()
191return 0 for success, or \-1 for failure (in which case
192.I errno
193is set appropriately).
194.SH ERRORS
195.TP
196.B EFAULT
197.I tp
198points outside the accessible address space.
199.TP
200.B EINVAL
c13182ef 201The
fea681da
MK
202.I clk_id
203specified is not supported on this system.
a113440c
MK
204.\" Linux also gives this error on attempts to set CLOCK_PROCESS_CPUTIME_ID
205.\" and CLOCK_THREAD_CPUTIME_ID, when probably the proper error should be
206.\" EPERM.
fea681da
MK
207.TP
208.B EPERM
209.BR clock_settime ()
210does not have permission to set the clock indicated.
e272bb60 211.SH VERSIONS
50b25c38 212These system calls first appeared in Linux 2.6.
546e17ce
ZL
213.SH ATTRIBUTES
214For an explanation of the terms used in this section, see
215.BR attributes (7).
216.TS
217allbox;
6a95087e 218lbw32 lb lb
546e17ce
ZL
219l l l.
220Interface Attribute Value
221T{
222.BR clock_getres (),
223.BR clock_gettime (),
224.BR clock_settime ()
225T} Thread safety MT-Safe
226.TE
227
47297adb 228.SH CONFORMING TO
75ee6a07 229POSIX.1-2001, POSIX.1-2008, SUSv2.
2b2581ee
MK
230.SH AVAILABILITY
231On POSIX systems on which these functions are available, the symbol
232.B _POSIX_TIMERS
c84371c6 233is defined in \fI<unistd.h>\fP to a value greater than 0.
2b2581ee
MK
234The symbols
235.BR _POSIX_MONOTONIC_CLOCK ,
236.BR _POSIX_CPUTIME ,
237.B _POSIX_THREAD_CPUTIME
238indicate that
239.BR CLOCK_MONOTONIC ,
240.BR CLOCK_PROCESS_CPUTIME_ID ,
241.B CLOCK_THREAD_CPUTIME_ID
242are available.
243(See also
244.BR sysconf (3).)
19c98696 245.SH NOTES
f086b6aa
MK
246POSIX.1 specifies the following:
247.RS
248.PP
249Setting the value of the
250.B CLOCK_REALTIME
251clock via
e470433f 252.BR clock_settime ()
f086b6aa
MK
253shall have no effect on threads that are blocked waiting for a relative time
254service based upon this clock, including the
255.BR nanosleep ()
256function; nor on the expiration of relative timers based upon this clock.
257Consequently, these time services shall expire when the requested relative
258interval elapses, independently of the new or old value of the clock.
259.\"
78638aae
MK
260.SS Historical note for SMP systems
261Before Linux added kernel support for
fea681da
MK
262.B CLOCK_PROCESS_CPUTIME_ID
263and
78638aae
MK
264.BR CLOCK_THREAD_CPUTIME_ID ,
265glibc implemented these clocks on many platforms using timer
266registers from the CPUs
fea681da
MK
267(TSC on i386, AR.ITC on Itanium).
268These registers may differ between CPUs and as a consequence
269these clocks may return
270.B bogus results
271if a process is migrated to another CPU.
272.PP
f14ae16e 273If the CPUs in an SMP system have different clock sources, then
fea681da 274there is no way to maintain a correlation between the timer registers since
c13182ef 275each CPU will run at a slightly different frequency.
f14ae16e 276If that is the case, then
fea681da
MK
277.I clock_getcpuclockid(0)
278will return
279.B ENOENT
c13182ef 280to signify this condition.
33a0ccb2 281The two clocks will then be useful only if it
fea681da
MK
282can be ensured that a process stays on a certain CPU.
283.PP
284The processors in an SMP system do not start all at exactly the same
285time and therefore the timer registers are typically running at an offset.
286Some architectures include code that attempts to limit these offsets on bootup.
287However, the code cannot guarantee to accurately tune the offsets.
288Glibc contains no provisions to deal with these offsets (unlike the Linux
c13182ef
MK
289Kernel).
290Typically these offsets are small and therefore the effects may be
fea681da 291negligible in most cases.
78638aae
MK
292
293Since glibc 2.4,
294the wrapper functions for the system calls described in this page avoid
295the abovementioned problems by employing the kernel implementation of
296.B CLOCK_PROCESS_CPUTIME_ID
297and
298.BR CLOCK_THREAD_CPUTIME_ID ,
299on systems that provide such an implementation
300(i.e., Linux 2.6.12 and later).
3847be78 301.SH BUGS
a113440c 302According to POSIX.1-2001, a process with "appropriate privileges" may set the
3847be78
MK
303.B CLOCK_PROCESS_CPUTIME_ID
304and
305.B CLOCK_THREAD_CPUTIME_ID
a113440c 306clocks using
3847be78 307.BR clock_settime ().
a113440c
MK
308On Linux, these clocks are not settable
309(i.e., no process has "appropriate privileges").
310.\" See http://bugzilla.kernel.org/show_bug.cgi?id=11972
47297adb 311.SH SEE ALSO
fea681da 312.BR date (1),
fea681da
MK
313.BR gettimeofday (2),
314.BR settimeofday (2),
315.BR time (2),
65a0c012 316.BR adjtime (3),
edf60acb 317.BR clock_getcpuclockid (3),
fea681da
MK
318.BR ctime (3),
319.BR ftime (3),
24ad017d 320.BR pthread_getcpuclockid (3),
1d7c4d16 321.BR sysconf (3),
18688d17 322.BR time (7),
1ce611a3
MK
323.BR vdso (7),
324.BR hwclock (8)