1.\" $OpenBSD: microtime.9,v 1.8 2004/07/07 21:29:40 jmc 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.\" 3. All advertising materials mentioning features or use of this software 19.\" must display the following acknowledgement: 20.\" This product includes software developed by the NetBSD 21.\" Foundation, Inc. and its contributors. 22.\" 4. Neither the name of The NetBSD Foundation nor the names of its 23.\" contributors may be used to endorse or promote products derived 24.\" from this software without specific prior written permission. 25.\" 26.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36.\" POSSIBILITY OF SUCH DAMAGE. 37.\" 38.Dd September 14, 1998 39.Dt MICROTIME 9 40.Os 41.Sh NAME 42.Nm microtime , 43.Nm getmicrotime , 44.Nm microuptime , 45.Nm getmicrouptime , 46.Nm nanotime , 47.Nm getnanotime , 48.Nm nanouptime , 49.Nm getnanouptime , 50.Nm bintime , 51.Nm getbintime , 52.Nm binuptime , 53.Nm getbinuptime 54.Nd system clock 55.Sh SYNOPSIS 56.Fd #include <sys/time.h> 57.Ft void 58.Fo "microtime" 59.Fa "struct timeval *tv" 60.Fc 61.Ft void 62.Fo "getmicrotime" 63.Fa "struct timeval *tv" 64.Fc 65.Ft void 66.Fo "microuptime" 67.Fa "struct timeval *tv" 68.Fc 69.Ft void 70.Fo "getmicrouptime" 71.Fa "struct timeval *tv" 72.Fc 73.Ft void 74.Fo "nanotime" 75.Fa "struct timespec *tv" 76.Fc 77.Ft void 78.Fo "getnanotime" 79.Fa "struct timespec *tv" 80.Fc 81.Ft void 82.Fo "nanouptime" 83.Fa "struct timespec *tv" 84.Fc 85.Ft void 86.Fo "getnanouptime" 87.Fa "struct timespec *tv" 88.Fc 89.Ft void 90.Fo "bintime" 91.Fa "struct bintime *tv" 92.Fc 93.Ft void 94.Fo "getbintime" 95.Fa "struct bintime *tv" 96.Fc 97.Ft void 98.Fo "binuptime" 99.Fa "struct bintime *tv" 100.Fc 101.Ft void 102.Fo "getbinuptime" 103.Fa "struct bintime *tv" 104.Fc 105.Sh DESCRIPTION 106This family of functions return the system clock in various different formats. 107The functions with the "uptime" suffix return the monotonically increasing 108time since boot. 109The functions without "up" return UTC time. 110The various formats for the result are specified with: 111.Bl -tag -offset indent -width "micro" 112.It bin 113result in struct bintime containing seconds and 64-bit fractions of seconds. 114.It nano 115result in struct timespec containing seconds and nanoseconds 116.It micro 117result in struct timeval containing seconds and microseconds 118.El 119.Pp 120The functions with the "get" prefix return a less precise result, but much 121faster. 122They should be used where a precision of 10 msec is acceptable and where 123performance is critical. 124The functions without the "get" prefix return the best timestamp that can 125be produced in the given format. 126.Sh SEE ALSO 127.Xr settimeofday 2 , 128.Xr hardclock 9 , 129.Xr hz 9 , 130.Xr inittodr 9 , 131.Xr time 9 132.Sh CODE REFERENCES 133The implementation of these functions is partly machine dependent, but 134the bulk of the code is in the file 135.Pa sys/kern/kern_clock.c . 136