[PATCH] x86/time: make early NOW() uses slightly more precise

Jan Beulich posted 1 patch 1 week, 6 days ago
Failed in applying to current master (apply log)
[PATCH] x86/time: make early NOW() uses slightly more precise
Posted by Jan Beulich 1 week, 6 days ago
For early NOW() uses to yield sufficiently precise results (scaling incurs
some error, which grows with the delta being scaled), init_percpu_time()
wants to have run as early as possible. With 93340297802b ("x86/time:
calibrate TSC against platform timer") having moved the invocation of
init_platform_timer() from init_xen_time() to early_time_init(), this
other call could be moved as well.

Moving, however, has the unwanted effect of then growing the gap until
time calibration runs for the 1st time. Therefore keep the present
invocation, and add another from early_time_init().

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/arch/x86/time.c
+++ b/xen/arch/x86/time.c
@@ -2597,6 +2597,11 @@ int __init init_xen_time(void)
     /* Finish platform timer initialization. */
     try_platform_timer_tail();
 
+    /*
+     * While early_time_init() called this already, call it again here to
+     * reduce the gap until local_time_calibration() gets to run for the
+     * first time.
+     */
     init_percpu_time();
 
     init_timer(&calibration_timer, time_calibration, NULL, 0);
@@ -2642,6 +2647,8 @@ void __init early_time_init(void)
     set_time_scale(&t->tsc_scale, tmp);
     t->stamp.local_tsc = boot_tsc_stamp;
 
+    init_percpu_time();
+
     cpu_khz = DIV_ROUND(tmp, 1000);
     printk("Detected %lu.%03lu MHz processor.\n", 
            cpu_khz / 1000, cpu_khz % 1000);
Re: [PATCH] x86/time: make early NOW() uses slightly more precise
Posted by Roger Pau Monné 1 week, 6 days ago
On Wed, May 06, 2026 at 11:33:55AM +0200, Jan Beulich wrote:
> For early NOW() uses to yield sufficiently precise results (scaling incurs
> some error, which grows with the delta being scaled), init_percpu_time()
> wants to have run as early as possible. With 93340297802b ("x86/time:
> calibrate TSC against platform timer") having moved the invocation of
> init_platform_timer() from init_xen_time() to early_time_init(), this
> other call could be moved as well.
> 
> Moving, however, has the unwanted effect of then growing the gap until
> time calibration runs for the 1st time. Therefore keep the present
> invocation, and add another from early_time_init().

Yeah, keeping the second init_xen_time() will make sure the BSP
doesn't diverge too much from the platform timer during boot.  WE
migth as well skip it and wait for the first rendezvous, but this is
likely more accurate at the cost of doing the extra init_xen_time() in
the BSP.

> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Acked-by: Roger Pau Monné <roger.pau@citrix.com>

Thanks, Roger.