Skip to content

Use CLOCK_MONOTONIC_RAW instead of CLOCK_MONOTONIC for Instant #77807

Closed
@maxbla

Description

@maxbla

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.O-linuxOperating system: LinuxT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions