From b6422f89851f2bcf34043daac2cf961199345f0e Mon Sep 17 00:00:00 2001 From: Conghui Chen Date: Fri, 17 Jul 2020 23:53:43 +0800 Subject: [PATCH] hv: remove 'running' from vcpu structure vcpu->running is duplicated with THREAD_STS_RUNNING status of thread object. Introduce an API sleep_thread_sync(), which can utilize the inner status of thread object, to do the sync sleep for zombie_vcpu(). Tracked-On: #5057 Signed-off-by: Conghui Chen Reviewed-by: Shuo A Liu Acked-by: Eddie Dong --- hypervisor/arch/x86/guest/vcpu.c | 14 ++++---------- hypervisor/common/schedule.c | 8 ++++++++ hypervisor/include/arch/x86/guest/vcpu.h | 1 - hypervisor/include/common/schedule.h | 1 + 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/hypervisor/arch/x86/guest/vcpu.c b/hypervisor/arch/x86/guest/vcpu.c index a31f80bdf..a204c95a2 100644 --- a/hypervisor/arch/x86/guest/vcpu.c +++ b/hypervisor/arch/x86/guest/vcpu.c @@ -200,7 +200,6 @@ static void vcpu_reset_internal(struct acrn_vcpu *vcpu, enum reset_mode mode) struct acrn_vlapic *vlapic; vcpu->launched = false; - vcpu->running = false; vcpu->arch.nr_sipi = 0U; vcpu->arch.exception_info.exception = VECTOR_INVALID; @@ -731,11 +730,10 @@ void zombie_vcpu(struct acrn_vcpu *vcpu, enum vcpu_state new_state) vcpu_set_state(vcpu, new_state); if (prev_state == VCPU_RUNNING) { - sleep_thread(&vcpu->thread_obj); - } - if (pcpu_id != get_pcpu_id()) { - while (vcpu->running) { - asm_pause(); + if (pcpu_id == get_pcpu_id()) { + sleep_thread(&vcpu->thread_obj); + } else { + sleep_thread_sync(&vcpu->thread_obj); } } } @@ -772,8 +770,6 @@ static void context_switch_out(struct thread_object *prev) ectx->ia32_kernel_gs_base = msr_read(MSR_IA32_KERNEL_GS_BASE); save_xsave_area(ectx); - - vcpu->running = false; } static void context_switch_in(struct thread_object *next) @@ -789,8 +785,6 @@ static void context_switch_in(struct thread_object *next) msr_write(MSR_IA32_KERNEL_GS_BASE, ectx->ia32_kernel_gs_base); rstore_xsave_area(ectx); - - vcpu->running = true; } diff --git a/hypervisor/common/schedule.c b/hypervisor/common/schedule.c index 8709afadc..7a989207c 100644 --- a/hypervisor/common/schedule.c +++ b/hypervisor/common/schedule.c @@ -213,6 +213,14 @@ void sleep_thread(struct thread_object *obj) release_schedule_lock(pcpu_id, rflag); } +void sleep_thread_sync(struct thread_object *obj) +{ + sleep_thread(obj); + while (!is_blocked(obj)) { + asm_pause(); + } +} + void wake_thread(struct thread_object *obj) { uint16_t pcpu_id = obj->pcpu_id; diff --git a/hypervisor/include/arch/x86/guest/vcpu.h b/hypervisor/include/arch/x86/guest/vcpu.h index 052a69e1e..ddfeed0b0 100644 --- a/hypervisor/include/arch/x86/guest/vcpu.h +++ b/hypervisor/include/arch/x86/guest/vcpu.h @@ -265,7 +265,6 @@ struct acrn_vcpu { struct thread_object thread_obj; bool launched; /* Whether the vcpu is launched on target pcpu */ - volatile bool running; /* vcpu is picked up and run? */ struct instr_emul_ctxt inst_ctxt; struct io_request req; /* used by io/ept emulation */ diff --git a/hypervisor/include/common/schedule.h b/hypervisor/include/common/schedule.h index aa2fad463..a561e92c3 100644 --- a/hypervisor/include/common/schedule.h +++ b/hypervisor/include/common/schedule.h @@ -114,6 +114,7 @@ bool need_reschedule(uint16_t pcpu_id); void run_thread(struct thread_object *obj); void sleep_thread(struct thread_object *obj); +void sleep_thread_sync(struct thread_object *obj); void wake_thread(struct thread_object *obj); void kick_thread(const struct thread_object *obj); void yield_current(void);