xref: /openbsd/share/man/man9/microtime.9 (revision 8529ddd3)
1.\"	$OpenBSD: microtime.9,v 1.14 2013/06/04 19:27:10 schwarze 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 4 2013 $
32.Dt MICROTIME 9
33.Os
34.Sh NAME
35.Nm microtime ,
36.Nm getmicrotime ,
37.Nm microuptime ,
38.Nm getmicrouptime ,
39.Nm nanotime ,
40.Nm getnanotime ,
41.Nm nanouptime ,
42.Nm getnanouptime ,
43.Nm bintime ,
44.Nm binuptime
45.Nd system clock
46.Sh SYNOPSIS
47.In sys/time.h
48.Ft void
49.Fo "microtime"
50.Fa "struct timeval *tv"
51.Fc
52.Ft void
53.Fo "getmicrotime"
54.Fa "struct timeval *tv"
55.Fc
56.Ft void
57.Fo "microuptime"
58.Fa "struct timeval *tv"
59.Fc
60.Ft void
61.Fo "getmicrouptime"
62.Fa "struct timeval *tv"
63.Fc
64.Ft void
65.Fo "nanotime"
66.Fa "struct timespec *tv"
67.Fc
68.Ft void
69.Fo "getnanotime"
70.Fa "struct timespec *tv"
71.Fc
72.Ft void
73.Fo "nanouptime"
74.Fa "struct timespec *tv"
75.Fc
76.Ft void
77.Fo "getnanouptime"
78.Fa "struct timespec *tv"
79.Fc
80.Ft void
81.Fo "bintime"
82.Fa "struct bintime *tv"
83.Fc
84.Ft void
85.Fo "binuptime"
86.Fa "struct bintime *tv"
87.Fc
88.Sh DESCRIPTION
89This family of functions return the system clock in various different formats.
90The functions with the "uptime" suffix return the monotonically increasing
91time since boot.
92The functions without "up" return UTC time.
93The various formats for the result are specified with:
94.Bl -tag -offset indent -width "micro"
95.It bin
96result in struct bintime containing seconds and 64-bit fractions of seconds.
97.It nano
98result in struct timespec containing seconds and nanoseconds
99.It micro
100result in struct timeval containing seconds and microseconds
101.El
102.Pp
103The functions with the "get" prefix return a less precise result, but much
104faster.
105They should be used where a precision of 10 msec is acceptable and where
106performance is critical.
107The functions without the "get" prefix return the best timestamp that can
108be produced in the given format.
109.Sh CODE REFERENCES
110The implementation of these functions is partly machine dependent, but
111the bulk of the code is in the file
112.Pa sys/kern/kern_clock.c .
113.Sh SEE ALSO
114.Xr settimeofday 2 ,
115.Xr hardclock 9 ,
116.Xr hz 9 ,
117.Xr inittodr 9 ,
118.Xr time 9
119