]> xenbits.xensource.com Git - xen.git/commitdiff
x86/hvm: Run the RTC periodic timer on a consistent time series.
authorTim Deegan <tim@xen.org>
Thu, 28 Mar 2013 12:00:46 +0000 (12:00 +0000)
committerTim Deegan <tim@xen.org>
Fri, 29 Mar 2013 09:43:04 +0000 (09:43 +0000)
When the RTC periodic timer gets restarted, align it to the VM's boot
time, not to whatever time it is now.  Otherwise every read of REG_C
will restart the current period

Signed-off-by: Tim Deegan <tim@xen.org>
Acked-by: Keir Fraser <keir@xen.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/hvm/rtc.c
xen/include/asm-x86/hvm/vpt.h

index c1e09d8392ed6042645f3c7d78e626d504acf95b..e9aa81a390653758cf7064a7a7a90070642dbe2a 100644 (file)
@@ -80,7 +80,7 @@ void rtc_periodic_interrupt(void *opaque)
  * RTC_RATE_SELECT settings */
 static void rtc_timer_update(RTCState *s)
 {
-    int period_code, period;
+    int period_code, period, delta;
     struct vcpu *v = vrtc_vcpu(s);
 
     ASSERT(spin_is_locked(&s->lock));
@@ -98,7 +98,8 @@ static void rtc_timer_update(RTCState *s)
         {
             period = 1 << (period_code - 1); /* period in 32 Khz cycles */
             period = DIV_ROUND(period * 1000000000ULL, 32768); /* in ns */
-            create_periodic_time(v, &s->pt, period, period, RTC_IRQ, NULL, s);
+            delta = period - ((NOW() - s->start_time) % period);
+            create_periodic_time(v, &s->pt, delta, period, RTC_IRQ, NULL, s);
             break;
         }
         /* fall through */
@@ -740,6 +741,7 @@ void rtc_init(struct domain *d)
     s->hw.cmos_data[RTC_REG_D] = RTC_VRT;
 
     s->current_tm = gmtime(get_localtime(d));
+    s->start_time = NOW();
 
     rtc_copy_date(s);
 
index c75297bd5d7f82ff06bcb18bd6d44f2b9b533ef6..2e9c7d24eb46c36453da12816c5b980cf2935d13 100644 (file)
@@ -104,8 +104,9 @@ typedef struct RTCState {
     struct hvm_hw_rtc hw;
     /* RTC's idea of the current time */
     struct tm current_tm;
+    /* periodic timer */
+    s_time_t start_time;
     /* second update */
-    int64_t next_second_time;
     struct periodic_time pt;
     /* update-ended timer */
     struct timer update_timer;