Skip to content

add env var to override sys::Instant::actually_monotonic() for windows and unix#84448

Closed
the8472 wants to merge 2 commits intorust-lang:masterfrom
the8472:monotonic-override
Closed

add env var to override sys::Instant::actually_monotonic() for windows and unix#84448
the8472 wants to merge 2 commits intorust-lang:masterfrom
the8472:monotonic-override

Conversation

@the8472
Copy link
Member

@the8472 the8472 commented Apr 22, 2021

The environment variable is read on first use and cached in an atomic.

Various operating systems promise monotonic clocks and so does hardware and various hypervisors, often with explicit flags such as constant_tsc. And if that flag is absent they already force the timers to be monotonic through atomic operations (just as the standard library does). And this tends to work on most systems.

But there's the occasional broken hardware or hypervisor that makes this promise but then doesn't deliver. That's why the standard library doesn't rely on the API guarantees in some cases (e.g. windows). And in other cases (e.g. x86 linux) it does trust the OS guarantee and then this gets broken because rust trusts the os which trusts the hypervisor which trusts the hardware which is broken.

The result is that either we err on the side of caution and introduce cache contention in an operation that should be very fast and perfectly scalable even on systems that have reliable clocks or we trust too much and our guarantees get violated on some fraction of systems.

With the environment variable we can offer a way out. We can make a default decision for a particular platform depending on how common broken hardware is and then give users that encounter the opposite case a way out.

Questions:

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-time Area: Time needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.