hv:cleanup vcpu state

-- remove VCPU_PAUSED and resume_vcpu
-- remove vcpu->prev_state in vcpu structure
-- rename pause_vcpu to zombie_vcpu

Tracked-On: #4320
Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com>
This commit is contained in:
Mingqiang Chi 2020-05-19 15:59:51 +08:00 committed by wenlingz
parent 8287cfac6c
commit f994b5ffaf
8 changed files with 12 additions and 47 deletions

View File

@ -159,10 +159,7 @@ lifecycle:
.. doxygenfunction:: create_vcpu .. doxygenfunction:: create_vcpu
:project: Project ACRN :project: Project ACRN
.. doxygenfunction:: pause_vcpu .. doxygenfunction:: zombie_vcpu
:project: Project ACRN
.. doxygenfunction:: resume_vcpu
:project: Project ACRN :project: Project ACRN
.. doxygenfunction:: reset_vcpu .. doxygenfunction:: reset_vcpu

View File

@ -719,17 +719,18 @@ void reset_vcpu(struct acrn_vcpu *vcpu, enum reset_mode mode)
vcpu_set_state(vcpu, VCPU_INIT); vcpu_set_state(vcpu, VCPU_INIT);
} }
void pause_vcpu(struct acrn_vcpu *vcpu, enum vcpu_state new_state) void zombie_vcpu(struct acrn_vcpu *vcpu, enum vcpu_state new_state)
{ {
enum vcpu_state prev_state;
uint16_t pcpu_id = pcpuid_from_vcpu(vcpu); uint16_t pcpu_id = pcpuid_from_vcpu(vcpu);
pr_dbg("vcpu%hu paused, new state: %d", vcpu->vcpu_id, new_state); pr_dbg("vcpu%hu paused, new state: %d", vcpu->vcpu_id, new_state);
if (((vcpu->state == VCPU_RUNNING) || (vcpu->state == VCPU_INIT)) && (new_state == VCPU_ZOMBIE)) { if (((vcpu->state == VCPU_RUNNING) || (vcpu->state == VCPU_INIT)) && (new_state == VCPU_ZOMBIE)) {
vcpu->prev_state = vcpu->state; prev_state = vcpu->state;
vcpu_set_state(vcpu, new_state); vcpu_set_state(vcpu, new_state);
if (vcpu->prev_state == VCPU_RUNNING) { if (prev_state == VCPU_RUNNING) {
sleep_thread(&vcpu->thread_obj); sleep_thread(&vcpu->thread_obj);
} }
if (pcpu_id != get_pcpu_id()) { if (pcpu_id != get_pcpu_id()) {
@ -740,22 +741,6 @@ void pause_vcpu(struct acrn_vcpu *vcpu, enum vcpu_state new_state)
} }
} }
int32_t resume_vcpu(struct acrn_vcpu *vcpu)
{
int32_t ret = -1;
pr_dbg("vcpu%hu resumed", vcpu->vcpu_id);
if (vcpu->state == VCPU_PAUSED) {
vcpu_set_state(vcpu, vcpu->prev_state);
if (vcpu->state == VCPU_RUNNING) {
wake_thread(&vcpu->thread_obj);
}
ret = 0;
}
return ret;
}
void save_xsave_area(struct ext_context *ectx) void save_xsave_area(struct ext_context *ectx)
{ {
ectx->xcr0 = read_xcr(0); ectx->xcr0 = read_xcr(0);

View File

@ -1110,7 +1110,7 @@ vlapic_process_init_sipi(struct acrn_vcpu* target_vcpu, uint32_t mode, uint32_t
if (target_vcpu->state != VCPU_INIT) { if (target_vcpu->state != VCPU_INIT) {
/* put target vcpu to INIT state and wait for SIPI */ /* put target vcpu to INIT state and wait for SIPI */
pause_vcpu(target_vcpu, VCPU_ZOMBIE); zombie_vcpu(target_vcpu, VCPU_ZOMBIE);
reset_vcpu(target_vcpu, INIT_RESET); reset_vcpu(target_vcpu, INIT_RESET);
} }
/* new cpu model only need one SIPI to kick AP run, /* new cpu model only need one SIPI to kick AP run,

View File

@ -698,7 +698,7 @@ void pause_vm(struct acrn_vm *vm)
((is_rt_vm(vm)) && (vm->state == VM_READY_TO_POWEROFF)) || ((is_rt_vm(vm)) && (vm->state == VM_READY_TO_POWEROFF)) ||
(vm->state == VM_CREATED)) { (vm->state == VM_CREATED)) {
foreach_vcpu(i, vm, vcpu) { foreach_vcpu(i, vm, vcpu) {
pause_vcpu(vcpu, VCPU_ZOMBIE); zombie_vcpu(vcpu, VCPU_ZOMBIE);
} }
vm->state = VM_PAUSED; vm->state = VM_PAUSED;
} }

View File

@ -35,7 +35,7 @@ void vcpu_thread(struct thread_object *obj)
ret = acrn_handle_pending_request(vcpu); ret = acrn_handle_pending_request(vcpu);
if (ret < 0) { if (ret < 0) {
pr_fatal("vcpu handling pending request fail"); pr_fatal("vcpu handling pending request fail");
pause_vcpu(vcpu, VCPU_ZOMBIE); zombie_vcpu(vcpu, VCPU_ZOMBIE);
/* Fatal error happened (triple fault). Stop the vcpu running. */ /* Fatal error happened (triple fault). Stop the vcpu running. */
continue; continue;
} }
@ -47,7 +47,7 @@ void vcpu_thread(struct thread_object *obj)
ret = run_vcpu(vcpu); ret = run_vcpu(vcpu);
if (ret != 0) { if (ret != 0) {
pr_fatal("vcpu resume failed"); pr_fatal("vcpu resume failed");
pause_vcpu(vcpu, VCPU_ZOMBIE); zombie_vcpu(vcpu, VCPU_ZOMBIE);
/* Fatal error happened (resume vcpu failed). Stop the vcpu running. */ /* Fatal error happened (resume vcpu failed). Stop the vcpu running. */
continue; continue;
} }

View File

@ -64,7 +64,7 @@ int32_t hcall_sos_offline_cpu(struct acrn_vm *vm, uint64_t lapicid)
ret = -1; ret = -1;
break; break;
} }
pause_vcpu(vcpu, VCPU_ZOMBIE); zombie_vcpu(vcpu, VCPU_ZOMBIE);
offline_vcpu(vcpu); offline_vcpu(vcpu);
} }
} }

