Date: Wed, 3 Nov 2010 12:40:46 -0400 From: Ryan Stone <rysto32@gmail.com> To: mdf@freebsd.org Cc: freebsd-current@freebsd.org Subject: Re: MTX_DEF versus MTX_SPIN Message-ID: <AANLkTi=fiO6hY9sJB_nRaNURY2KEYxwWzQggnbqWdQcx@mail.gmail.com> In-Reply-To: <AANLkTi=12-dSAZ21DbZgw36YbRGiUq4KZbyCx3SjucPG@mail.gmail.com> References: <AANLkTi=12-dSAZ21DbZgw36YbRGiUq4KZbyCx3SjucPG@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Nov 3, 2010 at 12:27 PM, <mdf@freebsd.org> wrote: > It's not clear to me from the man pages (perhaps I didn't look at the > right one?) in which environments I need a spinlock. =A0For example, I > wouldn't think it's safe to use a MTX_DEF in a hard interrupt handler > (i.e one that was registered with BUS_SETUP_INTR), but I see some code > lying around here that does it and nothing I'm aware of has broken. You can get either a hard interrupt handler(or fast handler in FreeBSD parlance) or a soft handler using BUS_SETUP_INTR. On FreeBSD 7 and later fast interrupt handlers are passed to filter argument to BUS_SETUP_INTR and soft handlers are passed to the ithread argument(on earlier versions you had to pass the INTR_FAST flag to get a fast handler). You are correct that fast interrupt handlers may only acquire spinlocks, not mutexes. Soft interrupt handlers have their own thread associated with them and so it's safe to acquire MTX_DEF locks in that thread. In your particular example you are running from the context of a software interrupt thread, so you are safe to acquire MTX_DEF mutexes.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTi=fiO6hY9sJB_nRaNURY2KEYxwWzQggnbqWdQcx>