From: Jan Beulich Date: Fri, 9 Jan 2015 16:31:05 +0000 (+0100) Subject: rwlock: allow arch to override read_unlock() atomic X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~3954 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=9f5584f5b6e67627d6d721ed7003469263fdeaa9;p=xen.git rwlock: allow arch to override read_unlock() atomic On x86, LOCK DEC is cheaper than LOCK CMPXCHG and doesn't require a retry loop around it. Signed-off-by: Jan Beulich Reviewed-by: Tim Deegan Reviewed-by: Andrew Cooper --- diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index 13340a3f61..f6925ec5f7 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -333,14 +333,18 @@ int _read_trylock(rwlock_t *lock) return 1; } -void _read_unlock(rwlock_t *lock) -{ - uint32_t x, y; +#ifndef _raw_read_unlock +# define _raw_read_unlock(l) do { \ + uint32_t x = (l)->lock, y; \ + while ( (y = cmpxchg(&(l)->lock, x, x - 1)) != x ) \ + x = y; \ +} while (0) +#endif +inline void _read_unlock(rwlock_t *lock) +{ preempt_enable(); - x = lock->lock; - while ( (y = cmpxchg(&lock->lock, x, x-1)) != x ) - x = y; + _raw_read_unlock(lock); } void _read_unlock_irq(rwlock_t *lock) diff --git a/xen/include/asm-x86/spinlock.h b/xen/include/asm-x86/spinlock.h index 06d9b048b2..757e20b861 100644 --- a/xen/include/asm-x86/spinlock.h +++ b/xen/include/asm-x86/spinlock.h @@ -31,4 +31,7 @@ static always_inline int _raw_spin_trylock(raw_spinlock_t *lock) return (oldval > 0); } +#define _raw_read_unlock(l) \ + asm volatile ( "lock; dec%z0 %0" : "+m" ((l)->lock) :: "memory" ) + #endif /* __ASM_SPINLOCK_H */