From: "Jan Beulich" Subject: [PATCH 2/3] rwlock: allow arch to override read_unlock() atomic Date: Thu, 08 Jan 2015 16:13:29 +0000 Message-ID: <54AEBAB90200007800052C95@mail.emea.novell.com> References: <54AEB7C70200007800052C4D@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part87B270B9.1__=" Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Y9FiH-0006hb-Ni for xen-devel@lists.xenproject.org; Thu, 08 Jan 2015 16:13:33 +0000 In-Reply-To: <54AEB7C70200007800052C4D@mail.emea.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Ian Campbell , Keir Fraser , Ian Jackson , Tim Deegan List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part87B270B9.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On x86, LOCK DEC is cheaper than LOCK CMPXCHG and doesn't require a retry loop around it. Signed-off-by: Jan Beulich --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -333,14 +333,18 @@ int _read_trylock(rwlock_t *lock) return 1; } =20 -void _read_unlock(rwlock_t *lock) -{ - uint32_t x, y; +#ifndef _raw_read_unlock +# define _raw_read_unlock(l) do { \ + uint32_t x =3D (l)->lock, y; \ + while ( (y =3D cmpxchg(&(l)->lock, x, x - 1)) !=3D x ) \ + x =3D y; \ +} while (0) +#endif =20 +inline void _read_unlock(rwlock_t *lock) +{ preempt_enable(); - x =3D lock->lock; - while ( (y =3D cmpxchg(&lock->lock, x, x-1)) !=3D x ) - x =3D y; + _raw_read_unlock(lock); } =20 void _read_unlock_irq(rwlock_t *lock) --- 2014-08-25.orig/xen/include/asm-x86/spinlock.h 2014-10-07 = 14:42:41.000000000 +0200 +++ 2014-08-25/xen/include/asm-x86/spinlock.h 2014-10-07 15:33:18.0000000= 00 +0200 @@ -31,4 +31,7 @@ static always_inline int _raw_spin_trylo return (oldval > 0); } =20 +#define _raw_read_unlock(l) \ + asm volatile ( "lock; dec%z0 %0" : "+m" ((l)->lock) :: "memory" ) + #endif /* __ASM_SPINLOCK_H */ --=__Part87B270B9.1__= Content-Type: text/plain; name="arch-read-unlock.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="arch-read-unlock.patch" rwlock: allow arch to override read_unlock() atomic=0A=0AOn x86, LOCK DEC = is cheaper than LOCK CMPXCHG and doesn't require a=0Aretry loop around = it.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- a/xen/comm= on/spinlock.c=0A+++ b/xen/common/spinlock.c=0A@@ -333,14 +333,18 @@ int = _read_trylock(rwlock_t *lock)=0A return 1;=0A }=0A =0A-void _read_unloc= k(rwlock_t *lock)=0A-{=0A- uint32_t x, y;=0A+#ifndef _raw_read_unlock=0A= +# define _raw_read_unlock(l) do { \=0A+ uint32_t = x =3D (l)->lock, y; \=0A+ while ( (y =3D = cmpxchg(&(l)->lock, x, x - 1)) !=3D x ) \=0A+ x =3D y; = \=0A+} while (0)=0A+#endif=0A =0A+inline void = _read_unlock(rwlock_t *lock)=0A+{=0A preempt_enable();=0A- x =3D = lock->lock;=0A- while ( (y =3D cmpxchg(&lock->lock, x, x-1)) !=3D x = )=0A- x =3D y;=0A+ _raw_read_unlock(lock);=0A }=0A =0A void = _read_unlock_irq(rwlock_t *lock)=0A--- 2014-08-25.orig/xen/include/asm-x86/= spinlock.h 2014-10-07 14:42:41.000000000 +0200=0A+++ 2014-08-25/xen/in= clude/asm-x86/spinlock.h 2014-10-07 15:33:18.000000000 +0200=0A@@ = -31,4 +31,7 @@ static always_inline int _raw_spin_trylo=0A return = (oldval > 0);=0A }=0A =0A+#define _raw_read_unlock(l) \=0A+ asm = volatile ( "lock; dec%z0 %0" : "+m" ((l)->lock) :: "memory" )=0A+=0A = #endif /* __ASM_SPINLOCK_H */=0A --=__Part87B270B9.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part87B270B9.1__=--