File 22484-vlapic-tmcct-periodic.patch of Package xen.import4929

# HG changeset patch
# User Keir Fraser <keir@xen.org>
# Date 1291999745 0
# Node ID 3b3fce9050b9b14f3a11123f6943998413ea7e7e
# Parent  901c118b363e978566775f9d118b4f2f15598212
hvm vlapic: Fix tmcct read logic when in periodic mode.

Signed-off-by: Keir Fraser <keir@xen.org>

Index: xen-4.0.2-testing/xen/arch/x86/hvm/vlapic.c
===================================================================
--- xen-4.0.2-testing.orig/xen/arch/x86/hvm/vlapic.c
+++ xen-4.0.2-testing/xen/arch/x86/hvm/vlapic.c
@@ -428,12 +428,19 @@ int vlapic_ipi(
 static uint32_t vlapic_get_tmcct(struct vlapic *vlapic)
 {
     struct vcpu *v = current;
-    uint32_t tmcct, tmict = vlapic_get_reg(vlapic, APIC_TMICT);
+    uint32_t tmcct = 0, tmict = vlapic_get_reg(vlapic, APIC_TMICT);
     uint64_t counter_passed;
 
     counter_passed = ((hvm_get_guest_time(v) - vlapic->timer_last_update)
-                      / APIC_BUS_CYCLE_NS / vlapic->hw.timer_divisor);
-    tmcct = tmict - counter_passed;
+                      / (APIC_BUS_CYCLE_NS * vlapic->hw.timer_divisor));
+
+    if ( tmict != 0 )
+    {
+        if ( vlapic_lvtt_period(vlapic) )
+            counter_passed %= tmict;
+        if ( counter_passed < tmict )
+            tmcct = tmict - counter_passed;
+    }
 
     HVM_DBG_LOG(DBG_LEVEL_VLAPIC_TIMER,
                 "timer initial count %d, timer current count %d, "
openSUSE Build Service is sponsored by