FreeBSD spinlock - compatibility layer

Eric van Gyzen eric at vangyzen.net
Wed May 22 14:08:18 UTC 2013


On 05/22/2013 08:48, Orit Moskovich wrote:
> From the mutex man page " By default, MTX_DEF mutexes will context switch when they are already held."
> How is sleeping forbidden, but blocking on a mutex that might context switch is ok?

The duration is the distinction.  See the "Bounded vs. unbounded sleep"
section in the locking(9) man page.  In fact, it would serve you well to
read that entire man page.

> -----Original Message-----
> From: John Baldwin [mailto:jhb at freebsd.org] 
> Sent: Wednesday, May 22, 2013 04:06 PM
> To: Orit Moskovich
> Cc: freebsd-arch at freebsd.org
> Subject: Re: FreeBSD spinlock - compatibility layer
>
> On Wednesday, May 22, 2013 2:14:51 am Orit Moskovich wrote:
>> From what I've read in "FreeBSD - device drivers" book by Joseph Kong 
>> on
> interrupt handling, you cannot voluntarily context switch (that is, sleep) in interrupt threads .
>
> That is not the same thing.  By sleep it means call a *sleep() function or wait on a cond var.  Not block on a mutex or rwlock.
>
>> In any case, I think that the functionality of spin mutex should 
>> remain as
> is, and not modified to sleep mutex, as it can be used in places that sleep mustn't be used, or that require the properties of the spin due to performance considerations.
>
> No, spin locks are _slower_ and reduce performance.  FreeBSD is much more like Solaris in this regard.  Spin mutexes on FreeBSD are similar to dispatcher locks in Solaris which 99% of the kernel should never use.


More information about the freebsd-arch mailing list