diff --git a/hypervisor/arch/x86/guest/vcpu.c b/hypervisor/arch/x86/guest/vcpu.c index 45709743f..f85e0e152 100644 --- a/hypervisor/arch/x86/guest/vcpu.c +++ b/hypervisor/arch/x86/guest/vcpu.c @@ -611,7 +611,7 @@ static uint64_t build_stack_frame(struct acrn_vcpu *vcpu) frame -= 1; frame->magic = SP_BOTTOM_MAGIC; - frame->rip = (uint64_t)run_sched_thread; /*return address*/ + frame->rip = (uint64_t)vcpu->thread_obj.thread_entry; /*return address*/ frame->rflag = 0UL; frame->rbx = 0UL; frame->rbp = 0UL; diff --git a/hypervisor/arch/x86/init.c b/hypervisor/arch/x86/init.c index e3990efd5..5b1242df6 100644 --- a/hypervisor/arch/x86/init.c +++ b/hypervisor/arch/x86/init.c @@ -49,16 +49,11 @@ static void init_debug_post(uint16_t pcpu_id) } /*TODO: move into guest-vcpu module */ -static void enter_guest_mode(uint16_t pcpu_id) +static void init_guest_mode(uint16_t pcpu_id) { vmx_on(); launch_vms(pcpu_id); - - switch_to_idle(default_idle); - - /* Control should not come here */ - cpu_dead(); } static void init_primary_pcpu_post(void) @@ -71,7 +66,9 @@ static void init_primary_pcpu_post(void) init_debug_post(BOOT_CPU_ID); - enter_guest_mode(BOOT_CPU_ID); + init_guest_mode(BOOT_CPU_ID); + + run_idle_thread(); } /* NOTE: this function is using temp stack, and after SWITCH_TO(runtime_sp, to) @@ -101,5 +98,7 @@ void init_secondary_pcpu(void) init_debug_post(pcpu_id); - enter_guest_mode(pcpu_id); + init_guest_mode(pcpu_id); + + run_idle_thread(); } diff --git a/hypervisor/common/hv_main.c b/hypervisor/common/hv_main.c index 0b3a00946..a1a83eb9e 100644 --- a/hypervisor/common/hv_main.c +++ b/hypervisor/common/hv_main.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -90,3 +91,22 @@ void default_idle(__unused struct thread_object *obj) } } } + +void run_idle_thread(void) +{ + uint16_t pcpu_id = get_pcpu_id(); + struct thread_object *idle = &per_cpu(idle, pcpu_id); + char idle_name[16]; + + snprintf(idle_name, 16U, "idle%hu", pcpu_id); + (void)strncpy_s(idle->name, 16U, idle_name, 16U); + idle->pcpu_id = pcpu_id; + idle->thread_entry = default_idle; + idle->switch_out = NULL; + idle->switch_in = NULL; + + run_thread(idle); + + /* Control should not come here */ + cpu_dead(); +} diff --git a/hypervisor/common/schedule.c b/hypervisor/common/schedule.c index 6be289933..fcca1e071 100644 --- a/hypervisor/common/schedule.c +++ b/hypervisor/common/schedule.c @@ -194,29 +194,14 @@ void wake_thread(struct thread_object *obj) release_schedule_lock(pcpu_id); } -void run_sched_thread(struct thread_object *obj) +void run_thread(struct thread_object *obj) { + get_schedule_lock(obj->pcpu_id); + get_cpu_var(sched_ctl).curr_obj = obj; + set_thread_status(obj, THREAD_STS_RUNNING); + release_schedule_lock(obj->pcpu_id); + if (obj->thread_entry != NULL) { obj->thread_entry(obj); } - - ASSERT(false, "Shouldn't go here, invalid thread entry!"); -} - -void switch_to_idle(thread_entry_t idle_thread) -{ - uint16_t pcpu_id = get_pcpu_id(); - struct thread_object *idle = &per_cpu(idle, pcpu_id); - char idle_name[16]; - - snprintf(idle_name, 16U, "idle%hu", pcpu_id); - (void)strncpy_s(idle->name, 16U, idle_name, 16U); - idle->pcpu_id = pcpu_id; - idle->thread_entry = idle_thread; - idle->switch_out = NULL; - idle->switch_in = NULL; - get_cpu_var(sched_ctl).curr_obj = idle; - set_thread_status(idle, THREAD_STS_RUNNING); - - run_sched_thread(idle); } diff --git a/hypervisor/include/common/schedule.h b/hypervisor/include/common/schedule.h index a481c2502..964d670e1 100644 --- a/hypervisor/include/common/schedule.h +++ b/hypervisor/include/common/schedule.h @@ -53,7 +53,6 @@ uint16_t sched_get_pcpuid(const struct thread_object *obj); struct thread_object *sched_get_current(uint16_t pcpu_id); void init_sched(uint16_t pcpu_id); -void switch_to_idle(thread_entry_t idle_thread); void get_schedule_lock(uint16_t pcpu_id); void release_schedule_lock(uint16_t pcpu_id); @@ -63,11 +62,12 @@ void remove_thread_obj(struct thread_object *obj, uint16_t pcpu_id); void make_reschedule_request(uint16_t pcpu_id, uint16_t delmode); bool need_reschedule(uint16_t pcpu_id); +void run_thread(struct thread_object *obj); void sleep_thread(struct thread_object *obj); void wake_thread(struct thread_object *obj); void schedule(void); -void run_sched_thread(struct thread_object *obj); void arch_switch_to(void *prev_sp, void *next_sp); +void run_idle_thread(void); #endif /* SCHEDULE_H */