Synchronization in drivers (after SMP improvements)
M. Warner Losh
imp at bsdimp.com
Wed May 28 14:19:23 UTC 2008
In message: <483D62D0.6070800 at po4ta.com>
Ilya Bobir <ilya at po4ta.com> writes:
: Alexander Popov wrote:
: > Hi, Benjamin, also Ilya,
: >
: >
: > Thanks for your quick responses. mtx_sleep() would
: > definitely help. Does it mean that user process executing in kernel space is
: > guaranteed not to be preempted between mtx_lock() and mtx_sleep()? Because then
: > I would get a sleeping thread with
: > non-sleepable mutex anyway... or have I been in application
: > development for too long? :-)
: > Regards,
: >
: > Alexander.
: >
: >
:
: According to locking(9) (" Context mode table." at the very bottom) the
: only type of mutex you can use in your interrupt handler is a spin
: mutex. And you are trying to synchronize with an interrupt handler.
: So, the sc->mtx ought to be a spin mutex. While a spin mutex is held
: all interrupts on the current CPU are blocked or deferred (mutex(9),
: DESCRIPTION fifth paragraph) and the thread holding the mutex will not
: be preempted.
That's only true of 'fast' interrupt handlers. Normal Ithread
interrupt hanlders, mutexes are fine since you aren't really in an
interrupt context. If this is indeed a usb device driver, then the
context for a callback routine for an interrupt endpoint really is a
taskqueue...
Warner
More information about the freebsd-drivers
mailing list