Skip to content

time.rs should consider using CLOCK_MONOTONIC_RAW instead of CLOCK_MONOTONIC on Linux #37902

Closed
@marcust

Description

@marcust

I have reproducible compiler crashes on arm64:

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

thread 'rustc' panicked at 'other was less than the current instant', /buildslave/rust-buildbot/slave/beta-dist-rustc-cross-host-linux/build/src/libstd/sys/unix/time.rs:276
note: Run with `RUST_BACKTRACE=1` for a backtrace.

I'm not really sure where that behavior originates but I suspect the rather old Kernel in combination with the (obscure) hardware I'm running. longsleep/linux-pine64#44 has some more details, basically I see CLOCK_MONOTONIC jumping backwards from time to time. Looking somehow further I see other people used to have the same issue (http://stackoverflow.com/questions/3657289/linux-clock-gettimeclock-monotonic-strange-non-monotonic-behavior)

My Linux Kernel docs say:

       CLOCK_MONOTONIC
              Clock that cannot be set and represents monotonic time since some unspecified starting point.  This clock is not affected by
              discontinuous jumps in the system time (e.g., if the system administrator manually changes the clock), but  is  affected  by
              the incremental adjustments performed by adjtime(3) and NTP.

       CLOCK_MONOTONIC_RAW (since Linux 2.6.28; Linux-specific)
              Similar  to  CLOCK_MONOTONIC, but provides access to a raw hardware-based time that is not subject to NTP adjustments or the
              incremental adjustments performed by adjtime(3).

I see this behavior even without OpenNTPd running (so I still suspect that there is a Kernel/HW-Issue), but it might be better to use the Linux specific RAW version of the monotonic clock in order to get strict monotonic increasing values.

I just saw #37137 but as this is on real hardware that might be more relevant. Even when I'm not running anything that obviously does clock adjustments I see this behavior, RAW seems to be very consistently monotonically increasing. As rust is the only thing that I saw complaining so far you maybe want to consider changing this call.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API 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