[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen stable-4.21] xen/cpu: round cpu_khz calculations



commit 54db249531ac2bf2ea37d8b9d4fcf2ba06d2bc75
Author:     Roger Pau Monné <roger.pau@xxxxxxxxxx>
AuthorDate: Mon Apr 20 12:29:10 2026 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Mon Apr 20 12:29:10 2026 +0200

    xen/cpu: round cpu_khz calculations
    
    All arches truncate the cpu_khz without taking into account the less
    significant digits.  Instead use DIV_ROUND() when scaling from Hz to kHz
    to get as more accurate kHz value.
    
    Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
    master commit: 986707b461eb56d75f55581dd1c8e2633f814795
    master date: 2026-04-16 15:28:32 +0200
---
 xen/arch/arm/time.c   | 4 ++--
 xen/arch/riscv/time.c | 2 +-
 xen/arch/x86/time.c   | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/xen/arch/arm/time.c b/xen/arch/arm/time.c
index e74d30d258..61536081eb 100644
--- a/xen/arch/arm/time.c
+++ b/xen/arch/arm/time.c
@@ -128,7 +128,7 @@ static void __init preinit_dt_xen_time(void)
     res = dt_property_read_u32(timer, "clock-frequency", &rate);
     if ( res )
     {
-        cpu_khz = rate / 1000;
+        cpu_khz = DIV_ROUND(rate, 1000);
         validate_timer_frequency();
         timer_dt_clock_frequency = rate;
     }
@@ -146,7 +146,7 @@ void __init preinit_xen_time(void)
 
     if ( !cpu_khz )
     {
-        cpu_khz = (READ_SYSREG(CNTFRQ_EL0) & CNTFRQ_MASK) / 1000;
+        cpu_khz = DIV_ROUND(READ_SYSREG(CNTFRQ_EL0) & CNTFRQ_MASK, 1000);
         validate_timer_frequency();
     }
 
diff --git a/xen/arch/riscv/time.c b/xen/arch/riscv/time.c
index e962f8518d..4391488a73 100644
--- a/xen/arch/riscv/time.c
+++ b/xen/arch/riscv/time.c
@@ -36,7 +36,7 @@ static void __init preinit_dt_xen_time(void)
     if ( !dt_property_read_u32(timer, "timebase-frequency", &rate) )
         panic("Unable to find clock frequency\n");
 
-    cpu_khz = rate / 1000;
+    cpu_khz = DIV_ROUND(rate, 1000);
 }
 
 void __init preinit_xen_time(void)
diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c
index d9f7772ab4..0bae4ff339 100644
--- a/xen/arch/x86/time.c
+++ b/xen/arch/x86/time.c
@@ -2634,7 +2634,7 @@ void __init early_time_init(void)
     set_time_scale(&t->tsc_scale, tmp);
     t->stamp.local_tsc = boot_tsc_stamp;
 
-    cpu_khz = tmp / 1000;
+    cpu_khz = DIV_ROUND(tmp, 1000);
     printk("Detected %lu.%03lu MHz processor.\n", 
            cpu_khz / 1000, cpu_khz % 1000);
 
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.21



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.