Fix clock_gettime() and tick_nanosecs() macro#263
Open
mardy wants to merge 1 commit intodevkitPro:masterfrom
Open
Fix clock_gettime() and tick_nanosecs() macro#263mardy wants to merge 1 commit intodevkitPro:masterfrom
mardy wants to merge 1 commit intodevkitPro:masterfrom
Conversation
clock_gettime() uses the tick_nanosecs() macro to extract the sub-second component of a time expressed in PPC ticks, and returns the sub-second component expressed in nanoseconds. To do so, it relied on the PPCTicksToNs() function, which will overflow and return incorrect results if its argument is sufficiently large (in my case it was 50446082889576108). This in turn causes clock_gettime() to return the wrong number of nanoseconds, which confuses applications because they occasionally see the time jump back. We fix it by using a simpler formula for tick_nanosecs(), which is guaranteed not to overflow on u64 variables.
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.
clock_gettime() uses the tick_nanosecs() macro to extract the sub-second component of a time expressed in PPC ticks, and returns the sub-second component expressed in nanoseconds.
To do so, it relied on the PPCTicksToNs() function, which will overflow and return incorrect results if its argument is sufficiently large (in my case it was 50446082889576108). This in turn causes clock_gettime() to return the wrong number of nanoseconds, which confuses applications because they occasionally see the time jump back.
We fix it by using a simpler formula for tick_nanosecs(), which is guaranteed not to overflow on u64 variables.