2 .\" Copyright (c) 1980, 1991, 1993
3 .\" The Regents of the University of California. All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\" 3. Neither the name of the University nor the names of its contributors
14 .\" may be used to endorse or promote products derived from this software
15 .\" without specific prior written permission.
17 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 .Nm clock_gettime_nsec_np
37 .Nd get/set date and time
41 .Fn clock_gettime "clockid_t clock_id" "struct timespec *tp"
43 .Fn clock_settime "clockid_t clock_id" "const struct timespec *tp"
45 .Fn clock_getres "clockid_t clock_id" "struct timespec *tp"
47 .Fn clock_gettime_nsec_np "clockid_t clock_id"
54 allow the calling process to retrieve or set the value used by a clock
60 one of 8 predefined values:
63 the system's real time (i.e. wall time) clock, expressed as the amount of time
65 This is the same as the value returned by
67 .It Dv CLOCK_MONOTONIC
68 clock that increments monotonically, tracking the time since an arbitrary
69 point, and will continue to increment while the system is asleep.
70 .It Dv CLOCK_MONOTONIC_RAW
71 clock that increments monotonically, tracking the time since an arbitrary point
72 like CLOCK_MONOTONIC. However, this clock is unaffected by frequency or time
73 adjustments. It should not be compared to other system time sources.
74 .It Dv CLOCK_MONOTONIC_RAW_APPROX
75 like CLOCK_MONOTONIC_RAW, but reads a value cached by the system at context
76 switch. This can be read faster, but at a loss of accuracy as it may return
77 values that are milliseconds old.
78 .It Dv CLOCK_UPTIME_RAW
79 clock that increments monotonically, in the same manner as
80 .Dv CLOCK_MONOTONIC_RAW,
81 but that does not increment while the system is asleep.
82 The returned value is identical to the result of
83 .Fn mach_absolute_time
84 after the appropriate mach_timebase conversion is applied.
85 .It Dv CLOCK_UPTIME_RAW_APPROX
86 like CLOCK_UPTIME_RAW, but reads a value cached by the system at context
87 switch. This can be read faster, but at a loss of accuracy as it may return
88 values that are milliseconds old.
89 .It Dv CLOCK_PROCESS_CPUTIME_ID
90 clock that tracks the amount of CPU (in user- or kernel-mode) used by the
92 .It Dv CLOCK_THREAD_CPUTIME_ID
93 clock that tracks the amount of CPU (in user- or kernel-mode) used by the
97 The structure pointed to by
102 .Bd -literal -offset indent
104 time_t tv_sec; /* seconds */
105 long tv_nsec; /* and nanoseconds */
111 clock can be set, and only the superuser may do so.
113 The resolution of a clock is returned by the
116 This value is placed in a (non-null)
118 This value may be smaller than the actual precision of the underlying clock,
119 but represents a lower bound on the resolution.
121 As a non-portable extension, the
122 .Fn clock_gettime_nsec_np
123 function will return the clock value in 64-bit nanoseconds.
125 A 0 return value indicates that the call succeeded.
126 A \-1 return value indicates an error occurred, and in this
127 case an error code is stored into the global variable
130 .Fn clock_gettime_nsec_np
131 a return value of non-0 indicates success. A 0 return value indicates an error
132 occurred and an error code is stored in
139 .Fn clock_gettime_nsec_np
144 is not a valid value.
148 argument address referenced invalid memory.
153 may return the following errors:
156 A user other than the superuser attempted to set the time.
159 specifies a clock that isn't settable,
161 specifies a nanosecond value less than zero or greater than 1000 million,
162 or a value outside the range of the specified clock.
169 These functions first appeared
178 system calls conform to
180 .Fn cleck_gettime_nsec_np
181 is a non-portable Darwin extension.
183 .Fa CLOCK_MONOTONIC_RAW
186 are extensions to the POSIX interface.