Commit 105f8d40 authored by Avi Kivity's avatar Avi Kivity

KVM: Calculate available entries in coalesced mmio ring

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: default avatarAvi Kivity <avi@redhat.com>
parent 596ae895
...@@ -24,7 +24,8 @@ static int coalesced_mmio_in_range(struct kvm_io_device *this, ...@@ -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_dev *dev = to_mmio(this);
struct kvm_coalesced_mmio_zone *zone; struct kvm_coalesced_mmio_zone *zone;
int next; struct kvm_coalesced_mmio_ring *ring;
unsigned avail;
int i; int i;
if (!is_write) if (!is_write)
...@@ -40,10 +41,9 @@ static int coalesced_mmio_in_range(struct kvm_io_device *this, ...@@ -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 * check if we don't meet the first used entry
* there is always one unused entry in the buffer * there is always one unused entry in the buffer
*/ */
ring = dev->kvm->coalesced_mmio_ring;
next = (dev->kvm->coalesced_mmio_ring->last + 1) % avail = (ring->first - ring->last - 1) % KVM_COALESCED_MMIO_MAX;
KVM_COALESCED_MMIO_MAX; if (avail < 1) {
if (next == dev->kvm->coalesced_mmio_ring->first) {
/* full */ /* full */
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment