From 76919abb10e586819c2c66635bbab00e5fc02217 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Fri, 5 May 2023 15:25:55 +0100 Subject: [PATCH] x86_64: smp: initialise APs in parallel bring_all_ap_online() now initialises all APs in parallel, and waits for them all to come online (i.e. reach the end of ap_trampoline_exit, making them ready to start scheduling threads) before returning. --- arch/x86_64/acpi/smp.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/x86_64/acpi/smp.cpp b/arch/x86_64/acpi/smp.cpp index bf96901..da1e634 100644 --- a/arch/x86_64/acpi/smp.cpp +++ b/arch/x86_64/acpi/smp.cpp @@ -17,6 +17,9 @@ volatile uint8_t __all_ap_ok = 0; extern "C" void ap_trampoline_exit(void) { + struct vm_page *stack_page = (struct vm_page *)__ap_stack_page; + __this_ap_ok = 1; + ml_cpu_block *this_cpu = (ml_cpu_block *)kmalloc(sizeof *this_cpu, VM_NORMAL); ml_cpu_block_init(this_cpu); ml_cpu_block_use(this_cpu); @@ -31,7 +34,7 @@ extern "C" void ap_trampoline_exit(void) struct thread *this_thread = create_idle_thread(); this_thread->tr_id = cpu_id; - this_thread->tr_kstack = (struct vm_page *)__ap_stack_page; + this_thread->tr_kstack = (struct vm_page *)stack_page; self->c_rq.rq_idle = self->c_rq.rq_cur = this_thread; put_cpu(self); @@ -39,7 +42,6 @@ extern "C" void ap_trampoline_exit(void) ap_apic_init(); cpu_set_online(cpu_id); - __this_ap_ok = 1; irq_enable(); idle(); @@ -113,7 +115,12 @@ kern_status_t bring_all_ap_online(void) p += rec->r_length; } - printk("acpi: found %u logical cores", nr_processors); + while (cpu_nr_available() != cpu_nr_online()) { + ml_cpu_relax(); + } + + printk("acpi: %u APs online", cpu_nr_online()); + return KERN_OK; }