Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 May 2013 09:05:57 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        Alfred Perlstein <bright@mu.org>
Cc:        Orit Moskovich <oritm@mellanox.com>, freebsd-arch@freebsd.org
Subject:   Re: FreeBSD spinlock - compatibility layer
Message-ID:  <201305220905.57939.jhb@freebsd.org>
In-Reply-To: <519BDBB0.2070302@mu.org>
References:  <981733489AB3BD4DB24B48340F53E0A55B0CFD79@MTLDAG01.mtl.com> <201305200950.26834.jhb@freebsd.org> <519BDBB0.2070302@mu.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tuesday, May 21, 2013 4:40:16 pm Alfred Perlstein wrote:
> On 5/20/13 9:50 AM, John Baldwin wrote:
> > On Tuesday, May 14, 2013 6:04:21 am Orit Moskovich wrote:
> >> Hi,
> >>
> >> I read about the FreeBSD mutex implementation for spinlock in the
> > compatibility layer.
> >> I might be wrong, but I noticed a code section that might be problematic:
> >>
> >> Taken from
> > 
http://svn.freebsd.org/base/release/9.1.0/sys/ofed/include/linux/spinlock.h:
> >> static inline void
> >> spin_lock_init(spinlock_t *lock)
> >> {
> >>
> >>          memset(&lock->m, 0, sizeof(lock->m));
> >>          mtx_init(&lock->m, "lnxspin", NULL, MTX_DEF | MTX_NOWITNESS);
> >> }
> >>
> >> But MTX_DEF initializes mutex as a sleep mutex:
> >>
> >> By default, MTX_DEF mutexes will context switch when they are already
> >>
> >>       held.
> >>
> >>
> >> There is a flag MTX_SPIN Which I think is the right one in this case .
> >>
> >>
> >>
> >> I'd appreciate your take on this issue.
> > Since FreeBSD uses a different approach to interrupt handlers (they run in
> > threads, not in the bottom half), a regular mutex may in fact give the 
closest
> > match to the same semantics.  Regular mutexes are also cheaper and in 
general
> > preferable to spin mutexes whenever possible.
> >
> 
> Sure, but is it possible that someone might want some of the other 
> guarantees of MTX_SPIN spinlocks such as:
> 
> critical section/non-pre-emptable/non-migrating on cpu/latency versus 
> throughput ?

Probably not.  For example, on FreeBSD you want your driver lock to be 
preempted by an interrupt to avoid higher interrupt latency for filter 
handlers.  Most drivers should not need temporary pinning.  If they want to 
pin work to threads they should bind threads or IRQs to specific CPUs, not 
rely on temporary pinning.

-- 
John Baldwin



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