[PATCH 2/3] arch/powerpc/kvm: Optimize the server number -> ICP lookup
Gautam Menghani
gautam at linux.ibm.com
Tue May 7 02:17:30 AEST 2024
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 at 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
More information about the Linuxppc-dev
mailing list