Switch policy design
Current swilock components & implementation status
Lock & Unlock APIs✅
- Switch between CAS, qspinlock, TCLock (queue-based)
Helper thread✅
- Change lock type every 5s
FFWD⭕️
- Server thread: iterate through CPU requests, switch stack and process requests
- Client APIs: delegate() & delegate_finish(), can replace lock() & unlock()
Throughput live demo✅
Switch base on contention
Plan A
Consider how many threads are using the lock.
- Add a global counter
- When calling lock() & unlock(), increase & decrease counter
- Helper thread checks the counter, switch lock base on its value, e.g.
- (0,1] CAS
- [2,8] qspinlock
- (8,+inf) TCLock
Plan B
Consider how long the threads have been waiting
For each thread, calculate time between lock() & unlock()Helper thread maintains recent waiting times (e.g. 32 lateast values)Helper thread switch base on average waiting time?
Can also keep statistics of:
- waiting time
- overall throughput