From c7c685f6e6921f454be85c7d65a8e1735618fc0e Mon Sep 17 00:00:00 2001 From: Pawel Wieczorkiewicz Date: Wed, 6 Sep 2023 18:31:15 +0200 Subject: [PATCH] timers: APIC timer needs HPET or PIT for calibration Signed-off-by: Pawel Wieczorkiewicz --- common/setup.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/common/setup.c b/common/setup.c index 97645fea..819ca5dd 100644 --- a/common/setup.c +++ b/common/setup.c @@ -147,9 +147,9 @@ static void __text_init init_vga_console(void) { } void __text_init init_timers(cpu_t *cpu) { - if (cpu->bsp) { - bool hpet_initialized = false; + static bool __data_init hpet_initialized = false; + if (cpu->bsp) { if (opt_hpet) hpet_initialized = init_hpet(cpu); @@ -157,8 +157,13 @@ void __text_init init_timers(cpu_t *cpu) { init_pit(cpu); } - if (opt_apic_timer) - init_apic_timer(); + if (opt_apic_timer) { + if (hpet_initialized || opt_pit) /* Needed for APIC timer calibration */ + init_apic_timer(); + else + printk("CPU%u: Unable to initialize APIC timer - no calibration timers!\n", + cpu->id); + } } void __noreturn __text_init kernel_start(uint32_t multiboot_magic, unsigned long *mbi) {