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

[Xen-devel] [PATCH RFC v1 31/74] x86: read wallclock from Xen running in pvh mode



Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 xen/arch/x86/time.c | 38 ++++++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c
index ee35ffda6c..886fc45248 100644
--- a/xen/arch/x86/time.c
+++ b/xen/arch/x86/time.c
@@ -969,6 +969,36 @@ static unsigned long get_cmos_time(void)
     return mktime(rtc.year, rtc.mon, rtc.day, rtc.hour, rtc.min, rtc.sec);
 }
 
+static unsigned long noinline get_xen_wallclock_time(void)
+{
+#ifdef CONFIG_XEN_GUEST
+    struct shared_info *sh_info = XEN_shared_info;
+    uint32_t wc_version;
+    uint64_t wc_sec;
+
+    do {
+        wc_version = sh_info->wc_version & ~1;
+        smp_rmb();
+
+        wc_sec  = sh_info->wc_sec;
+        smp_rmb();
+    } while ( wc_version != sh_info->wc_version );
+
+    return wc_sec + read_xen_timer() / 1000000000;
+#else
+    ASSERT_UNREACHABLE();
+    return 0;
+#endif
+}
+
+static unsigned long get_wallclock_time(void)
+{
+    if ( !xen_guest )
+        return get_cmos_time();
+    else
+        return get_xen_wallclock_time();
+}
+
 /***************************************************************************
  * System Time
  ***************************************************************************/
@@ -1764,8 +1794,8 @@ int __init init_xen_time(void)
 
     open_softirq(TIME_CALIBRATE_SOFTIRQ, local_time_calibration);
 
-    /* NB. get_cmos_time() can take over one second to execute. */
-    do_settime(get_cmos_time(), 0, NOW());
+    /* NB. get_wallclock_time() can take over one second to execute. */
+    do_settime(get_wallclock_time(), 0, NOW());
 
     /* Finish platform timer initialization. */
     try_platform_timer_tail(false);
@@ -1875,7 +1905,7 @@ int time_suspend(void)
 {
     if ( smp_processor_id() == 0 )
     {
-        cmos_utc_offset = -get_cmos_time();
+        cmos_utc_offset = -get_wallclock_time();
         cmos_utc_offset += get_sec();
         kill_timer(&calibration_timer);
 
@@ -1902,7 +1932,7 @@ int time_resume(void)
 
     set_timer(&calibration_timer, NOW() + EPOCH);
 
-    do_settime(get_cmos_time() + cmos_utc_offset, 0, NOW());
+    do_settime(get_wallclock_time() + cmos_utc_offset, 0, NOW());
 
     update_vcpu_system_time(current);
 
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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