Re: MTX_DEF versus MTX_SPIN

From: Ryan Stone <rysto32_at_gmail.com>
Date: Wed, 3 Nov 2010 12:40:46 -0400
On Wed, Nov 3, 2010 at 12:27 PM,  <mdf_at_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.  For 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.
Received on Wed Nov 03 2010 - 16:10:00 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:08 UTC