]>
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 | .\" | |
30 | .TH CLOCK_GETRES 3 2003-08-24 "" "Linux Programmer's Manual" | |
31 | .SH NAME | |
32 | clock_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 ); | |
37 | .br | |
38 | .BI "int clock_gettime(clockid_t " clk_id ", struct timespec *" tp ); | |
39 | .br | |
40 | .BI "int clock_settime(clockid_t " clk_id ", const struct timespec *" tp ); | |
41 | .SH DESCRIPTION | |
42 | The function | |
43 | .BR clock_getres () | |
44 | finds the resolution (precision) of the specified clock | |
45 | .IR clk_id , | |
46 | and, if | |
47 | .I res | |
48 | is non-NULL, stores it in the struct timespec pointed to by | |
49 | .IR res . | |
50 | The resolution of clocks depends on the implementation and cannot be | |
51 | configured by a particular process. | |
52 | If the time value pointed to by the argument | |
53 | .I tp | |
54 | of | |
55 | .BR clock_settime () | |
56 | is not a multiple of | |
57 | .IR res , | |
58 | then it is truncated to a multiple of | |
59 | .IR res . | |
60 | .PP | |
61 | The functions | |
62 | .BR clock_gettime () | |
63 | and | |
64 | .BR clock_settime () | |
65 | retrieve and set the time of the specified clock | |
66 | .IR clk_id . | |
67 | .PP | |
68 | The | |
69 | .I res | |
70 | and | |
71 | .I tp | |
72 | arguments are | |
73 | .B timespec | |
74 | structs, as specified in | |
c13182ef | 75 | .IR <time.h> : |
fea681da MK |
76 | .sp |
77 | .nf | |
78 | struct timespec { | |
79 | .in +8 | |
80 | time_t tv_sec; /* seconds */ | |
81 | long tv_nsec; /* nanoseconds */ | |
82 | .in -8 | |
83 | }; | |
84 | .fi | |
85 | .PP | |
c13182ef | 86 | The |
fea681da MK |
87 | .I clk_id |
88 | argument is the identifier of the particular clock on which to act. | |
89 | A clock may be system-wide and hence visible for all processes, or | |
90 | per-process if it measures time only within a single process. | |
91 | .LP | |
92 | All implementations support the system-wide realtime clock, | |
93 | which is identified by | |
94 | .BR CLOCK_REALTIME . | |
95 | Its time represents seconds and nanoseconds since the Epoch. | |
96 | When its time is changed, timers for a relative interval are | |
97 | unaffected, but timers for an absolute point in time are affected. | |
98 | .LP | |
c13182ef MK |
99 | More clocks may be implemented. |
100 | The interpretation of the | |
fea681da MK |
101 | corresponding time values and the effect on timers is unspecified. |
102 | .LP | |
103 | Sufficiently recent versions of GNU libc and the Linux kernel | |
104 | support the following clocks: | |
105 | .TP | |
106 | .B CLOCK_REALTIME | |
107 | System-wide realtime clock. | |
108 | Setting this clock requires appropriate privileges. | |
109 | .TP | |
110 | .B CLOCK_MONOTONIC | |
111 | Clock that cannot be set and represents monotonic time since | |
112 | some unspecified starting point. | |
113 | .TP | |
114 | .B CLOCK_PROCESS_CPUTIME_ID | |
115 | High-resolution per-process timer from the CPU. | |
116 | .TP | |
117 | .B CLOCK_THREAD_CPUTIME_ID | |
118 | Thread-specific CPU-time clock. | |
119 | .SH "RETURN VALUE" | |
e1d6264d MK |
120 | .BR clock_gettime (), |
121 | .BR clock_settime () | |
fea681da MK |
122 | and |
123 | .BR clock_getres () | |
124 | return 0 for success, or \-1 for failure (in which case | |
125 | .I errno | |
126 | is set appropriately). | |
127 | .SH ERRORS | |
128 | .TP | |
129 | .B EFAULT | |
130 | .I tp | |
131 | points outside the accessible address space. | |
132 | .TP | |
133 | .B EINVAL | |
c13182ef | 134 | The |
fea681da MK |
135 | .I clk_id |
136 | specified is not supported on this system. | |
137 | .TP | |
138 | .B EPERM | |
139 | .BR clock_settime () | |
140 | does not have permission to set the clock indicated. | |
19c98696 | 141 | .SH NOTES |
fea681da MK |
142 | Most systems require the program be linked with the librt |
143 | library to use these functions. | |
19c98696 | 144 | .SS Note for SMP systems |
fea681da MK |
145 | The |
146 | .B CLOCK_PROCESS_CPUTIME_ID | |
147 | and | |
148 | .B CLOCK_THREAD_CPUTIME_ID | |
149 | clocks are realized on many platforms using timers from the CPUs | |
150 | (TSC on i386, AR.ITC on Itanium). | |
151 | These registers may differ between CPUs and as a consequence | |
152 | these clocks may return | |
153 | .B bogus results | |
154 | if a process is migrated to another CPU. | |
155 | .PP | |
156 | If the CPUs in an SMP system have different clock sources then | |
157 | there is no way to maintain a correlation between the timer registers since | |
c13182ef MK |
158 | each CPU will run at a slightly different frequency. |
159 | If that is the case then | |
fea681da MK |
160 | .I clock_getcpuclockid(0) |
161 | will return | |
162 | .B ENOENT | |
c13182ef MK |
163 | to signify this condition. |
164 | The two clocks will then only be useful if it | |
fea681da MK |
165 | can be ensured that a process stays on a certain CPU. |
166 | .PP | |
167 | The processors in an SMP system do not start all at exactly the same | |
168 | time and therefore the timer registers are typically running at an offset. | |
169 | Some architectures include code that attempts to limit these offsets on bootup. | |
170 | However, the code cannot guarantee to accurately tune the offsets. | |
171 | Glibc contains no provisions to deal with these offsets (unlike the Linux | |
c13182ef MK |
172 | Kernel). |
173 | Typically these offsets are small and therefore the effects may be | |
fea681da MK |
174 | negligible in most cases. |
175 | .SH AVAILABILITY | |
176 | On POSIX systems on which these functions are available, the symbol | |
177 | .B _POSIX_TIMERS | |
178 | is defined in <unistd.h> to a value greater than 0. | |
179 | The symbols | |
180 | .BR _POSIX_MONOTONIC_CLOCK , | |
181 | .BR _POSIX_CPUTIME , | |
182 | .B _POSIX_THREAD_CPUTIME | |
183 | indicate that | |
184 | .BR CLOCK_MONOTONIC , | |
185 | .BR CLOCK_PROCESS_CPUTIME_ID , | |
186 | .B CLOCK_THREAD_CPUTIME_ID | |
187 | are available. | |
188 | (See also | |
189 | .BR sysconf (3).) | |
190 | .SH "CONFORMING TO" | |
68e1685c | 191 | SUSv2, POSIX.1-2001. |
fea681da MK |
192 | .SH "SEE ALSO" |
193 | .BR date (1), | |
194 | .BR adjtimex (2), | |
195 | .BR gettimeofday (2), | |
196 | .BR settimeofday (2), | |
197 | .BR time (2), | |
198 | .BR ctime (3), | |
199 | .BR ftime (3), | |
200 | .BR sysconf (3) |