diff --git a/lib/libc/sys/clock_gettime.2 b/lib/libc/sys/clock_gettime.2 index 6dca19449be9..12be3c321a75 100644 --- a/lib/libc/sys/clock_gettime.2 +++ b/lib/libc/sys/clock_gettime.2 @@ -1,184 +1,197 @@ .\" $OpenBSD: clock_gettime.2,v 1.4 1997/05/08 20:21:16 kstailey Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $FreeBSD$ .\" -.Dd December 7, 2019 +.Dd July 30, 2021 .Dt CLOCK_GETTIME 2 .Os .Sh NAME .Nm clock_gettime , .Nm clock_settime , .Nm clock_getres .Nd get/set/calibrate date and time .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In time.h .Ft int .Fn clock_gettime "clockid_t clock_id" "struct timespec *tp" .Ft int .Fn clock_settime "clockid_t clock_id" "const struct timespec *tp" .Ft int .Fn clock_getres "clockid_t clock_id" "struct timespec *tp" .Sh DESCRIPTION The .Fn clock_gettime and .Fn clock_settime system calls allow the calling process to retrieve or set the value used by a clock which is specified by .Fa clock_id . .Pp The .Fa clock_id argument can be a value obtained from .Xr clock_getcpuclockid 3 or .Xr pthread_getcpuclockid 3 as well as the following values: .Pp .Bl -tag -width indent -compact .It Dv CLOCK_REALTIME .It Dv CLOCK_REALTIME_PRECISE .It Dv CLOCK_REALTIME_FAST +.It Dv CLOCK_REALTIME_COARSE Increments as a wall clock should. .It Dv CLOCK_MONOTONIC .It Dv CLOCK_MONOTONIC_PRECISE .It Dv CLOCK_MONOTONIC_FAST +.It Dv CLOCK_MONOTONIC_COARSE Increments in SI seconds. .It Dv CLOCK_UPTIME .It Dv CLOCK_UPTIME_PRECISE .It Dv CLOCK_UPTIME_FAST +.It Dv CLOCK_BOOTTIME Starts at zero when the kernel boots and increments monotonically in SI seconds while the machine is running. .It Dv CLOCK_VIRTUAL Increments only when the CPU is running in user mode on behalf of the calling process. .It Dv CLOCK_PROF Increments when the CPU is running in user or kernel mode. .It Dv CLOCK_SECOND Returns the current second without performing a full time counter query, using an in-kernel cached value of the current second. .It Dv CLOCK_PROCESS_CPUTIME_ID Returns the execution time of the calling process. .It Dv CLOCK_THREAD_CPUTIME_ID Returns the execution time of the calling thread. .El .Pp The clock IDs .Fa CLOCK_REALTIME_FAST , .Fa CLOCK_MONOTONIC_FAST , .Fa CLOCK_UPTIME_FAST are analogs of corresponding IDs without _FAST suffix but do not perform a full time counter query, so their accuracy is one timer tick. Similarly, .Fa CLOCK_REALTIME_PRECISE , .Fa CLOCK_MONOTONIC_PRECISE , .Fa CLOCK_UPTIME_PRECISE are used to get the most exact value as possible, at the expense of execution time. +The clock IDs +.Fa CLOCK_REALTIME_COARSE , +.Fa CLOCK_MONOTONIC_COARSE +are aliases of corresponding IDs with _FAST suffix for compatibility with other +systems. +Finally, +.Dv CLOCK_BOOTTIME +is an alias for +.Dv CLOCK_UPTIME +for compatibility with other systems. .Pp The structure pointed to by .Fa tp is defined in .In sys/timespec.h as: .Bd -literal struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* and nanoseconds */ }; .Ed .Pp Only the super-user may set the time of day, using only .Fa CLOCK_REALTIME . If the system securelevel is greater than 1 (see .Xr init 8 ) , the time may only be advanced. This limitation is imposed to prevent a malicious super-user from setting arbitrary time stamps on files. The system time can still be adjusted backwards using the .Xr adjtime 2 system call even when the system is secure. .Pp The resolution (granularity) of a clock is returned by the .Fn clock_getres system call. This value is placed in a (non-NULL) .Fa *tp . .Sh RETURN VALUES .Rv -std .Sh ERRORS The following error codes may be set in .Va errno : .Bl -tag -width Er .It Bq Er EINVAL The .Fa clock_id or .Fa timespec argument was not a valid value. .It Bq Er EPERM A user other than the super-user attempted to set the time. .El .Sh SEE ALSO .Xr date 1 , .Xr adjtime 2 , .Xr clock_getcpuclockid 3 , .Xr ctime 3 , .Xr pthread_getcpuclockid 3 , .Xr timed 8 .Sh STANDARDS The .Fn clock_gettime , .Fn clock_settime , and .Fn clock_getres system calls conform to .St -p1003.1b-93 . The clock IDs .Fa CLOCK_REALTIME_FAST , .Fa CLOCK_REALTIME_PRECISE , .Fa CLOCK_MONOTONIC_FAST , .Fa CLOCK_MONOTONIC_PRECISE , .Fa CLOCK_UPTIME , .Fa CLOCK_UPTIME_FAST , .Fa CLOCK_UPTIME_PRECISE , .Fa CLOCK_SECOND are FreeBSD extensions to the POSIX interface. .Sh HISTORY The .Fn clock_gettime , .Fn clock_settime , and .Fn clock_getres system calls first appeared in .Fx 3.0 . diff --git a/sys/sys/_clock_id.h b/sys/sys/_clock_id.h index f0a25ce0f3f1..a88eb063122f 100644 --- a/sys/sys/_clock_id.h +++ b/sys/sys/_clock_id.h @@ -1,95 +1,104 @@ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * (c) UNIX System Laboratories, Inc. * All or some portions of this file are derived from material licensed * to the University of California by American Telephone and Telegraph * Co. or Unix System Laboratories, Inc. and are reproduced herein with * the permission of UNIX System Laboratories, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)time.h 8.3 (Berkeley) 1/21/94 */ #ifndef _SYS_SYS__CLOCK_ID_H #define _SYS_SYS__CLOCK_ID_H /* * These macros are shared between time.h and sys/time.h. */ /* * Note: The values shown below as a comment for the __POSIX_VISIBLE values are * the ones FreeBSD traditionally used based on our reading of the POSIX * standards. However, glibc uses 199309 for all of them, even those many were * not defined there. To remain bug compatible with glibc means more software * that relied on the glibc behavior will compile easily on FreeBSD. * * Also, CLOCK_UPTIME_FAST is improperly visible temporarily for the lang/pocl * port until it can be updated properly. It incorrectly assumes that this was a * standard value. It will be moved back to the __BSD_VISIBLE section once the * issue is corrected. */ #if __POSIX_VISIBLE >= 199309 /* 199506 */ #define CLOCK_REALTIME 0 #endif /* __POSIX_VISIBLE >= 199309 */ #ifdef __BSD_VISIBLE #define CLOCK_VIRTUAL 1 #define CLOCK_PROF 2 #endif /* __BSD_VISIBLE */ #if __POSIX_VISIBLE >= 199309 /* 200112 */ #define CLOCK_MONOTONIC 4 #define CLOCK_UPTIME_FAST 8 #endif /* __POSIX_VISIBLE >= 199309 */ #ifdef __BSD_VISIBLE /* * FreeBSD-specific clocks. */ #define CLOCK_UPTIME 5 #define CLOCK_UPTIME_PRECISE 7 #define CLOCK_REALTIME_PRECISE 9 #define CLOCK_REALTIME_FAST 10 #define CLOCK_MONOTONIC_PRECISE 11 #define CLOCK_MONOTONIC_FAST 12 #define CLOCK_SECOND 13 #endif /* __BSD_VISIBLE */ #if __POSIX_VISIBLE >= 199309 /* 200112 */ #define CLOCK_THREAD_CPUTIME_ID 14 #define CLOCK_PROCESS_CPUTIME_ID 15 #endif /* __POSIX_VISIBLE >= 199309 */ +/* + * Linux compatible names. + */ +#if __BSD_VISIBLE +#define CLOCK_BOOTTIME CLOCK_UPTIME +#define CLOCK_REALTIME_COARSE CLOCK_REALTIME_FAST +#define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC_FAST +#endif + #if __BSD_VISIBLE #define TIMER_RELTIME 0x0 /* relative timer */ #endif #if __POSIX_VISIBLE >= 199309 #define TIMER_ABSTIME 0x1 /* absolute timer */ #endif /* __POSIX_VISIBLE >= 199309 */ #endif /* _SYS_SYS__CLOCK_ID_H */