1.\" $OpenBSD: microtime.9,v 1.19 2019/10/22 20:19:41 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: October 22 2019 $ 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 nanoboottime , 45.Nm bintime , 46.Nm binuptime , 47.Nm binboottime 48.Nd system clocks 49.Sh SYNOPSIS 50.In sys/time.h 51.Ft void 52.Fo microtime 53.Fa "struct timeval *tv" 54.Fc 55.Ft void 56.Fo getmicrotime 57.Fa "struct timeval *tv" 58.Fc 59.Ft void 60.Fo microuptime 61.Fa "struct timeval *tv" 62.Fc 63.Ft void 64.Fo getmicrouptime 65.Fa "struct timeval *tv" 66.Fc 67.Ft void 68.Fo microboottime 69.Fa "struct timeval *tv" 70.Fc 71.Ft void 72.Fo nanotime 73.Fa "struct timespec *tv" 74.Fc 75.Ft void 76.Fo getnanotime 77.Fa "struct timespec *tv" 78.Fc 79.Ft void 80.Fo nanouptime 81.Fa "struct timespec *tv" 82.Fc 83.Ft void 84.Fo getnanouptime 85.Fa "struct timespec *tv" 86.Fc 87.Ft void 88.Fo nanoboottime 89.Fa "struct timespec *tv" 90.Fc 91.Ft void 92.Fo bintime 93.Fa "struct bintime *tv" 94.Fc 95.Ft void 96.Fo binuptime 97.Fa "struct bintime *tv" 98.Fc 99.Ft void 100.Fo binboottime 101.Fa "struct bintime *tv" 102.Fc 103.Sh DESCRIPTION 104This family of functions return different system clocks in various formats. 105The "uptime" functions return the monotonically increasing time since boot. 106The "boottime" functions return the UTC time at which the system booted. 107The "time" functions return the current UTC time. 108The various formats for the result are specified with: 109.Bl -tag -offset indent -width "micro" 110.It bin 111result in struct bintime containing seconds and 64-bit fractions of seconds. 112.It nano 113result in struct timespec containing seconds and nanoseconds 114.It micro 115result in struct timeval containing seconds and microseconds 116.El 117.Pp 118The functions with the "get" prefix return a less precise result, but much 119faster. 120They should be used where a precision of 10 msec is acceptable and where 121performance is critical. 122The functions without the "get" prefix return the best timestamp that can 123be produced in the given format. 124.Sh CODE REFERENCES 125The implementation of these functions is partly machine dependent, but 126the bulk of the code is in the file 127.Pa sys/kern/kern_tc.c . 128.Sh SEE ALSO 129.Xr settimeofday 2 , 130.Xr hardclock 9 , 131.Xr hz 9 , 132.Xr inittodr 9 , 133.Xr time_second 9 134