Skip to contentSkip to conversation

Measuring intra-CPU stime skew

PATCH Dan Magenheimer 1 participant 1 message Jul 22, 2008

lore
Share & tools
lore
#0 lore raw

With the attached patch, I am trying to measure maximum intra-CPU stime skew. This is not (necessarily) intended to be applied, but I'd be very interested in review to see if I am measuring it accurately or if there might be other more accurate methods than these three.

I'd also be interested in measurements from other machines and configurations. (Output obtained with "xm debug-key t" which can be iterated in a shell loop to collect samples for one of the collection methods... they others are collected automatically.)

If it is accurate, skew is worse than I had previously thought. Not horribly worse, but I am seeing 30-40us skew (on hpet) instead of the 11us I was seeing before.

Thanks,
Dan

===================================
Thanks... for the memory
I really could use more / My throughput's on the floor The balloon is flat / My swap disk's fat / I've OOM's in store Overcommitted so much
(with apologies to the late great Bob Hope)

xen/arch/x86/time.c +44 -0
diff -r 092a15aa2430 xen/arch/x86/time.c
@@ -708,6 +708,29 @@ static unsigned long get_cmos_time(void)
  * System Time
  ***************************************************************************/
 
+u64 max_stime_skew = 0;   /* record max intra-CPU stime skew */
+
+static inline void measure_stime_skew(s_time_t now)
+{
+    long cur_procid;
+    static int ignore = 10000L;
+    static s_time_t last = 0;
+    static int last_procid;
+
+    if ( ignore > 0 )
+    {
+        ignore--;  /* ignore for awhile to wait for calibrate */
+        return;
+    }
+    cur_procid = smp_processor_id();
+    if ( last && last_procid != cur_procid &&
+         last > now && (last - now) > max_stime_skew ) {
+        max_stime_skew = last - now;
+    }
+    last = now;
+    last_procid = cur_procid;
+}
+
 s_time_t get_s_time(void)
 {
     struct cpu_time *t = &this_cpu(cpu_time);
@@ -717,6 +740,7 @@ s_time_t get_s_time(void)
     rdtscll(tsc);
     delta = tsc - t->local_tsc_stamp;
     now = t->stime_local_stamp + scale_delta(delta, &t->tsc_scale);
+    measure_stime_skew(now);
 
     return now;
 }
@@ -828,6 +852,10 @@ void do_settime(unsigned long secs, unsi
     rcu_read_unlock(&domlist_read_lock);
 }
 
+u64 stime_skew_max = 0;
+u32 stime_skew_count = 0;
+u64 stime_skew_sum = 0;
+
 static void local_time_calibration(void *unused)
 {
     struct cpu_time *t = &this_cpu(cpu_time);
@@ -861,6 +889,10 @@ static void local_time_calibration(void 
     /* The overall calibration scale multiplier. */
     u32 calibration_mul_frac;
 
+    /* record skew vs platform counter */
+    static int skip_max_skew_calc = 100;
+    u64 curr_stime_skew;
+
     prev_tsc          = t->local_tsc_stamp;
     prev_local_stime  = t->stime_local_stamp;
     prev_master_stime = t->stime_master_stamp;
@@ -875,6 +907,18 @@ static void local_time_calibration(void 
     rdtscll(curr_tsc);
     local_irq_enable();
 
+    if ( skip_max_skew_calc > 0)
+        skip_max_skew_calc--;  /* allow calibration to converge */
+    else
+    {
+        stime_skew_count++;
+        curr_stime_skew = curr_master_stime - curr_local_stime;
+        if ( (s64) curr_stime_skew < 0 )
+            curr_stime_skew = - curr_stime_skew;
+        if ( curr_stime_skew > stime_skew_max )
+            stime_skew_max = curr_stime_skew;
+        stime_skew_sum += curr_stime_skew;
+    }
 #if 0
     printk("PRE%d: tsc=%"PRIu64" stime=%"PRIu64" master=%"PRIu64"\n",
            smp_processor_id(), prev_tsc, prev_local_stime, prev_master_stime);
xen/common/keyhandler.c +24 -3
diff -r 092a15aa2430 xen/common/keyhandler.c
@@ -246,11 +246,25 @@ static void read_clocks_slave(void *unus
     cpu_clear(cpu, read_clocks_cpumask);
 }
 
+/*
+ * Print collected skew information; three different measures because:
+ *  1) Sync'ed skew is only sampled manually (e.g. xm debug-key t) but
+ *     measures precisely what we want
+ *  2) max_stime_skew is sampled in get_s_time at high frequency but 
+ *     max capture requires near simultaneous access by different processors
+ *     (and the code is ugly so Keir will probably remove ;-)
+ *  3) stime_skew_max is recorded at n Hz in local_time_calibration but
+ *     only records positive skew from platform timer (n = #CPUs)
+ * NOTE!: HVM's with timer_mode==0 intentionally cause intra-CPU skew
+ */
 static void read_clocks(unsigned char key)
 {
     unsigned int cpu = smp_processor_id(), min_cpu, max_cpu;
     u64 min, max, dif, difus;
+    static u64 sumdif = 0, maxdif = 0, count = 0;
     static DEFINE_SPINLOCK(lock);
+    extern u64 max_stime_skew;
+    extern u64 stime_skew_max, stime_skew_count, stime_skew_sum;
 
     spin_lock(&lock);
 
@@ -280,10 +294,17 @@ static void read_clocks(unsigned char ke
     spin_unlock(&lock);
 
     dif = difus = max - min;
+    if ( dif > maxdif )
+        maxdif = dif;
+    count++;
+    sumdif += dif;
     do_div(difus, 1000);
-    printk("Min = %"PRIu64" ; Max = %"PRIu64" ; Diff = %"PRIu64
-           " (%"PRIu64" microseconds)\n",
-           min, max, dif, difus);
+    printk("Synced skew: max=%"PRIu64"ns;avg=%"PRIu64"ns "
+           "cnt=%"PRIu64" cur=%"PRIu64"\n",
+           count, sumdif/count, count, dif);
+    printk("Max recorded stime skew: %"PRIu64"ns\n", max_stime_skew);
+    printk("Platform skew: max=%"PRIu64"ns; avg=%"PRIu64"ns; cnt=%"PRIu64"\n",
+           stime_skew_max, stime_skew_sum/stime_skew_count, stime_skew_count);
 }
 
 extern void dump_runq(unsigned char key);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel