Switch policy design
coconutnut

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.

  1. Add a global counter
  2. When calling lock() & unlock(), increase & decrease counter
  3. 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

  1. For each thread, calculate time between lock() & unlock()
  2. Helper thread maintains recent waiting times (e.g. 32 lateast values)
  3. Helper thread switch base on average waiting time?

Can also keep statistics of:

  1. waiting time
  2. overall throughput