diff --git a/arch/x86/cpu.c b/arch/x86/cpu.c index b5aad5e52..e0a739846 100644 --- a/arch/x86/cpu.c +++ b/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/include/arch/x86/cpu.h b/include/arch/x86/cpu.h index 9bd305fa9..6a3085932 100644 --- a/include/arch/x86/cpu.h +++ b/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))