1.\" $NetBSD: time_second.9,v 1.11 2024/09/07 19:13:29 rillig 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 https://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 July 16, 2023 36.Dt TIME_SECOND 9 37.Os 38.Sh NAME 39.Nm time_second , 40.Nm time_uptime , 41.Nm time_uptime32 42.Nd system time variables 43.Sh SYNOPSIS 44.In sys/time.h 45.Vt extern const time_t time_second; 46.Vt extern const time_t time_uptime; 47.Vt extern const uint32_t time_uptime32; 48.Sh DESCRIPTION 49The 50.Va time_second 51variable is the system's 52.Dq wall clock , 53giving the number of seconds since midnight (0 hour), 54January 1, 1970, (proleptic) UTC, 55minus the number of leap seconds. 56It is set at boot by 57.Xr inittodr 9 , 58and is updated periodically via 59.Xr timecounter 9 60framework, and also updated by the 61.Xr settimeofday 2 62system call. 63.Pp 64The 65.Va time_uptime 66variable is a monotonically increasing system clock. 67It is set at boot, and is updated periodically. 68(It is not updated by 69.Xr settimeofday 2 . ) 70.Pp 71The 72.Va time_uptime32 73variable is the low-order 32 bits of 74.Va time_uptime , 75which is cheaper to read on 32-bit platforms. 76.Pp 77You must only read the variables 78.Va time_second , 79.Va time_uptime , 80and 81.Va time_uptime32 ; 82you may not write to them or take their addresses. 83They may be implemented as macros. 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.Sh SEE ALSO 107.Xr clock_settime 2 , 108.Xr ntp_adjtime 2 , 109.Xr timespec 3 , 110.Xr hardclock 9 , 111.Xr hz 9 112