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