From: Dan Magenheimer Subject: RE: spinlock requests (was RE: [Patch] don't spin with irq disabled) Date: Tue, 31 Mar 2009 13:12:37 +0000 (GMT) Message-ID: References: <49D0629F.5020708@fujitsu-siemens.com> Mime-Version: 1.0 Content-Type: text/plain; charset=Windows-1252 Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <49D0629F.5020708@fujitsu-siemens.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Juergen Gross Cc: xen-devel@lists.xensource.com, Keir Fraser List-Id: xen-devel@lists.xenproject.org Thanks Juergen. Do you know of any GPLv2 code that implements this improved rwlock solution? (I don't think Linux does, does it?) Dan > -----Original Message----- > From: Juergen Gross [mailto:juergen.gross@fujitsu-siemens.com] > Sent: Monday, March 30, 2009 12:12 AM > To: Dan Magenheimer > Cc: Keir Fraser; Jan Beulich; xen-devel@lists.xensource.com > Subject: Re: spinlock requests (was RE: [Xen-devel] [Patch] don't spin > with irq disabled) >=20 >=20 > Dan Magenheimer wrote: > > Keir (and/or others) -- > >=20 > > If you are messing around in the spinlock code anyway, > > I have a couple of requests. Tmem needs: > >=20 > > rw_is_write_locked(rwlock_t *lock) > >=20 > > and > >=20 > > write_trylock(rwlock_t *lock) > >=20 > > I implemented the latter by grabbing the C code from Linux > > and it seems to work, but it would be nice if it was > > consistent with the other lock code in xen and > > my asm statement understanding is too poor to try. > >=20 > > For rw_is_write_locked(), I had a devil of a time > > because of what appeared to be a weird code generated > > race; the obvious simple implementation failed > > periodically... apparently due to racing against > > try_readlock attempts! (I use it in an ASSERT so it > > was a rather noticeable and spectacular failure!) > > The workaround I used below is a horrible hack > > but I haven't had problems since. > >=20 > > Thanks, > > Dan >=20 > Dan, >=20 > if you are planning to use rw_locks you should be aware that=20 > the current > implementation in Xen is sub-optimal on systems with high=20 > processor counts. > Read locks always succeed when other readers are already=20 > holding the lock, > even if a writer is waiting for the lock. If there are many=20 > potential readers > they might (in theory) lock out a writer for rather long times. > A better solution would be to stop further readers to acquire=20 > the lock if a > writer is waiting for it. >=20 > Juergen >=20 > --=20 > Juergen Gross Principal Developer > IP SW OS6 Telephone: +49 (0) 89 636 47950 > Fujitsu Siemens Computers e-mail:=20 > juergen.gross@fujitsu-siemens.com > Otto-Hahn-Ring 6 Internet: www.fujitsu-siemens.com > D-81739 Muenchen Company details:=20 www.fujitsu-siemens.com/imprint.html