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

[Xen-devel] [PATCH RFC 6/6] x86/time: convert counter to tsc for non-tsc clocksource



This commit is an attempt at suporting PVCLOCK_TSC_STABLE_BIT when
using other clocksources. master_tsc_stamp is set by converting
master_stime (returned from read_platform_stime()) and converting it
to a TSC by scaling the ns value accordingly.  We scale the system
time if TSC is reliable, and under the assumption there is a
considerable skew between platform timer and TSC. In my machine I was
measuring between -15 and 40 us between HPET and TSC.

Signed-off-by: Joao Martins <joao.m.martins@xxxxxxxxxx>
---
 xen/arch/x86/time.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c
index e623891..fa5f948 100644
--- a/xen/arch/x86/time.c
+++ b/xen/arch/x86/time.c
@@ -910,7 +910,7 @@ static void __update_vcpu_system_time(struct vcpu *v, int 
force)
 
     _u.tsc_timestamp = tsc_stamp;
     _u.system_time   = t->stime_local_stamp;
-    if ( clocksource_is_tsc )
+    if ( clocksource_is_tsc || host_tsc_is_safe() )
         _u.flags    |= PVCLOCK_TSC_STABLE_BIT;
 
     if ( is_hvm_domain(d) )
@@ -1378,6 +1378,15 @@ static void time_calibration_std_rendezvous(void *_r)
         r->master_stime = read_platform_stime(&last_counter);
         if ( clocksource_is_tsc )
             r->master_tsc_stamp = last_counter;
+        else if ( host_tsc_is_safe() )
+        {
+            struct cpu_time *t = &this_cpu(cpu_time);
+            struct time_scale plt_scale_r =
+                   scale_reciprocal(t->tsc_scale);
+
+            r->master_tsc_stamp = scale_delta(r->master_stime,
+                                              &plt_scale_r);
+        }
         mb(); /* write r->master_stime /then/ signal */
         atomic_inc(&r->semaphore);
     }
@@ -1389,7 +1398,7 @@ static void time_calibration_std_rendezvous(void *_r)
         mb(); /* receive signal /then/ read r->master_stime */
     }
 
-    if ( clocksource_is_tsc )
+    if ( clocksource_is_tsc || host_tsc_is_safe() )
         c->local_tsc_stamp = r->master_tsc_stamp;
     else
         c->local_tsc_stamp = rdtsc();
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

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