FreeBSD spinlock - compatibility layer

Orit Moskovich oritm at mellanox.com
Wed May 22 13:54:55 UTC 2013


>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?

-----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.

--
John Baldwin


More information about the freebsd-arch mailing list