]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/clock_getres.3
Italics for header file references
[thirdparty/man-pages.git] / man3 / clock_getres.3
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 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 \fIstruct timespec\fP 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
75 .IR <time.h> :
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
86 The
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
99 More clocks may be implemented.
100 The interpretation of the
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"
120 .BR clock_gettime (),
121 .BR clock_settime ()
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
134 The
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.
141 .SH "CONFORMING TO"
142 SUSv2, POSIX.1-2001.
143 .SH AVAILABILITY
144 On POSIX systems on which these functions are available, the symbol
145 .B _POSIX_TIMERS
146 is defined in \fI<unistd.h>\fP to a value greater than 0.
147 The symbols
148 .BR _POSIX_MONOTONIC_CLOCK ,
149 .BR _POSIX_CPUTIME ,
150 .B _POSIX_THREAD_CPUTIME
151 indicate that
152 .BR CLOCK_MONOTONIC ,
153 .BR CLOCK_PROCESS_CPUTIME_ID ,
154 .B CLOCK_THREAD_CPUTIME_ID
155 are available.
156 (See also
157 .BR sysconf (3).)
158 .SH NOTES
159 Most systems require the program be linked with the librt
160 library to use these functions.
161 .SS Note for SMP systems
162 The
163 .B CLOCK_PROCESS_CPUTIME_ID
164 and
165 .B CLOCK_THREAD_CPUTIME_ID
166 clocks are realized on many platforms using timers from the CPUs
167 (TSC on i386, AR.ITC on Itanium).
168 These registers may differ between CPUs and as a consequence
169 these clocks may return
170 .B bogus results
171 if a process is migrated to another CPU.
172 .PP
173 If the CPUs in an SMP system have different clock sources then
174 there is no way to maintain a correlation between the timer registers since
175 each CPU will run at a slightly different frequency.
176 If that is the case then
177 .I clock_getcpuclockid(0)
178 will return
179 .B ENOENT
180 to signify this condition.
181 The two clocks will then only be useful if it
182 can be ensured that a process stays on a certain CPU.
183 .PP
184 The processors in an SMP system do not start all at exactly the same
185 time and therefore the timer registers are typically running at an offset.
186 Some architectures include code that attempts to limit these offsets on bootup.
187 However, the code cannot guarantee to accurately tune the offsets.
188 Glibc contains no provisions to deal with these offsets (unlike the Linux
189 Kernel).
190 Typically these offsets are small and therefore the effects may be
191 negligible in most cases.
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)