Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 May 2009 14:37:48 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        Kip Macy <kmacy@freebsd.org>
Cc:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   Re: svn commit: r192604 - in user/kmacy/releng_7_2_fcs/sys: dev/hwpmc sys
Message-ID:  <200905261437.49148.jhb@freebsd.org>
In-Reply-To: <3c1674c90905261118y282d9b0fn7d54630f507d8363@mail.gmail.com>
References:  <200905222145.n4MLjhm3019802@svn.freebsd.org> <200905260830.36831.jhb@freebsd.org> <3c1674c90905261118y282d9b0fn7d54630f507d8363@mail.gmail.com>

index | next in thread | previous in thread | raw e-mail

On Tuesday 26 May 2009 2:18:00 pm Kip Macy wrote:
> On Tue, May 26, 2009 at 5:30 AM, John Baldwin <jhb@freebsd.org> wrote:
> > On Friday 22 May 2009 5:45:43 pm Kip Macy wrote:
> >> Author: kmacy
> >> Date: Fri May 22 21:45:43 2009
> >> New Revision: 192604
> >> URL: http://svn.freebsd.org/changeset/base/192604
> >>
> >> Log:
> >>   - remove pmc_kthread_mtx
> >>   - replace sleep/wakeup on kthread with a condvar
> >
> > If you do not sleep on the kthread/kproc when waiting for a kthread to
> > exit, then you open up a race window.  Usually this matters more for
> > any kthreads that live in a module since the race allows the module to
> > be unmapped before the thread is finished executing code from the module
> > resulting in a fatal page fault in the kernel.
> 
> 
> Yes, that is why the kthread explicitly calls cv_signal after clearing
> the kthread pointer.

Umm, that doesn't help.  Your kthread's main routine is "physically" located 
in your kld.  It needs to get into the text of kthread_exit() before it is 
safe for your module to unload, and so you have to sleep on the kthread/kproc 
pointer to wait for the wakeup in kthread_exit() to fire.  You could have 
easily used msleep_spin() for this w/o hacking up condvar's to support spin 
locks too, FWIW.

-- 
John Baldwin


help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905261437.49148.jhb>