]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/xen.git/commit
spinlock: fair read-write locks
authorJennifer Herbert <jennifer.herbert@citrix.com>
Wed, 3 Feb 2016 13:10:33 +0000 (14:10 +0100)
committerJan Beulich <jbeulich@suse.com>
Wed, 3 Feb 2016 13:10:33 +0000 (14:10 +0100)
commit55d8424e4e65c549eb7be4bff6d3c4c77f54afef
tree86cc756b589bbfac37369ebee04aa9ae0f0a9bcc
parent57fa2ce1a188caa222c7e524f2f5b6b34dec099a
spinlock: fair read-write locks

The current rwlocks are write-biased and unfair.  This allows writers
to starve readers in situations where there are many writers (e.g.,
p2m type changes from log dirty updates during domain save).

Replace the current implementation with queued read-write locks which use
a fair spinlock (a ticket lock in this case) to ensure fairness between
readers and writers when they are contended.

This implementation is from the Linux commit 70af2f8a4f48 by Waiman
Long and Peter Zijlstra.

    locking/rwlocks: Introduce 'qrwlocks' - fair, queued rwlocks

    This rwlock uses the arch_spin_lock_t as a waitqueue, and assuming
    the arch_spin_lock_t is a fair lock (ticket,mcs etc..) the
    resulting rwlock is a fair lock.

    It fits in the same 8 bytes as the regular rwlock_t by folding the
    reader and writer count into a single integer, using the remaining
    4 bytes for the arch_spinlock_t.

    Architectures that can single-copy adress bytes can optimize
    queue_write_unlock() with a 0 write to the LSB (the write count).

We do not yet make use of the architecture-specific optimization noted
above.

Signed-off-by: Jennifer Herbert <jennifer.herbert@citrix.com>
Signed-off-by: David Vrabel <david.vrabel@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
xen/common/rwlock.c
xen/common/spinlock.c
xen/include/xen/rwlock.h
xen/include/xen/spinlock.h