Skip to content

Commit

Permalink
KVM: Calculate available entries in coalesced mmio ring
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
avikivity committed Sep 10, 2009
1 parent 596ae89 commit 105f8d4
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions virt/kvm/coalesced_mmio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down

0 comments on commit 105f8d4

Please sign in to comment.