]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/xen.git/commit
use ticket locks for spin locks
authorDavid Vrabel <david.vrabel@citrix.com>
Fri, 15 May 2015 07:49:12 +0000 (09:49 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 15 May 2015 07:49:12 +0000 (09:49 +0200)
commit45fcc4568c5162b00fb3907fb158af82dd484a3d
tree6035a3145febd0ba0ae275883c3e0ec97d5b9ac8
parente13013dbf1d5997915548a3b5f1c39594d8c1d7b
use ticket locks for spin locks

Replace the byte locks with ticket locks.  Ticket locks are: a) fair;
and b) peform better when contented since they spin without an atomic
operation.

The lock is split into two ticket values: head and tail.  A locker
acquires a ticket by (atomically) increasing tail and using the
previous tail value.  A CPU holds the lock if its ticket == head.  The
lock is released by increasing head.

spin_lock_irq() and spin_lock_irqsave() now spin with irqs disabled
(previously, they would spin with irqs enabled if possible).  This is
required to prevent deadlocks when the irq handler tries to take the
same lock with a higher ticket.

Architectures need only provide arch_fetch_and_add() and two barriers:
arch_lock_acquire_barrier() and arch_lock_release_barrier().

Signed-off-by: David Vrabel <david.vrabel@citrix.com>
Reviewed-by: Tim Deegan <tim@xen.org>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/common/spinlock.c
xen/include/asm-arm/system.h
xen/include/asm-x86/system.h
xen/include/xen/spinlock.h