From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sasha Levin Subject: [PATCH v2 5/8] kvm tools: Add a brlock Date: Mon, 30 May 2011 11:30:44 +0300 Message-ID: <1306744247-26051-5-git-send-email-levinsasha928@gmail.com> References: <1306744247-26051-1-git-send-email-levinsasha928@gmail.com> Cc: kvm@vger.kernel.org, mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com, Sasha Levin To: penberg@kernel.org Return-path: Received: from mail-ww0-f44.google.com ([74.125.82.44]:35968 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752085Ab1E3Ibo (ORCPT ); Mon, 30 May 2011 04:31:44 -0400 Received: by mail-ww0-f44.google.com with SMTP id 36so3676409wwa.1 for ; Mon, 30 May 2011 01:31:43 -0700 (PDT) In-Reply-To: <1306744247-26051-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: 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 --- tools/kvm/include/kvm/brlock.h | 25 +++++++++++++++++++++++++ 1 files changed, 25 insertions(+), 0 deletions(-) create mode 100644 tools/kvm/include/kvm/brlock.h diff --git a/tools/kvm/include/kvm/brlock.h b/tools/kvm/include/kvm/brlock.h new file mode 100644 index 0000000..1863166 --- /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 -- 1.7.5.rc3