-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Use fair spinlocks in SMP #1488
Description
The spinlock implementation is very simple. Each CPU simply tries to acquire the spinlock via a test and set atomic operation, the first CPU to successfully perform the test and set is the "winner" and gets the spinlock. That CPU is complete arbitrary and not managed in any way.
This kind of spinlock can have adverse effects in SMP because under certain conditions other CPUs may always get the spinlock and one CPU can randomly be delayed for a significant amount of time.
We should consider replacing a fair spinlock implementation that enforces first-in, first out spinlocks. There are several fair spinlock algorithms. Some established and in common use, some simple and some complex, some straight-forward and some more controversial, some have undesirable side-effects. A first step would be to decide on an appropriate fair spinlock algorithm.