xref: /kvmtool/include/kvm/brlock.h (revision 20b65266ce86e6253eac5813e285e3c30713fe2a)
1 #ifndef KVM__BRLOCK_H
2 #define KVM__BRLOCK_H
3 
4 #include "kvm/kvm.h"
5 #include "kvm/barrier.h"
6 
7 /*
8  * brlock is a lock which is very cheap for reads, but very expensive
9  * for writes.
10  * This lock will be used when updates are very rare and reads are common.
11  * This lock is currently implemented by stopping the guest while
12  * performing the updates. We assume that the only threads whichread from
13  * the locked data are VCPU threads, and the only writer isn't a VCPU thread.
14  */
15 
16 #ifndef barrier
17 #define barrier()		__asm__ __volatile__("": : :"memory")
18 #endif
19 
20 #ifdef KVM_BRLOCK_DEBUG
21 
22 #include "kvm/rwsem.h"
23 
24 #define br_read_lock(kvm)	down_read(&(kvm)->brlock_sem);
25 #define br_read_unlock(kvm)	up_read(&(kvm)->brlock_sem);
26 
27 #define br_write_lock(kvm)	down_write(&(kvm)->brlock_sem);
28 #define br_write_unlock(kvm)	up_write(&(kvm)->brlock_sem);
29 
30 #else
31 
32 #define br_read_lock(kvm)	barrier()
33 #define br_read_unlock(kvm)	barrier()
34 
35 #define br_write_lock(kvm)	kvm__pause(kvm)
36 #define br_write_unlock(kvm)	kvm__continue(kvm)
37 #endif
38 
39 #endif
40