xref: /freebsd/share/man/man9/time.9 (revision 952d112864d8008aa87278a30a539d888a8493cd)
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.Dd March 22, 1997
33.Dt TIME 9
34.Os FreeBSD
35.Sh NAME
36.Nm boottime ,
37.Nm mono_time ,
38.Nm runtime ,
39.Nm time
40.Nd system time variables
41.Sh SYNOPSIS
42.Va extern struct timeval boottime;
43.br
44.Va extern volatile struct timeval mono_time;
45.br
46.Va extern struct timeval runtime;
47.br
48.Va extern struct timeval time;
49.Sh DESCRIPTION
50The
51.Va time
52variable is the system's
53.Dq wall time
54clock.
55It is set at boot by
56.Xr inittodr 9 ,
57and is updated by the
58.Xr settimeofday 2
59system call and by periodic clock interrupts.
60.Pp
61The
62.Va boottime
63variable holds the system boot time.  It is set from
64.Va time
65at system boot, and is updated when the system time is adjusted
66with
67.Xr settimeofday 2 .
68.Pp
69The
70.Va runtime
71variable holds the time that the system switched to the
72current process.
73It is set after each context switch,
74and is updated when the system time is adjusted with
75.Xr settimeofday 2 .
76Because
77.Va runtime
78is used for system accounting, it is set with the high-resolution
79.Xr microtime 9
80function, rather than being copied from
81.Va time .
82.Pp
83The
84.Va mono_time
85variable is a monotonically increasing system clock.  It is set
86from
87.Va time
88at boot, and is updated by the periodic timer interrupt.  (It is
89not updated by
90.Xr settimeofday 2 .)
91.Pp
92All of these variables contain times
93expressed in seconds and microseconds since midnight (0 hour),
94January 1, 1970.
95.Pp
96Clock interrupts should be blocked
97when reading or writing
98.Va time
99or
100.Va mono_time ,
101because those variables are updated by
102.Fn hardclock .
103The
104.Xr gettime 9
105function can be used to read the
106.Va time
107variable in an atomic manner.  There is no equivalent
108function for accessing
109.Va mono_time.
110The
111.Va boottime
112and
113.Va runtime
114variables may be read and written without special precautions.
115.Pp
116It should be noted that due to the differences in how the time values
117returned by
118.Xr gettime 9
119and
120.Xr microtime 9
121are updated, comparing the results of the two routines
122may result in a time value that appears to go backwards.
123This can be avoided by consistently using one function or the other
124for use in any given context.
125.Sh SEE ALSO
126.Xr settimeofday 2 ,
127.Xr gettime 9 ,
128.\" .Xr hz 9 ,
129.\" .Xr hardclock 9 ,
130.Xr inittodr 9 ,
131.Xr microtime 9
132.Sh BUGS
133The notion of having a single
134.Va runtime
135variable obviously would not be appropriate in multiprocessor systems.
136