From patchwork Sun Aug 16 09:29:50 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 41691 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n7G9Y7Vx007890 for ; Sun, 16 Aug 2009 09:34:10 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754724AbZHPJce (ORCPT ); Sun, 16 Aug 2009 05:32:34 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754094AbZHPJcc (ORCPT ); Sun, 16 Aug 2009 05:32:32 -0400 Received: from mx2.redhat.com ([66.187.237.31]:45361 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754060AbZHPJaN (ORCPT ); Sun, 16 Aug 2009 05:30:13 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n7G9UFch032049; Sun, 16 Aug 2009 05:30:15 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n7G9UDex023492; Sun, 16 Aug 2009 05:30:14 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n7G9UA2X005079; Sun, 16 Aug 2009 05:30:12 -0400 Received: from localhost.localdomain (cleopatra.tlv.redhat.com [10.35.255.11]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id 4D518250AF2; Sun, 16 Aug 2009 12:30:10 +0300 (IDT) From: Avi Kivity To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 30/48] KVM: Calculate available entries in coalesced mmio ring Date: Sun, 16 Aug 2009 12:29:50 +0300 Message-Id: <1250415008-17175-31-git-send-email-avi@redhat.com> In-Reply-To: <1250415008-17175-1-git-send-email-avi@redhat.com> References: <1250415008-17175-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Instead of checking whether we'll wrap around, calculate how many entries are available, and check whether we have enough (just one) for the pending mmio. By itself, this doesn't change anything, but it paves the way for making this function lockless. Signed-off-by: Avi Kivity --- virt/kvm/coalesced_mmio.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/virt/kvm/coalesced_mmio.c b/virt/kvm/coalesced_mmio.c index c4c7ec2..7549068 100644 --- a/virt/kvm/coalesced_mmio.c +++ b/virt/kvm/coalesced_mmio.c @@ -24,7 +24,8 @@ static int coalesced_mmio_in_range(struct kvm_io_device *this, { struct kvm_coalesced_mmio_dev *dev = to_mmio(this); struct kvm_coalesced_mmio_zone *zone; - int next; + struct kvm_coalesced_mmio_ring *ring; + unsigned avail; int i; if (!is_write) @@ -40,10 +41,9 @@ static int coalesced_mmio_in_range(struct kvm_io_device *this, * check if we don't meet the first used entry * there is always one unused entry in the buffer */ - - next = (dev->kvm->coalesced_mmio_ring->last + 1) % - KVM_COALESCED_MMIO_MAX; - if (next == dev->kvm->coalesced_mmio_ring->first) { + ring = dev->kvm->coalesced_mmio_ring; + avail = (ring->first - ring->last - 1) % KVM_COALESCED_MMIO_MAX; + if (avail < 1) { /* full */ return 0; }