xref: /freebsd/share/man/man9/time.9 (revision 4cf49a43559ed9fdad601bdcccd2c55963008675)
1.\"	$NetBSD: time.9,v 1.1 1995/11/25 21:24:53 perry Exp $
2.\"
3.\" Copyright (c) 1994 Christopher G. Demetriou
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"      This product includes software developed by Christopher G. Demetriou
17.\"      for the NetBSD Project.
18.\" 3. The name of the author may not be used to endorse or promote products
19.\"    derived from this software without specific prior written permission
20.\"
21.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31.\"
32.\" $FreeBSD$
33.\"
34.Dd March 22, 1997
35.Dt TIME 9
36.Os FreeBSD
37.Sh NAME
38.Nm boottime ,
39.Nm mono_time ,
40.Nm runtime ,
41.Nm time
42.Nd system time variables
43.Sh SYNOPSIS
44.Va extern struct timeval boottime;
45.br
46.Va extern volatile struct timeval mono_time;
47.br
48.Va extern struct timeval runtime;
49.br
50.Va extern struct timeval time;
51.Sh DESCRIPTION
52The
53.Va time
54variable is the system's
55.Dq wall time
56clock.
57It is set at boot by
58.Xr inittodr 9 ,
59and is updated by the
60.Xr settimeofday 2
61system call and by periodic clock interrupts.
62.Pp
63The
64.Va boottime
65variable holds the system boot time.  It is set from
66.Va time
67at system boot, and is updated when the system time is adjusted
68with
69.Xr settimeofday 2 .
70.Pp
71The
72.Va runtime
73variable holds the time that the system switched to the
74current process.
75It is set after each context switch,
76and is updated when the system time is adjusted with
77.Xr settimeofday 2 .
78Because
79.Va runtime
80is used for system accounting, it is set with the high-resolution
81.Xr microtime 9
82function, rather than being copied from
83.Va time .
84.Pp
85The
86.Va mono_time
87variable is a monotonically increasing system clock.  It is set
88from
89.Va time
90at boot, and is updated by the periodic timer interrupt.  (It is
91not updated by
92.Xr settimeofday 2 .)
93.Pp
94All of these variables contain times
95expressed in seconds and microseconds since midnight (0 hour),
96January 1, 1970.
97.Pp
98Clock interrupts should be blocked
99when reading or writing
100.Va time
101or
102.Va mono_time ,
103because those variables are updated by
104.Fn hardclock .
105The
106.Xr gettime 9
107function can be used to read the
108.Va time
109variable in an atomic manner.  There is no equivalent
110function for accessing
111.Va mono_time.
112The
113.Va boottime
114and
115.Va runtime
116variables may be read and written without special precautions.
117.Pp
118It should be noted that due to the differences in how the time values
119returned by
120.Xr gettime 9
121and
122.Xr microtime 9
123are updated, comparing the results of the two routines
124may result in a time value that appears to go backwards.
125This can be avoided by consistently using one function or the other
126for use in any given context.
127.Sh SEE ALSO
128.Xr settimeofday 2 ,
129.Xr gettime 9 ,
130.\" .Xr hz 9 ,
131.\" .Xr hardclock 9 ,
132.Xr inittodr 9 ,
133.Xr microtime 9
134.Sh BUGS
135The notion of having a single
136.Va runtime
137variable obviously would not be appropriate in multiprocessor systems.
138