Skip to content
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

Windows use hint::spin_loop() + expose fn native_sleep + add "experiments" testing bins #12

Merged
merged 7 commits into from
Feb 20, 2022

Conversation

alexheretic
Copy link
Owner

@alexheretic alexheretic commented Feb 18, 2022

  • Expose fn native_sleep.
  • Add SpinSleeper::with_spin_strategy which allows specifying a SpinStrategy.
  • Windows Use SpinStrategy::SpinLoopHint by default.

Add experiments directory with binaries to help pick OS defaults. In particular measuring spin latencies; I saw Linux has good performance using the current thread::yield_now() behaviour. However, on Windows performance under load is quite poor. This supports #11 in suggesting std::hint::spin_loop() is a better default on Windows.

The downside of the change is that in non-load scenarios on Windows we'll now spin more using more power.

Linux

Simulating 16 thread load
warming up...
5ms    None          avg-spins: 159018   avg-actual: 5.000058ms
5ms    SpinLoopHint  avg-spins: 122263   avg-actual: 5.000065ms
5ms    YieldThread   avg-spins: 23265    avg-actual: 5.000327ms
900µs  None          avg-spins: 27748    avg-actual: 938.427µs
900µs  SpinLoopHint  avg-spins: 21727    avg-actual: 900.062µs
900µs  YieldThread   avg-spins: 4054     avg-actual: 901.31µs
5µs    None          avg-spins: 157      avg-actual: 5.055µs
5µs    SpinLoopHint  avg-spins: 122      avg-actual: 5.057µs
5µs    YieldThread   avg-spins: 23       avg-actual: 5.07µs
100ns  None          avg-spins: 2        avg-actual: 147ns
100ns  SpinLoopHint  avg-spins: 1        avg-actual: 135ns
100ns  YieldThread   avg-spins: 1        avg-actual: 278ns

Windows

Simulating 16 thread load
warming up...
5ms    None          avg-spins: 105568   avg-actual: 5.838449ms
5ms    SpinLoopHint  avg-spins: 79548    avg-actual: 5.608363ms
5ms    YieldThread   avg-spins: 1        avg-actual: 17.526351ms
900µs  None          avg-spins: 19461    avg-actual: 1.127537ms
900µs  SpinLoopHint  avg-spins: 14578    avg-actual: 1.326708ms
900µs  YieldThread   avg-spins: 1        avg-actual: 17.526448ms
5µs    None          avg-spins: 108      avg-actual: 5µs
5µs    SpinLoopHint  avg-spins: 79       avg-actual: 6.298µs
5µs    YieldThread   avg-spins: 1        avg-actual: 11.417271ms
100ns  None          avg-spins: 1        avg-actual: 101ns
100ns  SpinLoopHint  avg-spins: 0        avg-actual: 102ns
100ns  YieldThread   avg-spins: 0        avg-actual: 7.716038ms

@alexheretic alexheretic changed the title Expose fn native_sleep & add "experiments" testing binaries Windows use hint::spin_loop() + expose fn native_sleep + add "experiments" testing bins Feb 20, 2022
Copy link

@ishitatsuyuki ishitatsuyuki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. I appreciate the effort into exposing configurable behaviors instead of hardcoding them.

@alexheretic alexheretic merged commit f8830c8 into master Feb 20, 2022
@alexheretic alexheretic deleted the experiments branch February 20, 2022 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants