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