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.\" $DragonFly: src/share/man/man9/time.9,v 1.2 2003/06/17 04:37:01 dillon Exp $ 34.\" 35.Dd March 22, 1997 36.Dt TIME 9 37.Os 38.Sh NAME 39.Nm boottime , 40.Nm mono_time , 41.Nm runtime , 42.Nm time 43.Nd system time variables 44.Sh SYNOPSIS 45.Bl -item -compact 46.It 47.Va extern struct timeval boottime ; 48.It 49.Va extern volatile struct timeval mono_time ; 50.It 51.Va extern struct timeval runtime ; 52.It 53.Va extern struct timeval time ; 54.El 55.Sh DESCRIPTION 56The 57.Va time 58variable is the system's 59.Dq wall time 60clock. 61It is set at boot by 62.Xr inittodr 9 , 63and is updated by the 64.Xr settimeofday 2 65system call and by periodic clock interrupts. 66.Pp 67The 68.Va boottime 69variable holds the system boot time. It 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. It is set 92from 93.Va time 94at boot, and is updated by the periodic timer interrupt. (It is 95not updated by 96.Xr settimeofday 2 . ) 97.Pp 98All of these variables contain times 99expressed in seconds and microseconds since midnight (0 hour), 100January 1, 1970. 101.Pp 102Clock interrupts should be blocked 103when reading or writing 104.Va time 105or 106.Va mono_time , 107because those variables are updated by 108.Fn hardclock . 109The 110.Xr gettime 9 111function can be used to read the 112.Va time 113variable in an atomic manner. There is no equivalent 114function for accessing 115.Va mono_time . 116The 117.Va boottime 118and 119.Va runtime 120variables may be read and written without special precautions. 121.Pp 122It should be noted that due to the differences in how the time values 123returned by 124.Xr gettime 9 125and 126.Xr microtime 9 127are updated, comparing the results of the two routines 128may result in a time value that appears to go backwards. 129This can be avoided by consistently using one function or the other 130for use in any given context. 131.Sh SEE ALSO 132.Xr settimeofday 2 , 133.Xr gettime 9 , 134.\" .Xr hardclock 9 , 135.\" .Xr hz 9 , 136.Xr inittodr 9 , 137.Xr microtime 9 138.Sh BUGS 139The notion of having a single 140.Va runtime 141variable obviously would not be appropriate in multiprocessor systems. 142