From c5d1eaae7268a55b59e5885a5e84bc83b0caf832 Mon Sep 17 00:00:00 2001 From: p-szafonimateusz Date: Fri, 17 May 2024 13:24:04 +0200 Subject: [PATCH] arch/intel64: get TSC frequency only when not provided from Kconfig on ACRN hypervisor obtaining frequency from CPUID seems to be broken, so we have to specify this value from Kconfig. If frequency autodetection is enabled but the returned data are incorrect - crash early. Signed-off-by: p-szafonimateusz --- arch/x86_64/src/intel64/Kconfig | 3 ++- arch/x86_64/src/intel64/intel64_freq.c | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/x86_64/src/intel64/Kconfig b/arch/x86_64/src/intel64/Kconfig index f0b5722ec3..4c62c4e69b 100644 --- a/arch/x86_64/src/intel64/Kconfig +++ b/arch/x86_64/src/intel64/Kconfig @@ -77,7 +77,8 @@ config ARCH_INTEL64_CORE_FREQ_KHZ default 2000000 ---help--- The CPU Core frequency (without Turbo boost). This is used - to set the TSC deadline timer frequency. + to set the TSC deadline timer frequency. If set to 0 we try to get + frequency from CPUID. endif diff --git a/arch/x86_64/src/intel64/intel64_freq.c b/arch/x86_64/src/intel64/intel64_freq.c index 421daaa6ea..e63b526e73 100644 --- a/arch/x86_64/src/intel64/intel64_freq.c +++ b/arch/x86_64/src/intel64/intel64_freq.c @@ -72,7 +72,7 @@ extern unsigned long g_x86_64_timer_freq; void x86_64_timer_calibrate_freq(void) { #ifdef CONFIG_ARCH_INTEL64_TSC_DEADLINE - +# if CONFIG_ARCH_INTEL64_CORE_FREQ_KHZ == 0 unsigned long crystal_freq; unsigned long numerator; unsigned long denominator; @@ -84,13 +84,15 @@ void x86_64_timer_calibrate_freq(void) if (numerator == 0 || denominator == 0 || crystal_freq == 0) { - g_x86_64_timer_freq = CONFIG_ARCH_INTEL64_CORE_FREQ_KHZ * 1000L; + PANIC(); } else { g_x86_64_timer_freq = crystal_freq / denominator * numerator; } - +# else + g_x86_64_timer_freq = CONFIG_ARCH_INTEL64_CORE_FREQ_KHZ * 1000L; +# endif #elif defined(CONFIG_ARCH_INTEL64_TSC) g_x86_64_timer_freq = CONFIG_ARCH_INTEL64_APIC_FREQ_KHZ * 1000L; #endif