]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/clock_getres.2
getcpu.2, sendfile.2, cmsg.3, rtnetlink.3, arp.7, ddp.7, fifo.7, icmp.7, ip.7, ipv6...
[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.\"
4b72fb64 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.\"
55f749ae 30.TH CLOCK_GETRES 2 2013-02-25 "" "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>
35.sp
36.BI "int clock_getres(clockid_t " clk_id ", struct timespec *" res );
5895e7eb 37
fea681da 38.BI "int clock_gettime(clockid_t " clk_id ", struct timespec *" tp );
5895e7eb 39
fea681da 40.BI "int clock_settime(clockid_t " clk_id ", const struct timespec *" tp );
cc4615cc 41.sp
02959991 42Link with \fI\-lrt\fP (only for glibc versions before 2.17).
b905d225 43.sp
cc4615cc
MK
44.in -4n
45Feature Test Macro Requirements for glibc (see
46.BR feature_test_macros (7)):
47.in
48.sp
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
CH
135Use when you need very fast, but not fine-grained timestamps.
136.TP
fea681da
MK
137.TP
138.B CLOCK_MONOTONIC
139Clock that cannot be set and represents monotonic time since
140some unspecified starting point.
63f0f3d9
MK
141This clock is not affected by discontinuous jumps in the system time
142(e.g., if the system administrator manually changes the clock),
143but is affected by the incremental adjustments performed by
65a0c012 144.BR adjtime (3)
63f0f3d9 145and NTP.
f5546fcd 146.TP
55f749ae
CH
147.BR CLOCK_MONOTONIC_COARSE " (since Linux 2.6.32; Linux-specific)"
148.\" Added in commit da15cfdae03351c689736f8d142618592e3cebc3
1d33f7d7
MK
149A faster but less precise version of
150.BR CLOCK_MONOTONIC .
55f749ae 151Use when you need very fast, but not fine-grained timestamps.
fea681da 152.TP
1ba3fba8
MK
153.BR CLOCK_MONOTONIC_RAW " (since Linux 2.6.28; Linux-specific)"
154.\" Added in commit 2d42244ae71d6c7b0884b5664cf2eda30fb2ae68, John Stultz
155Similar to
156.BR CLOCK_MONOTONIC ,
157but provides access to a raw hardware-based time
63f0f3d9
MK
158that is not subject to NTP adjustments or
159the incremental adjustments performed by
65a0c012 160.BR adjtime (3).
1ba3fba8 161.TP
b28712e1 162.BR CLOCK_BOOTTIME " (since Linux 2.6.39; Linux-specific)"
a5d9ce65
MK
163.\" commit 7fdd7f89006dd5a4c702fa0ce0c272345fa44ae0
164.\" commit 70a08cca1227dc31c784ec930099a4417a06e7d0
b28712e1
CH
165Identical to
166.BR CLOCK_MONOTONIC ,
a5d9ce65
MK
167except it also includes any time that the system is suspended.
168This allows applications to get a suspend-aware monotonic clock
169without having to deal with the complications of
170.BR CLOCK_REALTIME ,
171which may have discontinuities if the time is changed using
172.BR settimeofday (2).
b28712e1 173.TP
fea681da
MK
174.B CLOCK_PROCESS_CPUTIME_ID
175High-resolution per-process timer from the CPU.
176.TP
177.B CLOCK_THREAD_CPUTIME_ID
178Thread-specific CPU-time clock.
47297adb 179.SH RETURN VALUE
e1d6264d
MK
180.BR clock_gettime (),
181.BR clock_settime ()
fea681da
MK
182and
183.BR clock_getres ()
184return 0 for success, or \-1 for failure (in which case
185.I errno
186is set appropriately).
187.SH ERRORS
188.TP
189.B EFAULT
190.I tp
191points outside the accessible address space.
192.TP
193.B EINVAL
c13182ef 194The
fea681da
MK
195.I clk_id
196specified is not supported on this system.
a113440c
MK
197.\" Linux also gives this error on attempts to set CLOCK_PROCESS_CPUTIME_ID
198.\" and CLOCK_THREAD_CPUTIME_ID, when probably the proper error should be
199.\" EPERM.
fea681da
MK
200.TP
201.B EPERM
202.BR clock_settime ()
203does not have permission to set the clock indicated.
47297adb 204.SH CONFORMING TO
2b2581ee
MK
205SUSv2, POSIX.1-2001.
206.SH AVAILABILITY
207On POSIX systems on which these functions are available, the symbol
208.B _POSIX_TIMERS
c84371c6 209is defined in \fI<unistd.h>\fP to a value greater than 0.
2b2581ee
MK
210The symbols
211.BR _POSIX_MONOTONIC_CLOCK ,
212.BR _POSIX_CPUTIME ,
213.B _POSIX_THREAD_CPUTIME
214indicate that
215.BR CLOCK_MONOTONIC ,
216.BR CLOCK_PROCESS_CPUTIME_ID ,
217.B CLOCK_THREAD_CPUTIME_ID
218are available.
219(See also
220.BR sysconf (3).)
19c98696 221.SH NOTES
19c98696 222.SS Note for SMP systems
fea681da
MK
223The
224.B CLOCK_PROCESS_CPUTIME_ID
225and
226.B CLOCK_THREAD_CPUTIME_ID
227clocks are realized on many platforms using timers from the CPUs
228(TSC on i386, AR.ITC on Itanium).
229These registers may differ between CPUs and as a consequence
230these clocks may return
231.B bogus results
232if a process is migrated to another CPU.
233.PP
234If the CPUs in an SMP system have different clock sources then
235there is no way to maintain a correlation between the timer registers since
c13182ef
MK
236each CPU will run at a slightly different frequency.
237If that is the case then
fea681da
MK
238.I clock_getcpuclockid(0)
239will return
240.B ENOENT
c13182ef
MK
241to signify this condition.
242The two clocks will then only be useful if it
fea681da
MK
243can be ensured that a process stays on a certain CPU.
244.PP
245The processors in an SMP system do not start all at exactly the same
246time and therefore the timer registers are typically running at an offset.
247Some architectures include code that attempts to limit these offsets on bootup.
248However, the code cannot guarantee to accurately tune the offsets.
249Glibc contains no provisions to deal with these offsets (unlike the Linux
c13182ef
MK
250Kernel).
251Typically these offsets are small and therefore the effects may be
fea681da 252negligible in most cases.
3847be78 253.SH BUGS
a113440c 254According to POSIX.1-2001, a process with "appropriate privileges" may set the
3847be78
MK
255.B CLOCK_PROCESS_CPUTIME_ID
256and
257.B CLOCK_THREAD_CPUTIME_ID
a113440c 258clocks using
3847be78 259.BR clock_settime ().
a113440c
MK
260On Linux, these clocks are not settable
261(i.e., no process has "appropriate privileges").
262.\" See http://bugzilla.kernel.org/show_bug.cgi?id=11972
47297adb 263.SH SEE ALSO
fea681da 264.BR date (1),
fea681da
MK
265.BR gettimeofday (2),
266.BR settimeofday (2),
267.BR time (2),
65a0c012 268.BR adjtime (3),
edf60acb 269.BR clock_getcpuclockid (3),
fea681da
MK
270.BR ctime (3),
271.BR ftime (3),
24ad017d 272.BR pthread_getcpuclockid (3),
1d7c4d16 273.BR sysconf (3),
b3682895 274.BR time (7)