xref: /netbsd-src/share/man/man9/time_second.9 (revision 466a16a118933bd295a8a104f095714fadf9cf68)
1.\" $NetBSD: time_second.9,v 1.3 2008/11/28 22:31:01 wiz 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 for the
17.\"          NetBSD Project.  See http://www.NetBSD.org/ for
18.\"          information about NetBSD.
19.\" 4. The name of the author may not be used to endorse or promote products
20.\"    derived from this software without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32.\"
33.\" <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
34.\"
35.Dd November 28, 2008
36.Dt TIME_SECOND 9
37.Os
38.Sh NAME
39.Nm time_second ,
40.Nm time_uptime ,
41.Nm boottime
42.Nd system time variables
43.Sh SYNOPSIS
44.In sys/time.h
45.Pp
46.Va extern time_t time_second;
47.br
48.Va extern time_t time_uptime;
49.Pp
50.In sys/kernel.h
51.Pp
52.Va extern struct timeval boottime;
53.Sh DESCRIPTION
54The
55.Va time_second
56variable is the system's
57.Dq wall time
58clock.
59It is set at boot by
60.Xr inittodr 9 ,
61and is updated periodically via
62.Xr timecounter 9
63framework, and also updated by the
64.Xr settimeofday 2
65system call.
66.Pp
67The
68.Va time_uptime
69variable is a monotonically increasing system clock.
70It is set at boot, and is updated periodically.
71(It is not updated by
72.Xr settimeofday 2 . )
73.Pp
74The
75.Va boottime
76variable holds the system boot time.
77It is set at system boot, and is updated when the system time is adjusted
78with
79.Xr settimeofday 2 .
80.Pp
81All of these variables contain times
82expressed in seconds and microseconds since midnight (0 hour),
83January 1, 1970.
84.Pp
85The
86.Xr bintime 9 ,
87.Xr getbintime 9 ,
88.Xr microtime 9 ,
89.Xr getmicrotime 9 ,
90.Xr nanotime 9 ,
91and
92.Xr getnanotime 9
93functions can be used to get the current time more accurately and in an
94atomic manner.
95.Pp
96Similarly, the
97.Xr binuptime 9 ,
98.Xr getbinuptime 9 ,
99.Xr microuptime 9 ,
100.Xr getmicrouptime 9 ,
101.Xr nanouptime 9 ,
102and
103.Xr getnanouptime 9
104functions can be used to get the time elapsed since boot more accurately
105and in an atomic manner.
106.Pp
107.Va boottime
108may be read and written without special precautions.
109.Sh SEE ALSO
110.Xr clock_settime 2 ,
111.Xr ntp_adjtime 2 ,
112.Xr settimeofday 2 ,
113.Xr bintime 9 ,
114.Xr binuptime 9 ,
115.Xr getbintime 9 ,
116.Xr getbinuptime 9 ,
117.Xr getmicrotime 9 ,
118.Xr getmicrouptime 9 ,
119.Xr getnanotime 9 ,
120.Xr getnanouptime 9 ,
121.Xr hardclock 9 ,
122.Xr hz 9 ,
123.Xr inittodr 9 ,
124.Xr microtime 9 ,
125.Xr microuptime 9 ,
126.Xr nanotime 9 ,
127.Xr nanouptime 9 ,
128.Xr timecounter 9
129