1.\" $OpenBSD: microtime.9,v 1.22 2020/06/26 18:48:31 cheloha Exp $ 2.\" $NetBSD: microtime.9,v 1.2 1999/03/16 00:40:47 garbled Exp $ 3.\" 4.\" Copyright (c) 1998 The NetBSD Foundation, Inc. 5.\" All rights reserved. 6.\" 7.\" This code is derived from software contributed to The NetBSD Foundation 8.\" by Jeremy Cooper. 9.\" 10.\" Redistribution and use in source and binary forms, with or without 11.\" modification, are permitted provided that the following conditions 12.\" are met: 13.\" 1. Redistributions of source code must retain the above copyright 14.\" notice, this list of conditions and the following disclaimer. 15.\" 2. Redistributions in binary form must reproduce the above copyright 16.\" notice, this list of conditions and the following disclaimer in the 17.\" documentation and/or other materials provided with the distribution. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29.\" POSSIBILITY OF SUCH DAMAGE. 30.\" 31.Dd $Mdocdate: June 26 2020 $ 32.Dt MICROTIME 9 33.Os 34.Sh NAME 35.Nm microtime , 36.Nm getmicrotime , 37.Nm microuptime , 38.Nm getmicrouptime , 39.Nm microboottime , 40.Nm nanotime , 41.Nm getnanotime , 42.Nm nanouptime , 43.Nm getnanouptime , 44.Nm nanoruntime , 45.Nm nanoboottime , 46.Nm bintime , 47.Nm binuptime , 48.Nm binruntime , 49.Nm binboottime , 50.Nm gettime , 51.Nm getuptime 52.Nd system clocks 53.Sh SYNOPSIS 54.In sys/time.h 55.Ft void 56.Fo microtime 57.Fa "struct timeval *tv" 58.Fc 59.Ft void 60.Fo getmicrotime 61.Fa "struct timeval *tv" 62.Fc 63.Ft void 64.Fo microuptime 65.Fa "struct timeval *tv" 66.Fc 67.Ft void 68.Fo getmicrouptime 69.Fa "struct timeval *tv" 70.Fc 71.Ft void 72.Fo microboottime 73.Fa "struct timeval *tv" 74.Fc 75.Ft void 76.Fo nanotime 77.Fa "struct timespec *tv" 78.Fc 79.Ft void 80.Fo getnanotime 81.Fa "struct timespec *tv" 82.Fc 83.Ft void 84.Fo nanouptime 85.Fa "struct timespec *tv" 86.Fc 87.Ft void 88.Fo getnanouptime 89.Fa "struct timespec *tv" 90.Fc 91.Ft void 92.Fo nanoruntime 93.Fa "struct timespec *tv" 94.Fc 95.Ft void 96.Fo nanoboottime 97.Fa "struct timespec *tv" 98.Fc 99.Ft void 100.Fo bintime 101.Fa "struct bintime *tv" 102.Fc 103.Ft void 104.Fo binuptime 105.Fa "struct bintime *tv" 106.Fc 107.Ft void 108.Fo binruntime 109.Fa "struct bintime *tv" 110.Fc 111.Ft void 112.Fo binboottime 113.Fa "struct bintime *tv" 114.Fc 115.Ft time_t 116.Fo gettime 117.Fa "void" 118.Fc 119.Ft time_t 120.Fo getuptime 121.Fa "void" 122.Fc 123.Sh DESCRIPTION 124This family of functions return different system clocks in various formats. 125The "uptime" functions return the monotonically increasing time since boot. 126The "runtime" functions return the monotonically increasing time since boot, 127less any time spent suspended. 128The "boottime" functions return the UTC time at which the system booted. 129The "time" functions return the current UTC time. 130The various formats for the result are specified with: 131.Bl -tag -offset indent -width "micro" 132.It bin 133result in struct bintime containing seconds and 64-bit fractions of seconds. 134.It nano 135result in struct timespec containing seconds and nanoseconds 136.It micro 137result in struct timeval containing seconds and microseconds 138.El 139.Pp 140The functions with the "get" prefix return a less precise result, but much 141faster. 142They should be used where a precision of 10 msec is acceptable and where 143performance is critical. 144The functions without the "get" prefix return the best timestamp that can 145be produced in the given format. 146.Sh CODE REFERENCES 147The implementation of these functions is partly machine dependent, but 148the bulk of the code is in the file 149.Pa sys/kern/kern_tc.c . 150.Sh SEE ALSO 151.Xr settimeofday 2 , 152.Xr hardclock 9 , 153.Xr hz 9 , 154.Xr inittodr 9 155