Apicid isn't guaranteed to be consecutive or starting from BSP's. But there are many codes depending on BSP's apicid are smallest among others. This patch makes it works in any case. Bumping active_cpus in smp_reset_apic() isn't correct as it is already bumped in smp_init(). This can cause on_cpus() in dead loop. Fix it by removing that bumping in smp_reset_apic(). Signed-off-by: Zhenzhong Duan <zhenzhong.duan@xxxxxxxxx> --- lib/x86/apic.c | 6 ++++++ lib/x86/smp.c | 2 -- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/x86/apic.c b/lib/x86/apic.c index da8f301..562b3ec 100644 --- a/lib/x86/apic.c +++ b/lib/x86/apic.c @@ -237,8 +237,14 @@ extern unsigned char online_cpus[(MAX_TEST_CPUS + 7) / 8]; void init_apic_map(void) { unsigned int i, j = 0; + u32 bsp_apicid = apic_id(); + + /* BSP's logical id is 0 */ + id_map[j++] = bsp_apicid; for (i = 0; i < MAX_TEST_CPUS; i++) { + if (i == bsp_apicid) + continue; if ((1ul << (i % 8)) & (online_cpus[i / 8])) id_map[j++] = i; } diff --git a/lib/x86/smp.c b/lib/x86/smp.c index 2ac0ef7..46d2630 100644 --- a/lib/x86/smp.c +++ b/lib/x86/smp.c @@ -143,6 +143,4 @@ void smp_reset_apic(void) reset_apic(); for (i = 1; i < cpu_count(); ++i) on_cpu(i, do_reset_apic, 0); - - atomic_inc(&active_cpus); } -- 2.25.1