hv:Simplify for-loop when walk through the vcpu

-- Not return NULL for vcpu_from_vid
  We have replaced dynamic memory with static memory for vcpu,
  then if vcpu_id is valid, this API should not return NULL.
-- Simplify the for-loop when walk through the vcpu

Tracked-On: #861
Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com>
Reviewed-by: Li, Fei1 <fei1.li@intel.com>
Reviewed-by: Anthony Xu <anthony.xu@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Mingqiang Chi
2018-10-17 13:56:37 +08:00
committed by wenlingz
parent 813e3abccc
commit 85ececd2d7
5 changed files with 127 additions and 132 deletions

View File

@@ -199,6 +199,9 @@ static inline bool is_vm0(struct vm *vm)
return (vm->vm_id) == 0U;
}
/*
* @pre vcpu_id < CONFIG_MAX_VCPUS_PER_VM
*/
static inline struct vcpu *vcpu_from_vid(struct vm *vm, uint16_t vcpu_id)
{
uint16_t i;
@@ -206,11 +209,10 @@ static inline struct vcpu *vcpu_from_vid(struct vm *vm, uint16_t vcpu_id)
foreach_vcpu(i, vm, vcpu) {
if (vcpu->vcpu_id == vcpu_id) {
return vcpu;
break;
}
}
return NULL;
return vcpu;
}
static inline struct vcpu *vcpu_from_pid(struct vm *vm, uint16_t pcpu_id)