Re:3.7X speedup from removing a call to sleep
by planckscnst on Sunday September 02, 2012 @08:21AM
(#4466850)
They are encouraged in the Linux kernel in places where it is nessesary to lock for a very short time. Using mutexes takes a bit of overhead, so they can't give you very short sleep times; that is when spinlocks have to be used.
Re:3.7X speedup from removing a call to sleep
by cperciva on Sunday September 02, 2012 @09:01AM
(#4466909)
In FreeBSD the vast majority of sleep lock acquisitions are uncontended and end up being a single compare-and-exchange -- very fast. Spin locks are slightly more work, since we disable interrupts during them.
Re:3.7X speedup from removing a call to sleep
by raverbashing on Sunday September 02, 2012 @09:02AM
(#4466911)
Exactly
Spinlocks in linux are the "last resource locks", usually in kernel code only in situations where you can't have the scheduler kicking in but can have a race condition (in SMP systems usually)
So it's basically interrupt handlers.
Re:3.7X speedup from removing a call to sleep
by Flow on Sunday September 02, 2012 @08:48AM
(#4466879)
It sounds smart but it occurred to me that that I can only think of two situations where a spinlock needs to be promoted. 1. Too many cores access that tiny portion of the system at the same time or 2) a bug(like using a spinlock where something else should be used and a more old-fashioned bug).
Will 1) really happen often enough to not use simple spin locks?
That said, our sleep locks are actually adaptive locks, so on SMP systems they'll spin for a bit before giving up and asking to be descheduled.