From owner-freebsd-arch@FreeBSD.ORG Mon May 20 20:42:10 2013 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id EEE0F261 for ; Mon, 20 May 2013 20:42:10 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) by mx1.freebsd.org (Postfix) with ESMTP id B7BC0184D for ; Mon, 20 May 2013 20:42:10 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 71858B948; Mon, 20 May 2013 16:42:09 -0400 (EDT) From: John Baldwin To: freebsd-arch@freebsd.org Subject: Re: FreeBSD spinlock - compatibility layer Date: Mon, 20 May 2013 09:50:26 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p25; KDE/4.5.5; amd64; ; ) References: <981733489AB3BD4DB24B48340F53E0A55B0CFD79@MTLDAG01.mtl.com> In-Reply-To: <981733489AB3BD4DB24B48340F53E0A55B0CFD79@MTLDAG01.mtl.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201305200950.26834.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Mon, 20 May 2013 16:42:09 -0400 (EDT) Cc: Orit Moskovich X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 May 2013 20:42:11 -0000 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. -- John Baldwin