-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Specialize sleep_until implementation for unix (except mac) #141829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
r? @cuviper |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This can be done without touching all pal's, ill be doing that tomorrow, now its bed time 😴 edit: I was mistaken, tidy does not allow #[cfg(...)] in |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
fn add_100_millis(mut ts: libc::timespec) -> libc::timespec { | ||
const SECOND: i64 = 1_000_000_000; | ||
ts.tv_nsec += SECOND / 10; | ||
ts.tv_sec = ts.tv_nsec / SECOND; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this still wrong?
ts.tv_sec = ts.tv_nsec / SECOND; | |
// If this pushes tv_nsec to SECOND or higher, we need to overflow to tv_sec. | |
ts.tv_sec += ts.tv_nsec / SECOND; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be this now:
fn add_100_millis(mut ts: libc::timespec) -> libc::timespec {
const SECOND: i64 = 1_000_000_000;
ts.tv_nsec += SECOND / 10;
ts.tv_sec = ts.tv_nsec / SECOND;
ts.tv_nsec %= SECOND;
ts
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that's wrong, as I already said above. Why do you reset tv_sec
to 0 or 1??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the overflow of tv_nsec
is taken care of by:
ts.tv_nsec %= SECOND;
right?
I tested it in the playground and there it seems to work https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=8c8dcb8b0f9c7238b747b61e073ddc14
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that's wrong, as I already said above. Why do you reset
tv_sec
to 0 or 1??
oh damn I get it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry I'm struggling with this, no idea why. Thanks for your patience Ralf.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better take a bit more time and think things through twice next time. :)
My suggestion above has a comment, I think that's still a useful comment to explain the (clearly non-obvious!) logic. Please add that comment.
Miri code looks good once the last comment nit is resolved. :) |
Regarding trying on more Unix platforms... this should cover various unix flavors |
Specialize sleep_until implementation for unix (except mac) related tracking issue: #113752 Supersedes #118480 for the reasons see: #113752 (comment) Replaces the generic catch all implementation with target_os specific ones for: linux/netbsd/freebsd/android/solaris/illumos etc. Other platforms like wasi, macos/ios/tvos/watchos and windows will follow in later separate PR's (once this is merged). try-job: dist-x86_64-*
This comment has been minimized.
This comment has been minimized.
@rustbot author |
@rustbot ready |
The non-Miri part was already approved before, so please clean up the history and then we can land this. :) |
Using clock nanosleep leads to more accurate sleep times on platforms where it is supported. To enable using clock_nanosleep this makes `sleep_until` platform specific. That unfortunatly requires identical placeholder implementations for the other platforms (windows/mac/wasm etc). we will land platform specific implementations for those later. See the `sleep_until` tracking issue. This requires an accessors for the Instant type. As that accessor is only used on the platforms that have clock_nanosleep it is marked as allow_unused. 32bit time_t targets do not use clock_nanosleep atm, they instead rely on the same placeholder as the other platforms. We could make them use clock_nanosleep too in the future using `__clock_nanosleep_time64`. __clock_nanosleep_time64 is documented at: https://www.gnu.org/software/libc/manual/html_node/64_002dbit-time-symbol-handling.html
The clock_nanosleep support is there to allow code using `sleep_until` to run under Miri. Therefore the implementation is minimal. - Only the clocks REALTIME and MONOTONIC are supported. The first is supported simply because it was trivial to add not because it was needed for sleep_until. - The only supported flag combinations are no flags or TIMER_ABSTIME only. If an unsupported flag combination or clock is passed in this throws unsupported.
Squashed to two commits |
@bors r=cuviper,RalfJung |
☀️ Test successful - checks-actions |
What is this?This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.Comparing a84ab0c (parent) -> ca98d4d (this PR) Test differencesShow 49 test diffsStage 1
Additionally, 48 doctest diffs were found. These are ignored, as they are noisy. Job group index
Test dashboardRun cargo run --manifest-path src/ci/citool/Cargo.toml -- \
test-dashboard ca98d4d4b3114116203699c2734805547df86f9a --output-dir test-dashboard And then open Job duration changes
How to interpret the job duration changes?Job durations can vary a lot, based on the actual runner instance |
Finished benchmarking commit (ca98d4d): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (secondary -1.9%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 2.9%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 464.608s -> 463.852s (-0.16%) |
related tracking issue: #113752
Supersedes #118480 for the reasons see: #113752 (comment)
Replaces the generic catch all implementation with target_os specific ones for: linux/netbsd/freebsd/android/solaris/illumos etc. Other platforms like wasi, macos/ios/tvos/watchos and windows will follow in later separate PR's (once this is merged).