Description
According to man pages, CLOCK_MONOTONIC_RAW
doesn't get adjustments from NTP or adjtime
, whereas CLOCK_MONOTONIC
does. This seems ideal for Instant
. CLOCK_MONOTONIC_RAW appears to prevent slewing or jumping, closer matching user expectations about Instant
(despite the fact that Instant is explicitly allowed to jump forward and slew)
This wasn't done earlier due to Rust's minimum supported Linux kernel version (now 2.6.32) since CLOCK_MONOTONIC_RAW was added in 2.6.28. See also #37902
I'd also like to change thread::sleep's implementation to use clock_nanosleep(CLOCK_MONOTONIC_RAW
) from it's current nanosleep()
. Note that
POSIX.1 specifies that nanosleep() should measure time against the CLOCK_REALTIME clock. However, Linux measures the time using the CLOCK_MONOTONIC clock.
from linux.die. This has negative implications for the implementation of thread::sleep on BSD, which should probably use CLOCK_MONOTONIC.
Of course, CLOCK_MONATONIC_RAW is Linux-specific, so other Unix platforms will still use CLOCK_MONATONIC