mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-06 16:40:47 +00:00
Redefine CLOCK_BOOTTIME to alias CLOCK_MONOTONIC, not CLOCK_UPTIME
The suspend-awareness situation with monotonic clocks across platforms is kind of a mess, let's try not making it worse. On Linux, CLOCK_MONOTONIC does NOT count suspended time, and CLOCK_BOOTTIME was introduced to INCLUDE suspended time. On OpenBSD, CLOCK_MONOTONIC DOES count suspended time, and CLOCK_UPTIME was introduced to EXCLUDE suspended time. On macOS, it's the same as OpenBSD, but with CLOCK_UPTIME_RAW. Right now, we do not have a monotonic clock that counts suspended time. We have CLOCK_UPTIME as a distinct ID alias, and CLOCK_BOOTTIME as a preprocessor alias, both being effectively `CLOCK_MONOTONIC` for now. When we introduce a suspend-aware clock in the future, it would make a lot more sense to do it the OpenBSD/macOS way, i.e. to make CLOCK_MONOTONIC include suspended time and make CLOCK_UPTIME exclude it, because that's what the name CLOCK_UPTIME implies: a deviation from the default intended for the uptime command to allow it to only show the time the system was actually up and not suspended. Let's change the define right now to make sure software using the define would not end up using the ID of the wrong clock in the future, and fix the IDs in the Linux compat code to match the expected changes too. See https://bugzilla.mozilla.org/show_bug.cgi?id=1824084 for more discussion. Fixes:155f15118a
("clock_gettime: Add Linux aliases for CLOCK_*") Fixes:25ada63736
("Map Linux CLOCK_BOOTTIME to native CLOCK_UPTIME.") Sponsored by: https://www.patreon.com/valpackett Reviewed by: kib, imp Differential Revision: https://reviews.freebsd.org/D39270
This commit is contained in:
parent
676041c41b
commit
108de78451
|
@ -287,7 +287,7 @@ linux_to_native_clockid(clockid_t *n, clockid_t l)
|
|||
*n = CLOCK_REALTIME;
|
||||
break;
|
||||
case LINUX_CLOCK_MONOTONIC:
|
||||
*n = CLOCK_MONOTONIC;
|
||||
*n = CLOCK_UPTIME;
|
||||
break;
|
||||
case LINUX_CLOCK_PROCESS_CPUTIME_ID:
|
||||
*n = CLOCK_PROCESS_CPUTIME_ID;
|
||||
|
@ -300,10 +300,10 @@ linux_to_native_clockid(clockid_t *n, clockid_t l)
|
|||
break;
|
||||
case LINUX_CLOCK_MONOTONIC_COARSE:
|
||||
case LINUX_CLOCK_MONOTONIC_RAW:
|
||||
*n = CLOCK_MONOTONIC_FAST;
|
||||
*n = CLOCK_UPTIME_FAST;
|
||||
break;
|
||||
case LINUX_CLOCK_BOOTTIME:
|
||||
*n = CLOCK_UPTIME;
|
||||
*n = CLOCK_MONOTONIC;
|
||||
break;
|
||||
case LINUX_CLOCK_REALTIME_ALARM:
|
||||
case LINUX_CLOCK_BOOTTIME_ALARM:
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
* Linux compatible names.
|
||||
*/
|
||||
#if __BSD_VISIBLE
|
||||
#define CLOCK_BOOTTIME CLOCK_UPTIME
|
||||
#define CLOCK_BOOTTIME CLOCK_MONOTONIC
|
||||
#define CLOCK_REALTIME_COARSE CLOCK_REALTIME_FAST
|
||||
#define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC_FAST
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue