Skip to contentSkip to conversation

x86/time: set AP's TSC scale estimate earlier

RFC PATCH New Jan Beulich 1 participant 1 message May 12

lore
Share & tools
lore
#0 lore raw

RFC PATCH v2 1/1 x86/time: set AP's TSC scale estimate earlier

NOW() (in particular) can be used ahead of init_percpu_time(). As the initial scale value set is merely the BSP's, we can as well set it very early when the AP is coming up.

Setting the scale alone, however, doesn't work, so the entire struct cpu_time is copied.

---
RFC: Copying the entire struct won't work very well when tsc_adjust[] is
in use (and values there differ between sockets).

This in particular mostly eliminates an anomaly with log messages issued early while APs are coming up, when "boot" console timestamps are in use.
---
v2: Call the function from very early in start_secondary()

xen/arch/x86/include/asm/time.h +1 -0
@@ -21,6 +21,7 @@ mktime (unsigned int year, unsigned int
 int time_suspend(void);
 int time_resume(void);
 
+void preinit_percpu_time(unsigned int cpu);
 void init_percpu_time(void);
 void time_latch_stamps(void);
 
xen/arch/x86/smpboot.c +2 -0
@@ -356,6 +356,8 @@ void asmlinkage start_secondary(void)
     /* Safe to enable feature such as CR4.MCE with the IDT set up now. */
     write_cr4(mmu_cr4_features);
 
+    preinit_percpu_time(cpu);
+
     percpu_traps_init();
 
     cpu_init();
xen/arch/x86/time.c +6 -3
@@ -2346,6 +2346,12 @@ void time_latch_stamps(void)
     ap_bringup_ref.local_stime = get_s_time_fixed(ap_bringup_ref.local_tsc);
 }
 
+void preinit_percpu_time(unsigned int cpu)
+{
+    /* Initial estimate for TSC rate etc. */
+    per_cpu(cpu_time, cpu) = per_cpu(cpu_time, 0);
+}
+
 void init_percpu_time(void)
 {
     struct cpu_time *t = &this_cpu(cpu_time);
@@ -2353,9 +2359,6 @@ void init_percpu_time(void)
     u64 tsc;
     s_time_t now;
 
-    /* Initial estimate for TSC rate. */
-    t->tsc_scale = per_cpu(cpu_time, 0).tsc_scale;
-
     if ( tsc_adjust )
     {
         unsigned int socket = cpu_to_socket(smp_processor_id());