Files
kvmtool/include/kvm/brlock.h
T
Sasha Levin 5124781543 kvm tools: Add debug mode to brlock
Adds a debug mode which allows to switch the brlock into
a big rwlock.
This can be used to verify we don't end up with a BKL kind
of lock with the current brlock implementation.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:44 +01:00

42 lines
1004 B
C

#ifndef KVM__BRLOCK_H
#define KVM__BRLOCK_H
#include "kvm/kvm.h"
#include "kvm/barrier.h"
/*
* brlock is a lock which is very cheap for reads, but very expensive
* for writes.
* This lock will be used when updates are very rare and reads are common.
* This lock is currently implemented by stopping the guest while
* performing the updates. We assume that the only threads whichread from
* the locked data are VCPU threads, and the only writer isn't a VCPU thread.
*/
#ifndef barrier
#define barrier() __asm__ __volatile__("": : :"memory")
#endif
#ifdef KVM_BRLOCK_DEBUG
#include "kvm/rwsem.h"
DECLARE_RWSEM(brlock_sem);
#define br_read_lock() down_read(&brlock_sem);
#define br_read_unlock() up_read(&brlock_sem);
#define br_write_lock() down_write(&brlock_sem);
#define br_write_unlock() up_write(&brlock_sem);
#else
#define br_read_lock() barrier()
#define br_read_unlock() barrier()
#define br_write_lock() kvm__pause()
#define br_write_unlock() kvm__continue()
#endif
#endif