From 05eb70e9f06c4030c7122fefb714300e57f5868a Mon Sep 17 00:00:00 2001 From: mintsuki Date: Mon, 13 Sep 2021 05:13:02 +0200 Subject: [PATCH] smp: Use rdtsc to delay rather than dummy port IO --- stage23/sys/smp.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/stage23/sys/smp.c b/stage23/sys/smp.c index 79f463e9..14c3d777 100644 --- a/stage23/sys/smp.c +++ b/stage23/sys/smp.c @@ -39,9 +39,10 @@ struct madt_x2apic { uint32_t acpi_processor_uid; } __attribute__((packed)); -static void delay(uint32_t cycles) { - for (uint32_t i = 0; i < cycles; i++) - inb(0x80); +static void delay(uint64_t cycles) { + uint64_t next_stop = rdtsc() + cycles; + + while (rdtsc() < next_stop); } extern symbol _binary_smp_trampoline_bin_start; @@ -95,7 +96,7 @@ static bool smp_start_ap(uint32_t lapic_id, struct gdtr *gdtr, lapic_write(LAPIC_REG_ICR1, lapic_id << 24); lapic_write(LAPIC_REG_ICR0, 0x4500); } - delay(5000); + delay(10000000); // Send the Startup IPI if (x2apic) { @@ -110,7 +111,7 @@ static bool smp_start_ap(uint32_t lapic_id, struct gdtr *gdtr, if (locked_read(&passed_info->smp_tpl_booted_flag) == 1) { return true; } - delay(10000); + delay(10000000); } return false;