From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christian Borntraeger Subject: [PATCH 3/4] KVM: use heuristic for fast VCPU lookup by id Date: Thu, 19 Nov 2015 09:37:30 +0100 Message-ID: <1447922251-54261-4-git-send-email-borntraeger@de.ibm.com> References: <1447922251-54261-1-git-send-email-borntraeger@de.ibm.com> Return-path: In-Reply-To: <1447922251-54261-1-git-send-email-borntraeger@de.ibm.com> Sender: kvm-owner@vger.kernel.org List-Archive: List-Post: To: Paolo Bonzini , Alexander Graf , Paul Mackerras , David Hildenbrand Cc: KVM , Cornelia Huck , Jens Freimann , linux-s390 , kvm-ppc@vger.kernel.org, Christian Borntraeger List-ID: From: David Hildenbrand Usually, VCPU ids match the array index. So let's try a fast lookup first before falling back to the slow iteration. Suggested-by: Christian Borntraeger Reviewed-by: Dominik Dingel Reviewed-by: Christian Borntraeger Signed-off-by: David Hildenbrand Signed-off-by: Christian Borntraeger --- include/linux/kvm_host.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index b9f345f..7821137 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -465,6 +465,11 @@ static inline struct kvm_vcpu *kvm_lookup_vcpu(struct kvm *kvm, int id) struct kvm_vcpu *vcpu; int i; + if (id < 0 || id >= KVM_MAX_VCPUS) + return NULL; + vcpu = kvm_get_vcpu(kvm, id); + if (vcpu && vcpu->vcpu_id == id) + return vcpu; kvm_for_each_vcpu(i, vcpu, kvm) if (vcpu->vcpu_id == id) return vcpu; -- 2.3.0