smp: Fix BSP timing out while waiting for APs on AArch64
When running with KVM, the BSP seems to time out while waiting for APs to come up, which leads to the OS only being told about 1 AP, and all the APs using the same info struct and stack pointer.
diff --git a/common/sys/cpu.h b/common/sys/cpu.h
index 72a63666..dbe3807f 100644
--- a/common/sys/cpu.h
+++ b/common/sys/cpu.h
@@ -227,6 +227,12 @@ static inline uint64_t rdtsc(void) {
return v;
}
+static inline void delay(uint64_t cycles) {
+ uint64_t next_stop = rdtsc() + cycles;
+
+ while (rdtsc() < next_stop);
+}
+
#define locked_read(var) ({ \
typeof(*var) locked_read__ret = 0; \
asm volatile ( \
diff --git a/common/sys/smp.c b/common/sys/smp.c
index 70578fbe..43666b45 100644
--- a/common/sys/smp.c
+++ b/common/sys/smp.c
@@ -396,12 +396,12 @@ static bool try_start_ap(int boot_method, uint64_t method_ptr,
for (int i = 0; i < 1000000; i++) {
// We do not need cache invalidation here as by the time the AP gets to
- // set this flag, it has enabled it's caches
+ // set this flag, it has enabled its caches
if (locked_read(&passed_info->smp_tpl_booted_flag) == 1) {
return true;
}
- //delay(10000000);
+ delay(100000);
}
return false;
