svn commit: r308424 - head/sys/arm/broadcom/bcm2835

John Baldwin jhb at freebsd.org
Wed Nov 9 17:05:31 UTC 2016


On Wednesday, November 09, 2016 05:10:09 PM Hans Petter Selasky wrote:
> Hi,
> 
> On 11/09/16 16:02, John Baldwin wrote:
>  > On the other hand, doing the wakeup outside of the lock
> > avoids preempting during the wakeup only to immediately block on the lock and
> > switch back to the thread that did the wakeup.
> 
> This can be predicted and avoided by the turnstiles iff cv_signal() is 
> used under a lock. Else not.

It isn't predicted and avoided by turnstiles.  In particular, the cv_signal has
no idea what lock is associated, so it can't try to do something "smart" and
move the thread from the sleepq to the lockq.  You will pay the double context
switch.

> Won't doing the wakeup outside the lock cause double preemtion? First at 
> mtx_unlock() and then inside cv_signal()/cv_broadcast().

No.  The other thread can't be blocked on both the mutex and cv.  If the
thread is blocked on the mutex and you preempt to it, then it won't ever
bother sleeping on the cv anyway (and the cv_signal will be a nop once
the awakening thread resumes).

-- 
John Baldwin


More information about the svn-src-head mailing list