Use clock BOOTTIME for thread::sleep on linux#113513
Closed
yara-blue wants to merge 1 commit intorust-lang:masterfrom
yara-blue:master
Closed
Use clock BOOTTIME for thread::sleep on linux#113513yara-blue wants to merge 1 commit intorust-lang:masterfrom yara-blue:master
yara-blue wants to merge 1 commit intorust-lang:masterfrom
yara-blue:master
Conversation
Thread::sleep uses nanosleep. Nanosleep uses the MONOTONIC clock. That clock does not take suspend time into account. Since kernel commit d6ed449 the MONOTONIC clock behaves the same as the BOOTTIME clock. The BOOTTIME clock does count time spend suspended. Commit d6ed449 was merged somewhere between v4.14 and v4.19. Rust supports kernels before and after that. This commit changes sleep to use the BOOTTIME clock on linux targes. This makes sleep behave consistently on linux regardless of kernel version.
Collaborator
|
r? @cuviper (rustbot has picked a reviewer for you, use r? to override) |
Collaborator
|
The job Click to see the possible cause of the failure (guessed by this bot) |
Member
That's wrong. It was reverted shortly after in torvalds/linux@a3ed0e4 |
Author
I missed that, thanks a lot! No need for this then. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thread::sleepuses nanosleep. Nanosleep uses theMONOTONICclock. That clock does not take suspend time into account. Since kernel commit d6ed449 the MONOTONIC clock behaves the same as theBOOTTIMEclock. TheBOOTTIMEclock does count time spend suspended.Kernel commit d6ed449 was merged somewhere between v4.14 and v4.19. Rust supports kernels before and after that.
This commit changes sleep to use the
BOOTTIMEclock on linux targes. This makes sleep behave consistently on linux regardless of kernel version.I discovered this while preparing the implementation for rust-lang/libs-team#237. Fixing it changes behavior of rust code on older kernel versions and could therefore be seen as breaking. Since the kernel also broke behavior the same way I think it might be okay.
A proposal (#88714) to switch to the
BOOTTIMEclock forInstantran into trouble as the minimally supported linux kernel did no supportBOOTTIME. Since then the minimal kernel version has been increased and this is no longer an issue.It might be useful to re-evaluate that given the change made in kernel commit d6ed449. Lets however first look at
sleepbefore we open that can of worms.I think this change is small and simple enough for a PR if its not let me know and I'll move it to a libs team RFC.
Sources: