From 96f7ff3be1f7581933bede3c725f845dff5bad3c Mon Sep 17 00:00:00 2001 From: Jason Chen CJ Date: Tue, 10 Apr 2018 19:51:29 +0800 Subject: [PATCH] cpu: add physical cpu active bitmap support use pcpu_active_bitmap presents which cpu is active Signed-off-by: Mingqiang Chi Acked-by: Tian, Kevin --- hypervisor/arch/x86/cpu.c | 9 +++++++++ hypervisor/include/arch/x86/cpu.h | 1 + 2 files changed, 10 insertions(+) diff --git a/hypervisor/arch/x86/cpu.c b/hypervisor/arch/x86/cpu.c index b5aad5e52..e0a739846 100644 --- a/hypervisor/arch/x86/cpu.c +++ b/hypervisor/arch/x86/cpu.c @@ -59,6 +59,9 @@ int phy_cpu_num; unsigned long pcpu_sync = 0; uint32_t up_count = 0; +/* physical cpu active bitmap, support up to 64 cpus */ +uint64_t pcpu_active_bitmap = 0; + DEFINE_CPU_DATA(uint8_t[STACK_SIZE], stack) __aligned(16); DEFINE_CPU_DATA(uint8_t, lapic_id); DEFINE_CPU_DATA(void *, vcpu); @@ -392,6 +395,8 @@ void bsp_boot_init(void) VMX_MACHINE_T_GUEST_SPEC_CTRL_OFFSET, "run_context ia32_spec_ctrl offset not match"); + bitmap_set(CPU_BOOT_ID, &pcpu_active_bitmap); + /* Get CPU capabilities thru CPUID, including the physical address bit * limit which is required for initializing paging. */ @@ -535,6 +540,8 @@ void cpu_secondary_init(void) (get_cur_lapic_id()), CPU_STATE_INITIALIZING); + bitmap_set(get_cpu_id(), &pcpu_active_bitmap); + /* Switch to run-time stack */ CPU_SP_WRITE(&get_cpu_var(stack)[STACK_SIZE - 1]); @@ -646,6 +653,8 @@ void cpu_halt(uint32_t logical_id) /* Set state to show CPU is halted */ cpu_set_current_state(logical_id, CPU_STATE_HALTED); + bitmap_clr(get_cpu_id(), &pcpu_active_bitmap); + /* Halt the CPU */ do { asm volatile ("hlt"); diff --git a/hypervisor/include/arch/x86/cpu.h b/hypervisor/include/arch/x86/cpu.h index 9bd305fa9..6a3085932 100644 --- a/hypervisor/include/arch/x86/cpu.h +++ b/hypervisor/include/arch/x86/cpu.h @@ -198,6 +198,7 @@ EXTERN_CPU_DATA(uint8_t[STACK_SIZE], stack) __aligned(16); extern void *per_cpu_data_base_ptr; extern int phy_cpu_num; +extern uint64_t pcpu_active_bitmap; #define PER_CPU_DATA_OFFSET(sym_addr) \ ((uint64_t)(sym_addr) - (uint64_t)(_ld_cpu_data_start))