You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2024/06/27 14:49:55 UTC

(nuttx) branch master updated: arch/intel64: get TSC frequency only when not provided from Kconfig

This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new c5d1eaae72 arch/intel64: get TSC frequency only when not provided from Kconfig
c5d1eaae72 is described below

commit c5d1eaae7268a55b59e5885a5e84bc83b0caf832
Author: p-szafonimateusz <p-...@xiaomi.com>
AuthorDate: Fri May 17 13:24:04 2024 +0200

    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 <p-...@xiaomi.com>
---
 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