Patchwork [RFC,v2,1/4] mc145818rtc: fix saving of rtc-td hack properly upgrading the version number

login
register
mail settings
Submitter Juan Quintela
Date Sept. 9, 2009, 11:12 p.m.
Message ID <1252537974-26209-1-git-send-email-quintela@redhat.com>
Download mbox | patch
Permalink /patch/33234/
State Superseded
Headers show

Comments

Juan Quintela - Sept. 9, 2009, 11:12 p.m.
Hi

v2:

Only call rtc_coalesced_timer_update() if rtc_td_hack is true.
Patch was failing to load its own images.

v1:

There hasn't still released a version with the rtc_td hack.
Do we want to release 0.11 with this hack or change to a more maintenable mode,
i.e. just upgrade the version to 3 and save always the new values.
We should also propably add rtd_hack to the state, and make sure that value is the
same in origing and destination of th emigration.
Another problem is what we do with kvm, they have already done releases
with the "mc146818rtc-td" savevm section.

Notice that rtc-td-hack should really, really be enabled by defaulet.  It is
needed to have windows guest running correctly under load.

What do you think?  What should we do?

Later, Juan.

PD. Once that I was looking here, this driver has several features that are not
    used anywhere else.
- rtc_mm_init() is defined and exported but not used
- rtc_init_sqw() is defined, but only called from rtc_init() with sqw_irq = NULL
- sqw_irq is only assigned in rtc_init_sqw() and always to NULL value.

Is there a reason why we have the functionality that is not used anywhere?


Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/mc146818rtc.c |   47 +++++++++++++----------------------------------
 1 files changed, 13 insertions(+), 34 deletions(-)

Patch

diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index b7f09e5..db9f26f 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -75,11 +75,9 @@  struct RTCState {
     int64_t next_periodic_time;
     /* second update */
     int64_t next_second_time;
-#ifdef TARGET_I386
     uint32_t irq_coalesced;
     uint32_t period;
     QEMUTimer *coalesced_timer;
-#endif
     QEMUTimer *second_timer;
     QEMUTimer *second_timer2;
 };
@@ -522,13 +520,15 @@  static void rtc_save(QEMUFile *f, void *opaque)
     qemu_put_be64(f, s->next_second_time);
     qemu_put_timer(f, s->second_timer);
     qemu_put_timer(f, s->second_timer2);
+    qemu_put_be32(f, s->irq_coalesced);
+    qemu_put_be32(f, s->period);
 }

 static int rtc_load(QEMUFile *f, void *opaque, int version_id)
 {
     RTCState *s = opaque;

-    if (version_id != 1)
+    if (version_id < 1 || version_id > 2)
         return -EINVAL;

     qemu_get_buffer(f, s->cmos_data, 128);
@@ -548,31 +548,18 @@  static int rtc_load(QEMUFile *f, void *opaque, int version_id)
     s->next_second_time=qemu_get_be64(f);
     qemu_get_timer(f, s->second_timer);
     qemu_get_timer(f, s->second_timer2);
-    return 0;
-}

+    if (version_id >= 2) {
+        s->irq_coalesced = qemu_get_be32(f);
+        s->period = qemu_get_be32(f);
 #ifdef TARGET_I386
-static void rtc_save_td(QEMUFile *f, void *opaque)
-{
-    RTCState *s = opaque;
-
-    qemu_put_be32(f, s->irq_coalesced);
-    qemu_put_be32(f, s->period);
-}
-
-static int rtc_load_td(QEMUFile *f, void *opaque, int version_id)
-{
-    RTCState *s = opaque;
-
-    if (version_id != 1)
-        return -EINVAL;
-
-    s->irq_coalesced = qemu_get_be32(f);
-    s->period = qemu_get_be32(f);
-    rtc_coalesced_timer_update(s);
+        if (rtc_td_hack) {
+            rtc_coalesced_timer_update(s);
+        }
+#endif
+    }
     return 0;
 }
-#endif

 static void rtc_reset(void *opaque)
 {
@@ -622,11 +609,7 @@  RTCState *rtc_init_sqw(int base, qemu_irq irq, qemu_irq sqw_irq, int base_year)
     register_ioport_write(base, 2, 1, cmos_ioport_write, s);
     register_ioport_read(base, 2, 1, cmos_ioport_read, s);

-    register_savevm("mc146818rtc", base, 1, rtc_save, rtc_load, s);
-#ifdef TARGET_I386
-    if (rtc_td_hack)
-        register_savevm("mc146818rtc-td", base, 1, rtc_save_td, rtc_load_td, s);
-#endif
+    register_savevm("mc146818rtc", base, 2, rtc_save, rtc_load, s);
     qemu_register_reset(rtc_reset, s);

     return s;
@@ -739,11 +722,7 @@  RTCState *rtc_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq,
     io_memory = cpu_register_io_memory(rtc_mm_read, rtc_mm_write, s);
     cpu_register_physical_memory(base, 2 << it_shift, io_memory);

-    register_savevm("mc146818rtc", base, 1, rtc_save, rtc_load, s);
-#ifdef TARGET_I386
-    if (rtc_td_hack)
-        register_savevm("mc146818rtc-td", base, 1, rtc_save_td, rtc_load_td, s);
-#endif
+    register_savevm("mc146818rtc", base, 2, rtc_save, rtc_load, s);
     qemu_register_reset(rtc_reset, s);
     return s;
 }