From owner-svn-src-projects@FreeBSD.ORG Wed Aug 4 12:10:34 2010 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 30C051065674; Wed, 4 Aug 2010 12:10:34 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 0A3A68FC24; Wed, 4 Aug 2010 12:10:34 +0000 (UTC) Received: from fledge.watson.org (fledge.watson.org [65.122.17.41]) by cyrus.watson.org (Postfix) with ESMTPS id 8D81B46BC0; Wed, 4 Aug 2010 08:10:33 -0400 (EDT) Date: Wed, 4 Aug 2010 13:10:33 +0100 (BST) From: Robert Watson X-X-Sender: robert@fledge.watson.org To: Jeff Roberson In-Reply-To: <201008030838.o738cQaS090469@svn.freebsd.org> Message-ID: References: <201008030838.o738cQaS090469@svn.freebsd.org> User-Agent: Alpine 2.00 (BSF 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: svn-src-projects@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r210790 - projects/ofed/head/sys/ofed/include/linux X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Aug 2010 12:10:34 -0000 On Tue, 3 Aug 2010, Jeff Roberson wrote: > - Convert the linux semaphores to use BSD sempahores rather than sx locks. > There are places where we need counting semaphore semantics. This is > unfortunate since sema(9) is not implemented with the most expedient > possible mechanism. sema(9) also has near-zero consumers in the tree, hence a lack of optimization focus, etc. In many ways it would be nice to make it go away simply to narrow the menu on synchronization primitives a bit. Of course, that would mean not introducing new consumers... :-) Robert > > Sponsored by: Isilon Systems, iX Systems, and Panasas. > > Modified: > projects/ofed/head/sys/ofed/include/linux/semaphore.h > > Modified: projects/ofed/head/sys/ofed/include/linux/semaphore.h > ============================================================================== > --- projects/ofed/head/sys/ofed/include/linux/semaphore.h Tue Aug 3 08:37:16 2010 (r210789) > +++ projects/ofed/head/sys/ofed/include/linux/semaphore.h Tue Aug 3 08:38:25 2010 (r210790) > @@ -30,25 +30,35 @@ > > #include > #include > -#include > +#include > > +/* > + * XXX BSD semaphores are disused and slow. They also do not provide a > + * sema_wait_sig method. This must be resolved eventually. > + */ > struct semaphore { > - struct sx sx; > + struct sema sema; > }; > > -#define init_MUTEX(_rw) sx_init_flags(&(_rw)->sx, \ > - "lnxsema", SX_NOWITNESS) > -#define down(_rw) sx_xlock(&(_rw)->sx) > -#define down_interruptible(_rw) sx_xlock_sig(&(_rw)->sx) > -#define down_trylock(_rw) !sx_try_xlock(&(_rw)->sx) > -#define up(_rw) sx_xunlock(&(_rw)->sx) > +#define down(_sem) sema_wait(&(_sem)->sema) > +#define down_interruptible(_sem) sema_wait(&(_sem)->sema), 0 > +#define down_trylock(_sem) !sema_trywait(&(_sem)->sema) > +#define up(_sem) sema_post(&(_sem)->sema) > > static inline void > -sema_init(struct semaphore *sem, int val) > +linux_sema_init(struct semaphore *sem, int val) > { > - init_MUTEX(sem); > - if (val == 0) > - down(sem); > + > + sema_init(&sem->sema, val, "lnxsema"); > } > > +static inline void > +init_MUTEX(struct semaphore *sem) > +{ > + > + sema_init(&sem->sema, 1, "lnxsema"); > +} > + > +#define sema_init linux_sema_init > + > #endif /* _LINUX_SEMAPHORE_H_ */ >