diff --git a/include/time.h b/include/time.h index 2a9bcb6a1107..a64a331ee52e 100644 --- a/include/time.h +++ b/include/time.h @@ -46,6 +46,7 @@ #include #include #include +#include #if __POSIX_VISIBLE > 0 && __POSIX_VISIBLE < 200112 || __BSD_VISIBLE /* @@ -97,35 +98,6 @@ typedef __pid_t pid_t; #endif #endif -/* These macros are also in sys/time.h. */ -#if !defined(CLOCK_REALTIME) && __POSIX_VISIBLE >= 199506 -#define CLOCK_REALTIME 0 -#endif /* !defined(CLOCK_REALTIME) && __POSIX_VISIBLE >= 199506 */ -#if !defined(CLOCK_VIRTUAL) && __BSD_VISIBLE -#define CLOCK_VIRTUAL 1 -#define CLOCK_PROF 2 -#endif /* !defined(CLOCK_VIRTUAL) && __BSD_VISIBLE */ -#if !defined(CLOCK_MONOTONIC) && __POSIX_VISIBLE >= 200112 -#define CLOCK_MONOTONIC 4 -#define CLOCK_UPTIME 5 /* FreeBSD-specific. */ -#define CLOCK_UPTIME_PRECISE 7 /* FreeBSD-specific. */ -#define CLOCK_UPTIME_FAST 8 /* FreeBSD-specific. */ -#define CLOCK_REALTIME_PRECISE 9 /* FreeBSD-specific. */ -#define CLOCK_REALTIME_FAST 10 /* FreeBSD-specific. */ -#define CLOCK_MONOTONIC_PRECISE 11 /* FreeBSD-specific. */ -#define CLOCK_MONOTONIC_FAST 12 /* FreeBSD-specific. */ -#define CLOCK_SECOND 13 /* FreeBSD-specific. */ -#define CLOCK_THREAD_CPUTIME_ID 14 -#define CLOCK_PROCESS_CPUTIME_ID 15 -#endif /* !defined(CLOCK_MONOTONIC) && __POSIX_VISIBLE >= 200112 */ - -#if __BSD_VISIBLE -#define TIMER_RELTIME 0x0 /* relative timer */ -#endif -#if !defined(TIMER_ABSTIME) && __POSIX_VISIBLE >= 199506 -#define TIMER_ABSTIME 0x1 /* absolute timer */ -#endif /* !defined(TIMER_ABSTIME) && __POSIX_VISIBLE >= 199506 */ - struct tm { int tm_sec; /* seconds after the minute [0-60] */ int tm_min; /* minutes after the hour [0-59] */ diff --git a/lib/libc/sys/clock_gettime.2 b/lib/libc/sys/clock_gettime.2 index 4552819ea902..d620ed0f03f2 100644 --- a/lib/libc/sys/clock_gettime.2 +++ b/lib/libc/sys/clock_gettime.2 @@ -29,7 +29,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 13, 2021 +.Dd July 1, 2021 .Dt CLOCK_GETTIME 2 .Os .Sh NAME @@ -68,14 +68,17 @@ as well as the following values: .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 @@ -104,6 +107,16 @@ Similarly, .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 diff --git a/sys/sys/_clock_id.h b/sys/sys/_clock_id.h new file mode 100644 index 000000000000..550854189044 --- /dev/null +++ b/sys/sys/_clock_id.h @@ -0,0 +1,81 @@ +/*- + * 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. */ +#if __POSIX_VISIBLE >= 199506 +#define CLOCK_REALTIME 0 +#endif /* __POSIX_VISIBLE >= 199506 */ +#ifdef __BSD_VISIBLE +#define CLOCK_VIRTUAL 1 +#define CLOCK_PROF 2 +#endif /* __BSD_VISIBLE */ +#if __POSIX_VISIBLE >= 200112 +#define CLOCK_MONOTONIC 4 +#endif /* __POSIX_VISIBLE >= 200112 */ +#ifdef __BSD_VISIBLE +#define CLOCK_UPTIME 5 /* FreeBSD-specific. */ +#define CLOCK_UPTIME_PRECISE 7 /* FreeBSD-specific. */ +#define CLOCK_UPTIME_FAST 8 /* FreeBSD-specific. */ +#define CLOCK_REALTIME_PRECISE 9 /* FreeBSD-specific. */ +#define CLOCK_REALTIME_FAST 10 /* FreeBSD-specific. */ +#define CLOCK_MONOTONIC_PRECISE 11 /* FreeBSD-specific. */ +#define CLOCK_MONOTONIC_FAST 12 /* FreeBSD-specific. */ +#define CLOCK_SECOND 13 /* FreeBSD-specific. */ +#endif /* __BSD_VISIBLE */ +#if __POSIX_VISIBLE >= 200112 +#define CLOCK_THREAD_CPUTIME_ID 14 +#define CLOCK_PROCESS_CPUTIME_ID 15 +#endif /* __POSIX_VISIBLE >= 200112 */ + +#if __BSD_VISIBLE +#define CLOCK_BOOTTIME CLOCK_UPTIME /* Linux compat */ +#define CLOCK_REALTIME_COARSE CLOCK_REALTIME_FAST /* Linux compat */ +#define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC_FAST /* Linux compat */ +#endif + +#if __BSD_VISIBLE +#define TIMER_RELTIME 0x0 /* relative timer */ +#endif +#if __POSIX_VISIBLE >= 199506 +#define TIMER_ABSTIME 0x1 /* absolute timer */ +#endif /* __POSIX_VISIBLE >= 199506 */ + +#endif /* _SYS_SYS__CLOCK_ID_H */ diff --git a/sys/sys/time.h b/sys/sys/time.h index a48aa3fe5548..866a9e788cd0 100644 --- a/sys/sys/time.h +++ b/sys/sys/time.h @@ -38,6 +38,7 @@ #include #include #include +#include struct timezone { int tz_minuteswest; /* minutes west of Greenwich */ @@ -471,33 +472,6 @@ struct clockinfo { int profhz; /* profiling clock frequency */ }; -/* These macros are also in time.h. */ -#ifndef CLOCK_REALTIME -#define CLOCK_REALTIME 0 -#endif -#ifndef CLOCK_VIRTUAL -#define CLOCK_VIRTUAL 1 -#define CLOCK_PROF 2 -#endif -#ifndef CLOCK_MONOTONIC -#define CLOCK_MONOTONIC 4 -#define CLOCK_UPTIME 5 /* FreeBSD-specific. */ -#define CLOCK_UPTIME_PRECISE 7 /* FreeBSD-specific. */ -#define CLOCK_UPTIME_FAST 8 /* FreeBSD-specific. */ -#define CLOCK_REALTIME_PRECISE 9 /* FreeBSD-specific. */ -#define CLOCK_REALTIME_FAST 10 /* FreeBSD-specific. */ -#define CLOCK_MONOTONIC_PRECISE 11 /* FreeBSD-specific. */ -#define CLOCK_MONOTONIC_FAST 12 /* FreeBSD-specific. */ -#define CLOCK_SECOND 13 /* FreeBSD-specific. */ -#define CLOCK_THREAD_CPUTIME_ID 14 -#define CLOCK_PROCESS_CPUTIME_ID 15 -#endif - -#ifndef TIMER_ABSTIME -#define TIMER_RELTIME 0x0 /* relative timer */ -#define TIMER_ABSTIME 0x1 /* absolute timer */ -#endif - #if __BSD_VISIBLE #define CPUCLOCK_WHICH_PID 0 #define CPUCLOCK_WHICH_TID 1