WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] rdtsc emulation (PV and HVM) must be monotonically i

To: "Xen-Devel (E-mail)" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH] rdtsc emulation (PV and HVM) must be monotonically increasing
From: Dan Magenheimer <dan.magenheimer@xxxxxxxxxx>
Date: Tue, 1 Sep 2009 16:02:37 -0700 (PDT)
Delivery-date: Tue, 01 Sep 2009 16:05:35 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
The Intel SDM (section 18.10) clearly states that rdtsc
returns a "monotonically increasing unique value".
Current emulation code for rdtsc (both PV and HVM) returns
only a monotonically-non-decreasing (non-unique) value,
so ensure stale value is always incremented.

Signed-off-by: Dan Magenheimer <dan.magenheimer@xxxxxxxxxx>

diff -r 8fc927798476 xen/arch/x86/hvm/vpt.c
--- a/xen/arch/x86/hvm/vpt.c    Tue Sep 01 11:36:51 2009 +0100
+++ b/xen/arch/x86/hvm/vpt.c    Tue Sep 01 16:53:42 2009 -0600
@@ -47,10 +47,10 @@ u64 hvm_get_guest_time(struct vcpu *v)
 
     spin_lock(&pl->pl_time_lock);
     now = get_s_time() + pl->stime_offset;
-    if ( (int64_t)(now - pl->last_guest_time) >= 0 )
+    if ( (int64_t)(now - pl->last_guest_time) > 0 )
         pl->last_guest_time = now;
     else
-        now = pl->last_guest_time;
+        now = ++pl->last_guest_time;
     spin_unlock(&pl->pl_time_lock);
 
     return now + v->arch.hvm_vcpu.stime_offset;
diff -r 8fc927798476 xen/arch/x86/time.c
--- a/xen/arch/x86/time.c       Tue Sep 01 11:36:51 2009 +0100
+++ b/xen/arch/x86/time.c       Tue Sep 01 16:53:42 2009 -0600
@@ -1454,10 +1454,10 @@ void pv_soft_rdtsc(struct vcpu *v, struc
         rdtsc_usercount++;
         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 )
+        if ( (int64_t)(now - v->domain->arch.vtsc_last) > 0 )
             v->domain->arch.vtsc_last = now;
         else
-            now = v->domain->arch.vtsc_last;
+            now = ++v->domain->arch.vtsc_last;
         spin_unlock(&v->domain->arch.vtsc_lock);
         regs->eax = (uint32_t)now;
         regs->edx = (uint32_t)(now >> 32);

Attachment: vtsc-mono.patch
Description: Binary data

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] rdtsc emulation (PV and HVM) must be monotonically increasing, Dan Magenheimer <=