xref: /freebsd/share/man/man7/clocks.7 (revision 1e413cf93298b5b97441a21d9a50fdcd0ee9945e)
1.\"
2.\" Copyright (c) 1996 Joerg Wunsch
3.\"
4.\" All rights reserved.
5.\"
6.\" This program is free software.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\"
17.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
18.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
21.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27.\"
28.\" $FreeBSD$
29.\" "
30.Dd February 24, 2005
31.Os
32.Dt CLOCKS 7
33.Sh NAME
34.Nm clocks
35.Nd various system timers
36.Sh SYNOPSIS
37.In time.h
38.Sh DESCRIPTION
39.Dv HZ
40is not part of the application interface in
41.Bx .
42.Pp
43There are many different real and virtual (timekeeping) clocks with
44different frequencies:
45.Bl -bullet
46.It
47The scheduling clock.
48This is a real clock with frequency that happens to be 100.
49It is not available to applications.
50.It
51The statistics clock.
52This is a real clock with frequency that happens to be 128.
53It is not directly available to applications.
54.It
55The clock reported by
56.Xr clock 3 .
57This is a virtual clock with a frequency that happens to be 128.
58Its actual frequency is given by the macro
59.Dv CLOCKS_PER_SEC .
60Note that
61.Dv CLOCKS_PER_SEC
62may be floating point.
63Do not use
64.Xr clock 3
65in new programs under
66.Fx .
67It is feeble compared with
68.Xr getrusage 2 .
69It is provided for
70.Tn ANSI
71conformance.
72It is implemented by calling
73.Xr getrusage 2
74and throwing away information and resolution.
75.It
76The clock reported by
77.Xr times 3 .
78This is a virtual clock with a frequency that happens to be 128.
79Its actual frequency is given by the macro
80.Dv CLK_TCK
81(deprecated; do not use) and by
82.Fn sysconf SC_CLK_TCK
83and by
84.Xr sysctl 3 .
85Note that its frequency may be different from
86.Dv CLOCKS_PER_SEC .
87Do not use
88.Xr times 3
89in new programs under
90.Fx .
91It is feeble compared with
92.Xr gettimeofday 2
93together with
94.Xr getrusage 2 .
95It is provided for
96.Tn POSIX
97conformance.
98It is implemented by calling
99.Xr gettimeofday 2
100and
101.Xr getrusage 2
102and throwing away information and resolution.
103.It
104The profiling clock.
105This is a real clock with frequency 1024.
106It is used mainly by
107.Xr moncontrol 3 ,
108.Xr kgmon 8
109and
110.Xr gprof 1 .
111Applications should determine its actual frequency using
112.Xr sysctl 3
113or by reading it from the header in the profiling data file.
114.It
115The mc146818a clock.
116This is a real clock with a nominal frequency of 32768.
117It is divided down to give the statistic clock and the profiling clock.
118It is not available to applications.
119.It
120The microseconds clock.
121This is a virtual clock with frequency 1000000.
122It is used for most timekeeping in
123.Bx
124and is exported to applications in
125.Xr getrusage 2 ,
126.Xr gettimeofday 2 ,
127.Xr select 2 ,
128.Xr getitimer 2 ,
129etc.
130This is the clock that should normally be used by
131.Bx
132applications.
133.It
134The i8254 clock.
135This is a real clock/timer with a nominal frequency of 1193182.
136It has three independent time counters to be used.
137It is divided down to give the scheduling clock.
138It is not available to applications.
139.It
140The TSC clock (64-bit register) on fifth-generation or later x86 systems.
141This is a real clock with a frequency that is equivalent to the number of
142cycles per second of the CPU(s).
143Its frequency can be found using the
144.Va machdep.tsc_freq
145sysctl, if it is available.
146It is used to interpolate between values of the scheduling clock.
147It can be accessed using the
148.Dv PMIOTSTAMP
149request of
150.Xr perfmon 4 .
151.It
152The ACPI clock.
153This is a real clock/timer with a nominal frequency of 3579545.
154It is accessed via a 24 or 32 bit register.
155Unlike the TSC clock, it maintains a constant tick rate even when the CPU
156sleeps or its clock rate changes.
157It is not available to applications.
158.El
159.Pp
160Summary: if
161.Dv HZ
162is not 1000000 then the application is probably using the wrong clock.
163.Sh SEE ALSO
164.Xr gprof 1 ,
165.Xr clock_gettime 2 ,
166.Xr getitimer 2 ,
167.Xr getrusage 2 ,
168.Xr gettimeofday 2 ,
169.Xr select 2 ,
170.Xr clock 3 ,
171.Xr moncontrol 3 ,
172.Xr times 3
173.Sh AUTHORS
174.An -nosplit
175This manual page was written by
176.An J\(:org Wunsch
177after a description posted by
178.An Bruce Evans .
179