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