-
Notifications
You must be signed in to change notification settings - Fork 121
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
Fix Jitter time measurement on Apple platforms #722
Merged
Merged
Conversation
This file contains 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
On Apple platforms, Jitter RNG implementation uses `mach_absolute_time` function to get the current value of the clock. However, this function deals in "tick" units, not in time units. On Intel based Apple platforms 1 tick = 1 ns, which is good enough timer resolution for Jitter. On M1 macbooks 1 tick ~ 41.67 ns. This seems to be a problem for Jitter since it causes frequent failures to produce enough entropy on M1 macbooks. Another potential cause for the issue might be that `mach_absolute_time` clock doesn't increment while they system is asleep. I am not sure what is the definition of "asleep" on M1 macs, how it correlates to performance and efficiency cores and different power saving states, etc. So to be on the safe side we change: - Instead of `mach_absolute_time` we call `clock_gettime_nsec_np` function, as suggested by Apple's documentation [1], - Instead of using `CLOCK_UPTIME_RAW` that corresponds to `mach_absolut_time`, we use `CLOCK_MONOTONIC_RAW` that corresponds to `mach_continuous_time` whose clock increments even while the system is asleep [2]. [1] https://developer.apple.com/documentation/kernel/1462446-mach_absolute_time [2] https://developer.apple.com/documentation/kernel/1646199-mach_continuous_time
Taffer
reviewed
Dec 12, 2022
This is required for the |
Taffer
previously approved these changes
Dec 14, 2022
torben-hansen
approved these changes
Dec 14, 2022
Taffer
approved these changes
Dec 14, 2022
Taffer
pushed a commit
to Taffer/aws-lc
that referenced
this pull request
Dec 14, 2022
On Apple platforms, Jitter RNG implementation uses `mach_absolute_time` function to get the current value of the clock. However, this function deals in "tick" units, not in time units. On Intel based Apple platforms 1 tick = 1 ns, which is good enough timer resolution for Jitter. On M1 macbooks 1 tick ~ 41.67 ns. This seems to be a problem for Jitter since it causes frequent failures to produce enough entropy on M1 macbooks. Another potential cause for the issue might be that `mach_absolute_time` clock doesn't increment while they system is asleep. I am not sure what is the definition of "asleep" on M1 macs, how it correlates to performance and efficiency cores and different power saving states, etc. The upstream Jitter RNG repository has recently added support for using the system counter on `aarch64` which seems like way to go for all 64-bit Arm platforms. So this change: - Adds the system counter calls on `aarch64` platforms, - Removes the `__MACH__` special case.
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.
Issues:
CryptoAlg-1441
Description of changes:
On Apple platforms, Jitter RNG implementation uses
mach_absolute_time
function to get the current value of the clock. However, this function
deals in "tick" units, not in time units. On Intel based Apple
platforms 1 tick = 1 ns, which is good enough timer resolution for
Jitter. On M1 macbooks 1 tick ~ 41.67 ns. This seems to be a problem
for Jitter since it causes frequent failures to produce enough entropy
on M1 macbooks. Another potential cause for the issue might be that
mach_absolute_time
clock doesn't increment while they system isasleep. I am not sure what is the definition of "asleep" on M1 macs,
how it correlates to performance and efficiency cores and different
power saving states, etc. The upstream Jitter RNG repository has
recently added support for using the system counter on
aarch64
which seems like way to go for all 64-bit Arm platforms.
So this change:
aarch64
platforms,__MACH__
special case.Call-outs:
Point out areas that need special attention or support during the review process. Discuss architecture or design changes.
Testing:
How is this change tested (unit tests, fuzz tests, etc.)? Are there any testing steps to be verified by the reviewer?
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and
the ISC license.