Patchwork [RFC,3/3] mc146818rtc: Handle host clock warps

login
register
mail settings
Submitter Jan Kiszka
Date Dec. 17, 2010, 2:58 p.m.
Message ID <ec20cf0d520ca3cc3a04802344a92ef67d903aa2.1292597932.git.jan.kiszka@siemens.com>
Download mbox | patch
Permalink /patch/75905/
State New
Headers show

Comments

Jan Kiszka - Dec. 17, 2010, 2:58 p.m.
Make use of the new warp notifier to update the RTC whenever rtc_clock
is the host clock and that happens to jump backward. This avoids that
the RTC stalls for the period the host clock was set back.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 hw/mc146818rtc.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

Patch

diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 6466aff..f65ea5a 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -563,6 +563,21 @@  static const VMStateDescription vmstate_rtc = {
     }
 };
 
+static void rtc_clock_warp(QEMUClock *clock, int64_t now, void *opaque)
+{
+    RTCState *s = opaque;
+
+    rtc_set_date_from_host(&s->dev);
+    s->next_second_time = now + (get_ticks_per_sec() * 99) / 100;
+    qemu_mod_timer(s->second_timer2, s->next_second_time);
+    rtc_timer_update(s, now);
+#ifdef TARGET_I386
+    if (rtc_td_hack) {
+        rtc_coalesced_timer_update(s);
+    }
+#endif
+}
+
 static void rtc_reset(void *opaque)
 {
     RTCState *s = opaque;
@@ -599,6 +614,8 @@  static int rtc_initfn(ISADevice *dev)
     s->second_timer = qemu_new_timer(rtc_clock, rtc_update_second, s);
     s->second_timer2 = qemu_new_timer(rtc_clock, rtc_update_second2, s);
 
+    qemu_register_clock_warp(rtc_clock, rtc_clock_warp, s);
+
     s->next_second_time =
         qemu_get_clock(rtc_clock) + (get_ticks_per_sec() * 99) / 100;
     qemu_mod_timer(s->second_timer2, s->next_second_time);