From: Avi Kivity Subject: [PATCH 4/4] KVM: Reduce atomic operations on vcpu->requests Date: Sun, 20 Jun 2010 19:21:58 +0300 Message-ID: <1277050918-12744-5-git-send-email-avi@redhat.com> References: <1277050918-12744-1-git-send-email-avi@redhat.com> Cc: kvm@vger.kernel.org To: Marcelo Tosatti Return-path: Received: from mx1.redhat.com ([209.132.183.28]:61521 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752168Ab0FTQWA (ORCPT ); Sun, 20 Jun 2010 12:22:00 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5KGM0PO018400 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 20 Jun 2010 12:22:00 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5KGLx28028063 for ; Sun, 20 Jun 2010 12:21:59 -0400 In-Reply-To: <1277050918-12744-1-git-send-email-avi@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Usually the vcpu->requests bitmap is sparse, so a test_and_clear_bit() for each request generates a large number of unneeded atomics if a bit is set. Replace with a separate test/clear sequence. This is safe since there is no clear_bit() outside the vcpu thread. Signed-off-by: Avi Kivity --- include/linux/kvm_host.h | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index e706c1e..e478f3f 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -642,7 +642,12 @@ static inline bool kvm_make_check_request(int req, struct kvm_vcpu *vcpu) static inline bool kvm_check_request(int req, struct kvm_vcpu *vcpu) { - return test_and_clear_bit(req, &vcpu->requests); + if (test_bit(req, &vcpu->requests)) { + clear_bit(req, &vcpu->requests); + return true; + } else { + return false; + } } #endif -- 1.7.1