OSDN Git Service

(split) LDP: Update original to LDP v3.40.
[linuxjm/LDP_man-pages.git] / original / man2 / clock_getres.2
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.
14 .\"
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.
22 .\"
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 .\" FIXME: Linux 2.6.39 adds CLOCK_BOOTTIME
31 .\"
32 .TH CLOCK_GETRES 2 2012-04-25 "" "Linux Programmer's Manual"
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 );
39
40 .BI "int clock_gettime(clockid_t " clk_id ", struct timespec *" tp );
41
42 .BI "int clock_settime(clockid_t " clk_id ", const struct timespec *" tp );
43 .sp
44 Link with \fI\-lrt\fP.
45 .sp
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 ():
55 .RS
56 _POSIX_C_SOURCE\ >=\ 199309L
57 .RE
58 .ad b
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
66 is non-NULL, stores it in the \fIstruct timespec\fP pointed to by
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
91 .I timespec
92 structures, as specified in
93 .IR <time.h> :
94 .sp
95 .in +4n
96 .nf
97 struct timespec {
98     time_t   tv_sec;        /* seconds */
99     long     tv_nsec;       /* nanoseconds */
100 };
101 .fi
102 .in
103 .PP
104 The
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
110 All implementations support the system-wide real-time clock,
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
117 More clocks may be implemented.
118 The interpretation of the
119 corresponding time values and the effect on timers is unspecified.
120 .LP
121 Sufficiently recent versions of glibc and the Linux kernel
122 support the following clocks:
123 .TP
124 .B CLOCK_REALTIME
125 System-wide real-time clock.
126 Setting this clock requires appropriate privileges.
127 .TP
128 .B CLOCK_MONOTONIC
129 Clock that cannot be set and represents monotonic time since
130 some unspecified starting point.
131 This clock is not affected by discontinuous jumps in the system time
132 (e.g., if the system administrator manually changes the clock),
133 but is affected by the incremental adjustments performed by
134 .BR adjtime (2)
135 and NTP.
136 .TP
137 .BR CLOCK_MONOTONIC_RAW " (since Linux 2.6.28; Linux-specific)"
138 .\" Added in commit 2d42244ae71d6c7b0884b5664cf2eda30fb2ae68, John Stultz
139 Similar to
140 .BR CLOCK_MONOTONIC ,
141 but provides access to a raw hardware-based time
142 that is not subject to NTP adjustments or
143 the incremental adjustments performed by
144 .BR adjtime (2).
145 .TP
146 .B CLOCK_PROCESS_CPUTIME_ID
147 High-resolution per-process timer from the CPU.
148 .TP
149 .B CLOCK_THREAD_CPUTIME_ID
150 Thread-specific CPU-time clock.
151 .SH "RETURN VALUE"
152 .BR clock_gettime (),
153 .BR clock_settime ()
154 and
155 .BR clock_getres ()
156 return 0 for success, or \-1 for failure (in which case
157 .I errno
158 is set appropriately).
159 .SH ERRORS
160 .TP
161 .B EFAULT
162 .I tp
163 points outside the accessible address space.
164 .TP
165 .B EINVAL
166 The
167 .I clk_id
168 specified is not supported on this system.
169 .\" Linux also gives this error on attempts to set CLOCK_PROCESS_CPUTIME_ID
170 .\" and CLOCK_THREAD_CPUTIME_ID, when probably the proper error should be
171 .\" EPERM.
172 .TP
173 .B EPERM
174 .BR clock_settime ()
175 does not have permission to set the clock indicated.
176 .SH "CONFORMING TO"
177 SUSv2, POSIX.1-2001.
178 .SH AVAILABILITY
179 On POSIX systems on which these functions are available, the symbol
180 .B _POSIX_TIMERS
181 is defined in \fI<unistd.h>\fP to a value greater than 0.
182 The symbols
183 .BR _POSIX_MONOTONIC_CLOCK ,
184 .BR _POSIX_CPUTIME ,
185 .B _POSIX_THREAD_CPUTIME
186 indicate that
187 .BR CLOCK_MONOTONIC ,
188 .BR CLOCK_PROCESS_CPUTIME_ID ,
189 .B CLOCK_THREAD_CPUTIME_ID
190 are available.
191 (See also
192 .BR sysconf (3).)
193 .SH NOTES
194 .SS Note for SMP systems
195 The
196 .B CLOCK_PROCESS_CPUTIME_ID
197 and
198 .B CLOCK_THREAD_CPUTIME_ID
199 clocks are realized on many platforms using timers from the CPUs
200 (TSC on i386, AR.ITC on Itanium).
201 These registers may differ between CPUs and as a consequence
202 these clocks may return
203 .B bogus results
204 if a process is migrated to another CPU.
205 .PP
206 If the CPUs in an SMP system have different clock sources then
207 there is no way to maintain a correlation between the timer registers since
208 each CPU will run at a slightly different frequency.
209 If that is the case then
210 .I clock_getcpuclockid(0)
211 will return
212 .B ENOENT
213 to signify this condition.
214 The two clocks will then only be useful if it
215 can be ensured that a process stays on a certain CPU.
216 .PP
217 The processors in an SMP system do not start all at exactly the same
218 time and therefore the timer registers are typically running at an offset.
219 Some architectures include code that attempts to limit these offsets on bootup.
220 However, the code cannot guarantee to accurately tune the offsets.
221 Glibc contains no provisions to deal with these offsets (unlike the Linux
222 Kernel).
223 Typically these offsets are small and therefore the effects may be
224 negligible in most cases.
225 .SH BUGS
226 According to POSIX.1-2001, a process with "appropriate privileges" may set the
227 .B CLOCK_PROCESS_CPUTIME_ID
228 and
229 .B CLOCK_THREAD_CPUTIME_ID
230 clocks using
231 .BR clock_settime ().
232 On Linux, these clocks are not settable
233 (i.e., no process has "appropriate privileges").
234 .\" See http://bugzilla.kernel.org/show_bug.cgi?id=11972
235 .SH "SEE ALSO"
236 .BR date (1),
237 .BR adjtime (2),
238 .BR gettimeofday (2),
239 .BR settimeofday (2),
240 .BR time (2),
241 .BR clock_getcpuclockid (3),
242 .BR ctime (3),
243 .BR ftime (3),
244 .BR pthread_getcpuclockid (3),
245 .BR sysconf (3),
246  time (7)