Date: Tue, 23 Feb 2010 11:09:42 -0500 From: John Baldwin <jhb@freebsd.org> To: freebsd-hackers@freebsd.org Cc: shrivatsan@gmail.com, Shrivatsan <shrivatsan_v@yahoo.com> Subject: Re: sched_lock mutex and sleepq_wait Message-ID: <201002231109.42603.jhb@freebsd.org> In-Reply-To: <986041.3700.qm@web112005.mail.gq1.yahoo.com> References: <986041.3700.qm@web112005.mail.gq1.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tuesday 23 February 2010 2:34:11 am Shrivatsan wrote:
> Hi,
>
> I am trying to understand how msleep() routine suspends the currently
> executing thread. I see that msleep() calls sleepq_wait().
>
> What I don't understand here is the way in which sched_lock mutex is
> handled.
>
> I took the following snippet from FreeBSD 6:
>
> sleepq_wait(void *wchan)
> {
> MPASS(!(curthread->td_flags & TDF_SINTR));
> mtx_lock_spin(&sched_lock);
> sleepq_switch(wchan);
> mtx_unlock_spin(&sched_lock);
> }
>
> sched_lock mutex is held, and sleepq_switch() eventually calls
> cpu_switch() which switches to a new thread.
>
> I don't exactly understand when the sched_lock mutex is released.
>
> Can someone please help me?
mi_switch() changes the owner of sched_lock to hand it off to the new thread
during the switch. The new thread then returns from mi_switch() and
eventually returns to something like sleepq_wait() where it unlocks
sched_lock.
--
John Baldwin
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201002231109.42603.jhb>
