From: Sasha Levin Date: Mon, 30 May 2011 17:27:55 +0000 (+0300) Subject: kvm tools: Add a brlock X-Git-Tag: next-20110824~3^2~240 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=b2604398c296be2c3c8157d144b2ee0b62491240;p=karo-tx-linux.git kvm tools: Add a brlock 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 which read from the locked data are VCPU threads, and the only writer isn't a VCPU thread. Signed-off-by: Sasha Levin Signed-off-by: Pekka Enberg --- diff --git a/tools/kvm/include/kvm/brlock.h b/tools/kvm/include/kvm/brlock.h new file mode 100644 index 000000000000..2e2e0f80f3a1 --- /dev/null +++ b/tools/kvm/include/kvm/brlock.h @@ -0,0 +1,25 @@ +#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 + +#define br_read_lock() barrier() +#define br_read_unlock() barrier() + +#define br_write_lock() kvm__pause() +#define br_write_unlock() kvm__continue() +#endif