From 3ab376d1281df60ca9d76aa8ee5f5d5eea6c608f Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Tue, 29 Nov 2022 15:10:33 +0100 Subject: [PATCH 1/2] use CLOCK_BOOTTIME in Instant::now There was a discussion on rust-lang/rust#87907 that all platforms expect linux advance its monotonic timer if the system goes into a sleep state (e.g. suspend or hibernate). It was decided that CLOCK_BOOTTIME should be used on unix targets. --- library/std/src/sys/unix/time.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/library/std/src/sys/unix/time.rs b/library/std/src/sys/unix/time.rs index d5abd9b581c65..d6e29969e756c 100644 --- a/library/std/src/sys/unix/time.rs +++ b/library/std/src/sys/unix/time.rs @@ -291,8 +291,13 @@ mod inner { pub fn now() -> Instant { #[cfg(target_os = "macos")] const clock_id: libc::clockid_t = libc::CLOCK_UPTIME_RAW; - #[cfg(not(target_os = "macos"))] + + #[cfg(target_os = "linux")] + const clock_id: libc::clockid_t = libc::CLOCK_BOOTTIME; + + #[cfg(not(any(target_os = "macos", target_os = "linux")))] const clock_id: libc::clockid_t = libc::CLOCK_MONOTONIC; + Instant { t: Timespec::now(clock_id) } } From 2ab523db1666b49fa013569bf07216c904bd4cab Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Wed, 30 Nov 2022 07:21:57 +0100 Subject: [PATCH 2/2] add CLOCK_BOOTTIME to miri shims --- src/tools/miri/src/shims/time.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/tools/miri/src/shims/time.rs b/src/tools/miri/src/shims/time.rs index bc0b71fbc2096..2fc5c2fb5ecf2 100644 --- a/src/tools/miri/src/shims/time.rs +++ b/src/tools/miri/src/shims/time.rs @@ -45,6 +45,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { relative_clocks = vec![ this.eval_libc_i32("CLOCK_MONOTONIC")?, this.eval_libc_i32("CLOCK_MONOTONIC_COARSE")?, + // This is the equivalent to `CLOCK_UPTIME_RAW` in the macos section + // We support it, because std relies on it + this.eval_libc_i32("CLOCK_BOOTTIME")?, ]; } "macos" => {