1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (c) 2003 Nick Clifford (zaf@nrc.co.nz), Jan 25, 2003
4 .\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl), Aug 24, 2003
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
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
30 .\" FIXME: Linux 2.6.39 adds CLOCK_BOOTTIME
32 .TH CLOCK_GETRES 2 2012-04-30 "" "Linux Programmer's Manual"
34 clock_getres, clock_gettime, clock_settime \- clock and time functions
38 .BI "int clock_getres(clockid_t " clk_id ", struct timespec *" res );
40 .BI "int clock_gettime(clockid_t " clk_id ", struct timespec *" tp );
42 .BI "int clock_settime(clockid_t " clk_id ", const struct timespec *" tp );
44 Link with \fI\-lrt\fP.
47 Feature Test Macro Requirements for glibc (see
48 .BR feature_test_macros (7)):
56 _POSIX_C_SOURCE\ >=\ 199309L
62 finds the resolution (precision) of the specified clock
66 is non-NULL, stores it in the \fIstruct timespec\fP pointed to by
68 The resolution of clocks depends on the implementation and cannot be
69 configured by a particular process.
70 If the time value pointed to by the argument
76 then it is truncated to a multiple of
83 retrieve and set the time of the specified clock
92 structures, as specified in
98 time_t tv_sec; /* seconds */
99 long tv_nsec; /* nanoseconds */
106 argument is the identifier of the particular clock on which to act.
107 A clock may be system-wide and hence visible for all processes, or
108 per-process if it measures time only within a single process.
110 All implementations support the system-wide real-time clock,
111 which is identified by
113 Its time represents seconds and nanoseconds since the Epoch.
114 When its time is changed, timers for a relative interval are
115 unaffected, but timers for an absolute point in time are affected.
117 More clocks may be implemented.
118 The interpretation of the
119 corresponding time values and the effect on timers is unspecified.
121 Sufficiently recent versions of glibc and the Linux kernel
122 support the following clocks:
125 System-wide clock that measures real (i.e., wall-clock) time.
126 Setting this clock requires appropriate privileges.
127 This clock is affected by discontinuous jumps in the system time
128 (e.g., if the system administrator manually changes the clock),
129 and by the incremental adjustments performed by
134 Clock that cannot be set and represents monotonic time since
135 some unspecified starting point.
136 This clock is not affected by discontinuous jumps in the system time
137 (e.g., if the system administrator manually changes the clock),
138 but is affected by the incremental adjustments performed by
142 .BR CLOCK_MONOTONIC_RAW " (since Linux 2.6.28; Linux-specific)"
143 .\" Added in commit 2d42244ae71d6c7b0884b5664cf2eda30fb2ae68, John Stultz
145 .BR CLOCK_MONOTONIC ,
146 but provides access to a raw hardware-based time
147 that is not subject to NTP adjustments or
148 the incremental adjustments performed by
151 .B CLOCK_PROCESS_CPUTIME_ID
152 High-resolution per-process timer from the CPU.
154 .B CLOCK_THREAD_CPUTIME_ID
155 Thread-specific CPU-time clock.
157 .BR clock_gettime (),
161 return 0 for success, or \-1 for failure (in which case
163 is set appropriately).
168 points outside the accessible address space.
173 specified is not supported on this system.
174 .\" Linux also gives this error on attempts to set CLOCK_PROCESS_CPUTIME_ID
175 .\" and CLOCK_THREAD_CPUTIME_ID, when probably the proper error should be
180 does not have permission to set the clock indicated.
184 On POSIX systems on which these functions are available, the symbol
186 is defined in \fI<unistd.h>\fP to a value greater than 0.
188 .BR _POSIX_MONOTONIC_CLOCK ,
190 .B _POSIX_THREAD_CPUTIME
192 .BR CLOCK_MONOTONIC ,
193 .BR CLOCK_PROCESS_CPUTIME_ID ,
194 .B CLOCK_THREAD_CPUTIME_ID
199 .SS Note for SMP systems
201 .B CLOCK_PROCESS_CPUTIME_ID
203 .B CLOCK_THREAD_CPUTIME_ID
204 clocks are realized on many platforms using timers from the CPUs
205 (TSC on i386, AR.ITC on Itanium).
206 These registers may differ between CPUs and as a consequence
207 these clocks may return
209 if a process is migrated to another CPU.
211 If the CPUs in an SMP system have different clock sources then
212 there is no way to maintain a correlation between the timer registers since
213 each CPU will run at a slightly different frequency.
214 If that is the case then
215 .I clock_getcpuclockid(0)
218 to signify this condition.
219 The two clocks will then only be useful if it
220 can be ensured that a process stays on a certain CPU.
222 The processors in an SMP system do not start all at exactly the same
223 time and therefore the timer registers are typically running at an offset.
224 Some architectures include code that attempts to limit these offsets on bootup.
225 However, the code cannot guarantee to accurately tune the offsets.
226 Glibc contains no provisions to deal with these offsets (unlike the Linux
228 Typically these offsets are small and therefore the effects may be
229 negligible in most cases.
231 According to POSIX.1-2001, a process with "appropriate privileges" may set the
232 .B CLOCK_PROCESS_CPUTIME_ID
234 .B CLOCK_THREAD_CPUTIME_ID
236 .BR clock_settime ().
237 On Linux, these clocks are not settable
238 (i.e., no process has "appropriate privileges").
239 .\" See http://bugzilla.kernel.org/show_bug.cgi?id=11972
242 .BR gettimeofday (2),
243 .BR settimeofday (2),
246 .BR clock_getcpuclockid (3),
249 .BR pthread_getcpuclockid (3),