Spin Locks and Contention
Focus so far: Correctness and Progress
New Focus: Performance
Kinds of Architectures
Kinds of Architectures
MIMD Architectures
Today: Revisit Mutual Exclusion
What Should you do if you can’t get a lock?
What Should you do if you can’t get a lock?
Basic Spin-Lock
Basic Spin-Lock
Basic Spin-Lock
Basic Spin-Lock
Basic Spin-Lock
Basic Spin-Lock
Review: Test-and-Set
Review: Test-and-Set
Review: Test-and-Set
Review: Test-and-Set
Review: Test-and-Set
Review: Test-and-Set
Test-and-Set Locks
Test-and-set Lock
Test-and-set Lock
Test-and-set Lock
Test-and-set Lock
Space Complexity
Performance
Graph
Mystery #1
Test-and-Test-and-Set Locks
Test-and-test-and-set Lock
Test-and-test-and-set Lock
Test-and-test-and-set Lock
Mystery #2
Mystery
Opinion
Bus-Based Architectures
Bus-Based Architectures
Bus-Based Architectures
Bus-Based Architectures
Jargon Watch
Jargon Watch
Cave Canem
Processor Issues Load Request
Processor Issues Load Request
Memory Responds
Processor Issues Load Request
Processor Issues Load Request
Processor Issues Load Request
Other Processor Responds
Other Processor Responds
Modify Cached Data
Modify Cached Data
Modify Cached Data
Modify Cached Data
Cache Coherence
Write-Back Caches
Write-Back Caches
Invalidate
Invalidate
Invalidate
Invalidate
Invalidate
Invalidate
Another Processor Asks for Data
Owner Responds
End of the Day …
Mutual Exclusion
Simple TASLock
Test-and-test-and-set
Local Spinning while Lock is Busy
On Release
On Release
On Release
Problems
Measuring Quiescence Time
Quiescence Time
Mystery Explained
Solution: Introduce Delay
Dynamic Example: Exponential Backoff
Exponential Backoff Lock
Exponential Backoff Lock
Exponential Backoff Lock
Exponential Backoff Lock
Exponential Backoff Lock
Exponential Backoff Lock
Spin-Waiting Overhead
Backoff: Other Issues
Idea
Anderson Queue Lock
Anderson Queue Lock
Anderson Queue Lock
Anderson Queue Lock
Anderson Queue Lock
Anderson Queue Lock
Anderson Queue Lock
Anderson Queue Lock
Anderson Queue Lock
Anderson Queue Lock
Anderson Queue Lock
Anderson Queue Lock
Anderson Queue Lock
Anderson Queue Lock
Anderson Queue Lock
Anderson Queue Lock
Anderson Queue Lock
Anderson Queue Lock
Anderson Queue Lock
Local Spinning
False Sharing
The Solution: Padding
Performance
Anderson Queue Lock
Anderson Queue Lock
CLH Lock
Initially
Initially
Initially
Initially
Purple Wants the Lock
Purple Wants the Lock
Purple Wants the Lock
Purple Has the Lock
Red Wants the Lock
Red Wants the Lock
Red Wants the Lock
Red Wants the Lock
Red Wants the Lock
Red Wants the Lock
Red Wants the Lock
Purple Releases
Purple Releases
Space Usage
CLH Queue Lock
CLH Queue Lock
CLH Queue Lock
CLH Queue Lock
CLH Queue Lock
CLH Queue Lock
CLH Queue Lock
CLH Queue Lock
CLH Queue Lock
CLH Queue Lock
CLH Queue Lock
CLH Lock
NUMA Architecturs
NUMA Machines
NUMA Machines
CLH Lock
MCS Lock
Initially
Acquiring
Acquiring
Acquiring
Acquired
Acquiring
Acquiring
Acquiring
Acquiring
Acquiring
Acquiring
MCS Queue Lock
MCS Queue Lock
MCS Queue Lock
MCS Queue Lock
MCS Queue Lock
MCS Queue Lock
MCS Queue Unlock
MCS Queue Lock
MCS Queue Lock
MCS Queue Lock
MCS Queue Lock
Purple Release
Purple Release
Purple Release
Purple Release
Purple Release
Purple Release
Purple Release
Abortable Locks
Back-off Lock
Queue Locks
Queue Locks
Queue Locks
Queue Locks
Queue Locks
Queue Locks
Queue Locks
Queue Locks
Queue Locks
Queue Locks
Abortable CLH Lock
Initially
Initially
Acquiring
Acquiring
Acquiring
Acquiring
Acquired
Normal Case
One Thread Aborts
Successor Notices
Recycle Predecessor’s Node
Spin on Earlier Node
Spin on Earlier Node
Time-out Lock
Time-out Lock
Time-out Lock
Time-out Lock
Time-out Lock
Time-out Lock
Time-out Lock
Time-out Lock
Time-out Lock
Time-out Lock
Time-out Lock
Time-out Lock
Time-out Lock
Time-out Lock
Time-out Lock
Time-out Lock
Time-Out Unlock
Time-out Unlock
Timing-out Lock
One Lock To Rule Them All?