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 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 55The 56.Va time 57variable is the system's 58.Dq wall time 59clock. 60It is set at boot by 61.Xr inittodr 9 , 62and is updated by the 63.Xr settimeofday 2 64system call and by periodic clock interrupts. 65.Pp 66The 67.Va boottime 68variable holds the system boot time. 69It is set from 70.Va time 71at system boot, and is updated when the system time is adjusted 72with 73.Xr settimeofday 2 . 74.Pp 75The 76.Va runtime 77variable holds the time that the system switched to the 78current process. 79It is set after each context switch, 80and is updated when the system time is adjusted with 81.Xr settimeofday 2 . 82Because 83.Va runtime 84is used for system accounting, it is set with the high-resolution 85.Xr microtime 9 86function, rather than being copied from 87.Va time . 88.Pp 89The 90.Va mono_time 91variable is a monotonically increasing system clock. 92It is set 93from 94.Va time 95at boot, and is updated by the periodic timer interrupt. 96.Po 97It is 98not updated by 99.Xr settimeofday 2 . 100.Pc 101.Pp 102All of these variables contain times 103expressed in seconds and microseconds since midnight (0 hour), 104January 1, 1970. 105.Pp 106Clock interrupts should be blocked 107when reading or writing 108.Va time 109or 110.Va mono_time , 111because those variables are updated by 112.Fn hardclock . 113The 114.Xr gettime 9 115function can be used to read the 116.Va time 117variable in an atomic manner. 118There is no equivalent function for accessing 119.Va mono_time . 120The 121.Va boottime 122and 123.Va runtime 124variables may be read and written without special precautions. 125.Pp 126It should be noted that due to the differences in how the time values 127returned by 128.Xr gettime 9 129and 130.Xr microtime 9 131are updated, comparing the results of the two routines 132may result in a time value that appears to go backwards. 133This can be avoided by consistently using one function or the other 134for use in any given context. 135.Sh SEE ALSO 136.Xr settimeofday 2 , 137.Xr gettime 9 , 138.\" .Xr hardclock 9 , 139.\" .Xr hz 9 , 140.Xr inittodr 9 , 141.Xr microtime 9 142.Sh BUGS 143The notion of having a single 144.Va runtime 145variable obviously would not be appropriate in multiprocessor systems. 146