MTX_DEF versus MTX_SPIN

From: <mdf_at_FreeBSD.org>
Date: Wed, 3 Nov 2010 09:27:07 -0700
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.

Perhaps this comes to me still not understanding exactly how
interrupts work on FreeBSD.  If I capture the stack in a hard
interrupt, it looks something like:

#0 0xffffff87b07f43b5 at rnv_hard_intr+0x35
#1 0xffffffff8026e7ce at ithread_execute_handlers+0x9e
#2 0xffffffff8026ead0 at ithread_loop+0x70
#3 0xffffffff8026b84c at fork_exit+0x9c
#4 0xffffffff804a7f7e at fork_trampoline+0xe

And there the stack ends.  From my perspective, this doesn't look like
anything was actually interrupted.

By way of explaining what I mean, on AIX we defined 10 levels of
software interrupt, and we trained the kernel debugger to understand
the save frames that were acquired on interrupt to print a full stack.
 So a full stack dump might show something like a few frames from one
interrupt handler, then a save area, then a frames from a lower
priority interrupt, then another save area, then the base-level stack.
 In this kind of programming environment, it was important to know at
what interrupt level your handler would execute, so that locks
acquired to synchronize between the top-half and bottom-half were
acquired with interupts disabled to the same level.

So, back to my question.  Is it safe to take a MTX_DEF in a hard
interrupt?  What about a soft interrupt?  I have to assume it's okay
in a soft-interrupt context (swi_sched, callout, etc.), since
softclock() will acquire a MTX_DEF on behalf of a callout.

Thanks,
matthew
Received on Wed Nov 03 2010 - 15:27:09 UTC

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