diff --git a/hypervisor/arch/x86/guest/vcpu.c b/hypervisor/arch/x86/guest/vcpu.c index cf292ee99..bc7157854 100644 --- a/hypervisor/arch/x86/guest/vcpu.c +++ b/hypervisor/arch/x86/guest/vcpu.c @@ -193,6 +193,18 @@ void vcpu_reset_eoi_exit_bitmaps(struct acrn_vcpu *vcpu) vcpu_make_request(vcpu, ACRN_REQUEST_EOI_EXIT_BITMAP_UPDATE); } +struct acrn_vcpu *get_running_vcpu(uint16_t pcpu_id) +{ + struct thread_object *curr = sched_get_current(pcpu_id); + struct acrn_vcpu *vcpu = NULL; + + if ((curr != NULL) && (!is_idle_thread(curr))) { + vcpu = list_entry(curr, struct acrn_vcpu, thread_obj); + } + + return vcpu; +} + struct acrn_vcpu *get_ever_run_vcpu(uint16_t pcpu_id) { return per_cpu(ever_run_vcpu, pcpu_id); @@ -400,8 +412,6 @@ int32_t create_vcpu(uint16_t pcpu_id, struct acrn_vm *vm, struct acrn_vcpu **rtn * needs revise. */ - per_cpu(vcpu, pcpu_id) = vcpu; - pr_info("Create VM%d-VCPU%d, Role: %s", vcpu->vm->vm_id, vcpu->vcpu_id, is_vcpu_bsp(vcpu) ? "PRIMARY" : "SECONDARY"); diff --git a/hypervisor/boot/guest/deprivilege_boot.c b/hypervisor/boot/guest/deprivilege_boot.c index 9c92df0cf..fb172c55f 100644 --- a/hypervisor/boot/guest/deprivilege_boot.c +++ b/hypervisor/boot/guest/deprivilege_boot.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include diff --git a/hypervisor/boot/guest/vboot_info.c b/hypervisor/boot/guest/vboot_info.c index e4defc3b6..f03fc1463 100644 --- a/hypervisor/boot/guest/vboot_info.c +++ b/hypervisor/boot/guest/vboot_info.c @@ -270,7 +270,7 @@ static int32_t init_general_vm_boot_info(struct acrn_vm *vm) static void depri_boot_spurious_handler(uint32_t vector) { if (get_pcpu_id() == BOOT_CPU_ID) { - struct acrn_vcpu *vcpu = per_cpu(vcpu, BOOT_CPU_ID); + struct acrn_vcpu *vcpu = vcpu_from_vid(get_sos_vm(), BOOT_CPU_ID); if (vcpu != NULL) { vlapic_set_intr(vcpu, vector, LAPIC_TRIG_EDGE); diff --git a/hypervisor/common/schedule.c b/hypervisor/common/schedule.c index 71e5f0744..df252036c 100644 --- a/hypervisor/common/schedule.c +++ b/hypervisor/common/schedule.c @@ -13,6 +13,12 @@ #include #include +bool is_idle_thread(const struct thread_object *obj) +{ + uint16_t pcpu_id = obj->pcpu_id; + return (obj == &per_cpu(idle, pcpu_id)); +} + /** * @pre obj != NULL */ @@ -67,6 +73,12 @@ static struct thread_object *get_next_sched_obj(const struct sched_control *ctl) return ctl->thread_obj == NULL ? &get_cpu_var(idle) : ctl->thread_obj; } +struct thread_object *sched_get_current(uint16_t pcpu_id) +{ + struct sched_control *ctl = &per_cpu(sched_ctl, pcpu_id); + return ctl->curr_obj; +} + /** * @pre delmode == DEL_MODE_IPI || delmode == DEL_MODE_INIT */ diff --git a/hypervisor/debug/dump.c b/hypervisor/debug/dump.c index 4330fb2d9..83e67f958 100644 --- a/hypervisor/debug/dump.c +++ b/hypervisor/debug/dump.c @@ -183,9 +183,8 @@ static void show_guest_call_trace(struct acrn_vcpu *vcpu) static void dump_guest_context(uint16_t pcpu_id) { - struct acrn_vcpu *vcpu; + struct acrn_vcpu *vcpu = get_running_vcpu(pcpu_id); - vcpu = per_cpu(vcpu, pcpu_id); if (vcpu != NULL) { dump_guest_reg(vcpu); dump_guest_stack(vcpu); diff --git a/hypervisor/include/arch/x86/guest/vcpu.h b/hypervisor/include/arch/x86/guest/vcpu.h index 623d0592a..97473c574 100644 --- a/hypervisor/include/arch/x86/guest/vcpu.h +++ b/hypervisor/include/arch/x86/guest/vcpu.h @@ -538,6 +538,7 @@ static inline bool is_pae(struct acrn_vcpu *vcpu) return (vcpu_get_cr4(vcpu) & CR4_PAE) != 0UL; } +struct acrn_vcpu *get_running_vcpu(uint16_t pcpu_id); struct acrn_vcpu* get_ever_run_vcpu(uint16_t pcpu_id); /** diff --git a/hypervisor/include/arch/x86/per_cpu.h b/hypervisor/include/arch/x86/per_cpu.h index 2c5a26d81..b5deda4fd 100644 --- a/hypervisor/include/arch/x86/per_cpu.h +++ b/hypervisor/include/arch/x86/per_cpu.h @@ -31,7 +31,6 @@ struct per_cpu_region { uint64_t irq_count[NR_IRQS]; uint64_t softirq_pending; uint64_t spurious; - struct acrn_vcpu *vcpu; struct acrn_vcpu *ever_run_vcpu; #ifdef STACK_PROTECTOR struct stack_canary stk_canary; diff --git a/hypervisor/include/common/schedule.h b/hypervisor/include/common/schedule.h index faedf4884..9b7baded9 100644 --- a/hypervisor/include/common/schedule.h +++ b/hypervisor/include/common/schedule.h @@ -35,7 +35,9 @@ struct sched_control { struct thread_object *thread_obj; }; +bool is_idle_thread(const struct thread_object *obj); uint16_t sched_get_pcpuid(const struct thread_object *obj); +struct thread_object *sched_get_current(uint16_t pcpu_id); void init_scheduler(void); void switch_to_idle(thread_entry_t idle_thread);