FreeBSD spinlock - compatibility layer

Orit Moskovich oritm at mellanox.com
Wed May 22 17:13:03 UTC 2013


Thanks, I appreciate all your help!

The section about the unbounded sleep wasn't included in the man page I've read so I wan't familiar with that concept...(http://www.unix.com/man-page/FreeBSD/9/locking/)



________________________________________
From: John Baldwin [jhb at freebsd.org]
Sent: Wednesday, May 22, 2013 6:17 PM
To: Orit Moskovich
Cc: freebsd-arch at freebsd.org
Subject: Re: FreeBSD spinlock - compatibility layer

On Wednesday, May 22, 2013 9:48:00 am 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?

Because they are different.  When you block on a lock you propragate your
priority to the lock holder and will resume execution if you are more
important as soon as the holder drops the lock.  In other words, you are going
to make forward progress.

With "event" sleeps like *sleep() and condition variables, there is no owner
to propagate priority to, and the sleep may very well be waiting for some
arbitrary event (such as the arrival of a network packet or completion of an
I/O request), so there is not the same guarantee of making forward progress.

The other half of this that keeps this true is that you are not permitted to
perform "event" sleeps while holding a mutex.  You have to drop the lock while
you wait which frees any threads waiting for the lock to run.  When you block
on a mutex the only thing you are ever waiting on is CPU time for either
yourself or the lock holder to run.

--
John Baldwin


More information about the freebsd-arch mailing list