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

[Xen-changelog] [xen stable-4.10] x86: APIC timer calibration when running as a guest



commit 949eb11d5813466f1456a6229ff01e294fb1cdeb
Author:     Wei Liu <wei.liu2@xxxxxxxxxx>
AuthorDate: Fri Nov 17 12:46:41 2017 +0000
Commit:     Roger Pau Monne <roger.pau@xxxxxxxxxx>
CommitDate: Thu Jan 11 17:51:19 2018 +0000

    x86: APIC timer calibration when running as a guest
    
    The timer calibration currently depends on PIT. Introduce a variant
    to wait for a tick's worth of time to elapse when running as a PVH
    guest.
    
    Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/arch/x86/apic.c | 38 ++++++++++++++++++++++++++++++--------
 1 file changed, 30 insertions(+), 8 deletions(-)

diff --git a/xen/arch/x86/apic.c b/xen/arch/x86/apic.c
index ed59440c45..5039173827 100644
--- a/xen/arch/x86/apic.c
+++ b/xen/arch/x86/apic.c
@@ -36,6 +36,8 @@
 #include <mach_apic.h>
 #include <io_ports.h>
 #include <xen/kexec.h>
+#include <asm/guest.h>
+#include <asm/time.h>
 
 static bool __read_mostly tdt_enabled;
 static bool __initdata tdt_enable = true;
@@ -1091,6 +1093,20 @@ static void setup_APIC_timer(void)
     local_irq_restore(flags);
 }
 
+static void wait_tick_pvh(void)
+{
+    u64 lapse_ns = 1000000000ULL / HZ;
+    s_time_t start, curr_time;
+
+    start = NOW();
+
+    /* Won't wrap around */
+    do {
+        cpu_relax();
+        curr_time = NOW();
+    } while ( curr_time - start < lapse_ns );
+}
+
 /*
  * In this function we calibrate APIC bus clocks to the external
  * timer. Unfortunately we cannot use jiffies and the timer irq
@@ -1123,12 +1139,15 @@ static int __init calibrate_APIC_clock(void)
      */
     __setup_APIC_LVTT(1000000000);
 
-    /*
-     * The timer chip counts down to zero. Let's wait
-     * for a wraparound to start exact measurement:
-     * (the current tick might have been already half done)
-     */
-    wait_8254_wraparound();
+    if ( !xen_guest )
+        /*
+         * The timer chip counts down to zero. Let's wait
+         * for a wraparound to start exact measurement:
+         * (the current tick might have been already half done)
+         */
+        wait_8254_wraparound();
+    else
+        wait_tick_pvh();
 
     /*
      * We wrapped around just now. Let's start:
@@ -1137,10 +1156,13 @@ static int __init calibrate_APIC_clock(void)
     tt1 = apic_read(APIC_TMCCT);
 
     /*
-     * Let's wait LOOPS wraprounds:
+     * Let's wait LOOPS ticks:
      */
     for (i = 0; i < LOOPS; i++)
-        wait_8254_wraparound();
+        if ( !xen_guest )
+            wait_8254_wraparound();
+        else
+            wait_tick_pvh();
 
     tt2 = apic_read(APIC_TMCCT);
     t2 = rdtsc_ordered();
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.10

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

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