add spinlock with exponential backoff#3
Open
AneesPatel wants to merge 1 commit into
Open
Conversation
The basic TTAS spinlock was hammering the cache under 8+ threads. Exponential backoff reduces coherence traffic at high contention. MIN=1 MAX=1024 pause cycles felt right in testing.
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.
What
Variant of the existing
SpinLockthat adds exponential backoff. Same TTAS structure but when a CAS fails, it waits an increasing number of pause cycles before retrying.Why
Under heavy contention (8+ threads), the basic spinlock turns into a cache line stampede. Every thread hammers the same lock word with acquire RMWs and trashes each other's L1 caches. Backing off spreads out the retry attempts and gives the current lock holder time to actually finish.
When NOT to use this
At low contention the plain
SpinLockis faster - the extra delay adds up when the lock is usually free. This one pays off when you have many threads and longer critical sections.Notes
spin_for()loop usesCPU_PAUSE()so it still hints the CPU properly.Files
include/BackoffSpinLock.htests/test_backoffspinlock.cppCMakeLists.txt