OSDN Git Service

(split) Import translated manuals from JM CVS Repository.
[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 .TH CLOCK_GETRES 2 2010-02-03 "" "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
38 .BI "int clock_gettime(clockid_t " clk_id ", struct timespec *" tp );
39
40 .BI "int clock_settime(clockid_t " clk_id ", const struct timespec *" tp );
41 .sp
42 Link with \fI\-lrt\fP.
43 .sp
44 .in -4n
45 Feature 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 ():
53 _POSIX_C_SOURCE\ >=\ 199309L
54 .ad b
55 .SH DESCRIPTION
56 The function
57 .BR clock_getres ()
58 finds the resolution (precision) of the specified clock
59 .IR clk_id ,
60 and, if
61 .I res
62 is non-NULL, stores it in the \fIstruct timespec\fP pointed to by
63 .IR res .
64 The resolution of clocks depends on the implementation and cannot be
65 configured by a particular process.
66 If the time value pointed to by the argument
67 .I tp
68 of
69 .BR clock_settime ()
70 is not a multiple of
71 .IR res ,
72 then it is truncated to a multiple of
73 .IR res .
74 .PP
75 The functions
76 .BR clock_gettime ()
77 and
78 .BR clock_settime ()
79 retrieve and set the time of the specified clock
80 .IR clk_id .
81 .PP
82 The
83 .I res
84 and
85 .I tp
86 arguments are
87 .I timespec
88 structures, as specified  in
89 .IR <time.h> :
90 .sp
91 .in +4n
92 .nf
93 struct timespec {
94     time_t   tv_sec;        /* seconds */
95     long     tv_nsec;       /* nanoseconds */
96 };
97 .fi
98 .in
99 .PP
100 The
101 .I clk_id
102 argument is the identifier of the particular clock on which to act.
103 A clock may be system-wide and hence visible for all processes, or
104 per-process if it measures time only within a single process.
105 .LP
106 All implementations support the system-wide real-time clock,
107 which is identified by
108 .BR CLOCK_REALTIME .
109 Its time represents seconds and nanoseconds since the Epoch.
110 When its time is changed, timers for a relative interval are
111 unaffected, but timers for an absolute point in time are affected.
112 .LP
113 More clocks may be implemented.
114 The interpretation of the
115 corresponding time values and the effect on timers is unspecified.
116 .LP
117 Sufficiently recent versions of glibc and the Linux kernel
118 support the following clocks:
119 .TP
120 .B CLOCK_REALTIME
121 System-wide real-time clock.
122 Setting this clock requires appropriate privileges.
123 .TP
124 .B CLOCK_MONOTONIC
125 Clock that cannot be set and represents monotonic time since
126 some unspecified starting point.
127 .TP
128 .BR CLOCK_MONOTONIC_RAW " (since Linux 2.6.28; Linux-specific)"
129 .\" Added in commit 2d42244ae71d6c7b0884b5664cf2eda30fb2ae68, John Stultz
130 Similar to
131 .BR CLOCK_MONOTONIC ,
132 but provides access to a raw hardware-based time
133 that is not subject to NTP adjustments.
134 .TP
135 .B CLOCK_PROCESS_CPUTIME_ID
136 High-resolution per-process timer from the CPU.
137 .TP
138 .B CLOCK_THREAD_CPUTIME_ID
139 Thread-specific CPU-time clock.
140 .SH "RETURN VALUE"
141 .BR clock_gettime (),
142 .BR clock_settime ()
143 and
144 .BR clock_getres ()
145 return 0 for success, or \-1 for failure (in which case
146 .I errno
147 is set appropriately).
148 .SH ERRORS
149 .TP
150 .B EFAULT
151 .I tp
152 points outside the accessible address space.
153 .TP
154 .B EINVAL
155 The
156 .I clk_id
157 specified is not supported on this system.
158 .\" Linux also gives this error on attempts to set CLOCK_PROCESS_CPUTIME_ID
159 .\" and CLOCK_THREAD_CPUTIME_ID, when probably the proper error should be
160 .\" EPERM.
161 .TP
162 .B EPERM
163 .BR clock_settime ()
164 does not have permission to set the clock indicated.
165 .SH "CONFORMING TO"
166 SUSv2, POSIX.1-2001.
167 .SH AVAILABILITY
168 On POSIX systems on which these functions are available, the symbol
169 .B _POSIX_TIMERS
170 is defined in \fI<unistd.h>\fP to a value greater than 0.
171 The symbols
172 .BR _POSIX_MONOTONIC_CLOCK ,
173 .BR _POSIX_CPUTIME ,
174 .B _POSIX_THREAD_CPUTIME
175 indicate that
176 .BR CLOCK_MONOTONIC ,
177 .BR CLOCK_PROCESS_CPUTIME_ID ,
178 .B CLOCK_THREAD_CPUTIME_ID
179 are available.
180 (See also
181 .BR sysconf (3).)
182 .SH NOTES
183 .SS Note for SMP systems
184 The
185 .B CLOCK_PROCESS_CPUTIME_ID
186 and
187 .B CLOCK_THREAD_CPUTIME_ID
188 clocks are realized on many platforms using timers from the CPUs
189 (TSC on i386, AR.ITC on Itanium).
190 These registers may differ between CPUs and as a consequence
191 these clocks may return
192 .B bogus results
193 if a process is migrated to another CPU.
194 .PP
195 If the CPUs in an SMP system have different clock sources then
196 there is no way to maintain a correlation between the timer registers since
197 each CPU will run at a slightly different frequency.
198 If that is the case then
199 .I clock_getcpuclockid(0)
200 will return
201 .B ENOENT
202 to signify this condition.
203 The two clocks will then only be useful if it
204 can be ensured that a process stays on a certain CPU.
205 .PP
206 The processors in an SMP system do not start all at exactly the same
207 time and therefore the timer registers are typically running at an offset.
208 Some architectures include code that attempts to limit these offsets on bootup.
209 However, the code cannot guarantee to accurately tune the offsets.
210 Glibc contains no provisions to deal with these offsets (unlike the Linux
211 Kernel).
212 Typically these offsets are small and therefore the effects may be
213 negligible in most cases.
214 .SH BUGS
215 According to POSIX.1-2001, a process with "appropriate privileges" may set the
216 .B CLOCK_PROCESS_CPUTIME_ID
217 and
218 .B CLOCK_THREAD_CPUTIME_ID
219 clocks using
220 .BR clock_settime ().
221 On Linux, these clocks are not settable
222 (i.e., no process has "appropriate privileges").
223 .\" See http://bugzilla.kernel.org/show_bug.cgi?id=11972
224 .SH "SEE ALSO"
225 .BR date (1),
226 .BR adjtimex (2),
227 .BR gettimeofday (2),
228 .BR settimeofday (2),
229 .BR time (2),
230 .BR clock_getcpuclockid (3),
231 .BR ctime (3),
232 .BR ftime (3),
233 .BR pthread_getcpuclockid (3),
234 .BR sysconf (3),
235 .BR time (7)