]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Hey Emacs! This file is -*- nroff -*- source. |
2 | .\" | |
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 | |
5 | .\" | |
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. | |
9 | .\" | |
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. | |
c13182ef | 14 | .\" |
fea681da MK |
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 | |
21 | .\" professionally. | |
c13182ef | 22 | .\" |
fea681da MK |
23 | .\" Formatted or processed versions of this manual, if unaccompanied by |
24 | .\" the source, must acknowledge the copyright and authors of this work. | |
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 | .\" | |
0245dc09 MK |
30 | .\" FIXME: Linux 2.6.39 adds CLOCK_BOOTTIME |
31 | .\" | |
55f749ae | 32 | .TH CLOCK_GETRES 2 2013-02-25 "" "Linux Programmer's Manual" |
fea681da MK |
33 | .SH NAME |
34 | clock_getres, clock_gettime, clock_settime \- clock and time functions | |
35 | .SH SYNOPSIS | |
36 | .B #include <time.h> | |
37 | .sp | |
38 | .BI "int clock_getres(clockid_t " clk_id ", struct timespec *" res ); | |
5895e7eb | 39 | |
fea681da | 40 | .BI "int clock_gettime(clockid_t " clk_id ", struct timespec *" tp ); |
5895e7eb | 41 | |
fea681da | 42 | .BI "int clock_settime(clockid_t " clk_id ", const struct timespec *" tp ); |
cc4615cc | 43 | .sp |
02959991 | 44 | Link with \fI\-lrt\fP (only for glibc versions before 2.17). |
b905d225 | 45 | .sp |
cc4615cc MK |
46 | .in -4n |
47 | Feature Test Macro Requirements for glibc (see | |
48 | .BR feature_test_macros (7)): | |
49 | .in | |
50 | .sp | |
51 | .ad l | |
52 | .BR clock_getres (), | |
53 | .BR clock_gettime (), | |
54 | .BR clock_settime (): | |
8260c01f | 55 | .RS |
cc4615cc | 56 | _POSIX_C_SOURCE\ >=\ 199309L |
8260c01f | 57 | .RE |
cc4615cc | 58 | .ad b |
fea681da MK |
59 | .SH DESCRIPTION |
60 | The function | |
61 | .BR clock_getres () | |
62 | finds the resolution (precision) of the specified clock | |
63 | .IR clk_id , | |
64 | and, if | |
65 | .I res | |
0c2ec4f1 | 66 | is non-NULL, stores it in the \fIstruct timespec\fP pointed to by |
fea681da MK |
67 | .IR res . |
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 | |
71 | .I tp | |
72 | of | |
73 | .BR clock_settime () | |
74 | is not a multiple of | |
75 | .IR res , | |
76 | then it is truncated to a multiple of | |
77 | .IR res . | |
78 | .PP | |
79 | The functions | |
80 | .BR clock_gettime () | |
81 | and | |
82 | .BR clock_settime () | |
83 | retrieve and set the time of the specified clock | |
84 | .IR clk_id . | |
85 | .PP | |
86 | The | |
87 | .I res | |
88 | and | |
89 | .I tp | |
90 | arguments are | |
f19a0f03 | 91 | .I timespec |
4e836144 | 92 | structures, as specified in |
c13182ef | 93 | .IR <time.h> : |
fea681da | 94 | .sp |
3ad4ddcd | 95 | .in +4n |
fea681da MK |
96 | .nf |
97 | struct timespec { | |
cc4615cc MK |
98 | time_t tv_sec; /* seconds */ |
99 | long tv_nsec; /* nanoseconds */ | |
fea681da MK |
100 | }; |
101 | .fi | |
3ad4ddcd | 102 | .in |
fea681da | 103 | .PP |
c13182ef | 104 | The |
fea681da MK |
105 | .I clk_id |
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. | |
109 | .LP | |
6f36deb4 | 110 | All implementations support the system-wide real-time clock, |
fea681da MK |
111 | which is identified by |
112 | .BR CLOCK_REALTIME . | |
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. | |
116 | .LP | |
c13182ef MK |
117 | More clocks may be implemented. |
118 | The interpretation of the | |
fea681da MK |
119 | corresponding time values and the effect on timers is unspecified. |
120 | .LP | |
5260fe08 | 121 | Sufficiently recent versions of glibc and the Linux kernel |
fea681da MK |
122 | support the following clocks: |
123 | .TP | |
124 | .B CLOCK_REALTIME | |
22594a3c | 125 | System-wide clock that measures real (i.e., wall-clock) time. |
fea681da | 126 | Setting this clock requires appropriate privileges. |
22594a3c MK |
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 | |
65a0c012 | 130 | .BR adjtime (3) |
22594a3c | 131 | and NTP. |
55f749ae CH |
132 | .BR CLOCK_REALTIME_COARSE " (since Linux 2.6.32; Linux-specific)" |
133 | .\" Added in commit da15cfdae03351c689736f8d142618592e3cebc3 | |
134 | Faster but less precise version of | |
135 | .BR CLOCK_REALTIME. | |
136 | Use when you need very fast, but not fine-grained timestamps. | |
137 | .TP | |
fea681da MK |
138 | .TP |
139 | .B CLOCK_MONOTONIC | |
140 | Clock that cannot be set and represents monotonic time since | |
141 | some unspecified starting point. | |
63f0f3d9 MK |
142 | This clock is not affected by discontinuous jumps in the system time |
143 | (e.g., if the system administrator manually changes the clock), | |
144 | but is affected by the incremental adjustments performed by | |
65a0c012 | 145 | .BR adjtime (3) |
63f0f3d9 | 146 | and NTP. |
55f749ae CH |
147 | .BR CLOCK_MONOTONIC_COARSE " (since Linux 2.6.32; Linux-specific)" |
148 | .\" Added in commit da15cfdae03351c689736f8d142618592e3cebc3 | |
149 | Faster but less precise version of | |
150 | .BR CLOCK_MONOTONIC. | |
151 | Use 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 | |
155 | Similar to | |
156 | .BR CLOCK_MONOTONIC , | |
157 | but provides access to a raw hardware-based time | |
63f0f3d9 MK |
158 | that is not subject to NTP adjustments or |
159 | the incremental adjustments performed by | |
65a0c012 | 160 | .BR adjtime (3). |
1ba3fba8 | 161 | .TP |
fea681da MK |
162 | .B CLOCK_PROCESS_CPUTIME_ID |
163 | High-resolution per-process timer from the CPU. | |
164 | .TP | |
165 | .B CLOCK_THREAD_CPUTIME_ID | |
166 | Thread-specific CPU-time clock. | |
47297adb | 167 | .SH RETURN VALUE |
e1d6264d MK |
168 | .BR clock_gettime (), |
169 | .BR clock_settime () | |
fea681da MK |
170 | and |
171 | .BR clock_getres () | |
172 | return 0 for success, or \-1 for failure (in which case | |
173 | .I errno | |
174 | is set appropriately). | |
175 | .SH ERRORS | |
176 | .TP | |
177 | .B EFAULT | |
178 | .I tp | |
179 | points outside the accessible address space. | |
180 | .TP | |
181 | .B EINVAL | |
c13182ef | 182 | The |
fea681da MK |
183 | .I clk_id |
184 | specified is not supported on this system. | |
a113440c MK |
185 | .\" Linux also gives this error on attempts to set CLOCK_PROCESS_CPUTIME_ID |
186 | .\" and CLOCK_THREAD_CPUTIME_ID, when probably the proper error should be | |
187 | .\" EPERM. | |
fea681da MK |
188 | .TP |
189 | .B EPERM | |
190 | .BR clock_settime () | |
191 | does not have permission to set the clock indicated. | |
47297adb | 192 | .SH CONFORMING TO |
2b2581ee MK |
193 | SUSv2, POSIX.1-2001. |
194 | .SH AVAILABILITY | |
195 | On POSIX systems on which these functions are available, the symbol | |
196 | .B _POSIX_TIMERS | |
c84371c6 | 197 | is defined in \fI<unistd.h>\fP to a value greater than 0. |
2b2581ee MK |
198 | The symbols |
199 | .BR _POSIX_MONOTONIC_CLOCK , | |
200 | .BR _POSIX_CPUTIME , | |
201 | .B _POSIX_THREAD_CPUTIME | |
202 | indicate that | |
203 | .BR CLOCK_MONOTONIC , | |
204 | .BR CLOCK_PROCESS_CPUTIME_ID , | |
205 | .B CLOCK_THREAD_CPUTIME_ID | |
206 | are available. | |
207 | (See also | |
208 | .BR sysconf (3).) | |
19c98696 | 209 | .SH NOTES |
19c98696 | 210 | .SS Note for SMP systems |
fea681da MK |
211 | The |
212 | .B CLOCK_PROCESS_CPUTIME_ID | |
213 | and | |
214 | .B CLOCK_THREAD_CPUTIME_ID | |
215 | clocks are realized on many platforms using timers from the CPUs | |
216 | (TSC on i386, AR.ITC on Itanium). | |
217 | These registers may differ between CPUs and as a consequence | |
218 | these clocks may return | |
219 | .B bogus results | |
220 | if a process is migrated to another CPU. | |
221 | .PP | |
222 | If the CPUs in an SMP system have different clock sources then | |
223 | there is no way to maintain a correlation between the timer registers since | |
c13182ef MK |
224 | each CPU will run at a slightly different frequency. |
225 | If that is the case then | |
fea681da MK |
226 | .I clock_getcpuclockid(0) |
227 | will return | |
228 | .B ENOENT | |
c13182ef MK |
229 | to signify this condition. |
230 | The two clocks will then only be useful if it | |
fea681da MK |
231 | can be ensured that a process stays on a certain CPU. |
232 | .PP | |
233 | The processors in an SMP system do not start all at exactly the same | |
234 | time and therefore the timer registers are typically running at an offset. | |
235 | Some architectures include code that attempts to limit these offsets on bootup. | |
236 | However, the code cannot guarantee to accurately tune the offsets. | |
237 | Glibc contains no provisions to deal with these offsets (unlike the Linux | |
c13182ef MK |
238 | Kernel). |
239 | Typically these offsets are small and therefore the effects may be | |
fea681da | 240 | negligible in most cases. |
3847be78 | 241 | .SH BUGS |
a113440c | 242 | According to POSIX.1-2001, a process with "appropriate privileges" may set the |
3847be78 MK |
243 | .B CLOCK_PROCESS_CPUTIME_ID |
244 | and | |
245 | .B CLOCK_THREAD_CPUTIME_ID | |
a113440c | 246 | clocks using |
3847be78 | 247 | .BR clock_settime (). |
a113440c MK |
248 | On Linux, these clocks are not settable |
249 | (i.e., no process has "appropriate privileges"). | |
250 | .\" See http://bugzilla.kernel.org/show_bug.cgi?id=11972 | |
47297adb | 251 | .SH SEE ALSO |
fea681da | 252 | .BR date (1), |
fea681da MK |
253 | .BR gettimeofday (2), |
254 | .BR settimeofday (2), | |
255 | .BR time (2), | |
65a0c012 | 256 | .BR adjtime (3), |
edf60acb | 257 | .BR clock_getcpuclockid (3), |
fea681da MK |
258 | .BR ctime (3), |
259 | .BR ftime (3), | |
24ad017d | 260 | .BR pthread_getcpuclockid (3), |
1d7c4d16 | 261 | .BR sysconf (3), |
b3682895 | 262 | .BR time (7) |