From 53d4a7169bafcc75f599113e43273d9249e834e0 Mon Sep 17 00:00:00 2001 From: Conghui Chen Date: Fri, 17 Jul 2020 22:24:31 +0800 Subject: [PATCH] hv: remove kick_thread from scheduler module kick_thread function is only used by kick_vcpu to kick vcpu out of non-root mode, the implementation in it is sending IPI to target CPU if target obj is running and target PCPU is not current one; while for runnable obj, it will just make reschedule request. So the kick_thread is not actually belong to scheduler module, we can drop it and just do the cpu notification in kick_vcpu. Tracked-On: #5057 Signed-off-by: Conghui Chen Reviewed-by: Shuo A Liu Acked-by: Eddie Dong --- hypervisor/arch/x86/guest/vcpu.c | 15 +++++++++-- hypervisor/common/schedule.c | 33 ------------------------ hypervisor/include/arch/x86/guest/vcpu.h | 2 +- hypervisor/include/common/schedule.h | 1 - 4 files changed, 14 insertions(+), 37 deletions(-) diff --git a/hypervisor/arch/x86/guest/vcpu.c b/hypervisor/arch/x86/guest/vcpu.c index a204c95a2..42f71507e 100644 --- a/hypervisor/arch/x86/guest/vcpu.c +++ b/hypervisor/arch/x86/guest/vcpu.c @@ -17,6 +17,7 @@ #include #include #include +#include /* stack_frame is linked with the sequence of stack operation in arch_switch_to() */ struct stack_frame { @@ -672,9 +673,19 @@ void offline_vcpu(struct acrn_vcpu *vcpu) vcpu_set_state(vcpu, VCPU_OFFLINE); } -void kick_vcpu(const struct acrn_vcpu *vcpu) +void kick_vcpu(struct acrn_vcpu *vcpu) { - kick_thread(&vcpu->thread_obj); + uint16_t pcpu_id = pcpuid_from_vcpu(vcpu); + + if ((get_pcpu_id() != pcpu_id) && + (per_cpu(vmcs_run, pcpu_id) == vcpu->arch.vmcs)) { + if (is_lapic_pt_enabled(vcpu)) { + /* For lapic-pt vCPUs */ + send_single_nmi(pcpu_id); + } else { + send_single_ipi(pcpu_id, NOTIFY_VCPU_VECTOR); + } + } } /* diff --git a/hypervisor/common/schedule.c b/hypervisor/common/schedule.c index 7a989207c..8dee0f41a 100644 --- a/hypervisor/common/schedule.c +++ b/hypervisor/common/schedule.c @@ -24,11 +24,6 @@ static inline bool is_blocked(const struct thread_object *obj) return obj->status == THREAD_STS_BLOCKED; } -static inline bool is_runnable(const struct thread_object *obj) -{ - return obj->status == THREAD_STS_RUNNABLE; -} - static inline bool is_running(const struct thread_object *obj) { return obj->status == THREAD_STS_RUNNING; @@ -239,34 +234,6 @@ void wake_thread(struct thread_object *obj) release_schedule_lock(pcpu_id, rflag); } -void kick_thread(const struct thread_object *obj) -{ - uint16_t pcpu_id = obj->pcpu_id; - uint64_t rflag; - - obtain_schedule_lock(pcpu_id, &rflag); - if (is_running(obj)) { - if (get_pcpu_id() != pcpu_id) { - if (obj->notify_mode == SCHED_NOTIFY_IPI) { - send_single_ipi(pcpu_id, NOTIFY_VCPU_VECTOR); - } else { - /* For lapic-pt vCPUs */ - send_single_nmi(pcpu_id); - } - } - } else if (is_runnable(obj)) { - if (obj->notify_mode == SCHED_NOTIFY_IPI) { - make_reschedule_request(pcpu_id, DEL_MODE_IPI); - } else { - /* For lapic-pt vCPUs */ - make_reschedule_request(pcpu_id, DEL_MODE_NMI); - } - } else { - /* do nothing */ - } - release_schedule_lock(pcpu_id, rflag); -} - void yield_current(void) { make_reschedule_request(get_pcpu_id(), DEL_MODE_IPI); diff --git a/hypervisor/include/arch/x86/guest/vcpu.h b/hypervisor/include/arch/x86/guest/vcpu.h index ddfeed0b0..757bb3ff7 100644 --- a/hypervisor/include/arch/x86/guest/vcpu.h +++ b/hypervisor/include/arch/x86/guest/vcpu.h @@ -666,7 +666,7 @@ void launch_vcpu(struct acrn_vcpu *vcpu); * * @return None */ -void kick_vcpu(const struct acrn_vcpu *vcpu); +void kick_vcpu(struct acrn_vcpu *vcpu); /** * @brief create a vcpu for the vm and mapped to the pcpu. diff --git a/hypervisor/include/common/schedule.h b/hypervisor/include/common/schedule.h index a561e92c3..8400c75ab 100644 --- a/hypervisor/include/common/schedule.h +++ b/hypervisor/include/common/schedule.h @@ -116,7 +116,6 @@ 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); void schedule(void);