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

[Xen-changelog] [xen-unstable] RTC: Add UIP(update in progress) check logic



# HG changeset patch
# User Yang Zhang <yang.z.zhang@xxxxxxxxx>
# Date 1331105775 0
# Node ID f06a031fdaf9b6d5192265c9458356190ca23085
# Parent  c343c98ed82d5d7f28ccd5949ade78660c4b313b
RTC: Add UIP(update in progress) check logic

The UIP(update in progress) is set when RTC is in updating. And the
update cycle begins 244us later after UIP is set.

Signed-off-by: Yang Zhang <yang.z.zhang@xxxxxxxxx>
Committed-by: Keir Fraser <keir@xxxxxxx>
---


diff -r c343c98ed82d -r f06a031fdaf9 xen/arch/x86/hvm/rtc.c
--- a/xen/arch/x86/hvm/rtc.c    Wed Mar 07 07:34:55 2012 +0000
+++ b/xen/arch/x86/hvm/rtc.c    Wed Mar 07 07:36:15 2012 +0000
@@ -28,6 +28,8 @@
 #include <asm/hvm/support.h>
 #include <asm/current.h>
 
+#define USEC_PER_SEC    1000000UL
+
 #define domain_vrtc(x) (&(x)->arch.hvm_domain.pl_time.vrtc)
 #define vcpu_vrtc(x)   (domain_vrtc((x)->domain))
 #define vrtc_domain(x) (container_of((x), struct domain, \
@@ -239,6 +241,22 @@
     s->hw.cmos_data[RTC_YEAR] = to_bcd(s, tm->tm_year % 100);
 }
 
+static int update_in_progress(RTCState *s)
+{
+    uint64_t guest_usec;
+    struct domain *d = vrtc_domain(s);
+
+    if (s->hw.cmos_data[RTC_REG_B] & RTC_SET)
+        return 0;
+
+    guest_usec = get_localtime_us(d);
+    /* UIP bit will be set at last 244us of every second. */
+    if ((guest_usec % USEC_PER_SEC) >= (USEC_PER_SEC - 244))
+        return 1;
+
+    return 0;
+}
+
 static uint32_t rtc_ioport_read(RTCState *s, uint32_t addr)
 {
     int ret;
@@ -268,6 +286,8 @@
         break;
     case RTC_REG_A:
         ret = s->hw.cmos_data[s->hw.cmos_index];
+        if (update_in_progress(s))
+            ret |= RTC_UIP;
         break;
     case RTC_REG_C:
         ret = s->hw.cmos_data[s->hw.cmos_index];
diff -r c343c98ed82d -r f06a031fdaf9 xen/arch/x86/time.c
--- a/xen/arch/x86/time.c       Wed Mar 07 07:34:55 2012 +0000
+++ b/xen/arch/x86/time.c       Wed Mar 07 07:36:15 2012 +0000
@@ -1601,6 +1601,13 @@
         + d->time_offset_seconds;
 }
 
+/* Return microsecs after 00:00:00 localtime, 1 January, 1970. */
+uint64_t get_localtime_us(struct domain *d)
+{
+    return ((wc_sec + d->time_offset_seconds) * 1000000000ULL
+        + wc_nsec + NOW()) / 1000UL;
+}
+
 unsigned long get_sec(void)
 {
     return wc_sec + (wc_nsec + NOW()) / 1000000000ULL;
diff -r c343c98ed82d -r f06a031fdaf9 xen/include/xen/time.h
--- a/xen/include/xen/time.h    Wed Mar 07 07:34:55 2012 +0000
+++ b/xen/include/xen/time.h    Wed Mar 07 07:36:15 2012 +0000
@@ -34,6 +34,7 @@
 
 s_time_t get_s_time(void);
 unsigned long get_localtime(struct domain *d);
+uint64_t get_localtime_us(struct domain *d);
 
 struct tm {
     int     tm_sec;         /* seconds */

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
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®.