View File

@ -655,9 +655,6 @@ static int32_t shell_list_vcpu(__unused int32_t argc, __unused char **argv)
case VCPU_INIT: case VCPU_INIT:
(void)strncpy_s(vcpu_state_str, 32U, "Init", 32U); (void)strncpy_s(vcpu_state_str, 32U, "Init", 32U);
break; break;
case VCPU_PAUSED:
(void)strncpy_s(vcpu_state_str, 32U, "Paused", 32U);
break;
case VCPU_RUNNING: case VCPU_RUNNING:
(void)strncpy_s(vcpu_state_str, 32U, "Running", 32U); (void)strncpy_s(vcpu_state_str, 32U, "Running", 32U);
break; break;

View File

@ -136,7 +136,6 @@ enum vcpu_state {
VCPU_OFFLINE = 0U, VCPU_OFFLINE = 0U,
VCPU_INIT, VCPU_INIT,
VCPU_RUNNING, VCPU_RUNNING,
VCPU_PAUSED,
VCPU_ZOMBIE, VCPU_ZOMBIE,
}; };
@ -256,8 +255,6 @@ struct acrn_vcpu {
uint16_t vcpu_id; /* virtual identifier for VCPU */ uint16_t vcpu_id; /* virtual identifier for VCPU */
struct acrn_vm *vm; /* Reference to the VM this VCPU belongs to */ struct acrn_vm *vm; /* Reference to the VM this VCPU belongs to */
/* State of this VCPU before suspend */
volatile enum vcpu_state prev_state;
volatile enum vcpu_state state; /* State of this VCPU */ volatile enum vcpu_state state; /* State of this VCPU */
struct thread_object thread_obj; struct thread_object thread_obj;
@ -634,25 +631,14 @@ void reset_vcpu(struct acrn_vcpu *vcpu, enum reset_mode mode);
/** /**
* @brief pause the vcpu and set new state * @brief pause the vcpu and set new state
* *
* Change a vCPU state to VCPU_PAUSED or VCPU_ZOMBIE, and make a reschedule request for it. * Change a vCPU state to VCPU_ZOMBIE, and make a reschedule request for it.
* *
* @param[inout] vcpu pointer to vcpu data structure * @param[inout] vcpu pointer to vcpu data structure
* @param[in] new_state the state to set vcpu * @param[in] new_state the state to set vcpu
* *
* @return None * @return None
*/ */
void pause_vcpu(struct acrn_vcpu *vcpu, enum vcpu_state new_state); void zombie_vcpu(struct acrn_vcpu *vcpu, enum vcpu_state new_state);
/**
* @brief resume the vcpu
*
* Change a vCPU state to VCPU_RUNNING, and make a reschedule request for it.
*
* @param[inout] vcpu pointer to vcpu data structure
*
* @return 0 on success, -1 on failure.
*/
int32_t resume_vcpu(struct acrn_vcpu *vcpu);
/** /**
* @brief set the vcpu to running state, then it will be scheculed. * @brief set the vcpu to running state, then it will be scheculed.