perf(completion): make terminal waits lock-free - #288
Open
ryux1 wants to merge 1 commit into
Open
Conversation
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.
Closes #246.
Summary
RawWaker::clonedrops the completer, proving clone callbacks cannot deadlock against completion state.Design notes
Completion and abandonment hold the waiter mutex while detaching the current waiter cohort, then publish the terminal state with a release store. Polls use acquire loads, so observing
Completedalso observes the initializedOnceLockvalue and observing either terminal state happens after waiter detachment. A poll that initially seesPendingclones its waker before locking, then rechecks status under the waiter mutex before registering.Wait::dropuses the same load/lock/recheck pattern.Three
cargo x benchruns were collected for upstreammain(93b3413) and this branch on an Intel Core i9-10900F (Linux x86_64); the table reports the median of each set:ready_waitcancel_pendingcomplete_then_waitnotify_pendingfanout/1fanout/2fanout/4fanout/8fanout/32The pending cancellation path pays about 3.1 ns to clone outside the lock; terminal waits and every measured completion/notification path improve.
Validated with:
cargo x checkcargo x testcargo x lintcargo x miricargo +nightly miri test --package tests-integration --test completion_testcargo x bench