From: Gautam Menghani <gautam@linux.ibm.com>
To: mpe@ellerman.id.au, npiggin@gmail.com,
christophe.leroy@csgroup.eu, naveen.n.rao@linux.ibm.com,
clg@kaod.org
Cc: Gautam Menghani <gautam@linux.ibm.com>,
linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
kvm@vger.kernel.org
Subject: [RESEND PATCH 2/3] arch/powerpc/kvm: Optimize the server number -> ICP lookup
Date: Mon, 20 May 2024 13:50:09 +0530 [thread overview]
Message-ID: <20240520082014.140697-3-gautam@linux.ibm.com> (raw)
In-Reply-To: <20240520082014.140697-1-gautam@linux.ibm.com>
Given a server number, kvmppc_xics_find_server() does a linear search
over the vcpus of a VM. Optimize this logic by using an array to
maintain the mapping between server number -> icp.
Signed-off-by: Gautam Menghani <gautam@linux.ibm.com>
---
arch/powerpc/kvm/book3s_xics.c | 4 ++--
arch/powerpc/kvm/book3s_xics.h | 10 ++--------
2 files changed, 4 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/kvm/book3s_xics.c b/arch/powerpc/kvm/book3s_xics.c
index 12de526f04c4..1dc2f77571e7 100644
--- a/arch/powerpc/kvm/book3s_xics.c
+++ b/arch/powerpc/kvm/book3s_xics.c
@@ -47,8 +47,6 @@
* TODO
* ====
*
- * - Speed up server# -> ICP lookup (array ? hash table ?)
- *
* - Make ICS lockless as well, or at least a per-interrupt lock or hashed
* locks array to improve scalability
*/
@@ -1062,6 +1060,7 @@ static struct kvmppc_ics *kvmppc_xics_create_ics(struct kvm *kvm,
static int kvmppc_xics_create_icp(struct kvm_vcpu *vcpu, unsigned long server_num)
{
struct kvmppc_icp *icp;
+ struct kvm *kvm = vcpu->kvm;
if (!vcpu->kvm->arch.xics)
return -ENODEV;
@@ -1078,6 +1077,7 @@ static int kvmppc_xics_create_icp(struct kvm_vcpu *vcpu, unsigned long server_nu
icp->state.mfrr = MASKED;
icp->state.pending_pri = MASKED;
vcpu->arch.icp = icp;
+ kvm->arch.xics->icps[server_num] = icp;
XICS_DBG("created server for vcpu %d\n", vcpu->vcpu_id);
diff --git a/arch/powerpc/kvm/book3s_xics.h b/arch/powerpc/kvm/book3s_xics.h
index 8fcb34ea47a4..feeb0897d555 100644
--- a/arch/powerpc/kvm/book3s_xics.h
+++ b/arch/powerpc/kvm/book3s_xics.h
@@ -111,19 +111,13 @@ struct kvmppc_xics {
u32 err_noics;
u32 err_noicp;
struct kvmppc_ics *ics[KVMPPC_XICS_MAX_ICS_ID + 1];
+ DECLARE_FLEX_ARRAY(struct kvmppc_icp *, icps);
};
static inline struct kvmppc_icp *kvmppc_xics_find_server(struct kvm *kvm,
u32 nr)
{
- struct kvm_vcpu *vcpu = NULL;
- unsigned long i;
-
- kvm_for_each_vcpu(i, vcpu, kvm) {
- if (vcpu->arch.icp && nr == vcpu->arch.icp->server_num)
- return vcpu->arch.icp;
- }
- return NULL;
+ return kvm->arch.xics->icps[nr];
}
static inline struct kvmppc_ics *kvmppc_xics_find_ics(struct kvmppc_xics *xics,
--
2.44.0
next prev parent reply other threads:[~2024-05-20 8:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-20 8:20 [RESEND PATCH 0/3] XICS emulation optimizations in KVM for PPC Gautam Menghani
2024-05-20 8:20 ` [RESEND PATCH 1/3] arch/powerpc/kvm: Use bitmap to speed up resend of irqs in ICS Gautam Menghani
2024-05-20 8:20 ` Gautam Menghani [this message]
2024-05-20 8:20 ` [RESEND PATCH 3/3] arch/powerpc/kvm: Reduce lock contention by moving spinlock from ics to irq_state Gautam Menghani
2024-05-29 5:00 ` [RESEND PATCH 0/3] XICS emulation optimizations in KVM for PPC Gautam Menghani
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=20240520082014.140697-3-gautam@linux.ibm.com \
--to=gautam@linux.ibm.com \
--cc=christophe.leroy@csgroup.eu \
--cc=clg@kaod.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=naveen.n.rao@linux.ibm.com \
--cc=npiggin@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).