public inbox for linuxppc-dev@ozlabs.org 
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel•org>
To: kvm@vger•kernel.org, linux-mips@vger•kernel.org,
	kvmarm@lists•cs.columbia.edu, linuxppc-dev@lists•ozlabs.org,
	Paolo Bonzini <pbonzini@redhat•com>
Cc: "Juergen Gross" <jgross@suse•com>,
	"Huacai Chen" <chenhuacai@kernel•org>,
	"Janosch Frank" <frankja@linux•ibm.com>,
	"David Hildenbrand" <david@redhat•com>,
	"Sean Christopherson" <seanjc@google•com>,
	"Anup Patel" <anup.patel@wdc•com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat•org>,
	"Nicholas Piggin" <npiggin@gmail•com>,
	"Christian Borntraeger" <borntraeger@de•ibm.com>,
	"Aleksandar Markovic" <aleksandar.qemu.devel@gmail•com>,
	"Paul Mackerras" <paulus@samba•org>,
	"James Morse" <james.morse@arm•com>,
	kernel-team@android•com,
	"Claudio Imbrenda" <imbrenda@linux•ibm.com>,
	"Alexandru Elisei" <alexandru.elisei@arm•com>,
	"Suzuki K Poulose" <suzuki.poulose@arm•com>
Subject: [PATCH v2 7/7] KVM: Convert kvm_for_each_vcpu() to using xa_for_each_range()
Date: Tue, 16 Nov 2021 16:04:03 +0000	[thread overview]
Message-ID: <20211116160403.4074052-8-maz@kernel.org> (raw)
In-Reply-To: <20211116160403.4074052-1-maz@kernel.org>

Now that the vcpu array is backed by an xarray, use the optimised
iterator that matches the underlying data structure.

Suggested-by: Sean Christopherson <seanjc@google•com>
Signed-off-by: Marc Zyngier <maz@kernel•org>
---
 include/linux/kvm_host.h | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index dc635fbfd901..d20e33378c63 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -705,11 +705,9 @@ static inline struct kvm_vcpu *kvm_get_vcpu(struct kvm *kvm, int i)
 	return xa_load(&kvm->vcpu_array, i);
 }
 
-#define kvm_for_each_vcpu(idx, vcpup, kvm) \
-	for (idx = 0; \
-	     idx < atomic_read(&kvm->online_vcpus) && \
-	     (vcpup = kvm_get_vcpu(kvm, idx)) != NULL; \
-	     idx++)
+#define kvm_for_each_vcpu(idx, vcpup, kvm)		   \
+	xa_for_each_range(&kvm->vcpu_array, idx, vcpup, 0, \
+			  (atomic_read(&kvm->online_vcpus) - 1))
 
 static inline struct kvm_vcpu *kvm_get_vcpu_by_id(struct kvm *kvm, int id)
 {
-- 
2.30.2


      parent reply	other threads:[~2021-11-16 16:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-16 16:03 [PATCH v2 0/7] KVM: Turn the vcpu array into an xarray Marc Zyngier
2021-11-16 16:03 ` [PATCH v2 1/7] KVM: Move wiping of the kvm->vcpus array to common code Marc Zyngier
2021-11-16 16:03 ` [PATCH v2 2/7] KVM: mips: Use kvm_get_vcpu() instead of open-coded access Marc Zyngier
2021-11-16 16:03 ` [PATCH v2 3/7] KVM: s390: " Marc Zyngier
2021-11-16 16:04 ` [PATCH v2 4/7] KVM: x86: " Marc Zyngier
2021-11-16 16:04 ` [PATCH v2 5/7] KVM: Convert the kvm->vcpus array to a xarray Marc Zyngier
2021-11-16 16:04 ` [PATCH v2 6/7] KVM: Use 'unsigned long' as kvm_for_each_vcpu()'s index Marc Zyngier
2021-11-16 16:04 ` Marc Zyngier [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211116160403.4074052-8-maz@kernel.org \
    --to=maz@kernel$(echo .)org \
    --cc=aleksandar.qemu.devel@gmail$(echo .)com \
    --cc=alexandru.elisei@arm$(echo .)com \
    --cc=anup.patel@wdc$(echo .)com \
    --cc=borntraeger@de$(echo .)ibm.com \
    --cc=chenhuacai@kernel$(echo .)org \
    --cc=david@redhat$(echo .)com \
    --cc=f4bug@amsat$(echo .)org \
    --cc=frankja@linux$(echo .)ibm.com \
    --cc=imbrenda@linux$(echo .)ibm.com \
    --cc=james.morse@arm$(echo .)com \
    --cc=jgross@suse$(echo .)com \
    --cc=kernel-team@android$(echo .)com \
    --cc=kvm@vger$(echo .)kernel.org \
    --cc=kvmarm@lists$(echo .)cs.columbia.edu \
    --cc=linux-mips@vger$(echo .)kernel.org \
    --cc=linuxppc-dev@lists$(echo .)ozlabs.org \
    --cc=npiggin@gmail$(echo .)com \
    --cc=paulus@samba$(echo .)org \
    --cc=pbonzini@redhat$(echo .)com \
    --cc=seanjc@google$(echo .)com \
    --cc=suzuki.poulose@arm$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox