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

Switch the unbounded thread pool to use a latch instead of parkers #2846

Merged
merged 4 commits into from
Apr 11, 2023

Conversation

stevenengler
Copy link
Contributor

@stevenengler stevenengler commented Apr 5, 2023

I'm not sure that the ThreadUnparker works correctly when using rust's parking API, so I've updated a comment in it and replaced it in the thread-per-core scheduler (the unbounded thread pool) with a simple futex-based latch instead. The thread-per-host scheduler continues to use the (possibly broken) ThreadUnparker.

Another advantage is that it can futex-wake all threads with one syscall, rather than unparking each thread individually.

I ran a benchmark on an earlier version of this PR and there was no performance improvement.

@stevenengler stevenengler self-assigned this Apr 5, 2023
@github-actions github-actions bot added the Component: Main Composing the core Shadow executable label Apr 5, 2023
@stevenengler stevenengler force-pushed the simplify-scheduler branch 3 times, most recently from 1b5b8f0 to e1d57a1 Compare April 6, 2023 04:49
@stevenengler stevenengler force-pushed the simplify-scheduler branch 3 times, most recently from eaa3d9e to 5204be9 Compare April 11, 2023 21:43
@stevenengler stevenengler marked this pull request as ready for review April 11, 2023 21:44
@stevenengler stevenengler changed the title Switch the unbounded thread pool to use futexes instead of parkers Switch the unbounded thread pool to use a latch instead of parkers Apr 11, 2023
@stevenengler stevenengler merged commit 518c851 into shadow:main Apr 11, 2023
21 checks passed
@stevenengler stevenengler deleted the simplify-scheduler branch April 11, 2023 23:46
stevenengler added a commit that referenced this pull request Apr 12, 2023
The latest nightly tor benchmark showed a huge runtime performance
change:

![run_time](https://user-images.githubusercontent.com/3708797/231516949-7dff1d67-dbcf-4c6f-be72-ce406e520abe.png)

@sporksmith found that we were performing futex operations on the `Arc`
address rather than its inner `AtomicI32` address, causing the waiter to
spin. This was caused by a bug in #2846.

We expect that this PR will increase the runtime back to the original
runtime, and we can investigate spinning properly later.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Main Composing the core Shadow executable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants