diff options
author | David Hildenbrand <dahi@linux.vnet.ibm.com> | 2015-11-05 09:55:08 +0100 |
---|---|---|
committer | Christian Borntraeger <borntraeger@de.ibm.com> | 2015-11-30 12:47:04 +0100 |
commit | c896939f7cff767091b5d84587cd144e5d3613b7 (patch) | |
tree | 33dedfeaca80a17888e1c3bf06a010cadf2ea759 /include/linux/kvm_host.h | |
parent | e09fefdeeb517ff653516dea8a882ce001e99237 (diff) |
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>
Diffstat (limited to 'include/linux/kvm_host.h')
-rw-r--r-- | include/linux/kvm_host.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 29119193a19f..a754fc08e194 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -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; |