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

[Xen-changelog] [xen-unstable] x86: Emulated TSC should run at same (1GHz) rate in guest kernel and apps.



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1254820161 -3600
# Node ID 56ab22093d645c33f0e6f878362ac9b3eb1b4226
# Parent  6f63970032a3fe5fda585beba929d2d7a5e14861
x86: Emulated TSC should run at same (1GHz) rate in guest kernel and apps.

Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
---
 xen/arch/x86/time.c          |   61 +++++++++++++++++++++++--------------------
 xen/include/asm-x86/domain.h |    1 
 2 files changed, 34 insertions(+), 28 deletions(-)

diff -r 6f63970032a3 -r 56ab22093d64 xen/arch/x86/time.c
--- a/xen/arch/x86/time.c       Fri Oct 02 09:10:27 2009 +0100
+++ b/xen/arch/x86/time.c       Tue Oct 06 10:09:21 2009 +0100
@@ -837,17 +837,26 @@ void update_vcpu_system_time(struct vcpu
     t = &this_cpu(cpu_time);
     u = &vcpu_info(v, time);
 
-    if ( u->tsc_timestamp == t->local_tsc_stamp )
-        return;
-
-    version_update_begin(&u->version);
-
-    u->tsc_timestamp     = t->local_tsc_stamp;
-    u->system_time       = t->stime_local_stamp;
-    u->tsc_to_system_mul = t->tsc_scale.mul_frac;
-    u->tsc_shift         = (s8)t->tsc_scale.shift;
-
-    version_update_end(&u->version);
+    if ( v->domain->arch.vtsc )
+    {
+        if ( u->tsc_timestamp == t->stime_local_stamp )
+            return;
+        version_update_begin(&u->version);
+        u->tsc_timestamp     = t->stime_local_stamp;
+        u->system_time       = t->stime_local_stamp;
+        u->tsc_to_system_mul = 0x80000000u;
+        u->tsc_shift         = 1;
+        version_update_end(&u->version);
+    }
+    else if ( u->tsc_timestamp != t->local_tsc_stamp )
+    {
+        version_update_begin(&u->version);
+        u->tsc_timestamp     = t->local_tsc_stamp;
+        u->system_time       = t->stime_local_stamp;
+        u->tsc_to_system_mul = t->tsc_scale.mul_frac;
+        u->tsc_shift         = (s8)t->tsc_scale.shift;
+        version_update_end(&u->version);
+    }
 }
 
 void update_domain_wallclock_time(struct domain *d)
@@ -1435,26 +1444,24 @@ struct tm wallclock_time(void)
 
 void pv_soft_rdtsc(struct vcpu *v, struct cpu_user_regs *regs)
 {
-    s_time_t now;
+    s_time_t now = get_s_time();
+
+    spin_lock(&v->domain->arch.vtsc_lock);
 
     if ( guest_kernel_mode(v, regs) )
-    {
         v->domain->arch.vtsc_kerncount++;
-        rdtsc(regs->eax, regs->edx);
-    }
     else
-    { 
-        v->domain->arch.vtsc_kerncount++;
-        spin_lock(&v->domain->arch.vtsc_lock);
-        now = get_s_time() + v->domain->arch.vtsc_stime_offset;
-        if ( (int64_t)(now - v->domain->arch.vtsc_last) > 0 )
-            v->domain->arch.vtsc_last = now;
-        else
-            now = ++v->domain->arch.vtsc_last;
-        spin_unlock(&v->domain->arch.vtsc_lock);
-        regs->eax = (uint32_t)now;
-        regs->edx = (uint32_t)(now >> 32);
-    }
+        v->domain->arch.vtsc_usercount++;
+
+    if ( (int64_t)(now - v->domain->arch.vtsc_last) > 0 )
+        v->domain->arch.vtsc_last = now;
+    else
+        now = ++v->domain->arch.vtsc_last;
+
+    spin_unlock(&v->domain->arch.vtsc_lock);
+
+    regs->eax = (uint32_t)now;
+    regs->edx = (uint32_t)(now >> 32);
 }
 
 /* vtsc may incur measurable performance degradation, diagnose with this */
diff -r 6f63970032a3 -r 56ab22093d64 xen/include/asm-x86/domain.h
--- a/xen/include/asm-x86/domain.h      Fri Oct 02 09:10:27 2009 +0100
+++ b/xen/include/asm-x86/domain.h      Tue Oct 06 10:09:21 2009 +0100
@@ -306,7 +306,6 @@ struct arch_domain
     spinlock_t vtsc_lock;
     uint64_t vtsc_kerncount; /* for hvm, counts all vtsc */
     uint64_t vtsc_usercount; /* not used for hvm */
-    int64_t vtsc_stime_offset;
 } __cacheline_aligned;
 
 #define has_arch_pdevs(d)    (!list_empty(&(d)->arch.pdev_list))

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

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