From 21092e6f6de02fcb18da79d30913fb1cf636a92c Mon Sep 17 00:00:00 2001 From: Jason Chen CJ Date: Fri, 18 Jan 2019 13:50:21 +0800 Subject: [PATCH] schedule: use per_cpu idle object To support full context switch scheduling, each physical CPU must have its own idle sched_obj. Tracked-On: #2394 Signed-off-by: Jason Chen CJ Acked-by: Xu, Anthony --- hypervisor/common/schedule.c | 15 ++++++--------- hypervisor/include/arch/x86/per_cpu.h | 1 + 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/hypervisor/common/schedule.c b/hypervisor/common/schedule.c index 70b121475..9a176bc75 100644 --- a/hypervisor/common/schedule.c +++ b/hypervisor/common/schedule.c @@ -8,7 +8,6 @@ #include static uint64_t pcpu_used_bitmap; -static struct sched_object idle; void init_scheduler(void) { @@ -191,7 +190,7 @@ void schedule(void) release_schedule_lock(pcpu_id); if (next == NULL) { - next = &idle; + next = &get_cpu_var(idle); } switch_to(next); @@ -202,15 +201,13 @@ void schedule(void) void switch_to_idle(run_thread_t idle_thread) { - uint16_t pcpu_id = get_cpu_id(); + struct sched_object *idle = &get_cpu_var(idle); - if (pcpu_id == BOOT_CPU_ID) { - idle.thread = idle_thread; - idle.prepare_switch_out = NULL; - idle.prepare_switch_in = NULL; - } + idle->thread = idle_thread; + idle->prepare_switch_out = NULL; + idle->prepare_switch_in = NULL; if (idle_thread != NULL) { - idle_thread(&idle); + idle_thread(idle); } } diff --git a/hypervisor/include/arch/x86/per_cpu.h b/hypervisor/include/arch/x86/per_cpu.h index dae009491..a082a0cc7 100644 --- a/hypervisor/include/arch/x86/per_cpu.h +++ b/hypervisor/include/arch/x86/per_cpu.h @@ -39,6 +39,7 @@ struct per_cpu_region { #endif struct per_cpu_timers cpu_timers; struct sched_context sched_ctx; + struct sched_object idle; struct instr_emul_ctxt g_inst_ctxt; struct host_gdt gdt; struct tss_64 tss;