mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-16 13:34:30 +00:00
KVM: use heuristic for fast VCPU lookup by id
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 <borntraeger@de.ibm.com> Reviewed-by: Dominik Dingel <dingel@linux.vnet.ibm.com> Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com> Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
This commit is contained in:
parent
e09fefdeeb
commit
c896939f7c
@ -472,6 +472,11 @@ static inline struct kvm_vcpu *kvm_get_vcpu_by_id(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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user