All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate
@ 2009-09-10  1:04 Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 01/26] ram: remove support for loading v1 Juan Quintela
                   ` (25 more replies)
  0 siblings, 26 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel

This series:
- remove support for RAM v1 and v2 (I created an image with latest qemu
  before switching to RAM v3 and try to load with current qemu).
  It don't work (physical_ram_size value has changed), and it don't work
  since at least April).  I went to that commit, and after fixing RAM,
  ide didn't load, and vga screen got corrupted).
- Remove SaveVM v2 support.  This support is older than then switch to RAMv3,
  if you can't load RAM -> you can't load any image in any meaningful way.
- port several devices to vmstate.
- To port timers, I have to move ticks_per_sec in an accessor function
  patch is quite big, but it is trivial.

Devices left to have my minimal pc using only vmstate:
- cpu (dragons here, this is huge and has all special cases that you can think)
- ide: medium size, identiyfy_data that can/can't be there is the
  more complicated thing.
- virtio-net: more dragons here, we need a nice way to split virtio & virtio-pci
  just now their relation is too incestuous.
- mc146818rtc: See my other RFC mail about changing how rtc-td-hack is handled
  during save/load.

I guess that I missed some device, but this is one start.

Later, Juan.

Juan Quintela (26):
  ram: remove support for loading v1
  ram: Remove SaveVM Version 2 support
  Remove SaveVM v2 support
  timers: remove useless check
  Unexport ticks_per_sec variable.  Create get_ticks_per_sec() function
  timers: Createt TimersState and put all timers state there
  timers: move them to VMState
  vmstate: add sensible arguments to vmstate_unregister()
  vmstate: rename run_after_load() -> post_load()
  vmstate: Add pre_load() hook
  vmstate: Add pre/post_save() hooks
  vmstate: port cpu_comon
  vmstate: port fw_cfg device
  vmstate: port i8259 device
  vmstate: add support for uint8_t equal
  vmstate: port fdc device
  vmstate: add support for arrays of uint16_t
  vmstate: port dma device
  vmstate: port vmmouse device
  vmstate: port pckbd device
  vmstate: add uint64 array support
  vmstate: port ioapic device
  hpet: it is imposible that qemu_timer field is NULL at this point
  vmstate: port hpet device
  vmstate: port serial device
  vmstate: port cirrus_vga device

 audio/audio.c        |    2 +-
 audio/noaudio.c      |    4 +-
 audio/wavaudio.c     |    2 +-
 exec.c               |   39 ++++++---
 hw/acpi.c            |   13 ++--
 hw/adlib.c           |    2 +-
 hw/baum.c            |    3 +-
 hw/bt-hci-csr.c      |    4 +-
 hw/bt-hci.c          |    4 +-
 hw/cirrus_vga.c      |  152 ++++++++++++---------------------
 hw/cuda.c            |   14 ++--
 hw/dma.c             |   85 +++++++-----------
 hw/dp8393x.c         |    2 +-
 hw/fdc.c             |  156 +++++++++++++--------------------
 hw/fw_cfg.c          |   33 +++-----
 hw/hpet.c            |   77 ++++++++--------
 hw/hw.h              |   32 +++++++-
 hw/i8254.c           |   14 ++-
 hw/i8259.c           |   77 ++++++-----------
 hw/ide/core.c        |    2 +-
 hw/ioapic.c          |   39 +++------
 hw/mc146818rtc.c     |   16 ++--
 hw/mips_timer.c      |   10 +-
 hw/omap1.c           |   16 ++--
 hw/omap2.c           |    4 +-
 hw/pckbd.c           |   41 ++++------
 hw/pcnet.c           |    2 +-
 hw/pflash_cfi02.c    |    4 +-
 hw/piix_pci.c        |    4 +-
 hw/pl031.c           |    6 +-
 hw/ppc.c             |   18 ++--
 hw/ppc405_uc.c       |    4 +-
 hw/pxa2xx_timer.c    |   14 ++--
 hw/rc4030.c          |    3 +-
 hw/rtl8139.c         |    5 +-
 hw/sb16.c            |    4 +-
 hw/serial.c          |   79 +++++++++--------
 hw/slavio_intctl.c   |    4 +-
 hw/spitz.c           |    3 +-
 hw/stellaris.c       |    2 +-
 hw/tcx.c             |    4 +-
 hw/tsc2005.c         |    2 +-
 hw/tsc210x.c         |    2 +-
 hw/tusb6010.c        |    4 +-
 hw/usb-musb.c        |    2 +-
 hw/usb-ohci.c        |   10 +-
 hw/usb-uhci.c        |    2 +-
 hw/vga.c             |    6 +-
 hw/vmmouse.c         |   48 ++++------
 hw/wdt_i6300esb.c    |    2 +-
 hw/wdt_ib700.c       |    2 +-
 monitor.c            |    6 +-
 net.c                |    2 +-
 qemu-timer.h         |    2 +-
 savevm.c             |   94 ++++++++++----------
 target-ppc/kvm_ppc.c |    2 +-
 vl.c                 |  235 +++++++++++---------------------------------------
 57 files changed, 590 insertions(+), 830 deletions(-)

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 01/26] ram: remove support for loading v1
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 02/26] ram: Remove SaveVM Version 2 support Juan Quintela
                   ` (24 subsequent siblings)
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel


Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 vl.c |   42 ------------------------------------------
 1 files changed, 0 insertions(+), 42 deletions(-)

diff --git a/vl.c b/vl.c
index c6c6a6b..148a592 100644
--- a/vl.c
+++ b/vl.c
@@ -2792,45 +2792,6 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
 /***********************************************************/
 /* ram save/restore */

-static int ram_get_page(QEMUFile *f, uint8_t *buf, int len)
-{
-    int v;
-
-    v = qemu_get_byte(f);
-    switch(v) {
-    case 0:
-        if (qemu_get_buffer(f, buf, len) != len)
-            return -EIO;
-        break;
-    case 1:
-        v = qemu_get_byte(f);
-        memset(buf, v, len);
-        break;
-    default:
-        return -EINVAL;
-    }
-
-    if (qemu_file_has_error(f))
-        return -EIO;
-
-    return 0;
-}
-
-static int ram_load_v1(QEMUFile *f, void *opaque)
-{
-    int ret;
-    ram_addr_t i;
-
-    if (qemu_get_be32(f) != last_ram_offset)
-        return -EINVAL;
-    for(i = 0; i < last_ram_offset; i+= TARGET_PAGE_SIZE) {
-        ret = ram_get_page(f, qemu_get_ram_ptr(i), TARGET_PAGE_SIZE);
-        if (ret)
-            return ret;
-    }
-    return 0;
-}
-
 #define BDRV_HASH_BLOCK_SIZE 1024
 #define IOBUF_SIZE 4096
 #define RAM_CBLOCK_MAGIC 0xfabe
@@ -3065,9 +3026,6 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
     ram_addr_t addr;
     int flags;

-    if (version_id == 1)
-        return ram_load_v1(f, opaque);
-
     if (version_id == 2) {
         if (qemu_get_be32(f) != last_ram_offset)
             return -EINVAL;
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 02/26] ram: Remove SaveVM Version 2 support
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 01/26] ram: remove support for loading v1 Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 03/26] Remove SaveVM v2 support Juan Quintela
                   ` (23 subsequent siblings)
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel

It don't work.  It fails in this check

        if (qemu_get_be32(f) != last_ram_offset)

With 512MB of ram, values were for me:

	v = 20c00000 last_ram_offset = 20840000

Last time that some code changed that was this one.

    commit 94a6b54fd6d2d3321066cb4db7abeeb417af9365
    Implement dynamic guest ram allocation.
    (I.e. it has been broken since at least April)

Going back to the previous commit, ram load correctly, but vga screen gets
corrupted and ide don't load correctly.  At this point I decide that removing
support is the only viable thing.

The last user of the ram_compress_* were RAM_SAVE_FLAG_FULL flag, but
that flag was never ever been stored in an image. Mark the flag obsolete
and remove the functions.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 vl.c |   94 +-----------------------------------------------------------------
 1 files changed, 1 insertions(+), 93 deletions(-)

diff --git a/vl.c b/vl.c
index 148a592..25cad98 100644
--- a/vl.c
+++ b/vl.c
@@ -2792,58 +2792,7 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
 /***********************************************************/
 /* ram save/restore */

-#define BDRV_HASH_BLOCK_SIZE 1024
-#define IOBUF_SIZE 4096
-#define RAM_CBLOCK_MAGIC 0xfabe
-
-typedef struct RamDecompressState {
-    z_stream zstream;
-    QEMUFile *f;
-    uint8_t buf[IOBUF_SIZE];
-} RamDecompressState;
-
-static int ram_decompress_open(RamDecompressState *s, QEMUFile *f)
-{
-    int ret;
-    memset(s, 0, sizeof(*s));
-    s->f = f;
-    ret = inflateInit(&s->zstream);
-    if (ret != Z_OK)
-        return -1;
-    return 0;
-}
-
-static int ram_decompress_buf(RamDecompressState *s, uint8_t *buf, int len)
-{
-    int ret, clen;
-
-    s->zstream.avail_out = len;
-    s->zstream.next_out = buf;
-    while (s->zstream.avail_out > 0) {
-        if (s->zstream.avail_in == 0) {
-            if (qemu_get_be16(s->f) != RAM_CBLOCK_MAGIC)
-                return -1;
-            clen = qemu_get_be16(s->f);
-            if (clen > IOBUF_SIZE)
-                return -1;
-            qemu_get_buffer(s->f, s->buf, clen);
-            s->zstream.avail_in = clen;
-            s->zstream.next_in = s->buf;
-        }
-        ret = inflate(&s->zstream, Z_PARTIAL_FLUSH);
-        if (ret != Z_OK && ret != Z_STREAM_END) {
-            return -1;
-        }
-    }
-    return 0;
-}
-
-static void ram_decompress_close(RamDecompressState *s)
-{
-    inflateEnd(&s->zstream);
-}
-
-#define RAM_SAVE_FLAG_FULL	0x01
+#define RAM_SAVE_FLAG_FULL	0x01 /* Obsolete, not used anymore */
 #define RAM_SAVE_FLAG_COMPRESS	0x02
 #define RAM_SAVE_FLAG_MEM_SIZE	0x04
 #define RAM_SAVE_FLAG_PAGE	0x08
@@ -2991,47 +2940,11 @@ static int ram_save_live(QEMUFile *f, int stage, void *opaque)
     return (stage == 2) && (expected_time <= migrate_max_downtime());
 }

-static int ram_load_dead(QEMUFile *f, void *opaque)
-{
-    RamDecompressState s1, *s = &s1;
-    uint8_t buf[10];
-    ram_addr_t i;
-
-    if (ram_decompress_open(s, f) < 0)
-        return -EINVAL;
-    for(i = 0; i < last_ram_offset; i+= BDRV_HASH_BLOCK_SIZE) {
-        if (ram_decompress_buf(s, buf, 1) < 0) {
-            fprintf(stderr, "Error while reading ram block header\n");
-            goto error;
-        }
-        if (buf[0] == 0) {
-            if (ram_decompress_buf(s, qemu_get_ram_ptr(i),
-                                   BDRV_HASH_BLOCK_SIZE) < 0) {
-                fprintf(stderr, "Error while reading ram block address=0x%08" PRIx64, (uint64_t)i);
-                goto error;
-            }
-        } else {
-        error:
-            printf("Error block header\n");
-            return -EINVAL;
-        }
-    }
-    ram_decompress_close(s);
-
-    return 0;
-}
-
 static int ram_load(QEMUFile *f, void *opaque, int version_id)
 {
     ram_addr_t addr;
     int flags;

-    if (version_id == 2) {
-        if (qemu_get_be32(f) != last_ram_offset)
-            return -EINVAL;
-        return ram_load_dead(f, opaque);
-    }
-
     if (version_id != 3)
         return -EINVAL;

@@ -3046,11 +2959,6 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
                 return -EINVAL;
         }

-        if (flags & RAM_SAVE_FLAG_FULL) {
-            if (ram_load_dead(f, opaque) < 0)
-                return -EINVAL;
-        }
-        
         if (flags & RAM_SAVE_FLAG_COMPRESS) {
             uint8_t ch = qemu_get_byte(f);
             memset(qemu_get_ram_ptr(addr), ch, TARGET_PAGE_SIZE);
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 03/26] Remove SaveVM v2 support
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 01/26] ram: remove support for loading v1 Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 02/26] ram: Remove SaveVM Version 2 support Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10 17:41   ` Stefano Stabellini
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 04/26] timers: remove useless check Juan Quintela
                   ` (22 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel

In previosu series I remove v2 support for RAM (that was the version that was
supported when SaveVM v3 appeared).  Now we can't load RAM for any image saved in SaveVM v2, we can as well remove SaveVM v2 entirely.

Note: That SaveVM RAM was at v2 when General SaveVM support went from v2 to v3 makes talking about versions confusing at least

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 savevm.c |   47 ++++-------------------------------------------
 1 files changed, 4 insertions(+), 43 deletions(-)

diff --git a/savevm.c b/savevm.c
index 34145f9..0dcab79 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1266,47 +1266,6 @@ typedef struct LoadStateEntry {
     int version_id;
 } LoadStateEntry;

-static int qemu_loadvm_state_v2(QEMUFile *f)
-{
-    SaveStateEntry *se;
-    int len, ret, instance_id, record_len, version_id;
-    int64_t total_len, end_pos, cur_pos;
-    char idstr[256];
-
-    total_len = qemu_get_be64(f);
-    end_pos = total_len + qemu_ftell(f);
-    for(;;) {
-        if (qemu_ftell(f) >= end_pos)
-            break;
-        len = qemu_get_byte(f);
-        qemu_get_buffer(f, (uint8_t *)idstr, len);
-        idstr[len] = '\0';
-        instance_id = qemu_get_be32(f);
-        version_id = qemu_get_be32(f);
-        record_len = qemu_get_be32(f);
-        cur_pos = qemu_ftell(f);
-        se = find_se(idstr, instance_id);
-        if (!se) {
-            fprintf(stderr, "qemu: warning: instance 0x%x of device '%s' not present in current VM\n",
-                    instance_id, idstr);
-        } else {
-            ret = vmstate_load(f, se, version_id);
-            if (ret < 0) {
-                fprintf(stderr, "qemu: warning: error while loading state for instance 0x%x of device '%s'\n",
-                        instance_id, idstr);
-                return ret;
-            }
-        }
-        /* always seek to exact end of record */
-        qemu_fseek(f, cur_pos + record_len, SEEK_SET);
-    }
-
-    if (qemu_file_has_error(f))
-        return -EIO;
-
-    return 0;
-}
-
 int qemu_loadvm_state(QEMUFile *f)
 {
     LIST_HEAD(, LoadStateEntry) loadvm_handlers =
@@ -1321,8 +1280,10 @@ int qemu_loadvm_state(QEMUFile *f)
         return -EINVAL;

     v = qemu_get_be32(f);
-    if (v == QEMU_VM_FILE_VERSION_COMPAT)
-        return qemu_loadvm_state_v2(f);
+    if (v == QEMU_VM_FILE_VERSION_COMPAT) {
+        fprintf(stderr, "SaveVM v2 format is obsolete and don't work anymore\n");
+        return -ENOTSUP;
+    }
     if (v != QEMU_VM_FILE_VERSION)
         return -ENOTSUP;

-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 04/26] timers: remove useless check
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (2 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 03/26] Remove SaveVM v2 support Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function Juan Quintela
                   ` (21 subsequent siblings)
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel

loadvm_state is called from: vl.c during startup, vmstart() is called after finishing loading.  The other caller do_loadvm() does the call after a vm_stop().  At both places where we can be saving state we are stoped a few lines before

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 vl.c |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)

diff --git a/vl.c b/vl.c
index 25cad98..448ec6c 100644
--- a/vl.c
+++ b/vl.c
@@ -1067,9 +1067,6 @@ void qemu_get_timer(QEMUFile *f, QEMUTimer *ts)

 static void timer_save(QEMUFile *f, void *opaque)
 {
-    if (cpu_ticks_enabled) {
-        hw_error("cannot save state if virtual timers are running");
-    }
     qemu_put_be64(f, cpu_ticks_offset);
     qemu_put_be64(f, ticks_per_sec);
     qemu_put_be64(f, cpu_clock_offset);
@@ -1079,9 +1076,6 @@ static int timer_load(QEMUFile *f, void *opaque, int version_id)
 {
     if (version_id != 1 && version_id != 2)
         return -EINVAL;
-    if (cpu_ticks_enabled) {
-        return -EINVAL;
-    }
     cpu_ticks_offset=qemu_get_be64(f);
     ticks_per_sec=qemu_get_be64(f);
     if (version_id == 2) {
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (3 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 04/26] timers: remove useless check Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:20   ` malc
  2009-09-11  9:04   ` Jan Kiszka
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 06/26] timers: Createt TimersState and put all timers state there Juan Quintela
                   ` (20 subsequent siblings)
  25 siblings, 2 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel


Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 audio/audio.c        |    2 +-
 audio/noaudio.c      |    4 ++--
 audio/wavaudio.c     |    2 +-
 hw/acpi.c            |    9 +++++----
 hw/adlib.c           |    2 +-
 hw/baum.c            |    3 ++-
 hw/bt-hci-csr.c      |    4 ++--
 hw/bt-hci.c          |    4 ++--
 hw/cuda.c            |   14 +++++++-------
 hw/dp8393x.c         |    2 +-
 hw/fdc.c             |    2 +-
 hw/i8254.c           |   14 +++++++++-----
 hw/i8259.c           |    3 ++-
 hw/ide/core.c        |    2 +-
 hw/mc146818rtc.c     |   16 ++++++++--------
 hw/mips_timer.c      |   10 +++++-----
 hw/omap1.c           |   16 +++++++++-------
 hw/omap2.c           |    4 ++--
 hw/pcnet.c           |    2 +-
 hw/pflash_cfi02.c    |    4 ++--
 hw/pl031.c           |    6 +++---
 hw/ppc.c             |   18 +++++++++---------
 hw/ppc405_uc.c       |    4 ++--
 hw/pxa2xx_timer.c    |   14 +++++++-------
 hw/rc4030.c          |    3 ++-
 hw/rtl8139.c         |    5 +++--
 hw/sb16.c            |    4 ++--
 hw/serial.c          |    6 +++---
 hw/spitz.c           |    3 ++-
 hw/stellaris.c       |    2 +-
 hw/tsc2005.c         |    2 +-
 hw/tsc210x.c         |    2 +-
 hw/tusb6010.c        |    4 ++--
 hw/usb-musb.c        |    2 +-
 hw/usb-ohci.c        |   10 +++++-----
 hw/usb-uhci.c        |    2 +-
 hw/vga.c             |    6 +++---
 hw/wdt_i6300esb.c    |    2 +-
 hw/wdt_ib700.c       |    2 +-
 monitor.c            |    6 +++---
 net.c                |    2 +-
 qemu-timer.h         |    2 +-
 target-ppc/kvm_ppc.c |    2 +-
 vl.c                 |   15 ++++++++++-----
 44 files changed, 130 insertions(+), 113 deletions(-)

diff --git a/audio/audio.c b/audio/audio.c
index c067afb..f247f42 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1822,7 +1822,7 @@ static void audio_init (void)
         }
         conf.period.ticks = 1;
     } else {
-        conf.period.ticks = ticks_per_sec / conf.period.hertz;
+        conf.period.ticks = get_ticks_per_sec() / conf.period.hertz;
     }

     e = qemu_add_vm_change_state_handler (audio_vm_change_state_handler, s);
diff --git a/audio/noaudio.c b/audio/noaudio.c
index 40a1a2f..2f25f17 100644
--- a/audio/noaudio.c
+++ b/audio/noaudio.c
@@ -53,7 +53,7 @@ static int no_run_out (HWVoiceOut *hw)

     now = qemu_get_clock (vm_clock);
     ticks = now - no->old_ticks;
-    bytes = (ticks * hw->info.bytes_per_second) / ticks_per_sec;
+    bytes = (ticks * hw->info.bytes_per_second) / get_ticks_per_sec();
     bytes = audio_MIN (bytes, INT_MAX);
     samples = bytes >> hw->info.shift;

@@ -109,7 +109,7 @@ static int no_run_in (HWVoiceIn *hw)
     if (dead) {
         int64_t now = qemu_get_clock (vm_clock);
         int64_t ticks = now - no->old_ticks;
-        int64_t bytes = (ticks * hw->info.bytes_per_second) / ticks_per_sec;
+        int64_t bytes = (ticks * hw->info.bytes_per_second) / get_ticks_per_sec();

         no->old_ticks = now;
         bytes = audio_MIN (bytes, INT_MAX);
diff --git a/audio/wavaudio.c b/audio/wavaudio.c
index c4aa60e..78eb758 100644
--- a/audio/wavaudio.c
+++ b/audio/wavaudio.c
@@ -54,7 +54,7 @@ static int wav_run_out (HWVoiceOut *hw)
     struct st_sample *src;
     int64_t now = qemu_get_clock (vm_clock);
     int64_t ticks = now - wav->old_ticks;
-    int64_t bytes = (ticks * hw->info.bytes_per_second) / ticks_per_sec;
+    int64_t bytes = (ticks * hw->info.bytes_per_second) / get_ticks_per_sec();

     if (bytes > INT_MAX) {
         samples = INT_MAX >> hw->info.shift;
diff --git a/hw/acpi.c b/hw/acpi.c
index 6eddd0e..ef4f782 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -79,7 +79,7 @@ static PIIX4PMState *pm_state;
 static uint32_t get_pmtmr(PIIX4PMState *s)
 {
     uint32_t d;
-    d = muldiv64(qemu_get_clock(vm_clock), PM_FREQ, ticks_per_sec);
+    d = muldiv64(qemu_get_clock(vm_clock), PM_FREQ, get_ticks_per_sec());
     return d & 0xffffff;
 }

@@ -88,7 +88,7 @@ static int get_pmsts(PIIX4PMState *s)
     int64_t d;
     int pmsts;
     pmsts = s->pmsts;
-    d = muldiv64(qemu_get_clock(vm_clock), PM_FREQ, ticks_per_sec);
+    d = muldiv64(qemu_get_clock(vm_clock), PM_FREQ, get_ticks_per_sec());
     if (d >= s->tmr_overflow_time)
         s->pmsts |= TMROF_EN;
     return s->pmsts;
@@ -105,7 +105,7 @@ static void pm_update_sci(PIIX4PMState *s)
     qemu_set_irq(s->irq, sci_level);
     /* schedule a timer interruption if needed */
     if ((s->pmen & TMROF_EN) && !(pmsts & TMROF_EN)) {
-        expire_time = muldiv64(s->tmr_overflow_time, ticks_per_sec, PM_FREQ);
+        expire_time = muldiv64(s->tmr_overflow_time, get_ticks_per_sec(), PM_FREQ);
         qemu_mod_timer(s->tmr_timer, expire_time);
     } else {
         qemu_del_timer(s->tmr_timer);
@@ -130,7 +130,8 @@ static void pm_ioport_writew(void *opaque, uint32_t addr, uint32_t val)
             pmsts = get_pmsts(s);
             if (pmsts & val & TMROF_EN) {
                 /* if TMRSTS is reset, then compute the new overflow time */
-                d = muldiv64(qemu_get_clock(vm_clock), PM_FREQ, ticks_per_sec);
+                d = muldiv64(qemu_get_clock(vm_clock), PM_FREQ,
+                             get_ticks_per_sec());
                 s->tmr_overflow_time = (d + 0x800000LL) & ~0x7fffffLL;
             }
             s->pmsts &= ~val;
diff --git a/hw/adlib.c b/hw/adlib.c
index e1e4077..1d8092b 100644
--- a/hw/adlib.c
+++ b/hw/adlib.c
@@ -165,7 +165,7 @@ static void timer_handler (int c, double interval_Sec)

     s->ticking[n] = 1;
 #ifdef DEBUG
-    interval = ticks_per_sec * interval_Sec;
+    interval = get_ticks_per_sec() * interval_Sec;
     exp = qemu_get_clock (vm_clock) + interval;
     s->exp[n] = exp;
 #endif
diff --git a/hw/baum.c b/hw/baum.c
index b47ea34..cbe4f0c 100644
--- a/hw/baum.c
+++ b/hw/baum.c
@@ -335,7 +335,8 @@ static int baum_eat_packet(BaumDriverState *baum, const uint8_t *buf, int len)
         int i;

         /* Allow 100ms to complete the DisplayData packet */
-        qemu_mod_timer(baum->cellCount_timer, qemu_get_clock(vm_clock) + ticks_per_sec / 10);
+        qemu_mod_timer(baum->cellCount_timer, qemu_get_clock(vm_clock) +
+                       get_ticks_per_sec() / 10);
         for (i = 0; i < baum->x * baum->y ; i++) {
             EAT(c);
             cells[i] = c;
diff --git a/hw/bt-hci-csr.c b/hw/bt-hci-csr.c
index 19d23f5..7300ea6 100644
--- a/hw/bt-hci-csr.c
+++ b/hw/bt-hci-csr.c
@@ -363,7 +363,7 @@ static int csrhci_ioctl(struct CharDriverState *chr, int cmd, void *arg)
     switch (cmd) {
     case CHR_IOCTL_SERIAL_SET_PARAMS:
         ssp = (QEMUSerialSetParams *) arg;
-        s->baud_delay = ticks_per_sec / ssp->speed;
+        s->baud_delay = get_ticks_per_sec() / ssp->speed;
         /* Moments later... (but shorter than 100ms) */
         s->modem_state |= CHR_TIOCM_CTS;
         break;
@@ -389,7 +389,7 @@ static void csrhci_reset(struct csrhci_s *s)
     s->out_len = 0;
     s->out_size = FIFO_LEN;
     s->in_len = 0;
-    s->baud_delay = ticks_per_sec;
+    s->baud_delay = get_ticks_per_sec();
     s->enable = 0;
     s->in_hdr = INT_MAX;
     s->in_data = INT_MAX;
diff --git a/hw/bt-hci.c b/hw/bt-hci.c
index d510d81..669866a 100644
--- a/hw/bt-hci.c
+++ b/hw/bt-hci.c
@@ -577,7 +577,7 @@ static void bt_hci_inquiry_result(struct bt_hci_s *hci,
 static void bt_hci_mod_timer_1280ms(QEMUTimer *timer, int period)
 {
     qemu_mod_timer(timer, qemu_get_clock(vm_clock) +
-                    muldiv64(period << 7, ticks_per_sec, 100));
+                   muldiv64(period << 7, get_ticks_per_sec(), 100));
 }

 static void bt_hci_inquiry_start(struct bt_hci_s *hci, int length)
@@ -1086,7 +1086,7 @@ static int bt_hci_mode_change(struct bt_hci_s *hci, uint16_t handle,
     bt_hci_event_status(hci, HCI_SUCCESS);

     qemu_mod_timer(link->acl_mode_timer, qemu_get_clock(vm_clock) +
-                            muldiv64(interval * 625, ticks_per_sec, 1000000));
+                   muldiv64(interval * 625, get_ticks_per_sec(), 1000000));
     bt_hci_lmp_mode_change_master(hci, link->link, mode, interval);

     return 0;
diff --git a/hw/cuda.c b/hw/cuda.c
index 3acd881..552e422 100644
--- a/hw/cuda.c
+++ b/hw/cuda.c
@@ -171,7 +171,7 @@ static unsigned int get_counter(CUDATimer *s)
     unsigned int counter;

     d = muldiv64(qemu_get_clock(vm_clock) - s->load_time,
-                 CUDA_TIMER_FREQ, ticks_per_sec);
+                 CUDA_TIMER_FREQ, get_ticks_per_sec());
     if (s->index == 0) {
         /* the timer goes down from latch to -1 (period of latch + 2) */
         if (d <= (s->counter_value + 1)) {
@@ -201,7 +201,7 @@ static int64_t get_next_irq_time(CUDATimer *s, int64_t current_time)

     /* current counter value */
     d = muldiv64(current_time - s->load_time,
-                 CUDA_TIMER_FREQ, ticks_per_sec);
+                 CUDA_TIMER_FREQ, get_ticks_per_sec());
     /* the timer goes down from latch to -1 (period of latch + 2) */
     if (d <= (s->counter_value + 1)) {
         counter = (s->counter_value - d) & 0xffff;
@@ -220,7 +220,7 @@ static int64_t get_next_irq_time(CUDATimer *s, int64_t current_time)
     }
     CUDA_DPRINTF("latch=%d counter=%" PRId64 " delta_next=%" PRId64 "\n",
                  s->latch, d, next_time - d);
-    next_time = muldiv64(next_time, ticks_per_sec, CUDA_TIMER_FREQ) +
+    next_time = muldiv64(next_time, get_ticks_per_sec(), CUDA_TIMER_FREQ) +
         s->load_time;
     if (next_time <= current_time)
         next_time = current_time + 1;
@@ -505,7 +505,7 @@ static void cuda_adb_poll(void *opaque)
     }
     qemu_mod_timer(s->adb_poll_timer,
                    qemu_get_clock(vm_clock) +
-                   (ticks_per_sec / CUDA_ADB_POLL_FREQ));
+                   (get_ticks_per_sec() / CUDA_ADB_POLL_FREQ));
 }

 static void cuda_receive_packet(CUDAState *s,
@@ -523,7 +523,7 @@ static void cuda_receive_packet(CUDAState *s,
             if (autopoll) {
                 qemu_mod_timer(s->adb_poll_timer,
                                qemu_get_clock(vm_clock) +
-                               (ticks_per_sec / CUDA_ADB_POLL_FREQ));
+                               (get_ticks_per_sec() / CUDA_ADB_POLL_FREQ));
             } else {
                 qemu_del_timer(s->adb_poll_timer);
             }
@@ -534,14 +534,14 @@ static void cuda_receive_packet(CUDAState *s,
         break;
     case CUDA_SET_TIME:
         ti = (((uint32_t)data[1]) << 24) + (((uint32_t)data[2]) << 16) + (((uint32_t)data[3]) << 8) + data[4];
-        s->tick_offset = ti - (qemu_get_clock(vm_clock) / ticks_per_sec);
+        s->tick_offset = ti - (qemu_get_clock(vm_clock) / get_ticks_per_sec());
         obuf[0] = CUDA_PACKET;
         obuf[1] = 0;
         obuf[2] = 0;
         cuda_send_packet_to_host(s, obuf, 3);
         break;
     case CUDA_GET_TIME:
-        ti = s->tick_offset + (qemu_get_clock(vm_clock) / ticks_per_sec);
+        ti = s->tick_offset + (qemu_get_clock(vm_clock) / get_ticks_per_sec());
         obuf[0] = CUDA_PACKET;
         obuf[1] = 0;
         obuf[2] = 0;
diff --git a/hw/dp8393x.c b/hw/dp8393x.c
index fcf0398..067831d 100644
--- a/hw/dp8393x.c
+++ b/hw/dp8393x.c
@@ -290,7 +290,7 @@ static void set_next_tick(dp8393xState *s)

     ticks = s->regs[SONIC_WT1] << 16 | s->regs[SONIC_WT0];
     s->wt_last_update = qemu_get_clock(vm_clock);
-    delay = ticks_per_sec * ticks / 5000000;
+    delay = get_ticks_per_sec() * ticks / 5000000;
     qemu_mod_timer(s->watchdog, s->wt_last_update + delay);
 }

diff --git a/hw/fdc.c b/hw/fdc.c
index db57710..19f44b1 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -1541,7 +1541,7 @@ static void fdctrl_handle_readid (fdctrl_t *fdctrl, int direction)
     /* XXX: should set main status register to busy */
     cur_drv->head = (fdctrl->fifo[1] >> 2) & 1;
     qemu_mod_timer(fdctrl->result_timer,
-                   qemu_get_clock(vm_clock) + (ticks_per_sec / 50));
+                   qemu_get_clock(vm_clock) + (get_ticks_per_sec() / 50));
 }

 static void fdctrl_handle_format_track (fdctrl_t *fdctrl, int direction)
diff --git a/hw/i8254.c b/hw/i8254.c
index 6a8cd3e..5c49e6e 100644
--- a/hw/i8254.c
+++ b/hw/i8254.c
@@ -66,7 +66,8 @@ static int pit_get_count(PITChannelState *s)
     uint64_t d;
     int counter;

-    d = muldiv64(qemu_get_clock(vm_clock) - s->count_load_time, PIT_FREQ, ticks_per_sec);
+    d = muldiv64(qemu_get_clock(vm_clock) - s->count_load_time, PIT_FREQ,
+                 get_ticks_per_sec());
     switch(s->mode) {
     case 0:
     case 1:
@@ -91,7 +92,8 @@ static int pit_get_out1(PITChannelState *s, int64_t current_time)
     uint64_t d;
     int out;

-    d = muldiv64(current_time - s->count_load_time, PIT_FREQ, ticks_per_sec);
+    d = muldiv64(current_time - s->count_load_time, PIT_FREQ,
+                 get_ticks_per_sec());
     switch(s->mode) {
     default:
     case 0:
@@ -130,7 +132,8 @@ static int64_t pit_get_next_transition_time(PITChannelState *s,
     uint64_t d, next_time, base;
     int period2;

-    d = muldiv64(current_time - s->count_load_time, PIT_FREQ, ticks_per_sec);
+    d = muldiv64(current_time - s->count_load_time, PIT_FREQ,
+                 get_ticks_per_sec());
     switch(s->mode) {
     default:
     case 0:
@@ -166,7 +169,8 @@ static int64_t pit_get_next_transition_time(PITChannelState *s,
         break;
     }
     /* convert to timer units */
-    next_time = s->count_load_time + muldiv64(next_time, ticks_per_sec, PIT_FREQ);
+    next_time = s->count_load_time + muldiv64(next_time, get_ticks_per_sec(),
+                                              PIT_FREQ);
     /* fix potential rounding problems */
     /* XXX: better solution: use a clock at PIT_FREQ Hz */
     if (next_time <= current_time)
@@ -373,7 +377,7 @@ static void pit_irq_timer_update(PITChannelState *s, int64_t current_time)
 #ifdef DEBUG_PIT
     printf("irq_level=%d next_delay=%f\n",
            irq_level,
-           (double)(expire_time - current_time) / ticks_per_sec);
+           (double)(expire_time - current_time) / get_ticks_per_sec());
 #endif
     s->next_transition_time = expire_time;
     if (expire_time != -1)
diff --git a/hw/i8259.c b/hw/i8259.c
index 74acc39..9b2896c 100644
--- a/hw/i8259.c
+++ b/hw/i8259.c
@@ -247,7 +247,8 @@ int pic_read_irq(PicState2 *s)
 #ifdef DEBUG_IRQ_LATENCY
     printf("IRQ%d latency=%0.3fus\n",
            irq,
-           (double)(qemu_get_clock(vm_clock) - irq_time[irq]) * 1000000.0 / ticks_per_sec);
+           (double)(qemu_get_clock(vm_clock) -
+                    irq_time[irq]) * 1000000.0 / get_ticks_per_sec());
 #endif
 #if defined(DEBUG_PIC)
     printf("pic_interrupt: irq=%d\n", irq);
diff --git a/hw/ide/core.c b/hw/ide/core.c
index fe5bd17..c938e65 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -644,7 +644,7 @@ static void ide_sector_write(IDEState *s)
            option _only_ to install Windows 2000. You must disable it
            for normal use. */
         qemu_mod_timer(s->sector_write_timer, 
-                       qemu_get_clock(vm_clock) + (ticks_per_sec / 1000));
+                       qemu_get_clock(vm_clock) + (get_ticks_per_sec() / 1000));
     } else 
 #endif
     {
diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 5f1760c..b7f09e5 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -108,7 +108,7 @@ static void rtc_coalesced_timer_update(RTCState *s)
         /* divide each RTC interval to 2 - 8 smaller intervals */
         int c = MIN(s->irq_coalesced, 7) + 1; 
         int64_t next_clock = qemu_get_clock(vm_clock) +
-		muldiv64(s->period / c, ticks_per_sec, 32768);
+		muldiv64(s->period / c, get_ticks_per_sec(), 32768);
         qemu_mod_timer(s->coalesced_timer, next_clock);
     }
 }
@@ -158,9 +158,9 @@ static void rtc_timer_update(RTCState *s, int64_t current_time)
         s->period = period;
 #endif
         /* compute 32 khz clock */
-        cur_clock = muldiv64(current_time, 32768, ticks_per_sec);
+        cur_clock = muldiv64(current_time, 32768, get_ticks_per_sec());
         next_irq_clock = (cur_clock & ~(period - 1)) + period;
-        s->next_periodic_time = muldiv64(next_irq_clock, ticks_per_sec, 32768) + 1;
+        s->next_periodic_time = muldiv64(next_irq_clock, get_ticks_per_sec(), 32768) + 1;
         qemu_mod_timer(s->periodic_timer, s->next_periodic_time);
     } else {
 #ifdef TARGET_I386
@@ -379,7 +379,7 @@ static void rtc_update_second(void *opaque)

     /* if the oscillator is not in normal operation, we do not update */
     if ((s->cmos_data[RTC_REG_A] & 0x70) != 0x20) {
-        s->next_second_time += ticks_per_sec;
+        s->next_second_time += get_ticks_per_sec();
         qemu_mod_timer(s->second_timer, s->next_second_time);
     } else {
         rtc_next_second(&s->current_tm);
@@ -390,7 +390,7 @@ static void rtc_update_second(void *opaque)
         }
         /* should be 244 us = 8 / 32768 seconds, but currently the
            timers do not have the necessary resolution. */
-        delay = (ticks_per_sec * 1) / 100;
+        delay = (get_ticks_per_sec() * 1) / 100;
         if (delay < 1)
             delay = 1;
         qemu_mod_timer(s->second_timer2,
@@ -430,7 +430,7 @@ static void rtc_update_second2(void *opaque)
     /* clear update in progress bit */
     s->cmos_data[RTC_REG_A] &= ~REG_A_UIP;

-    s->next_second_time += ticks_per_sec;
+    s->next_second_time += get_ticks_per_sec();
     qemu_mod_timer(s->second_timer, s->next_second_time);
 }

@@ -616,7 +616,7 @@ RTCState *rtc_init_sqw(int base, qemu_irq irq, qemu_irq sqw_irq, int base_year)
     s->second_timer2 = qemu_new_timer(vm_clock,
                                       rtc_update_second2, s);

-    s->next_second_time = qemu_get_clock(vm_clock) + (ticks_per_sec * 99) / 100;
+    s->next_second_time = qemu_get_clock(vm_clock) + (get_ticks_per_sec() * 99) / 100;
     qemu_mod_timer(s->second_timer2, s->next_second_time);

     register_ioport_write(base, 2, 1, cmos_ioport_write, s);
@@ -733,7 +733,7 @@ RTCState *rtc_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq,
     s->second_timer2 = qemu_new_timer(vm_clock,
                                       rtc_update_second2, s);

-    s->next_second_time = qemu_get_clock(vm_clock) + (ticks_per_sec * 99) / 100;
+    s->next_second_time = qemu_get_clock(vm_clock) + (get_ticks_per_sec() * 99) / 100;
     qemu_mod_timer(s->second_timer2, s->next_second_time);

     io_memory = cpu_register_io_memory(rtc_mm_read, rtc_mm_write, s);
diff --git a/hw/mips_timer.c b/hw/mips_timer.c
index d341e51..bb3c3e4 100644
--- a/hw/mips_timer.c
+++ b/hw/mips_timer.c
@@ -27,7 +27,7 @@ uint32_t cpu_mips_get_count (CPUState *env)
     else
         return env->CP0_Count +
             (uint32_t)muldiv64(qemu_get_clock(vm_clock),
-                               TIMER_FREQ, ticks_per_sec);
+                               TIMER_FREQ, get_ticks_per_sec());
 }

 static void cpu_mips_timer_update(CPUState *env)
@@ -37,8 +37,8 @@ static void cpu_mips_timer_update(CPUState *env)

     now = qemu_get_clock(vm_clock);
     wait = env->CP0_Compare - env->CP0_Count -
-	    (uint32_t)muldiv64(now, TIMER_FREQ, ticks_per_sec);
-    next = now + muldiv64(wait, ticks_per_sec, TIMER_FREQ);
+	    (uint32_t)muldiv64(now, TIMER_FREQ, get_ticks_per_sec());
+    next = now + muldiv64(wait, get_ticks_per_sec(), TIMER_FREQ);
     qemu_mod_timer(env->timer, next);
 }

@@ -50,7 +50,7 @@ void cpu_mips_store_count (CPUState *env, uint32_t count)
         /* Store new count register */
         env->CP0_Count =
             count - (uint32_t)muldiv64(qemu_get_clock(vm_clock),
-                                       TIMER_FREQ, ticks_per_sec);
+                                       TIMER_FREQ, get_ticks_per_sec());
         /* Update timer timer */
         cpu_mips_timer_update(env);
     }
@@ -75,7 +75,7 @@ void cpu_mips_stop_count(CPUState *env)
 {
     /* Store the current value */
     env->CP0_Count += (uint32_t)muldiv64(qemu_get_clock(vm_clock),
-                                         TIMER_FREQ, ticks_per_sec);
+                                         TIMER_FREQ, get_ticks_per_sec());
 }

 static void mips_timer_cb (void *opaque)
diff --git a/hw/omap1.c b/hw/omap1.c
index e870d96..06c7158 100644
--- a/hw/omap1.c
+++ b/hw/omap1.c
@@ -675,7 +675,7 @@ static inline uint32_t omap_timer_read(struct omap_mpu_timer_s *timer)

     if (timer->st && timer->enable && timer->rate)
         return timer->val - muldiv64(distance >> (timer->ptv + 1),
-                        timer->rate, ticks_per_sec);
+                                     timer->rate, get_ticks_per_sec());
     else
         return timer->val;
 }
@@ -693,7 +693,7 @@ static inline void omap_timer_update(struct omap_mpu_timer_s *timer)
     if (timer->enable && timer->st && timer->rate) {
         timer->val = timer->reset_val;	/* Should skip this on clk enable */
         expires = muldiv64((uint64_t) timer->val << (timer->ptv + 1),
-                        ticks_per_sec, timer->rate);
+                           get_ticks_per_sec(), timer->rate);

         /* If timer expiry would be sooner than in about 1 ms and
          * auto-reload isn't set, then fire immediately.  This is a hack
@@ -701,7 +701,7 @@ static inline void omap_timer_update(struct omap_mpu_timer_s *timer)
          * sets the interval to a very low value and polls the status bit
          * in a busy loop when it wants to sleep just a couple of CPU
          * ticks.  */
-        if (expires > (ticks_per_sec >> 10) || timer->ar)
+        if (expires > (get_ticks_per_sec() >> 10) || timer->ar)
             qemu_mod_timer(timer->timer, timer->time + expires);
         else
             qemu_bh_schedule(timer->tick);
@@ -1158,14 +1158,14 @@ static void omap_ulpd_pm_write(void *opaque, target_phys_addr_t addr,
                 now -= s->ulpd_gauge_start;

                 /* 32-kHz ticks */
-                ticks = muldiv64(now, 32768, ticks_per_sec);
+                ticks = muldiv64(now, 32768, get_ticks_per_sec());
                 s->ulpd_pm_regs[0x00 >> 2] = (ticks >>  0) & 0xffff;
                 s->ulpd_pm_regs[0x04 >> 2] = (ticks >> 16) & 0xffff;
                 if (ticks >> 32)	/* OVERFLOW_32K */
                     s->ulpd_pm_regs[0x14 >> 2] |= 1 << 2;

                 /* High frequency ticks */
-                ticks = muldiv64(now, 12000000, ticks_per_sec);
+                ticks = muldiv64(now, 12000000, get_ticks_per_sec());
                 s->ulpd_pm_regs[0x08 >> 2] = (ticks >>  0) & 0xffff;
                 s->ulpd_pm_regs[0x0c >> 2] = (ticks >> 16) & 0xffff;
                 if (ticks >> 32)	/* OVERFLOW_HI_FREQ */
@@ -3831,7 +3831,8 @@ static void omap_mcbsp_source_tick(void *opaque)
     s->rx_req = s->rx_rate << bps[(s->rcr[0] >> 5) & 7];

     omap_mcbsp_rx_newdata(s);
-    qemu_mod_timer(s->source_timer, qemu_get_clock(vm_clock) + ticks_per_sec);
+    qemu_mod_timer(s->source_timer, qemu_get_clock(vm_clock) +
+                   get_ticks_per_sec());
 }

 static void omap_mcbsp_rx_start(struct omap_mcbsp_s *s)
@@ -3876,7 +3877,8 @@ static void omap_mcbsp_sink_tick(void *opaque)
     s->tx_req = s->tx_rate << bps[(s->xcr[0] >> 5) & 7];

     omap_mcbsp_tx_newdata(s);
-    qemu_mod_timer(s->sink_timer, qemu_get_clock(vm_clock) + ticks_per_sec);
+    qemu_mod_timer(s->sink_timer, qemu_get_clock(vm_clock) +
+                   get_ticks_per_sec());
 }

 static void omap_mcbsp_tx_start(struct omap_mcbsp_s *s)
diff --git a/hw/omap2.c b/hw/omap2.c
index 6a681d6..ef338a5 100644
--- a/hw/omap2.c
+++ b/hw/omap2.c
@@ -412,7 +412,7 @@ static void omap_gp_timer_write(void *opaque, target_phys_addr_t addr,
         if (s->trigger == gpt_trigger_none)
             omap_gp_timer_out(s, s->scpwm);
         /* TODO: make sure this doesn't overflow 32-bits */
-        s->ticks_per_sec = ticks_per_sec << (s->pre ? s->ptv + 1 : 0);
+        s->ticks_per_sec = get_ticks_per_sec() << (s->pre ? s->ptv + 1 : 0);
         omap_gp_timer_update(s);
         break;

@@ -491,7 +491,7 @@ struct omap_gp_timer_s *omap_gp_timer_init(struct omap_target_agent_s *ta,

 /* 32-kHz Sync Timer of the OMAP2 */
 static uint32_t omap_synctimer_read(struct omap_synctimer_s *s) {
-    return muldiv64(qemu_get_clock(vm_clock), 0x8000, ticks_per_sec);
+    return muldiv64(qemu_get_clock(vm_clock), 0x8000, get_ticks_per_sec());
 }

 static void omap_synctimer_reset(struct omap_synctimer_s *s)
diff --git a/hw/pcnet.c b/hw/pcnet.c
index 8c352d2..ae98a20 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -726,7 +726,7 @@ static inline int64_t pcnet_get_next_poll_time(PCNetState *s, int64_t current_ti
 {
     int64_t next_time = current_time +
         muldiv64(65536 - (CSR_SPND(s) ? 0 : CSR_POLL(s)),
-                 ticks_per_sec, 33000000L);
+                 get_ticks_per_sec(), 33000000L);
     if (next_time <= current_time)
         next_time = current_time + 1;
     return next_time;
diff --git a/hw/pflash_cfi02.c b/hw/pflash_cfi02.c
index 7f5094b..135c850 100644
--- a/hw/pflash_cfi02.c
+++ b/hw/pflash_cfi02.c
@@ -389,7 +389,7 @@ static void pflash_write (pflash_t *pfl, uint32_t offset, uint32_t value,
             pflash_update(pfl, 0, pfl->chip_len);
             /* Let's wait 5 seconds before chip erase is done */
             qemu_mod_timer(pfl->timer,
-                           qemu_get_clock(vm_clock) + (ticks_per_sec * 5));
+                           qemu_get_clock(vm_clock) + (get_ticks_per_sec() * 5));
             break;
         case 0x30:
             /* Sector erase */
@@ -402,7 +402,7 @@ static void pflash_write (pflash_t *pfl, uint32_t offset, uint32_t value,
             pfl->status = 0x00;
             /* Let's wait 1/2 second before sector erase is done */
             qemu_mod_timer(pfl->timer,
-                           qemu_get_clock(vm_clock) + (ticks_per_sec / 2));
+                           qemu_get_clock(vm_clock) + (get_ticks_per_sec() / 2));
             break;
         default:
             DPRINTF("%s: invalid command %02x (wc 5)\n", __func__, cmd);
diff --git a/hw/pl031.c b/hw/pl031.c
index 19577dd..45b7032 100644
--- a/hw/pl031.c
+++ b/hw/pl031.c
@@ -67,7 +67,7 @@ static uint32_t pl031_get_count(pl031_state *s)
 {
     /* This assumes qemu_get_clock returns the time since the machine was
        created.  */
-    return s->tick_offset + qemu_get_clock(vm_clock) / ticks_per_sec;
+    return s->tick_offset + qemu_get_clock(vm_clock) / get_ticks_per_sec();
 }

 static void pl031_set_alarm(pl031_state *s)
@@ -76,7 +76,7 @@ static void pl031_set_alarm(pl031_state *s)
     uint32_t ticks;

     now = qemu_get_clock(vm_clock);
-    ticks = s->tick_offset + now / ticks_per_sec;
+    ticks = s->tick_offset + now / get_ticks_per_sec();

     /* The timer wraps around.  This subtraction also wraps in the same way,
        and gives correct results when alarm < now_ticks.  */
@@ -86,7 +86,7 @@ static void pl031_set_alarm(pl031_state *s)
         qemu_del_timer(s->timer);
         pl031_interrupt(s);
     } else {
-        qemu_mod_timer(s->timer, now + (int64_t)ticks * ticks_per_sec);
+        qemu_mod_timer(s->timer, now + (int64_t)ticks * get_ticks_per_sec());
     }
 }

diff --git a/hw/ppc.c b/hw/ppc.c
index a01bde9..2d66b9d 100644
--- a/hw/ppc.c
+++ b/hw/ppc.c
@@ -397,7 +397,7 @@ static inline uint64_t cpu_ppc_get_tb(ppc_tb_t *tb_env, uint64_t vmclk,
                                       int64_t tb_offset)
 {
     /* TB time in tb periods */
-    return muldiv64(vmclk, tb_env->tb_freq, ticks_per_sec) + tb_offset;
+    return muldiv64(vmclk, tb_env->tb_freq, get_ticks_per_sec()) + tb_offset;
 }

 uint32_t cpu_ppc_load_tbl (CPUState *env)
@@ -430,7 +430,7 @@ uint32_t cpu_ppc_load_tbu (CPUState *env)
 static inline void cpu_ppc_store_tb(ppc_tb_t *tb_env, uint64_t vmclk,
                                     int64_t *tb_offsetp, uint64_t value)
 {
-    *tb_offsetp = value - muldiv64(vmclk, tb_env->tb_freq, ticks_per_sec);
+    *tb_offsetp = value - muldiv64(vmclk, tb_env->tb_freq, get_ticks_per_sec());
     LOG_TB("%s: tb %016" PRIx64 " offset %08" PRIx64 "\n",
                 __func__, value, *tb_offsetp);
 }
@@ -557,9 +557,9 @@ static inline uint32_t _cpu_ppc_load_decr(CPUState *env, uint64_t next)

     diff = next - qemu_get_clock(vm_clock);
     if (diff >= 0)
-        decr = muldiv64(diff, tb_env->decr_freq, ticks_per_sec);
+        decr = muldiv64(diff, tb_env->decr_freq, get_ticks_per_sec());
     else
-        decr = -muldiv64(-diff, tb_env->decr_freq, ticks_per_sec);
+        decr = -muldiv64(-diff, tb_env->decr_freq, get_ticks_per_sec());
     LOG_TB("%s: %08" PRIx32 "\n", __func__, decr);

     return decr;
@@ -586,7 +586,7 @@ uint64_t cpu_ppc_load_purr (CPUState *env)

     diff = qemu_get_clock(vm_clock) - tb_env->purr_start;

-    return tb_env->purr_load + muldiv64(diff, tb_env->tb_freq, ticks_per_sec);
+    return tb_env->purr_load + muldiv64(diff, tb_env->tb_freq, get_ticks_per_sec());
 }

 /* When decrementer expires,
@@ -618,7 +618,7 @@ static void __cpu_ppc_store_decr (CPUState *env, uint64_t *nextp,
     LOG_TB("%s: %08" PRIx32 " => %08" PRIx32 "\n", __func__,
                 decr, value);
     now = qemu_get_clock(vm_clock);
-    next = now + muldiv64(value, ticks_per_sec, tb_env->decr_freq);
+    next = now + muldiv64(value, get_ticks_per_sec(), tb_env->decr_freq);
     if (is_excp)
         next += *nextp - now;
     if (next == now)
@@ -788,7 +788,7 @@ static void cpu_4xx_fit_cb (void *opaque)
         /* Cannot occur, but makes gcc happy */
         return;
     }
-    next = now + muldiv64(next, ticks_per_sec, tb_env->tb_freq);
+    next = now + muldiv64(next, get_ticks_per_sec(), tb_env->tb_freq);
     if (next == now)
         next++;
     qemu_mod_timer(ppcemb_timer->fit_timer, next);
@@ -818,7 +818,7 @@ static void start_stop_pit (CPUState *env, ppc_tb_t *tb_env, int is_excp)
                     __func__, ppcemb_timer->pit_reload);
         now = qemu_get_clock(vm_clock);
         next = now + muldiv64(ppcemb_timer->pit_reload,
-                              ticks_per_sec, tb_env->decr_freq);
+                              get_ticks_per_sec(), tb_env->decr_freq);
         if (is_excp)
             next += tb_env->decr_next - now;
         if (next == now)
@@ -878,7 +878,7 @@ static void cpu_4xx_wdt_cb (void *opaque)
         /* Cannot occur, but makes gcc happy */
         return;
     }
-    next = now + muldiv64(next, ticks_per_sec, tb_env->decr_freq);
+    next = now + muldiv64(next, get_ticks_per_sec(), tb_env->decr_freq);
     if (next == now)
         next++;
     LOG_TB("%s: TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx "\n", __func__,
diff --git a/hw/ppc405_uc.c b/hw/ppc405_uc.c
index 65d70d3..59def4c 100644
--- a/hw/ppc405_uc.c
+++ b/hw/ppc405_uc.c
@@ -1379,7 +1379,7 @@ static uint32_t ppc4xx_gpt_readl (void *opaque, target_phys_addr_t addr)
     case 0x00:
         /* Time base counter */
         ret = muldiv64(qemu_get_clock(vm_clock) + gpt->tb_offset,
-                       gpt->tb_freq, ticks_per_sec);
+                       gpt->tb_freq, get_ticks_per_sec());
         break;
     case 0x10:
         /* Output enable */
@@ -1434,7 +1434,7 @@ static void ppc4xx_gpt_writel (void *opaque,
     switch (addr) {
     case 0x00:
         /* Time base counter */
-        gpt->tb_offset = muldiv64(value, ticks_per_sec, gpt->tb_freq)
+        gpt->tb_offset = muldiv64(value, get_ticks_per_sec(), gpt->tb_freq)
             - qemu_get_clock(vm_clock);
         ppc4xx_gpt_compute_timer(gpt);
         break;
diff --git a/hw/pxa2xx_timer.c b/hw/pxa2xx_timer.c
index 154537b..43bad2c 100644
--- a/hw/pxa2xx_timer.c
+++ b/hw/pxa2xx_timer.c
@@ -98,11 +98,11 @@ static void pxa2xx_timer_update(void *opaque, uint64_t now_qemu)
     uint64_t new_qemu;

     now_vm = s->clock +
-            muldiv64(now_qemu - s->lastload, s->freq, ticks_per_sec);
+            muldiv64(now_qemu - s->lastload, s->freq, get_ticks_per_sec());

     for (i = 0; i < 4; i ++) {
         new_qemu = now_qemu + muldiv64((uint32_t) (s->timer[i].value - now_vm),
-                        ticks_per_sec, s->freq);
+                        get_ticks_per_sec(), s->freq);
         qemu_mod_timer(s->timer[i].qtimer, new_qemu);
     }
 }
@@ -127,10 +127,10 @@ static void pxa2xx_timer_update4(void *opaque, uint64_t now_qemu, int n)

     now_vm = s->tm4[counter].clock + muldiv64(now_qemu -
                     s->tm4[counter].lastload,
-                    s->tm4[counter].freq, ticks_per_sec);
+                    s->tm4[counter].freq, get_ticks_per_sec());

     new_qemu = now_qemu + muldiv64((uint32_t) (s->tm4[n].tm.value - now_vm),
-                    ticks_per_sec, s->tm4[counter].freq);
+                    get_ticks_per_sec(), s->tm4[counter].freq);
     qemu_mod_timer(s->tm4[n].tm.qtimer, new_qemu);
 }

@@ -158,7 +158,7 @@ static uint32_t pxa2xx_timer_read(void *opaque, target_phys_addr_t offset)
         return s->tm4[tm].tm.value;
     case OSCR:
         return s->clock + muldiv64(qemu_get_clock(vm_clock) -
-                        s->lastload, s->freq, ticks_per_sec);
+                        s->lastload, s->freq, get_ticks_per_sec());
     case OSCR11: tm ++;
     case OSCR10: tm ++;
     case OSCR9:  tm ++;
@@ -175,7 +175,7 @@ static uint32_t pxa2xx_timer_read(void *opaque, target_phys_addr_t offset)
                 s->snapshot = s->tm4[tm - 1].clock + muldiv64(
                                 qemu_get_clock(vm_clock) -
                                 s->tm4[tm - 1].lastload,
-                                s->tm4[tm - 1].freq, ticks_per_sec);
+                                s->tm4[tm - 1].freq, get_ticks_per_sec());
             else
                 s->snapshot = s->tm4[tm - 1].clock;
         }
@@ -183,7 +183,7 @@ static uint32_t pxa2xx_timer_read(void *opaque, target_phys_addr_t offset)
         if (!s->tm4[tm].freq)
             return s->tm4[tm].clock;
         return s->tm4[tm].clock + muldiv64(qemu_get_clock(vm_clock) -
-                        s->tm4[tm].lastload, s->tm4[tm].freq, ticks_per_sec);
+                        s->tm4[tm].lastload, s->tm4[tm].freq, get_ticks_per_sec());
     case OIER:
         return s->irq_enabled;
     case OSSR:	/* Status register */
diff --git a/hw/rc4030.c b/hw/rc4030.c
index f4ac83f..c2b2a3e 100644
--- a/hw/rc4030.c
+++ b/hw/rc4030.c
@@ -104,7 +104,8 @@ static void set_next_tick(rc4030State *s)

     tm_hz = 1000 / (s->itr + 1);

-    qemu_mod_timer(s->periodic_timer, qemu_get_clock(vm_clock) + ticks_per_sec / tm_hz);
+    qemu_mod_timer(s->periodic_timer, qemu_get_clock(vm_clock) +
+                   get_ticks_per_sec() / tm_hz);
 }

 /* called for accesses to rc4030 */
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index 3bd72e5..83cb1ff 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -3361,7 +3361,7 @@ static CPUWriteMemoryFunc * const rtl8139_mmio_write[3] = {
 static inline int64_t rtl8139_get_next_tctr_time(RTL8139State *s, int64_t current_time)
 {
     int64_t next_time = current_time +
-        muldiv64(1, ticks_per_sec, PCI_FREQUENCY);
+        muldiv64(1, get_ticks_per_sec(), PCI_FREQUENCY);
     if (next_time <= current_time)
         next_time = current_time + 1;
     return next_time;
@@ -3385,7 +3385,8 @@ static void rtl8139_timer(void *opaque)

     curr_time = qemu_get_clock(vm_clock);

-    curr_tick = muldiv64(curr_time - s->TCTR_base, PCI_FREQUENCY, ticks_per_sec);
+    curr_tick = muldiv64(curr_time - s->TCTR_base, PCI_FREQUENCY,
+                         get_ticks_per_sec());

     if (s->TimerInt && curr_tick >= s->TimerInt)
     {
diff --git a/hw/sb16.c b/hw/sb16.c
index ac41a13..a7b0b06 100644
--- a/hw/sb16.c
+++ b/hw/sb16.c
@@ -764,8 +764,8 @@ static void complete (SB16State *s)
                 freq = s->freq > 0 ? s->freq : 11025;
                 samples = dsp_get_lohi (s) + 1;
                 bytes = samples << s->fmt_stereo << (s->fmt_bits == 16);
-                ticks = (bytes * ticks_per_sec) / freq;
-                if (ticks < ticks_per_sec / 1024) {
+                ticks = (bytes * get_ticks_per_sec()) / freq;
+                if (ticks < get_ticks_per_sec() / 1024) {
                     qemu_irq_raise (s->pic);
                 }
                 else {
diff --git a/hw/serial.c b/hw/serial.c
index f5988a5..f9c7246 100644
--- a/hw/serial.c
+++ b/hw/serial.c
@@ -246,7 +246,7 @@ static void serial_update_parameters(SerialState *s)
     ssp.parity = parity;
     ssp.data_bits = data_bits;
     ssp.stop_bits = stop_bits;
-    s->char_transmit_time =  (ticks_per_sec / speed) * frame_size;
+    s->char_transmit_time =  (get_ticks_per_sec() / speed) * frame_size;
     qemu_chr_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp);
 #if 0
     printf("speed=%d parity=%c data=%d stop=%d\n",
@@ -286,7 +286,7 @@ static void serial_update_msl(SerialState *s)
        We'll be lazy and poll only every 10ms, and only poll it at all if MSI interrupts are turned on */

     if (s->poll_msl)
-        qemu_mod_timer(s->modem_status_poll, qemu_get_clock(vm_clock) + ticks_per_sec / 100);
+        qemu_mod_timer(s->modem_status_poll, qemu_get_clock(vm_clock) + get_ticks_per_sec() / 100);
 }

 static void serial_xmit(void *opaque)
@@ -695,7 +695,7 @@ static void serial_reset(void *opaque)
     s->mcr = UART_MCR_OUT2;
     s->scr = 0;
     s->tsr_retry = 0;
-    s->char_transmit_time = (ticks_per_sec / 9600) * 9;
+    s->char_transmit_time = (get_ticks_per_sec() / 9600) * 9;
     s->poll_msl = 0;

     fifo_clear(s,RECV_FIFO);
diff --git a/hw/spitz.c b/hw/spitz.c
index e19b8a2..564519b 100644
--- a/hw/spitz.c
+++ b/hw/spitz.c
@@ -392,7 +392,8 @@ static void spitz_keyboard_tick(void *opaque)
             s->fifopos = 0;
     }

-    qemu_mod_timer(s->kbdtimer, qemu_get_clock(vm_clock) + ticks_per_sec / 32);
+    qemu_mod_timer(s->kbdtimer, qemu_get_clock(vm_clock) +
+                   get_ticks_per_sec() / 32);
 }

 static void spitz_keyboard_pre_map(SpitzKeyboardState *s)
diff --git a/hw/stellaris.c b/hw/stellaris.c
index 0ea7652..bcde0a2 100644
--- a/hw/stellaris.c
+++ b/hw/stellaris.c
@@ -90,7 +90,7 @@ static void gptm_reload(gptm_state *s, int n, int reset)
         tick += (int64_t)count * system_clock_scale;
     } else if (s->config == 1) {
         /* 32-bit RTC.  1Hz tick.  */
-        tick += ticks_per_sec;
+        tick += get_ticks_per_sec();
     } else if (s->mode[n] == 0xa) {
         /* PWM mode.  Not implemented.  */
     } else {
diff --git a/hw/tsc2005.c b/hw/tsc2005.c
index efc63c0..b75cc86 100644
--- a/hw/tsc2005.c
+++ b/hw/tsc2005.c
@@ -290,7 +290,7 @@ static void tsc2005_pin_update(TSC2005State *s)
     s->precision = s->nextprecision;
     s->function = s->nextfunction;
     s->pdst = !s->pnd0;	/* Synchronised on internal clock */
-    expires = qemu_get_clock(vm_clock) + (ticks_per_sec >> 7);
+    expires = qemu_get_clock(vm_clock) + (get_ticks_per_sec() >> 7);
     qemu_mod_timer(s->timer, expires);
 }

diff --git a/hw/tsc210x.c b/hw/tsc210x.c
index 004e607..6bbe24d 100644
--- a/hw/tsc210x.c
+++ b/hw/tsc210x.c
@@ -864,7 +864,7 @@ static void tsc210x_pin_update(TSC210xState *s)
     s->busy = 1;
     s->precision = s->nextprecision;
     s->function = s->nextfunction;
-    expires = qemu_get_clock(vm_clock) + (ticks_per_sec >> 10);
+    expires = qemu_get_clock(vm_clock) + (get_ticks_per_sec() >> 10);
     qemu_mod_timer(s->timer, expires);
 }

diff --git a/hw/tusb6010.c b/hw/tusb6010.c
index 1ed9d4c..3887233 100644
--- a/hw/tusb6010.c
+++ b/hw/tusb6010.c
@@ -523,7 +523,7 @@ static void tusb_async_writew(void *opaque, target_phys_addr_t addr,
         if (value & TUSB_DEV_OTG_TIMER_ENABLE)
             qemu_mod_timer(s->otg_timer, qemu_get_clock(vm_clock) +
                             muldiv64(TUSB_DEV_OTG_TIMER_VAL(value),
-                                    ticks_per_sec, TUSB_DEVCLOCK));
+                                     get_ticks_per_sec(), TUSB_DEVCLOCK));
         else
             qemu_del_timer(s->otg_timer);
         break;
@@ -763,6 +763,6 @@ void tusb6010_power(TUSBState *s, int on)
         s->intr_ok = 0;
         tusb_intr_update(s);
         qemu_mod_timer(s->pwr_timer,
-                        qemu_get_clock(vm_clock) + ticks_per_sec / 2);
+                       qemu_get_clock(vm_clock) + get_ticks_per_sec() / 2);
     }
 }
diff --git a/hw/usb-musb.c b/hw/usb-musb.c
index 8fba84d..9eb0d63 100644
--- a/hw/usb-musb.c
+++ b/hw/usb-musb.c
@@ -511,7 +511,7 @@ static inline void musb_schedule_cb(USBPacket *packey, void *opaque, int dir)
         ep->intv_timer[dir] = qemu_new_timer(vm_clock, musb_cb_tick, opaque);

     qemu_mod_timer(ep->intv_timer[dir], qemu_get_clock(vm_clock) +
-                    muldiv64(timeout, ticks_per_sec, 8000));
+                   muldiv64(timeout, get_ticks_per_sec(), 8000));
 }

 static void musb_schedule0_cb(USBPacket *packey, void *opaque)
diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c
index 96a9555..6e428c4 100644
--- a/hw/usb-ohci.c
+++ b/hw/usb-ohci.c
@@ -1669,12 +1669,12 @@ static void usb_ohci_init(OHCIState *ohci, DeviceState *dev,

     if (usb_frame_time == 0) {
 #ifdef OHCI_TIME_WARP
-        usb_frame_time = ticks_per_sec;
-        usb_bit_time = muldiv64(1, ticks_per_sec, USB_HZ/1000);
+        usb_frame_time = get_ticks_per_sec();
+        usb_bit_time = muldiv64(1, get_ticks_per_sec(), USB_HZ/1000);
 #else
-        usb_frame_time = muldiv64(1, ticks_per_sec, 1000);
-        if (ticks_per_sec >= USB_HZ) {
-            usb_bit_time = muldiv64(1, ticks_per_sec, USB_HZ);
+        usb_frame_time = muldiv64(1, get_ticks_per_sec(), 1000);
+        if (get_ticks_per_sec() >= USB_HZ) {
+            usb_bit_time = muldiv64(1, get_ticks_per_sec(), USB_HZ);
         } else {
             usb_bit_time = 1;
         }
diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index 09ffd4b..6807413 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -1054,7 +1054,7 @@ static void uhci_frame_timer(void *opaque)

     /* prepare the timer for the next frame */
     expire_time = qemu_get_clock(vm_clock) +
-        (ticks_per_sec / FRAME_TIMER_FREQ);
+        (get_ticks_per_sec() / FRAME_TIMER_FREQ);
     qemu_mod_timer(s->frame_timer, expire_time);
 }

diff --git a/hw/vga.c b/hw/vga.c
index 5b16cc3..514371c 100644
--- a/hw/vga.c
+++ b/hw/vga.c
@@ -202,9 +202,9 @@ static void vga_precise_update_retrace_info(VGACommonState *s)

     r->total_chars = vtotal_lines * htotal_chars;
     if (r->freq) {
-        r->ticks_per_char = ticks_per_sec / (r->total_chars * r->freq);
+        r->ticks_per_char = get_ticks_per_sec() / (r->total_chars * r->freq);
     } else {
-        r->ticks_per_char = ticks_per_sec / chars_per_sec;
+        r->ticks_per_char = get_ticks_per_sec() / chars_per_sec;
     }

     r->vstart = vretr_start_line;
@@ -230,7 +230,7 @@ static void vga_precise_update_retrace_info(VGACommonState *s)
         "dots = %d\n"
         "ticks/char = %lld\n"
         "\n",
-        (double) ticks_per_sec / (r->ticks_per_char * r->total_chars),
+        (double) get_ticks_per_sec() / (r->ticks_per_char * r->total_chars),
         htotal_chars,
         hretr_start_char,
         hretr_skew_chars,
diff --git a/hw/wdt_i6300esb.c b/hw/wdt_i6300esb.c
index 6927d43..b54e6c6 100644
--- a/hw/wdt_i6300esb.c
+++ b/hw/wdt_i6300esb.c
@@ -130,7 +130,7 @@ static void i6300esb_restart_timer(I6300State *d, int stage)
         timeout <<= 5;

     /* Get the timeout in units of ticks_per_sec. */
-    timeout = ticks_per_sec * timeout / 33000000;
+    timeout = get_ticks_per_sec() * timeout / 33000000;

     i6300esb_debug("stage %d, timeout %" PRIi64 "\n", d->stage, timeout);

diff --git a/hw/wdt_ib700.c b/hw/wdt_ib700.c
index e0ee65a..0ee3a5c 100644
--- a/hw/wdt_ib700.c
+++ b/hw/wdt_ib700.c
@@ -52,7 +52,7 @@ static void ib700_write_enable_reg(void *vp, uint32_t addr, uint32_t data)

     ib700_debug("addr = %x, data = %x\n", addr, data);

-    timeout = (int64_t) time_map[data & 0xF] * ticks_per_sec;
+    timeout = (int64_t) time_map[data & 0xF] * get_ticks_per_sec();
     qemu_mod_timer(timer, qemu_get_clock (vm_clock) + timeout);
 }

diff --git a/monitor.c b/monitor.c
index f5f4d0e..cd1d067 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1162,7 +1162,7 @@ static void do_sendkey(Monitor *mon, const QDict *qdict)
     }
     /* delayed key up events */
     qemu_mod_timer(key_timer, qemu_get_clock(vm_clock) +
-                    muldiv64(ticks_per_sec, hold_time, 1000));
+                   muldiv64(get_ticks_per_sec(), hold_time, 1000));
 }

 static int mouse_button_state;
@@ -1461,9 +1461,9 @@ static void do_info_profile(Monitor *mon)
     if (total == 0)
         total = 1;
     monitor_printf(mon, "async time  %" PRId64 " (%0.3f)\n",
-                   dev_time, dev_time / (double)ticks_per_sec);
+                   dev_time, dev_time / (double)get_ticks_per_sec());
     monitor_printf(mon, "qemu time   %" PRId64 " (%0.3f)\n",
-                   qemu_time, qemu_time / (double)ticks_per_sec);
+                   qemu_time, qemu_time / (double)get_ticks_per_sec());
     qemu_time = 0;
     dev_time = 0;
 }
diff --git a/net.c b/net.c
index 340177e..4510694 100644
--- a/net.c
+++ b/net.c
@@ -2254,7 +2254,7 @@ static ssize_t dump_receive(VLANClientState *vc, const uint8_t *buf, size_t size
         return size;
     }

-    ts = muldiv64(qemu_get_clock(vm_clock), 1000000, ticks_per_sec);
+    ts = muldiv64(qemu_get_clock(vm_clock), 1000000, get_ticks_per_sec());
     caplen = size > s->pcap_caplen ? s->pcap_caplen : size;

     hdr.ts.tv_sec = ts / 1000000;
diff --git a/qemu-timer.h b/qemu-timer.h
index 8f69467..00b166d 100644
--- a/qemu-timer.h
+++ b/qemu-timer.h
@@ -26,7 +26,7 @@ void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time);
 int qemu_timer_pending(QEMUTimer *ts);
 int qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time);

-extern int64_t ticks_per_sec;
+int64_t get_ticks_per_sec(void);

 void qemu_get_timer(QEMUFile *f, QEMUTimer *ts);
 void qemu_put_timer(QEMUFile *f, QEMUTimer *ts);
diff --git a/target-ppc/kvm_ppc.c b/target-ppc/kvm_ppc.c
index 6b7f411..5093016 100644
--- a/target-ppc/kvm_ppc.c
+++ b/target-ppc/kvm_ppc.c
@@ -99,7 +99,7 @@ void kvmppc_init(void)
      * an idle guest does no IO, qemu's device model will never get a chance to
      * run. So, until Qemu gains IO threads, we create this timer to ensure
      * that the device model gets a chance to run. */
-    kvmppc_timer_rate = ticks_per_sec / 10;
+    kvmppc_timer_rate = get_ticks_per_sec() / 10;
     kvmppc_timer = qemu_new_timer(vm_clock, &kvmppc_timer_hack, NULL);
     qemu_mod_timer(kvmppc_timer, qemu_get_clock(vm_clock) + kvmppc_timer_rate);
 }
diff --git a/vl.c b/vl.c
index 448ec6c..33abef2 100644
--- a/vl.c
+++ b/vl.c
@@ -186,7 +186,7 @@ enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
 static DisplayState *display_state;
 DisplayType display_type = DT_DEFAULT;
 const char* keyboard_layout = NULL;
-int64_t ticks_per_sec;
+static int64_t ticks_per_sec;
 ram_addr_t ram_size;
 int nb_nics;
 NICInfo nd_table[MAX_NICS];
@@ -1032,6 +1032,11 @@ int64_t qemu_get_clock(QEMUClock *clock)
     }
 }

+int64_t get_ticks_per_sec(void)
+{
+    return ticks_per_sec;
+}
+
 static void init_timers(void)
 {
     init_get_clock();
@@ -1110,10 +1115,10 @@ static void host_alarm_handler(int host_signum)
             delta_cum += delta;
             if (++count == DISP_FREQ) {
                 printf("timer: min=%" PRId64 " us max=%" PRId64 " us avg=%" PRId64 " us avg_freq=%0.3f Hz\n",
-                       muldiv64(delta_min, 1000000, ticks_per_sec),
-                       muldiv64(delta_max, 1000000, ticks_per_sec),
-                       muldiv64(delta_cum, 1000000 / DISP_FREQ, ticks_per_sec),
-                       (double)ticks_per_sec / ((double)delta_cum / DISP_FREQ));
+                       muldiv64(delta_min, 1000000, get_ticks_per_sec()),
+                       muldiv64(delta_max, 1000000, get_ticks_per_sec()),
+                       muldiv64(delta_cum, 1000000 / DISP_FREQ, get_ticks_per_sec()),
+                       (double)get_ticks_per_sec() / ((double)delta_cum / DISP_FREQ));
                 count = 0;
                 delta_min = INT64_MAX;
                 delta_max = 0;
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 06/26] timers: Createt TimersState and put all timers state there
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (4 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 07/26] timers: move them to VMState Juan Quintela
                   ` (19 subsequent siblings)
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel


Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 vl.c |   70 ++++++++++++++++++++++++++++++++++++-----------------------------
 1 files changed, 39 insertions(+), 31 deletions(-)

diff --git a/vl.c b/vl.c
index 33abef2..19129ad 100644
--- a/vl.c
+++ b/vl.c
@@ -186,7 +186,6 @@ enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
 static DisplayState *display_state;
 DisplayType display_type = DT_DEFAULT;
 const char* keyboard_layout = NULL;
-static int64_t ticks_per_sec;
 ram_addr_t ram_size;
 int nb_nics;
 NICInfo nd_table[MAX_NICS];
@@ -609,10 +608,15 @@ static int64_t cpu_get_icount(void)
 /***********************************************************/
 /* guest cycle counter */

-static int64_t cpu_ticks_prev;
-static int64_t cpu_ticks_offset;
-static int64_t cpu_clock_offset;
-static int cpu_ticks_enabled;
+typedef struct TimersState {
+    int64_t cpu_ticks_prev;
+    int64_t cpu_ticks_offset;
+    int64_t cpu_clock_offset;
+    int32_t cpu_ticks_enabled;
+    int64_t ticks_per_sec;
+} TimersState;
+
+TimersState timers_state;

 /* return the host CPU cycle counter and handle stop/restart */
 int64_t cpu_get_ticks(void)
@@ -620,18 +624,18 @@ int64_t cpu_get_ticks(void)
     if (use_icount) {
         return cpu_get_icount();
     }
-    if (!cpu_ticks_enabled) {
-        return cpu_ticks_offset;
+    if (!timers_state.cpu_ticks_enabled) {
+        return timers_state.cpu_ticks_offset;
     } else {
         int64_t ticks;
         ticks = cpu_get_real_ticks();
-        if (cpu_ticks_prev > ticks) {
+        if (timers_state.cpu_ticks_prev > ticks) {
             /* Note: non increasing ticks may happen if the host uses
                software suspend */
-            cpu_ticks_offset += cpu_ticks_prev - ticks;
+            timers_state.cpu_ticks_offset += timers_state.cpu_ticks_prev - ticks;
         }
-        cpu_ticks_prev = ticks;
-        return ticks + cpu_ticks_offset;
+        timers_state.cpu_ticks_prev = ticks;
+        return ticks + timers_state.cpu_ticks_offset;
     }
 }

@@ -639,21 +643,21 @@ int64_t cpu_get_ticks(void)
 static int64_t cpu_get_clock(void)
 {
     int64_t ti;
-    if (!cpu_ticks_enabled) {
-        return cpu_clock_offset;
+    if (!timers_state.cpu_ticks_enabled) {
+        return timers_state.cpu_clock_offset;
     } else {
         ti = get_clock();
-        return ti + cpu_clock_offset;
+        return ti + timers_state.cpu_clock_offset;
     }
 }

 /* enable cpu_get_ticks() */
 void cpu_enable_ticks(void)
 {
-    if (!cpu_ticks_enabled) {
-        cpu_ticks_offset -= cpu_get_real_ticks();
-        cpu_clock_offset -= get_clock();
-        cpu_ticks_enabled = 1;
+    if (!timers_state.cpu_ticks_enabled) {
+        timers_state.cpu_ticks_offset -= cpu_get_real_ticks();
+        timers_state.cpu_clock_offset -= get_clock();
+        timers_state.cpu_ticks_enabled = 1;
     }
 }

@@ -661,10 +665,10 @@ void cpu_enable_ticks(void)
    cpu_get_ticks() after that.  */
 void cpu_disable_ticks(void)
 {
-    if (cpu_ticks_enabled) {
-        cpu_ticks_offset = cpu_get_ticks();
-        cpu_clock_offset = cpu_get_clock();
-        cpu_ticks_enabled = 0;
+    if (timers_state.cpu_ticks_enabled) {
+        timers_state.cpu_ticks_offset = cpu_get_ticks();
+        timers_state.cpu_clock_offset = cpu_get_clock();
+        timers_state.cpu_ticks_enabled = 0;
     }
 }

@@ -1034,13 +1038,13 @@ int64_t qemu_get_clock(QEMUClock *clock)

 int64_t get_ticks_per_sec(void)
 {
-    return ticks_per_sec;
+    return timers_state.ticks_per_sec;
 }

 static void init_timers(void)
 {
     init_get_clock();
-    ticks_per_sec = QEMU_TIMER_BASE;
+    timers_state.ticks_per_sec = QEMU_TIMER_BASE;
     rt_clock = qemu_new_clock(QEMU_TIMER_REALTIME);
     vm_clock = qemu_new_clock(QEMU_TIMER_VIRTUAL);
 }
@@ -1072,19 +1076,23 @@ void qemu_get_timer(QEMUFile *f, QEMUTimer *ts)

 static void timer_save(QEMUFile *f, void *opaque)
 {
-    qemu_put_be64(f, cpu_ticks_offset);
-    qemu_put_be64(f, ticks_per_sec);
-    qemu_put_be64(f, cpu_clock_offset);
+    struct TimersState *s = opaque;
+
+    qemu_put_be64(f, s->cpu_ticks_offset);
+    qemu_put_be64(f, s->ticks_per_sec);
+    qemu_put_be64(f, s->cpu_clock_offset);
 }

 static int timer_load(QEMUFile *f, void *opaque, int version_id)
 {
+    struct TimersState *s = opaque;
+
     if (version_id != 1 && version_id != 2)
         return -EINVAL;
-    cpu_ticks_offset=qemu_get_be64(f);
-    ticks_per_sec=qemu_get_be64(f);
+    s->cpu_ticks_offset = qemu_get_be64(f);
+    s->ticks_per_sec = qemu_get_be64(f);
     if (version_id == 2) {
-        cpu_clock_offset=qemu_get_be64(f);
+        s->cpu_clock_offset = qemu_get_be64(f);
     }
     return 0;
 }
@@ -5613,7 +5621,7 @@ int main(int argc, char **argv, char **envp)
     if (qemu_opts_foreach(&qemu_drive_opts, drive_init_func, machine, 1) != 0)
         exit(1);

-    register_savevm("timer", 0, 2, timer_save, timer_load, NULL);
+    register_savevm("timer", 0, 2, timer_save, timer_load, &timers_state);
     register_savevm_live("ram", 0, 3, ram_save_live, NULL, ram_load, NULL);

     /* Maintain compatibility with multiple stdio monitors */
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 07/26] timers: move them to VMState
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (5 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 06/26] timers: Createt TimersState and put all timers state there Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 08/26] vmstate: add sensible arguments to vmstate_unregister() Juan Quintela
                   ` (18 subsequent siblings)
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel


Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 vl.c |   34 ++++++++++++----------------------
 1 files changed, 12 insertions(+), 22 deletions(-)

diff --git a/vl.c b/vl.c
index 19129ad..3828eb4 100644
--- a/vl.c
+++ b/vl.c
@@ -1074,28 +1074,18 @@ void qemu_get_timer(QEMUFile *f, QEMUTimer *ts)
     }
 }

-static void timer_save(QEMUFile *f, void *opaque)
-{
-    struct TimersState *s = opaque;
-
-    qemu_put_be64(f, s->cpu_ticks_offset);
-    qemu_put_be64(f, s->ticks_per_sec);
-    qemu_put_be64(f, s->cpu_clock_offset);
-}
-
-static int timer_load(QEMUFile *f, void *opaque, int version_id)
-{
-    struct TimersState *s = opaque;
-
-    if (version_id != 1 && version_id != 2)
-        return -EINVAL;
-    s->cpu_ticks_offset = qemu_get_be64(f);
-    s->ticks_per_sec = qemu_get_be64(f);
-    if (version_id == 2) {
-        s->cpu_clock_offset = qemu_get_be64(f);
+static const VMStateDescription vmstate_timers = {
+    .name = "timer",
+    .version_id = 2,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField []) {
+        VMSTATE_INT64(cpu_ticks_offset, TimersState),
+        VMSTATE_INT64(ticks_per_sec, TimersState),
+        VMSTATE_INT64_V(cpu_clock_offset, TimersState, 2),
+        VMSTATE_END_OF_LIST()
     }
-    return 0;
-}
+};

 static void qemu_event_increment(void);

@@ -5621,7 +5611,7 @@ int main(int argc, char **argv, char **envp)
     if (qemu_opts_foreach(&qemu_drive_opts, drive_init_func, machine, 1) != 0)
         exit(1);

-    register_savevm("timer", 0, 2, timer_save, timer_load, &timers_state);
+    vmstate_register(0, &vmstate_timers ,&timers_state);
     register_savevm_live("ram", 0, 3, ram_save_live, NULL, ram_load, NULL);

     /* Maintain compatibility with multiple stdio monitors */
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 08/26] vmstate: add sensible arguments to vmstate_unregister()
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (6 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 07/26] timers: move them to VMState Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 09/26] vmstate: rename run_after_load() -> post_load() Juan Quintela
                   ` (17 subsequent siblings)
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel

vmsd alone is not enugh, because we can have several structs saved with the same description (vmsd).

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/hw.h  |    2 +-
 savevm.c |   11 +++++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/hw/hw.h b/hw/hw.h
index a0cb94e..c703975 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -509,5 +509,5 @@ extern void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
                                const void *opaque);
 extern int vmstate_register(int instance_id, const VMStateDescription *vmsd,
                             void *base);
-extern void vmstate_unregister(const char *idstr, void *opaque);
+void vmstate_unregister(const VMStateDescription *vmsd, void *opaque);
 #endif
diff --git a/savevm.c b/savevm.c
index 0dcab79..7b0989f 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1002,9 +1002,16 @@ int vmstate_register(int instance_id, const VMStateDescription *vmsd,
     return 0;
 }

-void vmstate_unregister(const char *idstr,  void *opaque)
+void vmstate_unregister(const VMStateDescription *vmsd, void *opaque)
 {
-    unregister_savevm(idstr, opaque);
+    SaveStateEntry *se, *new_se;
+
+    TAILQ_FOREACH_SAFE(se, &savevm_handlers, entry, new_se) {
+        if (se->vmsd == vmsd && se->opaque == opaque) {
+            TAILQ_REMOVE(&savevm_handlers, se, entry);
+            qemu_free(se);
+        }
+    }
 }

 int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 09/26] vmstate: rename run_after_load() -> post_load()
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (7 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 08/26] vmstate: add sensible arguments to vmstate_unregister() Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 10/26] vmstate: Add pre_load() hook Juan Quintela
                   ` (16 subsequent siblings)
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel

This naming was used in kvm tree, and is easier to remember

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/acpi.c          |    4 ++--
 hw/hw.h            |    2 +-
 hw/piix_pci.c      |    4 ++--
 hw/slavio_intctl.c |    4 ++--
 hw/tcx.c           |    4 ++--
 savevm.c           |    5 +++--
 6 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/hw/acpi.c b/hw/acpi.c
index ef4f782..b14b9f4 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -441,7 +441,7 @@ static void pm_write_config(PCIDevice *d,
         pm_io_space_update((PIIX4PMState *)d);
 }

-static int vmstate_acpi_after_load(void *opaque)
+static int vmstate_acpi_post_load(void *opaque)
 {
     PIIX4PMState *s = opaque;

@@ -454,7 +454,7 @@ static const VMStateDescription vmstate_acpi = {
     .version_id = 1,
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
-    .run_after_load = vmstate_acpi_after_load,
+    .post_load = vmstate_acpi_post_load,
     .fields      = (VMStateField []) {
         VMSTATE_PCI_DEVICE(dev, PIIX4PMState),
         VMSTATE_UINT16(pmsts, PIIX4PMState),
diff --git a/hw/hw.h b/hw/hw.h
index c703975..c85ce50 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -306,7 +306,7 @@ struct VMStateDescription {
     int minimum_version_id;
     int minimum_version_id_old;
     LoadStateHandler *load_state_old;
-    int (*run_after_load)(void *opaque);
+    int (*post_load)(void *opaque);
     VMStateField *fields;
 };

diff --git a/hw/piix_pci.c b/hw/piix_pci.c
index ef3463b..edd6df0 100644
--- a/hw/piix_pci.c
+++ b/hw/piix_pci.c
@@ -172,7 +172,7 @@ static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id)
     return 0;
 }

-static int i440fx_after_load(void *opaque)
+static int i440fx_post_load(void *opaque)
 {
     PCII440FXState *d = opaque;

@@ -186,7 +186,7 @@ static const VMStateDescription vmstate_i440fx = {
     .minimum_version_id = 3,
     .minimum_version_id_old = 1,
     .load_state_old = i440fx_load_old,
-    .run_after_load = i440fx_after_load,
+    .post_load = i440fx_post_load,
     .fields      = (VMStateField []) {
         VMSTATE_PCI_DEVICE(dev, PCII440FXState),
         VMSTATE_UINT8(smm_enabled, PCII440FXState),
diff --git a/hw/slavio_intctl.c b/hw/slavio_intctl.c
index 259e45e..6a95f9e 100644
--- a/hw/slavio_intctl.c
+++ b/hw/slavio_intctl.c
@@ -374,7 +374,7 @@ static void slavio_set_irq_all(void *opaque, int irq, int level)
     }
 }

-static int vmstate_intctl_after_load(void *opaque)
+static int vmstate_intctl_post_load(void *opaque)
 {
     SLAVIO_INTCTLState *s = opaque;

@@ -398,7 +398,7 @@ static const VMStateDescription vmstate_intctl = {
     .version_id = 1,
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
-    .run_after_load = vmstate_intctl_after_load,
+    .post_load = vmstate_intctl_post_load,
     .fields      = (VMStateField []) {
         VMSTATE_STRUCT_ARRAY(slaves, SLAVIO_INTCTLState, MAX_CPUS, 1,
                              vmstate_intctl_cpu, SLAVIO_CPUINTCTLState),
diff --git a/hw/tcx.c b/hw/tcx.c
index 9996219..012d01b 100644
--- a/hw/tcx.c
+++ b/hw/tcx.c
@@ -378,7 +378,7 @@ static void tcx24_invalidate_display(void *opaque)
     qemu_console_resize(s->ds, s->width, s->height);
 }

-static int vmstate_tcx_after_load(void *opaque)
+static int vmstate_tcx_post_load(void *opaque)
 {
     TCXState *s = opaque;

@@ -397,7 +397,7 @@ static const VMStateDescription vmstate_tcx = {
     .version_id = 4,
     .minimum_version_id = 4,
     .minimum_version_id_old = 4,
-    .run_after_load = vmstate_tcx_after_load,
+    .post_load = vmstate_tcx_post_load,
     .fields      = (VMStateField []) {
         VMSTATE_UINT16(height, TCXState),
         VMSTATE_UINT16(width, TCXState),
diff --git a/savevm.c b/savevm.c
index 7b0989f..38f9946 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1057,8 +1057,9 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
         }
         field++;
     }
-    if (vmsd->run_after_load)
-        return vmsd->run_after_load(opaque);
+    if (vmsd->post_load) {
+        return vmsd->post_load(opaque);
+    }
     return 0;
 }

-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 10/26] vmstate: Add pre_load() hook
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (8 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 09/26] vmstate: rename run_after_load() -> post_load() Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 11/26] vmstate: Add pre/post_save() hooks Juan Quintela
                   ` (15 subsequent siblings)
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel


Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/hw.h  |    1 +
 savevm.c |    5 +++++
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/hw/hw.h b/hw/hw.h
index c85ce50..8e75a04 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -306,6 +306,7 @@ struct VMStateDescription {
     int minimum_version_id;
     int minimum_version_id_old;
     LoadStateHandler *load_state_old;
+    int (*pre_load)(void *opaque);
     int (*post_load)(void *opaque);
     VMStateField *fields;
 };
diff --git a/savevm.c b/savevm.c
index 38f9946..8ae8d16 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1028,6 +1028,11 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
     if  (version_id < vmsd->minimum_version_id) {
         return vmsd->load_state_old(f, opaque, version_id);
     }
+    if (vmsd->pre_load) {
+        int ret = vmsd->pre_load(opaque);
+        if (ret)
+            return ret;
+    }
     while(field->name) {
         if (field->version_id <= version_id) {
             void *base_addr = opaque + field->offset;
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 11/26] vmstate: Add pre/post_save() hooks
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (9 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 10/26] vmstate: Add pre_load() hook Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 12/26] vmstate: port cpu_comon Juan Quintela
                   ` (14 subsequent siblings)
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel


Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/hw.h  |    2 ++
 savevm.c |    6 ++++++
 2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/hw/hw.h b/hw/hw.h
index 8e75a04..d64a0e8 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -308,6 +308,8 @@ struct VMStateDescription {
     LoadStateHandler *load_state_old;
     int (*pre_load)(void *opaque);
     int (*post_load)(void *opaque);
+    void (*pre_save)(const void *opaque);
+    void (*post_save)(const void *opaque);
     VMStateField *fields;
 };

diff --git a/savevm.c b/savevm.c
index 8ae8d16..c4bee37 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1073,6 +1073,9 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
 {
     VMStateField *field = vmsd->fields;

+    if (vmsd->pre_save) {
+        vmsd->pre_save(opaque);
+    }
     while(field->name) {
         const void *base_addr = opaque + field->offset;
         int i, n_elems = 1;
@@ -1096,6 +1099,9 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
         }
         field++;
     }
+    if (vmsd->post_save) {
+        vmsd->post_save(opaque);
+    }
 }

 static int vmstate_load(QEMUFile *f, SaveStateEntry *se, int version_id)
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 12/26] vmstate: port cpu_comon
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (10 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 11/26] vmstate: Add pre/post_save() hooks Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 13/26] vmstate: port fw_cfg device Juan Quintela
                   ` (13 subsequent siblings)
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel


Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 exec.c |   39 +++++++++++++++++++++++++--------------
 1 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/exec.c b/exec.c
index c5bc13a..6a62a8a 100644
--- a/exec.c
+++ b/exec.c
@@ -513,28 +513,25 @@ void cpu_exec_init_all(unsigned long tb_size)

 #if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)

-#define CPU_COMMON_SAVE_VERSION 1
-
-static void cpu_common_save(QEMUFile *f, void *opaque)
+static void cpu_common_pre_save(const void *opaque)
 {
-    CPUState *env = opaque;
+    CPUState *env = (void *)opaque;

     cpu_synchronize_state(env);
-
-    qemu_put_be32s(f, &env->halted);
-    qemu_put_be32s(f, &env->interrupt_request);
 }

-static int cpu_common_load(QEMUFile *f, void *opaque, int version_id)
+static int cpu_common_pre_load(void *opaque)
 {
     CPUState *env = opaque;

     cpu_synchronize_state(env);
-    if (version_id != CPU_COMMON_SAVE_VERSION)
-        return -EINVAL;
+    return 0;
+}
+
+static int cpu_common_post_load(void *opaque)
+{
+    CPUState *env = opaque;

-    qemu_get_be32s(f, &env->halted);
-    qemu_get_be32s(f, &env->interrupt_request);
     /* 0x01 was CPU_INTERRUPT_EXIT. This line can be removed when the
        version_id is increased. */
     env->interrupt_request &= ~0x01;
@@ -542,6 +539,21 @@ static int cpu_common_load(QEMUFile *f, void *opaque, int version_id)

     return 0;
 }
+
+static const VMStateDescription vmstate_cpu_common = {
+    .name = "cpu_common",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .pre_save = cpu_common_pre_save,
+    .pre_load = cpu_common_pre_load,
+    .post_load = cpu_common_post_load,
+    .fields      = (VMStateField []) {
+        VMSTATE_UINT32(halted, CPUState),
+        VMSTATE_UINT32(interrupt_request, CPUState),
+        VMSTATE_END_OF_LIST()
+    }
+};
 #endif

 CPUState *qemu_get_cpu(int cpu)
@@ -581,8 +593,7 @@ void cpu_exec_init(CPUState *env)
     cpu_list_unlock();
 #endif
 #if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)
-    register_savevm("cpu_common", cpu_index, CPU_COMMON_SAVE_VERSION,
-                    cpu_common_save, cpu_common_load, env);
+    vmstate_register(cpu_index, &vmstate_cpu_common, env);
     register_savevm("cpu", cpu_index, CPU_SAVE_VERSION,
                     cpu_save, cpu_load, env);
 #endif
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 13/26] vmstate: port fw_cfg device
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (11 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 12/26] vmstate: port cpu_comon Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 14/26] vmstate: port i8259 device Juan Quintela
                   ` (12 subsequent siblings)
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel


Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/fw_cfg.c |   33 ++++++++++++---------------------
 1 files changed, 12 insertions(+), 21 deletions(-)

diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
index 85f433a..37fe3b3 100644
--- a/hw/fw_cfg.c
+++ b/hw/fw_cfg.c
@@ -164,26 +164,17 @@ static void fw_cfg_reset(void *opaque)
     fw_cfg_select(s, 0);
 }

-static void fw_cfg_save(QEMUFile *f, void *opaque)
-{
-    FWCfgState *s = opaque;
-
-    qemu_put_be16s(f, &s->cur_entry);
-    qemu_put_be16s(f, &s->cur_offset);
-}
-
-static int fw_cfg_load(QEMUFile *f, void *opaque, int version_id)
-{
-    FWCfgState *s = opaque;
-
-    if (version_id > 1)
-        return -EINVAL;
-
-    qemu_get_be16s(f, &s->cur_entry);
-    qemu_get_be16s(f, &s->cur_offset);
-
-    return 0;
-}
+static const VMStateDescription vmstate_fw_cfg = {
+    .name = "fw_cfg",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField []) {
+        VMSTATE_UINT16(cur_entry, FWCfgState),
+        VMSTATE_UINT16(cur_offset, FWCfgState),
+        VMSTATE_END_OF_LIST()
+    }
+};

 int fw_cfg_add_bytes(void *opaque, uint16_t key, uint8_t *data, uint16_t len)
 {
@@ -282,7 +273,7 @@ void *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
     fw_cfg_add_i16(s, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
     fw_cfg_add_i16(s, FW_CFG_BOOT_MENU, (uint16_t)boot_menu);

-    register_savevm("fw_cfg", -1, 1, fw_cfg_save, fw_cfg_load, s);
+    vmstate_register(-1, &vmstate_fw_cfg, s);
     qemu_register_reset(fw_cfg_reset, s);
     fw_cfg_reset(s);

-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 14/26] vmstate: port i8259 device
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (12 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 13/26] vmstate: port fw_cfg device Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 15/26] vmstate: add support for uint8_t equal Juan Quintela
                   ` (11 subsequent siblings)
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel


Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/i8259.c |   74 +++++++++++++++++++++--------------------------------------
 1 files changed, 26 insertions(+), 48 deletions(-)

diff --git a/hw/i8259.c b/hw/i8259.c
index 9b2896c..3de22e3 100644
--- a/hw/i8259.c
+++ b/hw/i8259.c
@@ -446,53 +446,31 @@ static uint32_t elcr_ioport_read(void *opaque, uint32_t addr1)
     return s->elcr;
 }

-static void pic_save(QEMUFile *f, void *opaque)
-{
-    PicState *s = opaque;
-
-    qemu_put_8s(f, &s->last_irr);
-    qemu_put_8s(f, &s->irr);
-    qemu_put_8s(f, &s->imr);
-    qemu_put_8s(f, &s->isr);
-    qemu_put_8s(f, &s->priority_add);
-    qemu_put_8s(f, &s->irq_base);
-    qemu_put_8s(f, &s->read_reg_select);
-    qemu_put_8s(f, &s->poll);
-    qemu_put_8s(f, &s->special_mask);
-    qemu_put_8s(f, &s->init_state);
-    qemu_put_8s(f, &s->auto_eoi);
-    qemu_put_8s(f, &s->rotate_on_auto_eoi);
-    qemu_put_8s(f, &s->special_fully_nested_mode);
-    qemu_put_8s(f, &s->init4);
-    qemu_put_8s(f, &s->single_mode);
-    qemu_put_8s(f, &s->elcr);
-}
-
-static int pic_load(QEMUFile *f, void *opaque, int version_id)
-{
-    PicState *s = opaque;
-
-    if (version_id != 1)
-        return -EINVAL;
-
-    qemu_get_8s(f, &s->last_irr);
-    qemu_get_8s(f, &s->irr);
-    qemu_get_8s(f, &s->imr);
-    qemu_get_8s(f, &s->isr);
-    qemu_get_8s(f, &s->priority_add);
-    qemu_get_8s(f, &s->irq_base);
-    qemu_get_8s(f, &s->read_reg_select);
-    qemu_get_8s(f, &s->poll);
-    qemu_get_8s(f, &s->special_mask);
-    qemu_get_8s(f, &s->init_state);
-    qemu_get_8s(f, &s->auto_eoi);
-    qemu_get_8s(f, &s->rotate_on_auto_eoi);
-    qemu_get_8s(f, &s->special_fully_nested_mode);
-    qemu_get_8s(f, &s->init4);
-    qemu_get_8s(f, &s->single_mode);
-    qemu_get_8s(f, &s->elcr);
-    return 0;
-}
+static const VMStateDescription vmstate_pic = {
+    .name = "i8259",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField []) {
+        VMSTATE_UINT8(last_irr, PicState),
+        VMSTATE_UINT8(irr, PicState),
+        VMSTATE_UINT8(imr, PicState),
+        VMSTATE_UINT8(isr, PicState),
+        VMSTATE_UINT8(priority_add, PicState),
+        VMSTATE_UINT8(irq_base, PicState),
+        VMSTATE_UINT8(read_reg_select, PicState),
+        VMSTATE_UINT8(poll, PicState),
+        VMSTATE_UINT8(special_mask, PicState),
+        VMSTATE_UINT8(init_state, PicState),
+        VMSTATE_UINT8(auto_eoi, PicState),
+        VMSTATE_UINT8(rotate_on_auto_eoi, PicState),
+        VMSTATE_UINT8(special_fully_nested_mode, PicState),
+        VMSTATE_UINT8(init4, PicState),
+        VMSTATE_UINT8(single_mode, PicState),
+        VMSTATE_UINT8(elcr, PicState),
+        VMSTATE_END_OF_LIST()
+    }
+};

 /* XXX: add generic master/slave system */
 static void pic_init1(int io_addr, int elcr_addr, PicState *s)
@@ -503,7 +481,7 @@ static void pic_init1(int io_addr, int elcr_addr, PicState *s)
         register_ioport_write(elcr_addr, 1, 1, elcr_ioport_write, s);
         register_ioport_read(elcr_addr, 1, 1, elcr_ioport_read, s);
     }
-    register_savevm("i8259", io_addr, 1, pic_save, pic_load, s);
+    vmstate_register(io_addr, &vmstate_pic, s);
     qemu_register_reset(pic_reset, s);
 }

-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 15/26] vmstate: add support for uint8_t equal
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (13 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 14/26] vmstate: port i8259 device Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 16/26] vmstate: port fdc device Juan Quintela
                   ` (10 subsequent siblings)
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel


Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/hw.h  |    4 ++++
 savevm.c |   20 ++++++++++++++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/hw/hw.h b/hw/hw.h
index d64a0e8..4ff7dbd 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -318,6 +318,7 @@ extern const VMStateInfo vmstate_info_int16;
 extern const VMStateInfo vmstate_info_int32;
 extern const VMStateInfo vmstate_info_int64;

+extern const VMStateInfo vmstate_info_uint8_equal;
 extern const VMStateInfo vmstate_info_int32_equal;
 extern const VMStateInfo vmstate_info_int32_le;

@@ -461,6 +462,9 @@ extern const VMStateDescription vmstate_pci_device;
 #define VMSTATE_UINT64(_f, _s)                                        \
     VMSTATE_UINT64_V(_f, _s, 0)

+#define VMSTATE_UINT8_EQUAL(_f, _s)                                   \
+    VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t)
+
 #define VMSTATE_INT32_EQUAL(_f, _s)                                   \
     VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t)

diff --git a/savevm.c b/savevm.c
index c4bee37..651e0e0 100644
--- a/savevm.c
+++ b/savevm.c
@@ -847,6 +847,26 @@ const VMStateInfo vmstate_info_uint64 = {
     .put  = put_uint64,
 };

+/* 8 bit int. See that the received value is the same than the one
+   in the field */
+
+static int get_uint8_equal(QEMUFile *f, void *pv, size_t size)
+{
+    uint8_t *v = pv;
+    uint8_t v2;
+    qemu_get_8s(f, &v2);
+
+    if (*v == v2)
+        return 0;
+    return -EINVAL;
+}
+
+const VMStateInfo vmstate_info_uint8_equal = {
+    .name = "int32 equal",
+    .get  = get_uint8_equal,
+    .put  = put_uint8,
+};
+
 /* timers  */

 static int get_timer(QEMUFile *f, void *pv, size_t size)
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 16/26] vmstate: port fdc device
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (14 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 15/26] vmstate: add support for uint8_t equal Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 17/26] vmstate: add support for arrays of uint16_t Juan Quintela
                   ` (9 subsequent siblings)
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel

We can't move fifo back to an embeded array because it needs to be aligned

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/fdc.c |  154 +++++++++++++++++++++++++-------------------------------------
 1 files changed, 62 insertions(+), 92 deletions(-)

diff --git a/hw/fdc.c b/hw/fdc.c
index 19f44b1..2f3d420 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -481,6 +481,7 @@ struct fdctrl_t {
     uint8_t sra;
     uint8_t srb;
     uint8_t dor;
+    uint8_t dor_vmstate; /* only used as temp during vmstate */
     uint8_t tdr;
     uint8_t dsr;
     uint8_t msr;
@@ -490,6 +491,7 @@ struct fdctrl_t {
     uint8_t status2;
     /* Command FIFO */
     uint8_t *fifo;
+    int32_t fifo_size;
     uint32_t data_pos;
     uint32_t data_len;
     uint8_t data_state;
@@ -508,6 +510,7 @@ struct fdctrl_t {
     /* Sun4m quirks? */
     int sun4m;
     /* Floppy drives */
+    uint8_t num_floppies;
     fdrive_t drives[MAX_FD];
     int reset_sensei;
 };
@@ -627,108 +630,73 @@ static CPUWriteMemoryFunc * const fdctrl_mem_write_strict[3] = {
     NULL,
 };

-static void fd_save (QEMUFile *f, fdrive_t *fd)
-{
-    qemu_put_8s(f, &fd->head);
-    qemu_put_8s(f, &fd->track);
-    qemu_put_8s(f, &fd->sect);
-}
+static const VMStateDescription vmstate_fdrive = {
+    .name = "fdrive",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField []) {
+        VMSTATE_UINT8(head, fdrive_t),
+        VMSTATE_UINT8(track, fdrive_t),
+        VMSTATE_UINT8(sect, fdrive_t),
+        VMSTATE_END_OF_LIST()
+    }
+};

-static void fdc_save (QEMUFile *f, void *opaque)
+static void fdc_pre_save(const void *opaque)
 {
-    fdctrl_t *s = opaque;
-    uint8_t tmp;
-    int i;
-    uint8_t dor = s->dor | GET_CUR_DRV(s);
+    fdctrl_t *s = (void *)opaque;

-    /* Controller state */
-    qemu_put_8s(f, &s->sra);
-    qemu_put_8s(f, &s->srb);
-    qemu_put_8s(f, &dor);
-    qemu_put_8s(f, &s->tdr);
-    qemu_put_8s(f, &s->dsr);
-    qemu_put_8s(f, &s->msr);
-    qemu_put_8s(f, &s->status0);
-    qemu_put_8s(f, &s->status1);
-    qemu_put_8s(f, &s->status2);
-    /* Command FIFO */
-    qemu_put_buffer(f, s->fifo, FD_SECTOR_LEN);
-    qemu_put_be32s(f, &s->data_pos);
-    qemu_put_be32s(f, &s->data_len);
-    qemu_put_8s(f, &s->data_state);
-    qemu_put_8s(f, &s->data_dir);
-    qemu_put_8s(f, &s->eot);
-    /* States kept only to be returned back */
-    qemu_put_8s(f, &s->timer0);
-    qemu_put_8s(f, &s->timer1);
-    qemu_put_8s(f, &s->precomp_trk);
-    qemu_put_8s(f, &s->config);
-    qemu_put_8s(f, &s->lock);
-    qemu_put_8s(f, &s->pwrd);
-
-    tmp = MAX_FD;
-    qemu_put_8s(f, &tmp);
-    for (i = 0; i < MAX_FD; i++)
-        fd_save(f, &s->drives[i]);
+    s->dor_vmstate = s->dor | GET_CUR_DRV(s);
 }

-static int fd_load (QEMUFile *f, fdrive_t *fd)
+static int fdc_post_load(void *opaque)
 {
-    qemu_get_8s(f, &fd->head);
-    qemu_get_8s(f, &fd->track);
-    qemu_get_8s(f, &fd->sect);
+    fdctrl_t *s = opaque;

+    SET_CUR_DRV(s, s->dor_vmstate & FD_DOR_SELMASK);
+    s->dor = s->dor_vmstate & ~FD_DOR_SELMASK;
     return 0;
 }

-static int fdc_load (QEMUFile *f, void *opaque, int version_id)
-{
-    fdctrl_t *s = opaque;
-    int i, ret = 0;
-    uint8_t n;
-
-    if (version_id != 2)
-        return -EINVAL;
-
-    /* Controller state */
-    qemu_get_8s(f, &s->sra);
-    qemu_get_8s(f, &s->srb);
-    qemu_get_8s(f, &s->dor);
-    SET_CUR_DRV(s, s->dor & FD_DOR_SELMASK);
-    s->dor &= ~FD_DOR_SELMASK;
-    qemu_get_8s(f, &s->tdr);
-    qemu_get_8s(f, &s->dsr);
-    qemu_get_8s(f, &s->msr);
-    qemu_get_8s(f, &s->status0);
-    qemu_get_8s(f, &s->status1);
-    qemu_get_8s(f, &s->status2);
-    /* Command FIFO */
-    qemu_get_buffer(f, s->fifo, FD_SECTOR_LEN);
-    qemu_get_be32s(f, &s->data_pos);
-    qemu_get_be32s(f, &s->data_len);
-    qemu_get_8s(f, &s->data_state);
-    qemu_get_8s(f, &s->data_dir);
-    qemu_get_8s(f, &s->eot);
-    /* States kept only to be returned back */
-    qemu_get_8s(f, &s->timer0);
-    qemu_get_8s(f, &s->timer1);
-    qemu_get_8s(f, &s->precomp_trk);
-    qemu_get_8s(f, &s->config);
-    qemu_get_8s(f, &s->lock);
-    qemu_get_8s(f, &s->pwrd);
-    qemu_get_8s(f, &n);
-
-    if (n > MAX_FD)
-        return -EINVAL;
-
-    for (i = 0; i < n; i++) {
-        ret = fd_load(f, &s->drives[i]);
-        if (ret != 0)
-            break;
+static const VMStateDescription vmstate_fdc = {
+    .name = "fdc",
+    .version_id = 2,
+    .minimum_version_id = 2,
+    .minimum_version_id_old = 2,
+    .pre_save = fdc_pre_save,
+    .post_load = fdc_post_load,
+    .fields      = (VMStateField []) {
+        /* Controller State */
+        VMSTATE_UINT8(sra, fdctrl_t),
+        VMSTATE_UINT8(srb, fdctrl_t),
+        VMSTATE_UINT8(dor_vmstate, fdctrl_t),
+        VMSTATE_UINT8(tdr, fdctrl_t),
+        VMSTATE_UINT8(dsr, fdctrl_t),
+        VMSTATE_UINT8(msr, fdctrl_t),
+        VMSTATE_UINT8(status0, fdctrl_t),
+        VMSTATE_UINT8(status1, fdctrl_t),
+        VMSTATE_UINT8(status2, fdctrl_t),
+        /* Command FIFO */
+        VMSTATE_VARRAY(fifo, fdctrl_t, fifo_size, 0, vmstate_info_uint8, uint8),
+        VMSTATE_UINT32(data_pos, fdctrl_t),
+        VMSTATE_UINT32(data_len, fdctrl_t),
+        VMSTATE_UINT8(data_state, fdctrl_t),
+        VMSTATE_UINT8(data_dir, fdctrl_t),
+        VMSTATE_UINT8(eot, fdctrl_t),
+        /* States kept only to be returned back */
+        VMSTATE_UINT8(timer0, fdctrl_t),
+        VMSTATE_UINT8(timer1, fdctrl_t),
+        VMSTATE_UINT8(precomp_trk, fdctrl_t),
+        VMSTATE_UINT8(config, fdctrl_t),
+        VMSTATE_UINT8(lock, fdctrl_t),
+        VMSTATE_UINT8(pwrd, fdctrl_t),
+        VMSTATE_UINT8_EQUAL(num_floppies, fdctrl_t),
+        VMSTATE_STRUCT_ARRAY(drives, fdctrl_t, MAX_FD, 1,
+                             vmstate_fdrive, fdrive_t),
+        VMSTATE_END_OF_LIST()
     }
-
-    return ret;
-}
+};

 static void fdctrl_external_reset(void *opaque)
 {
@@ -1952,14 +1920,16 @@ static int fdctrl_init_common(fdctrl_t *fdctrl)

     FLOPPY_DPRINTF("init controller\n");
     fdctrl->fifo = qemu_memalign(512, FD_SECTOR_LEN);
+    fdctrl->fifo_size = 512;
     fdctrl->result_timer = qemu_new_timer(vm_clock,
                                           fdctrl_result_timer, fdctrl);

     fdctrl->version = 0x90; /* Intel 82078 controller */
     fdctrl->config = FD_CONFIG_EIS | FD_CONFIG_EFIFO; /* Implicit seek, polling & FIFO enabled */
+    fdctrl->num_floppies = MAX_FD;

     fdctrl_external_reset(fdctrl);
-    register_savevm("fdc", -1, 2, fdc_save, fdc_load, fdctrl);
+    vmstate_register(-1, &vmstate_fdc, fdctrl);
     qemu_register_reset(fdctrl_external_reset, fdctrl);
     return 0;
 }
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 17/26] vmstate: add support for arrays of uint16_t
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (15 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 16/26] vmstate: port fdc device Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 18/26] vmstate: port dma device Juan Quintela
                   ` (8 subsequent siblings)
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel


Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/hw.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/hw/hw.h b/hw/hw.h
index 4ff7dbd..b023ced 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -483,6 +483,12 @@ extern const VMStateDescription vmstate_pci_device;
 #define VMSTATE_PTIMER(_f, _s)                                        \
     VMSTATE_PTIMER_V(_f, _s, 0)

+#define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v)                         \
+    VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t)
+
+#define VMSTATE_UINT16_ARRAY(_f, _s, _n)                               \
+    VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0)
+
 #define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)                        \
     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t)

-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 18/26] vmstate: port dma device
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (16 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 17/26] vmstate: add support for arrays of uint16_t Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 19/26] vmstate: port vmmouse device Juan Quintela
                   ` (7 subsequent siblings)
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel


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

diff --git a/hw/dma.c b/hw/dma.c
index b95407b..f418e42 100644
--- a/hw/dma.c
+++ b/hw/dma.c
@@ -500,71 +500,54 @@ static void dma_init2(struct dma_cont *d, int base, int dshift,
     }
 }

-static void dma_save (QEMUFile *f, void *opaque)
-{
-    struct dma_cont *d = opaque;
-    int i;
-
-    /* qemu_put_8s (f, &d->status); */
-    qemu_put_8s (f, &d->command);
-    qemu_put_8s (f, &d->mask);
-    qemu_put_8s (f, &d->flip_flop);
-    qemu_put_be32 (f, d->dshift);
-
-    for (i = 0; i < 4; ++i) {
-        struct dma_regs *r = &d->regs[i];
-        qemu_put_be32 (f, r->now[0]);
-        qemu_put_be32 (f, r->now[1]);
-        qemu_put_be16s (f, &r->base[0]);
-        qemu_put_be16s (f, &r->base[1]);
-        qemu_put_8s (f, &r->mode);
-        qemu_put_8s (f, &r->page);
-        qemu_put_8s (f, &r->pageh);
-        qemu_put_8s (f, &r->dack);
-        qemu_put_8s (f, &r->eop);
+static const VMStateDescription vmstate_dma_regs = {
+    .name = "dma_regs",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField []) {
+        VMSTATE_INT32_ARRAY(now, struct dma_regs, 2),
+        VMSTATE_UINT16_ARRAY(base, struct dma_regs, 2),
+        VMSTATE_UINT8(mode, struct dma_regs),
+        VMSTATE_UINT8(page, struct dma_regs),
+        VMSTATE_UINT8(pageh, struct dma_regs),
+        VMSTATE_UINT8(dack, struct dma_regs),
+        VMSTATE_UINT8(eop, struct dma_regs),
+        VMSTATE_END_OF_LIST()
     }
-}
+};

-static int dma_load (QEMUFile *f, void *opaque, int version_id)
+static int dma_post_load(void *opaque)
 {
-    struct dma_cont *d = opaque;
-    int i;
-
-    if (version_id != 1)
-        return -EINVAL;
-
-    /* qemu_get_8s (f, &d->status); */
-    qemu_get_8s (f, &d->command);
-    qemu_get_8s (f, &d->mask);
-    qemu_get_8s (f, &d->flip_flop);
-    d->dshift=qemu_get_be32 (f);
-
-    for (i = 0; i < 4; ++i) {
-        struct dma_regs *r = &d->regs[i];
-        r->now[0]=qemu_get_be32 (f);
-        r->now[1]=qemu_get_be32 (f);
-        qemu_get_be16s (f, &r->base[0]);
-        qemu_get_be16s (f, &r->base[1]);
-        qemu_get_8s (f, &r->mode);
-        qemu_get_8s (f, &r->page);
-        qemu_get_8s (f, &r->pageh);
-        qemu_get_8s (f, &r->dack);
-        qemu_get_8s (f, &r->eop);
-    }
-
     DMA_run();

     return 0;
 }

+static const VMStateDescription vmstate_dma = {
+    .name = "dma",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .post_load = dma_post_load,
+    .fields      = (VMStateField []) {
+        VMSTATE_UINT8(command, struct dma_cont),
+        VMSTATE_UINT8(mask, struct dma_cont),
+        VMSTATE_UINT8(flip_flop, struct dma_cont),
+        VMSTATE_INT32(dshift, struct dma_cont),
+        VMSTATE_STRUCT_ARRAY(regs, struct dma_cont, 4, 1, vmstate_dma_regs, struct dma_regs),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 void DMA_init (int high_page_enable)
 {
     dma_init2(&dma_controllers[0], 0x00, 0, 0x80,
               high_page_enable ? 0x480 : -1);
     dma_init2(&dma_controllers[1], 0xc0, 1, 0x88,
               high_page_enable ? 0x488 : -1);
-    register_savevm ("dma", 0, 1, dma_save, dma_load, &dma_controllers[0]);
-    register_savevm ("dma", 1, 1, dma_save, dma_load, &dma_controllers[1]);
+    vmstate_register (0, &vmstate_dma, &dma_controllers[0]);
+    vmstate_register (1, &vmstate_dma, &dma_controllers[1]);

     dma_bh = qemu_bh_new(DMA_run_bh, NULL);
 }
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 19/26] vmstate: port vmmouse device
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (17 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 18/26] vmstate: port dma device Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 20/26] vmstate: port pckbd device Juan Quintela
                   ` (6 subsequent siblings)
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel


Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/vmmouse.c |   48 ++++++++++++++++++++----------------------------
 1 files changed, 20 insertions(+), 28 deletions(-)

diff --git a/hw/vmmouse.c b/hw/vmmouse.c
index c70e825..c207bb2 100644
--- a/hw/vmmouse.c
+++ b/hw/vmmouse.c
@@ -53,6 +53,7 @@
 typedef struct _VMMouseState
 {
     uint32_t queue[VMMOUSE_QUEUE_SIZE];
+    int32_t queue_size;
     uint16_t nb_queue;
     uint16_t status;
     uint8_t absolute;
@@ -234,40 +235,30 @@ static uint32_t vmmouse_ioport_read(void *opaque, uint32_t addr)
     return data[0];
 }

-static void vmmouse_save(QEMUFile *f, void *opaque)
+static int vmmouse_post_load(void *opaque)
 {
     VMMouseState *s = opaque;
-    int i;
-
-    qemu_put_be32(f, VMMOUSE_QUEUE_SIZE);
-    for (i = 0; i < VMMOUSE_QUEUE_SIZE; i++)
-        qemu_put_be32s(f, &s->queue[i]);
-    qemu_put_be16s(f, &s->nb_queue);
-    qemu_put_be16s(f, &s->status);
-    qemu_put_8s(f, &s->absolute);
-}
-
-static int vmmouse_load(QEMUFile *f, void *opaque, int version_id)
-{
-    VMMouseState *s = opaque;
-    int i;
-
-    if (version_id != 0)
-        return -EINVAL;
-
-    if (qemu_get_be32(f) != VMMOUSE_QUEUE_SIZE)
-        return -EINVAL;
-    for (i = 0; i < VMMOUSE_QUEUE_SIZE; i++)
-        qemu_get_be32s(f, &s->queue[i]);
-    qemu_get_be16s(f, &s->nb_queue);
-    qemu_get_be16s(f, &s->status);
-    qemu_get_8s(f, &s->absolute);

     vmmouse_update_handler(s);
-
     return 0;
 }

+static const VMStateDescription vmstate_vmmouse = {
+    .name = "vmmouse",
+    .version_id = 0,
+    .minimum_version_id = 0,
+    .minimum_version_id_old = 0,
+    .post_load = vmmouse_post_load,
+    .fields      = (VMStateField []) {
+        VMSTATE_INT32_EQUAL(queue_size, VMMouseState),
+        VMSTATE_UINT32_ARRAY(queue, VMMouseState, VMMOUSE_QUEUE_SIZE),
+        VMSTATE_UINT16(nb_queue, VMMouseState),
+        VMSTATE_UINT16(status, VMMouseState),
+        VMSTATE_UINT8(absolute, VMMouseState),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 void *vmmouse_init(void *m)
 {
     VMMouseState *s = NULL;
@@ -278,11 +269,12 @@ void *vmmouse_init(void *m)

     s->status = 0xffff;
     s->ps2_mouse = m;
+    s->queue_size = VMMOUSE_QUEUE_SIZE;

     vmport_register(VMMOUSE_STATUS, vmmouse_ioport_read, s);
     vmport_register(VMMOUSE_COMMAND, vmmouse_ioport_read, s);
     vmport_register(VMMOUSE_DATA, vmmouse_ioport_read, s);
-    register_savevm("vmmouse", 0, 0, vmmouse_save, vmmouse_load, s);
+    vmstate_register(0, &vmstate_vmmouse, s);

     return s;
 }
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 20/26] vmstate: port pckbd device
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (18 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 19/26] vmstate: port vmmouse device Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 21/26] vmstate: add uint64 array support Juan Quintela
                   ` (5 subsequent siblings)
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel


Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/pckbd.c |   41 ++++++++++++++++-------------------------
 1 files changed, 16 insertions(+), 25 deletions(-)

diff --git a/hw/pckbd.c b/hw/pckbd.c
index 3f83320..f119a33 100644
--- a/hw/pckbd.c
+++ b/hw/pckbd.c
@@ -339,28 +339,19 @@ static void kbd_reset(void *opaque)
     s->status = KBD_STAT_CMD | KBD_STAT_UNLOCKED;
 }

-static void kbd_save(QEMUFile* f, void* opaque)
-{
-    KBDState *s = (KBDState*)opaque;
-
-    qemu_put_8s(f, &s->write_cmd);
-    qemu_put_8s(f, &s->status);
-    qemu_put_8s(f, &s->mode);
-    qemu_put_8s(f, &s->pending);
-}
-
-static int kbd_load(QEMUFile* f, void* opaque, int version_id)
-{
-    KBDState *s = (KBDState*)opaque;
-
-    if (version_id != 3)
-        return -EINVAL;
-    qemu_get_8s(f, &s->write_cmd);
-    qemu_get_8s(f, &s->status);
-    qemu_get_8s(f, &s->mode);
-    qemu_get_8s(f, &s->pending);
-    return 0;
-}
+static const VMStateDescription vmstate_kbd = {
+    .name = "pckbd",
+    .version_id = 3,
+    .minimum_version_id = 3,
+    .minimum_version_id_old = 3,
+    .fields      = (VMStateField []) {
+        VMSTATE_UINT8(write_cmd, KBDState),
+        VMSTATE_UINT8(status, KBDState),
+        VMSTATE_UINT8(mode, KBDState),
+        VMSTATE_UINT8(pending, KBDState),
+        VMSTATE_END_OF_LIST()
+    }
+};

 void i8042_init(qemu_irq kbd_irq, qemu_irq mouse_irq, uint32_t io_base)
 {
@@ -370,7 +361,7 @@ void i8042_init(qemu_irq kbd_irq, qemu_irq mouse_irq, uint32_t io_base)
     s->irq_mouse = mouse_irq;

     kbd_reset(s);
-    register_savevm("pckbd", 0, 3, kbd_save, kbd_load, s);
+    vmstate_register(0, &vmstate_kbd, s);
     register_ioport_read(io_base, 1, 1, kbd_read_data, s);
     register_ioport_write(io_base, 1, 1, kbd_write_data, s);
     register_ioport_read(io_base + 4, 1, 1, kbd_read_status, s);
@@ -429,7 +420,7 @@ void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq,
     s->mask = mask;

     kbd_reset(s);
-    register_savevm("pckbd", 0, 3, kbd_save, kbd_load, s);
+    vmstate_register(0, &vmstate_kbd, s);
     s_io_memory = cpu_register_io_memory(kbd_mm_read, kbd_mm_write, s);
     cpu_register_physical_memory(base, size, s_io_memory);

@@ -454,7 +445,7 @@ static int i8042_initfn(ISADevice *dev)
     isa_init_irq(dev, &s->irq_mouse);

     kbd_reset(s);
-    register_savevm("pckbd", 0, 3, kbd_save, kbd_load, s);
+    vmstate_register(0, &vmstate_kbd, s);
     register_ioport_read(dev->iobase[0], 1, 1, kbd_read_data, s);
     register_ioport_write(dev->iobase[0], 1, 1, kbd_write_data, s);
     register_ioport_read(dev->iobase[1], 1, 1, kbd_read_status, s);
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 21/26] vmstate: add uint64 array support
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (19 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 20/26] vmstate: port pckbd device Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 22/26] vmstate: port ioapic device Juan Quintela
                   ` (4 subsequent siblings)
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel


Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/hw.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/hw/hw.h b/hw/hw.h
index b023ced..792f592 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -495,6 +495,12 @@ extern const VMStateDescription vmstate_pci_device;
 #define VMSTATE_UINT32_ARRAY(_f, _s, _n)                              \
     VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)

+#define VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)                        \
+    VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint64, uint64_t)
+
+#define VMSTATE_UINT64_ARRAY(_f, _s, _n)                              \
+    VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0)
+
 #define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v)                         \
     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t)

-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 22/26] vmstate: port ioapic device
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (20 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 21/26] vmstate: add uint64 array support Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 23/26] hpet: it is imposible that qemu_timer field is NULL at this point Juan Quintela
                   ` (3 subsequent siblings)
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel


Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/ioapic.c |   39 ++++++++++++---------------------------
 1 files changed, 12 insertions(+), 27 deletions(-)

diff --git a/hw/ioapic.c b/hw/ioapic.c
index b232527..b0ad78f 100644
--- a/hw/ioapic.c
+++ b/hw/ioapic.c
@@ -191,33 +191,18 @@ static void ioapic_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t va
     }
 }

-static void ioapic_save(QEMUFile *f, void *opaque)
-{
-    IOAPICState *s = opaque;
-    int i;
-
-    qemu_put_8s(f, &s->id);
-    qemu_put_8s(f, &s->ioregsel);
-    for (i = 0; i < IOAPIC_NUM_PINS; i++) {
-        qemu_put_be64s(f, &s->ioredtbl[i]);
-    }
-}
-
-static int ioapic_load(QEMUFile *f, void *opaque, int version_id)
-{
-    IOAPICState *s = opaque;
-    int i;
-
-    if (version_id != 1)
-        return -EINVAL;
-
-    qemu_get_8s(f, &s->id);
-    qemu_get_8s(f, &s->ioregsel);
-    for (i = 0; i < IOAPIC_NUM_PINS; i++) {
-        qemu_get_be64s(f, &s->ioredtbl[i]);
+static const VMStateDescription vmstate_ioapic = {
+    .name = "ioapic",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField []) {
+        VMSTATE_UINT8(id, IOAPICState),
+        VMSTATE_UINT8(ioregsel, IOAPICState),
+        VMSTATE_UINT64_ARRAY(ioredtbl, IOAPICState, IOAPIC_NUM_PINS),
+        VMSTATE_END_OF_LIST()
     }
-    return 0;
-}
+};

 static void ioapic_reset(void *opaque)
 {
@@ -254,7 +239,7 @@ qemu_irq *ioapic_init(void)
                                        ioapic_mem_write, s);
     cpu_register_physical_memory(0xfec00000, 0x1000, io_memory);

-    register_savevm("ioapic", 0, 1, ioapic_save, ioapic_load, s);
+    vmstate_register(0, &vmstate_ioapic, s);
     qemu_register_reset(ioapic_reset, s);
     irq = qemu_allocate_irqs(ioapic_set_irq, s, IOAPIC_NUM_PINS);

-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 23/26] hpet: it is imposible that qemu_timer field is NULL at this point
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (21 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 22/26] vmstate: port ioapic device Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 24/26] vmstate: port hpet device Juan Quintela
                   ` (2 subsequent siblings)
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel


Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/hpet.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/hw/hpet.c b/hw/hpet.c
index 20df7ef..98a769e 100644
--- a/hw/hpet.c
+++ b/hw/hpet.c
@@ -174,9 +174,7 @@ static void hpet_save(QEMUFile *f, void *opaque)
         qemu_put_be64s(f, &s->timer[i].fsb);
         qemu_put_be64s(f, &s->timer[i].period);
         qemu_put_8s(f, &s->timer[i].wrap_flag);
-        if (s->timer[i].qemu_timer) {
-            qemu_put_timer(f, s->timer[i].qemu_timer);
-        }
+        qemu_put_timer(f, s->timer[i].qemu_timer);
     }
 }

@@ -201,9 +199,7 @@ static int hpet_load(QEMUFile *f, void *opaque, int version_id)
         qemu_get_be64s(f, &s->timer[i].fsb);
         qemu_get_be64s(f, &s->timer[i].period);
         qemu_get_8s(f, &s->timer[i].wrap_flag);
-        if (s->timer[i].qemu_timer) {
-            qemu_get_timer(f, s->timer[i].qemu_timer);
-        }
+        qemu_get_timer(f, s->timer[i].qemu_timer);
     }
     return 0;
 }
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 24/26] vmstate: port hpet device
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (22 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 23/26] hpet: it is imposible that qemu_timer field is NULL at this point Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 25/26] vmstate: port serial device Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 26/26] vmstate: port cirrus_vga device Juan Quintela
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel


Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/hpet.c |   73 +++++++++++++++++++++++++++++++-----------------------------
 1 files changed, 38 insertions(+), 35 deletions(-)

diff --git a/hw/hpet.c b/hw/hpet.c
index 98a769e..c1ead34 100644
--- a/hw/hpet.c
+++ b/hw/hpet.c
@@ -157,53 +157,56 @@ static void update_irq(struct HPETTimer *timer)
     }
 }

-static void hpet_save(QEMUFile *f, void *opaque)
+static void hpet_pre_save(const void *opaque)
 {
-    HPETState *s = opaque;
-    int i;
-    qemu_put_be64s(f, &s->config);
-    qemu_put_be64s(f, &s->isr);
+    HPETState *s = (void *)opaque;
     /* save current counter value */
     s->hpet_counter = hpet_get_ticks();
-    qemu_put_be64s(f, &s->hpet_counter);
-
-    for (i = 0; i < HPET_NUM_TIMERS; i++) {
-        qemu_put_8s(f, &s->timer[i].tn);
-        qemu_put_be64s(f, &s->timer[i].config);
-        qemu_put_be64s(f, &s->timer[i].cmp);
-        qemu_put_be64s(f, &s->timer[i].fsb);
-        qemu_put_be64s(f, &s->timer[i].period);
-        qemu_put_8s(f, &s->timer[i].wrap_flag);
-        qemu_put_timer(f, s->timer[i].qemu_timer);
-    }
 }

-static int hpet_load(QEMUFile *f, void *opaque, int version_id)
+static int hpet_post_load(void *opaque)
 {
     HPETState *s = opaque;
-    int i;

-    if (version_id != 1)
-        return -EINVAL;
-
-    qemu_get_be64s(f, &s->config);
-    qemu_get_be64s(f, &s->isr);
-    qemu_get_be64s(f, &s->hpet_counter);
     /* Recalculate the offset between the main counter and guest time */
     s->hpet_offset = ticks_to_ns(s->hpet_counter) - qemu_get_clock(vm_clock);
-
-    for (i = 0; i < HPET_NUM_TIMERS; i++) {
-        qemu_get_8s(f, &s->timer[i].tn);
-        qemu_get_be64s(f, &s->timer[i].config);
-        qemu_get_be64s(f, &s->timer[i].cmp);
-        qemu_get_be64s(f, &s->timer[i].fsb);
-        qemu_get_be64s(f, &s->timer[i].period);
-        qemu_get_8s(f, &s->timer[i].wrap_flag);
-        qemu_get_timer(f, s->timer[i].qemu_timer);
-    }
     return 0;
 }

+static const VMStateDescription vmstate_hpet_timer = {
+    .name = "hpet_timer",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField []) {
+        VMSTATE_UINT8(tn, HPETTimer),
+        VMSTATE_UINT64(config, HPETTimer),
+        VMSTATE_UINT64(cmp, HPETTimer),
+        VMSTATE_UINT64(fsb, HPETTimer),
+        VMSTATE_UINT64(period, HPETTimer),
+        VMSTATE_UINT8(wrap_flag, HPETTimer),
+        VMSTATE_TIMER(qemu_timer, HPETTimer),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static const VMStateDescription vmstate_hpet = {
+    .name = "hpet",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .pre_save = hpet_pre_save,
+    .post_load = hpet_post_load,
+    .fields      = (VMStateField []) {
+        VMSTATE_UINT64(config, HPETState),
+        VMSTATE_UINT64(isr, HPETState),
+        VMSTATE_UINT64(hpet_counter, HPETState),
+        VMSTATE_STRUCT_ARRAY(timer, HPETState, HPET_NUM_TIMERS, 0,
+                             vmstate_hpet_timer, HPETTimer),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 /*
  * timer expiration callback
  */
@@ -575,7 +578,7 @@ void hpet_init(qemu_irq *irq) {
         timer->qemu_timer = qemu_new_timer(vm_clock, hpet_timer, timer);
     }
     hpet_reset(s);
-    register_savevm("hpet", -1, 1, hpet_save, hpet_load, s);
+    vmstate_register(-1, &vmstate_hpet, s);
     qemu_register_reset(hpet_reset, s);
     /* HPET Area */
     iomemtype = cpu_register_io_memory(hpet_ram_read,
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 25/26] vmstate: port serial device
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (23 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 24/26] vmstate: port hpet device Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 26/26] vmstate: port cirrus_vga device Juan Quintela
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel


Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/serial.c |   73 ++++++++++++++++++++++++++++++-----------------------------
 1 files changed, 37 insertions(+), 36 deletions(-)

diff --git a/hw/serial.c b/hw/serial.c
index f9c7246..6f7b30e 100644
--- a/hw/serial.c
+++ b/hw/serial.c
@@ -119,6 +119,8 @@ struct SerialState {
     uint8_t msr; /* read only */
     uint8_t scr;
     uint8_t fcr;
+    uint8_t fcr_vmstate; /* we can't write directly this value
+                            it has side effects */
     /* NOTE: this hidden state is necessary for tx irq generation as
        it can be reset while reading iir */
     int thr_ipending;
@@ -635,51 +637,50 @@ static void serial_event(void *opaque, int event)
         serial_receive_break(s);
 }

-static void serial_save(QEMUFile *f, void *opaque)
+static void serial_pre_save(const void *opaque)
 {
-    SerialState *s = opaque;
-
-    qemu_put_be16s(f,&s->divider);
-    qemu_put_8s(f,&s->rbr);
-    qemu_put_8s(f,&s->ier);
-    qemu_put_8s(f,&s->iir);
-    qemu_put_8s(f,&s->lcr);
-    qemu_put_8s(f,&s->mcr);
-    qemu_put_8s(f,&s->lsr);
-    qemu_put_8s(f,&s->msr);
-    qemu_put_8s(f,&s->scr);
-    qemu_put_8s(f,&s->fcr);
+    SerialState *s = (void *)opaque;
+    s->fcr_vmstate = s->fcr;
 }

-static int serial_load(QEMUFile *f, void *opaque, int version_id)
+static int serial_pre_load(void *opaque)
 {
     SerialState *s = opaque;
-    uint8_t fcr = 0;
-
-    if(version_id > 3)
-        return -EINVAL;
+    s->fcr_vmstate = 0;
+    return 0;
+}

-    if (version_id >= 2)
-        qemu_get_be16s(f, &s->divider);
-    else
-        s->divider = qemu_get_byte(f);
-    qemu_get_8s(f,&s->rbr);
-    qemu_get_8s(f,&s->ier);
-    qemu_get_8s(f,&s->iir);
-    qemu_get_8s(f,&s->lcr);
-    qemu_get_8s(f,&s->mcr);
-    qemu_get_8s(f,&s->lsr);
-    qemu_get_8s(f,&s->msr);
-    qemu_get_8s(f,&s->scr);
-
-    if (version_id >= 3)
-        qemu_get_8s(f,&fcr);
+static int serial_post_load(void *opaque)
+{
+    SerialState *s = opaque;

     /* Initialize fcr via setter to perform essential side-effects */
-    serial_ioport_write(s, 0x02, fcr);
+    serial_ioport_write(s, 0x02, s->fcr_vmstate);
     return 0;
 }

+static const VMStateDescription vmstate_serial = {
+    .name = "serial",
+    .version_id = 3,
+    .minimum_version_id = 2,
+    .pre_save = serial_pre_save,
+    .pre_load = serial_pre_load,
+    .post_load = serial_post_load,
+    .fields      = (VMStateField []) {
+        VMSTATE_UINT16_V(divider, SerialState, 2),
+        VMSTATE_UINT8(rbr, SerialState),
+        VMSTATE_UINT8(ier, SerialState),
+        VMSTATE_UINT8(iir, SerialState),
+        VMSTATE_UINT8(lcr, SerialState),
+        VMSTATE_UINT8(mcr, SerialState),
+        VMSTATE_UINT8(lsr, SerialState),
+        VMSTATE_UINT8(msr, SerialState),
+        VMSTATE_UINT8(scr, SerialState),
+        VMSTATE_UINT8_V(fcr_vmstate, SerialState, 3),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static void serial_reset(void *opaque)
 {
     SerialState *s = opaque;
@@ -737,7 +738,7 @@ SerialState *serial_init(int base, qemu_irq irq, int baudbase,

     serial_init_core(s, irq, baudbase, chr);

-    register_savevm("serial", base, 3, serial_save, serial_load, s);
+    vmstate_register(base, &vmstate_serial, s);

     register_ioport_write(base, 8, 1, serial_ioport_write, s);
     register_ioport_read(base, 8, 1, serial_ioport_read, s);
@@ -828,7 +829,7 @@ SerialState *serial_mm_init (target_phys_addr_t base, int it_shift,
     s->it_shift = it_shift;

     serial_init_core(s, irq, baudbase, chr);
-    register_savevm("serial", base, 3, serial_save, serial_load, s);
+    vmstate_register(base, &vmstate_serial, s);

     if (ioregister) {
         s_io_memory = cpu_register_io_memory(serial_mm_read,
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 26/26] vmstate: port cirrus_vga device
  2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
                   ` (24 preceding siblings ...)
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 25/26] vmstate: port serial device Juan Quintela
@ 2009-09-10  1:04 ` Juan Quintela
  25 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:04 UTC (permalink / raw)
  To: qemu-devel


Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/cirrus_vga.c |  152 +++++++++++++++++++-----------------------------------
 hw/hw.h         |    9 +++
 2 files changed, 63 insertions(+), 98 deletions(-)

diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index 5cdb11f..7e95f10 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -2955,85 +2955,12 @@ static CPUWriteMemoryFunc * const cirrus_mmio_write[3] = {

 /* load/save state */

-static void cirrus_vga_save(QEMUFile *f, void *opaque)
+static int cirrus_post_load(void *opaque)
 {
     CirrusVGAState *s = opaque;

-    qemu_put_be32s(f, &s->vga.latch);
-    qemu_put_8s(f, &s->vga.sr_index);
-    qemu_put_buffer(f, s->vga.sr, 256);
-    qemu_put_8s(f, &s->vga.gr_index);
-    qemu_put_8s(f, &s->cirrus_shadow_gr0);
-    qemu_put_8s(f, &s->cirrus_shadow_gr1);
-    qemu_put_buffer(f, s->vga.gr + 2, 254);
-    qemu_put_8s(f, &s->vga.ar_index);
-    qemu_put_buffer(f, s->vga.ar, 21);
-    qemu_put_be32(f, s->vga.ar_flip_flop);
-    qemu_put_8s(f, &s->vga.cr_index);
-    qemu_put_buffer(f, s->vga.cr, 256);
-    qemu_put_8s(f, &s->vga.msr);
-    qemu_put_8s(f, &s->vga.fcr);
-    qemu_put_8s(f, &s->vga.st00);
-    qemu_put_8s(f, &s->vga.st01);
-
-    qemu_put_8s(f, &s->vga.dac_state);
-    qemu_put_8s(f, &s->vga.dac_sub_index);
-    qemu_put_8s(f, &s->vga.dac_read_index);
-    qemu_put_8s(f, &s->vga.dac_write_index);
-    qemu_put_buffer(f, s->vga.dac_cache, 3);
-    qemu_put_buffer(f, s->vga.palette, 768);
-
-    qemu_put_be32(f, s->vga.bank_offset);
-
-    qemu_put_8s(f, &s->cirrus_hidden_dac_lockindex);
-    qemu_put_8s(f, &s->cirrus_hidden_dac_data);
-
-    qemu_put_be32s(f, &s->hw_cursor_x);
-    qemu_put_be32s(f, &s->hw_cursor_y);
-    /* XXX: we do not save the bitblt state - we assume we do not save
-       the state when the blitter is active */
-}
-
-static int cirrus_vga_load(QEMUFile *f, void *opaque, int version_id)
-{
-    CirrusVGAState *s = opaque;
-
-    if (version_id > 2)
-        return -EINVAL;
-
-    qemu_get_be32s(f, &s->vga.latch);
-    qemu_get_8s(f, &s->vga.sr_index);
-    qemu_get_buffer(f, s->vga.sr, 256);
-    qemu_get_8s(f, &s->vga.gr_index);
-    qemu_get_8s(f, &s->cirrus_shadow_gr0);
-    qemu_get_8s(f, &s->cirrus_shadow_gr1);
     s->vga.gr[0x00] = s->cirrus_shadow_gr0 & 0x0f;
     s->vga.gr[0x01] = s->cirrus_shadow_gr1 & 0x0f;
-    qemu_get_buffer(f, s->vga.gr + 2, 254);
-    qemu_get_8s(f, &s->vga.ar_index);
-    qemu_get_buffer(f, s->vga.ar, 21);
-    s->vga.ar_flip_flop=qemu_get_be32(f);
-    qemu_get_8s(f, &s->vga.cr_index);
-    qemu_get_buffer(f, s->vga.cr, 256);
-    qemu_get_8s(f, &s->vga.msr);
-    qemu_get_8s(f, &s->vga.fcr);
-    qemu_get_8s(f, &s->vga.st00);
-    qemu_get_8s(f, &s->vga.st01);
-
-    qemu_get_8s(f, &s->vga.dac_state);
-    qemu_get_8s(f, &s->vga.dac_sub_index);
-    qemu_get_8s(f, &s->vga.dac_read_index);
-    qemu_get_8s(f, &s->vga.dac_write_index);
-    qemu_get_buffer(f, s->vga.dac_cache, 3);
-    qemu_get_buffer(f, s->vga.palette, 768);
-
-    s->vga.bank_offset = qemu_get_be32(f);
-
-    qemu_get_8s(f, &s->cirrus_hidden_dac_lockindex);
-    qemu_get_8s(f, &s->cirrus_hidden_dac_data);
-
-    qemu_get_be32s(f, &s->hw_cursor_x);
-    qemu_get_be32s(f, &s->hw_cursor_y);

     cirrus_update_memory_access(s);
     /* force refresh */
@@ -3043,30 +2970,59 @@ static int cirrus_vga_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }

-static void pci_cirrus_vga_save(QEMUFile *f, void *opaque)
-{
-    PCICirrusVGAState *s = opaque;
-
-    pci_device_save(&s->dev, f);
-    cirrus_vga_save(f, &s->cirrus_vga);
-}
-
-static int pci_cirrus_vga_load(QEMUFile *f, void *opaque, int version_id)
-{
-    PCICirrusVGAState *s = opaque;
-    int ret;
-
-    if (version_id > 2)
-        return -EINVAL;
-
-    if (version_id >= 2) {
-        ret = pci_device_load(&s->dev, f);
-        if (ret < 0)
-            return ret;
+static const VMStateDescription vmstate_cirrus_vga = {
+    .name = "cirrus_vga",
+    .version_id = 2,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .post_load = cirrus_post_load,
+    .fields      = (VMStateField []) {
+        VMSTATE_UINT32(vga.latch, CirrusVGAState),
+        VMSTATE_UINT8(vga.sr_index, CirrusVGAState),
+        VMSTATE_BUFFER(vga.sr, CirrusVGAState),
+        VMSTATE_UINT8(vga.gr_index, CirrusVGAState),
+        VMSTATE_UINT8(cirrus_shadow_gr0, CirrusVGAState),
+        VMSTATE_UINT8(cirrus_shadow_gr1, CirrusVGAState),
+        VMSTATE_BUFFER_START_MIDDLE(vga.gr, CirrusVGAState, 2),
+        VMSTATE_UINT8(vga.ar_index, CirrusVGAState),
+        VMSTATE_BUFFER(vga.ar, CirrusVGAState),
+        VMSTATE_INT32(vga.ar_flip_flop, CirrusVGAState),
+        VMSTATE_UINT8(vga.cr_index, CirrusVGAState),
+        VMSTATE_BUFFER(vga.cr, CirrusVGAState),
+        VMSTATE_UINT8(vga.msr, CirrusVGAState),
+        VMSTATE_UINT8(vga.fcr, CirrusVGAState),
+        VMSTATE_UINT8(vga.st00, CirrusVGAState),
+        VMSTATE_UINT8(vga.st01, CirrusVGAState),
+        VMSTATE_UINT8(vga.dac_state, CirrusVGAState),
+        VMSTATE_UINT8(vga.dac_sub_index, CirrusVGAState),
+        VMSTATE_UINT8(vga.dac_read_index, CirrusVGAState),
+        VMSTATE_UINT8(vga.dac_write_index, CirrusVGAState),
+        VMSTATE_BUFFER(vga.dac_cache, CirrusVGAState),
+        VMSTATE_BUFFER(vga.palette, CirrusVGAState),
+        VMSTATE_INT32(vga.bank_offset, CirrusVGAState),
+        VMSTATE_UINT8(cirrus_hidden_dac_lockindex, CirrusVGAState),
+        VMSTATE_UINT8(cirrus_hidden_dac_data, CirrusVGAState),
+        VMSTATE_UINT32(hw_cursor_x, CirrusVGAState),
+        VMSTATE_UINT32(hw_cursor_y, CirrusVGAState),
+        /* XXX: we do not save the bitblt state - we assume we do not save
+           the state when the blitter is active */
+        VMSTATE_END_OF_LIST()
     }
+};

-    return cirrus_vga_load(f, &s->cirrus_vga, version_id);
-}
+static const VMStateDescription vmstate_pci_cirrus_vga = {
+    .name = "cirrus_vga",
+    .version_id = 2,
+    .minimum_version_id = 2,
+    .minimum_version_id_old = 2,
+    .post_load = cirrus_post_load,
+    .fields      = (VMStateField []) {
+        VMSTATE_PCI_DEVICE(dev, PCICirrusVGAState),
+        VMSTATE_STRUCT(cirrus_vga, PCICirrusVGAState, 0,
+                       vmstate_cirrus_vga, CirrusVGAState),
+        VMSTATE_END_OF_LIST()
+    }
+};

 /***************************************
  *
@@ -3203,7 +3159,7 @@ void isa_cirrus_vga_init(void)
     s->vga.ds = graphic_console_init(s->vga.update, s->vga.invalidate,
                                      s->vga.screen_dump, s->vga.text_update,
                                      &s->vga);
-    register_savevm("cirrus_vga", 0, 2, cirrus_vga_save, cirrus_vga_load, s);
+    vmstate_register(0, &vmstate_cirrus_vga, s);
     /* XXX ISA-LFB support */
 }

@@ -3286,7 +3242,7 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
          pci_register_bar((PCIDevice *)d, 1, CIRRUS_PNPMMIO_SIZE,
                           PCI_ADDRESS_SPACE_MEM, cirrus_pci_mmio_map);
      }
-     register_savevm("cirrus_vga", 0, 2, pci_cirrus_vga_save, pci_cirrus_vga_load, d);
+     vmstate_register(0, &vmstate_pci_cirrus_vga, d);
      /* XXX: ROM BIOS */
      return 0;
 }
diff --git a/hw/hw.h b/hw/hw.h
index 792f592..cf266b3 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -408,6 +408,15 @@ extern const VMStateInfo vmstate_info_buffer;
         + type_check_array(uint8_t,typeof_field(_state, _field),sizeof(typeof_field(_state,_field))) \
 }

+#define VMSTATE_BUFFER_START_MIDDLE(_field, _state, start) {         \
+    .name       = (stringify(_field)),                               \
+    .size       = sizeof(typeof_field(_state,_field)) - start,       \
+    .info       = &vmstate_info_buffer,                              \
+    .flags      = VMS_BUFFER,                                        \
+    .offset     = offsetof(_state, _field) + start                   \
+        + type_check_array(uint8_t,typeof_field(_state, _field),sizeof(typeof_field(_state,_field))) \
+}
+
 extern const VMStateDescription vmstate_pci_device;

 #define VMSTATE_PCI_DEVICE(_field, _state) {                         \
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function Juan Quintela
@ 2009-09-10  1:20   ` malc
  2009-09-10  1:57     ` [Qemu-devel] " Juan Quintela
  2009-09-11  9:04   ` Jan Kiszka
  1 sibling, 1 reply; 62+ messages in thread
From: malc @ 2009-09-10  1:20 UTC (permalink / raw)
  To: Juan Quintela; +Cc: qemu-devel

On Thu, 10 Sep 2009, Juan Quintela wrote:

Point being?

[..snip..]

-- 
mailto:av1474@comtv.ru

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-10  1:20   ` malc
@ 2009-09-10  1:57     ` Juan Quintela
  2009-09-10  2:21       ` malc
  0 siblings, 1 reply; 62+ messages in thread
From: Juan Quintela @ 2009-09-10  1:57 UTC (permalink / raw)
  To: malc; +Cc: qemu-devel

malc <av1474@comtv.ru> wrote:
> On Thu, 10 Sep 2009, Juan Quintela wrote:
>
> Point being?
>
> [..snip..]

See next patch.  We need to put the variable in one struct, we don't
want to change everything to read the variable from the struct.

And at some point code, timer code have to move to qemu-timer.c code,
not in vl.c.

Later, Juan.

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-10  1:57     ` [Qemu-devel] " Juan Quintela
@ 2009-09-10  2:21       ` malc
  2009-09-10 16:44         ` Juan Quintela
  0 siblings, 1 reply; 62+ messages in thread
From: malc @ 2009-09-10  2:21 UTC (permalink / raw)
  To: Juan Quintela; +Cc: qemu-devel

On Thu, 10 Sep 2009, Juan Quintela wrote:

> malc <av1474@comtv.ru> wrote:
> > On Thu, 10 Sep 2009, Juan Quintela wrote:
> >
> > Point being?
> >
> > [..snip..]
> 
> See next patch.  We need to put the variable in one struct, we don't
> want to change everything to read the variable from the struct.

So put the in the _pre vmstate callback (or whatever it's called).

> 
> And at some point code, timer code have to move to qemu-timer.c code,
> not in vl.c.

So?

-- 
mailto:av1474@comtv.ru

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-10  2:21       ` malc
@ 2009-09-10 16:44         ` Juan Quintela
  2009-09-10 17:02           ` malc
  0 siblings, 1 reply; 62+ messages in thread
From: Juan Quintela @ 2009-09-10 16:44 UTC (permalink / raw)
  To: malc; +Cc: qemu-devel

malc <av1474@comtv.ru> wrote:
> On Thu, 10 Sep 2009, Juan Quintela wrote:
>
>> malc <av1474@comtv.ru> wrote:
>> > On Thu, 10 Sep 2009, Juan Quintela wrote:
>> >
>> > Point being?
>> >
>> > [..snip..]
>> 
>> See next patch.  We need to put the variable in one struct, we don't
>> want to change everything to read the variable from the struct.
>
> So put the in the _pre vmstate callback (or whatever it's called).
>
>> 
>> And at some point code, timer code have to move to qemu-timer.c code,
>> not in vl.c.
>
> So?

What is the problem with this approach?

ticks_per_sec is not a variable that can _modify_ anybody, it can only
be read by anybody.

I need to move where it lives now, and probably will be moved again in
the near future.

What is your problem with exporting a function that gives us exactly
what we want?

init_timers() <- it initializes it, right to assign to it.
save/load vmstate code <- it needs to set it, obviously.

Everybody else only uses it as a read only value.  What is your problem
with giving the value with _one_ function, one value that you can't
modify in case that you have one error?

I can't see what is your big problem with this patch.  I agree that I
can achieve the movement to one struct with pre_save/post_load, but I
think that this patch is good _independently_ of that.

My goal is having less global variables/state not more.  And your point
to have it as it is today?

Later, Juan.

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-10 16:44         ` Juan Quintela
@ 2009-09-10 17:02           ` malc
  2009-09-10 17:38             ` Anthony Liguori
  2009-09-10 17:39             ` Juan Quintela
  0 siblings, 2 replies; 62+ messages in thread
From: malc @ 2009-09-10 17:02 UTC (permalink / raw)
  To: Juan Quintela; +Cc: qemu-devel

On Thu, 10 Sep 2009, Juan Quintela wrote:

> malc <av1474@comtv.ru> wrote:
> > On Thu, 10 Sep 2009, Juan Quintela wrote:
> >
> >> malc <av1474@comtv.ru> wrote:
> >> > On Thu, 10 Sep 2009, Juan Quintela wrote:
> >> >
> >> > Point being?
> >> >
> >> > [..snip..]
> >> 
> >> See next patch.  We need to put the variable in one struct, we don't
> >> want to change everything to read the variable from the struct.
> >
> > So put the in the _pre vmstate callback (or whatever it's called).
> >
> >> 
> >> And at some point code, timer code have to move to qemu-timer.c code,
> >> not in vl.c.
> >
> > So?
> 
> What is the problem with this approach?

My problem with this patch is that it is completely pointless, touches
a gob of places and the fact that you apparently never seen what a
function call entails on PPC64 (any ABI).

[..snip..]

> My goal is having less global variables/state not more.  And your point
> to have it as it is today?

Yes, if it aint broke don't fix it.

-- 
mailto:av1474@comtv.ru

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-10 17:02           ` malc
@ 2009-09-10 17:38             ` Anthony Liguori
  2009-09-10 21:31               ` malc
  2009-09-10 17:39             ` Juan Quintela
  1 sibling, 1 reply; 62+ messages in thread
From: Anthony Liguori @ 2009-09-10 17:38 UTC (permalink / raw)
  To: malc; +Cc: qemu-devel, Juan Quintela

malc wrote:
> My problem with this patch is that it is completely pointless, touches
> a gob of places and the fact that you apparently never seen what a
> function call entails on PPC64 (any ABI).
>   

But there is nothing to suggest this variable is every in the fast path 
so any overhead argument is unfounded.

More importantly, using a function to access this variable gives us the 
ability to change how the behavior is implemented without touching a gob 
of places.

This is refactoring 101 and unless there is some concrete objection, I 
don't see what's wrong with it.

Regards,

Anthony Liguori

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-10 17:02           ` malc
  2009-09-10 17:38             ` Anthony Liguori
@ 2009-09-10 17:39             ` Juan Quintela
  2009-09-10 22:16               ` Paolo Bonzini
  1 sibling, 1 reply; 62+ messages in thread
From: Juan Quintela @ 2009-09-10 17:39 UTC (permalink / raw)
  To: malc; +Cc: qemu-devel

malc <av1474@comtv.ru> wrote:
> On Thu, 10 Sep 2009, Juan Quintela wrote:
>
>> malc <av1474@comtv.ru> wrote:
>> > On Thu, 10 Sep 2009, Juan Quintela wrote:
>> >
>> >> malc <av1474@comtv.ru> wrote:
>> >> > On Thu, 10 Sep 2009, Juan Quintela wrote:
>> >> >
>> >> > Point being?
>> >> >
>> >> > [..snip..]
>> >> 
>> >> See next patch.  We need to put the variable in one struct, we don't
>> >> want to change everything to read the variable from the struct.
>> >
>> > So put the in the _pre vmstate callback (or whatever it's called).
>> >
>> >> 
>> >> And at some point code, timer code have to move to qemu-timer.c code,
>> >> not in vl.c.
>> >
>> > So?
>> 
>> What is the problem with this approach?
>
> My problem with this patch is that it is completely pointless, 

Don't agree.

> touches a gob of places

Right, it happens each time that you changes an API, nothing new to see here.

> and the fact that you apparently never seen what a
> function call entails on PPC64 (any ABI).

Obviously I am not a expert on function calls, but if an architecture is
limiting the number of functions you can call -> Darwin will do his job.

>
> [..snip..]
>
>> My goal is having less global variables/state not more.  And your point
>> to have it as it is today?
>
> Yes, if it aint broke don't fix it.

Obviously, I can't disagree more with you.

Modularity, encapsulaption and _make sure_ that nobody can change this
variable becaues it is _not_ a variable are alien concepts here.

Later, Juan.

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] [PATCH 03/26] Remove SaveVM v2 support
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 03/26] Remove SaveVM v2 support Juan Quintela
@ 2009-09-10 17:41   ` Stefano Stabellini
  2009-09-10 17:43     ` [Qemu-devel] " Juan Quintela
  0 siblings, 1 reply; 62+ messages in thread
From: Stefano Stabellini @ 2009-09-10 17:41 UTC (permalink / raw)
  To: Juan Quintela; +Cc: qemu-devel

On Thu, 10 Sep 2009, Juan Quintela wrote:
> In previosu series I remove v2 support for RAM (that was the version that was
> supported when SaveVM v3 appeared).  Now we can't load RAM for any image saved in SaveVM v2, we can as well remove SaveVM v2 entirely.
> 
> Note: That SaveVM RAM was at v2 when General SaveVM support went from v2 to v3 makes talking about versions confusing at least
> 

Please do not commit this patch, we are using the loadvm v2 code
actively, we should fix the v2 loading functions instead.
If no one else is going to do it, I'll fix it.

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 03/26] Remove SaveVM v2 support
  2009-09-10 17:41   ` Stefano Stabellini
@ 2009-09-10 17:43     ` Juan Quintela
  2009-09-10 18:15       ` Stefano Stabellini
  0 siblings, 1 reply; 62+ messages in thread
From: Juan Quintela @ 2009-09-10 17:43 UTC (permalink / raw)
  To: Stefano Stabellini; +Cc: qemu-devel

Stefano Stabellini <stefano.stabellini@eu.citrix.com> wrote:
> On Thu, 10 Sep 2009, Juan Quintela wrote:
>> In previosu series I remove v2 support for RAM (that was the version that was
>> supported when SaveVM v3 appeared).  Now we can't load RAM for any image saved in SaveVM v2, we can as well remove SaveVM v2 entirely.
>> 
>> Note: That SaveVM RAM was at v2 when General SaveVM support went from v2 to v3 makes talking about versions confusing at least
>> 
>
> Please do not commit this patch, we are using the loadvm v2 code
> actively, we should fix the v2 loading functions instead.
> If no one else is going to do it, I'll fix it.

Details please.

What parts do you need?  all of it? part of it?  Notice that you can
only be using it for loading state, writing state is done in V3.  We are
moving towards V4 (still nothing done), will like to know what are your
use case.

Later, Juan.

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 03/26] Remove SaveVM v2 support
  2009-09-10 17:43     ` [Qemu-devel] " Juan Quintela
@ 2009-09-10 18:15       ` Stefano Stabellini
  2009-09-10 18:22         ` Anthony Liguori
  0 siblings, 1 reply; 62+ messages in thread
From: Stefano Stabellini @ 2009-09-10 18:15 UTC (permalink / raw)
  To: Juan Quintela; +Cc: qemu-devel, Stefano Stabellini

On Thu, 10 Sep 2009, Juan Quintela wrote:
> Stefano Stabellini <stefano.stabellini@eu.citrix.com> wrote:
> > On Thu, 10 Sep 2009, Juan Quintela wrote:
> >> In previosu series I remove v2 support for RAM (that was the version that was
> >> supported when SaveVM v3 appeared).  Now we can't load RAM for any image saved in SaveVM v2, we can as well remove SaveVM v2 entirely.
> >> 
> >> Note: That SaveVM RAM was at v2 when General SaveVM support went from v2 to v3 makes talking about versions confusing at least
> >> 
> >
> > Please do not commit this patch, we are using the loadvm v2 code
> > actively, we should fix the v2 loading functions instead.
> > If no one else is going to do it, I'll fix it.
> 
> Details please.
> 
> What parts do you need?  all of it? part of it?  Notice that you can
> only be using it for loading state, writing state is done in V3.  We are
> moving towards V4 (still nothing done), will like to know what are your
> use case.
> 

First of all sorry if I come late into the discussion but I was on
vacation.

We just need the loading function and we don't even need the ram loading
portion of it but just the device state loading. Of course for qemu
doesn't make sense to keep only the device loading function around
therefore I suggested to keep it all and fix it instead.

As I have mentioned before I think it is really important to provide
backward compatibility, and we do in xen and xenserver without too much
trouble.
I am willing to send patches to fix the device state loading functions,
and we might already have few fixes in qemu-xen.

I realize that my use case is off the tree so you have all the rights
not to be interested in it, nonetheless I hope you don't completely
discard it because it would make our life difficult.

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] Re: [PATCH 03/26] Remove SaveVM v2 support
  2009-09-10 18:15       ` Stefano Stabellini
@ 2009-09-10 18:22         ` Anthony Liguori
  2009-09-11 14:05           ` Stefano Stabellini
  0 siblings, 1 reply; 62+ messages in thread
From: Anthony Liguori @ 2009-09-10 18:22 UTC (permalink / raw)
  To: Stefano Stabellini; +Cc: qemu-devel, Juan Quintela

Stefano Stabellini wrote:
> First of all sorry if I come late into the discussion but I was on
> vacation.
>
> We just need the loading function and we don't even need the ram loading
> portion of it but just the device state loading. Of course for qemu
> doesn't make sense to keep only the device loading function around
> therefore I suggested to keep it all and fix it instead.
>
> As I have mentioned before I think it is really important to provide
> backward compatibility, and we do in xen and xenserver without too much
> trouble.
> I am willing to send patches to fix the device state loading functions,
> and we might already have few fixes in qemu-xen.
>
> I realize that my use case is off the tree so you have all the rights
> not to be interested in it, nonetheless I hope you don't completely
> discard it because it would make our life difficult.
>   

Practically speaking, we only have the ability to support back to 
0.10.0.  We simply didn't have the necessary infrastructure in place to 
support anything older than that.
v3 of the savevm protocol came before 0.10.0 so there's no need for us 
to every support v2 or v1 of the protocol.

There are some major changes happen to the savevm infrastructure for 
0.12.0.  I'd suggest that instead of not removing v2, we remove it, 
finish up the changes, then you can look at re-adding support for it.

Some of the features of v2 may be difficult to carry forward (like the 
savevm section sizes).

And FWIW, I don't necessarily think we'll see a v4 for 0.12.0.  I'm not 
convinced it's needed and/or useful.

Regards,

Anthony Liguori

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-10 17:38             ` Anthony Liguori
@ 2009-09-10 21:31               ` malc
  2009-09-10 22:08                 ` Anthony Liguori
  0 siblings, 1 reply; 62+ messages in thread
From: malc @ 2009-09-10 21:31 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: qemu-devel, Juan Quintela

On Thu, 10 Sep 2009, Anthony Liguori wrote:

> malc wrote:
> > My problem with this patch is that it is completely pointless, touches
> > a gob of places and the fact that you apparently never seen what a
> > function call entails on PPC64 (any ABI).
> >   
> 
> But there is nothing to suggest this variable is every in the fast path 
> so any overhead argument is unfounded.
> 
> More importantly, using a function to access this variable gives us the
> ability to change how the behavior is implemented without touching a gob of
> places.
>

Untill such an ability is needed, the patch adds nothing, oh no it does
wonderful little global-replace gems like:

-        usb_frame_time = ticks_per_sec;
-        usb_bit_time = muldiv64(1, ticks_per_sec, USB_HZ/1000);
+        usb_frame_time = get_ticks_per_sec();
+        usb_bit_time = muldiv64(1, get_ticks_per_sec(), USB_HZ/1000);

> This is refactoring 101 and unless there is some concrete objection, I don't
> see what's wrong with it.

Once again, it adds nothing.

-- 
mailto:av1474@comtv.ru

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-10 21:31               ` malc
@ 2009-09-10 22:08                 ` Anthony Liguori
  2009-09-10 23:10                   ` malc
  0 siblings, 1 reply; 62+ messages in thread
From: Anthony Liguori @ 2009-09-10 22:08 UTC (permalink / raw)
  To: malc; +Cc: qemu-devel, Juan Quintela

malc wrote:
> On Thu, 10 Sep 2009, Anthony Liguori wrote:
>
>   
>> malc wrote:
>>     
>>> My problem with this patch is that it is completely pointless, touches
>>> a gob of places and the fact that you apparently never seen what a
>>> function call entails on PPC64 (any ABI).
>>>   
>>>       
>> But there is nothing to suggest this variable is every in the fast path 
>> so any overhead argument is unfounded.
>>
>> More importantly, using a function to access this variable gives us the
>> ability to change how the behavior is implemented without touching a gob of
>> places.
>>
>>     
>
> Untill such an ability is needed, the patch adds nothing,

Except that it eliminates the possibility of misusing the interface and 
setting it somewhere it shouldn't be.

It makes the code more defensive because you cannot accidentally use it 
like it's a local variable.  The key bit of the patch is:

-int64_t ticks_per_sec;
+static int64_t ticks_per_sec;


That is *always* a worthwhile change to make.  We need more patches like 
this.

Regards,

Anthony Liguori

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-10 17:39             ` Juan Quintela
@ 2009-09-10 22:16               ` Paolo Bonzini
  2009-09-10 23:11                 ` malc
  0 siblings, 1 reply; 62+ messages in thread
From: Paolo Bonzini @ 2009-09-10 22:16 UTC (permalink / raw)
  To: Juan Quintela; +Cc: qemu-devel


> Obviously I am not a expert on function calls, but if an architecture is
> limiting the number of functions you can call ->  Darwin will do his job.

Besides, the next version of GCC will support link-time optimization and 
cross-module inlining.  There is really no excuse to add more 
abstractions if it helps.

Paolo

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-10 22:08                 ` Anthony Liguori
@ 2009-09-10 23:10                   ` malc
  2009-09-10 23:33                     ` Juan Quintela
                                       ` (3 more replies)
  0 siblings, 4 replies; 62+ messages in thread
From: malc @ 2009-09-10 23:10 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: qemu-devel, Juan Quintela

On Thu, 10 Sep 2009, Anthony Liguori wrote:

> malc wrote:
> > On Thu, 10 Sep 2009, Anthony Liguori wrote:
> > 
> >   
> > > malc wrote:
> > >     
> > > > My problem with this patch is that it is completely pointless, touches
> > > > a gob of places and the fact that you apparently never seen what a
> > > > function call entails on PPC64 (any ABI).
> > > >         
> > > But there is nothing to suggest this variable is every in the fast path so
> > > any overhead argument is unfounded.
> > > 
> > > More importantly, using a function to access this variable gives us the
> > > ability to change how the behavior is implemented without touching a gob
> > > of
> > > places.
> > > 
> > >     
> > 
> > Untill such an ability is needed, the patch adds nothing,
> 
> Except that it eliminates the possibility of misusing the interface and
> setting it somewhere it shouldn't be.
> 
> It makes the code more defensive because you cannot accidentally use it like
> it's a local variable.  The key bit of the patch is:
> 
> -int64_t ticks_per_sec;
> +static int64_t ticks_per_sec;
> 
> 
> That is *always* a worthwhile change to make.  We need more patches like this.
> 

And generalizations are always true. Anyhow, i'm explicitly against the
patch, so first obtain the express acknowledgment from the leaders,
otherwise i'll revert it should it go in.

-- 
mailto:av1474@comtv.ru

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-10 22:16               ` Paolo Bonzini
@ 2009-09-10 23:11                 ` malc
  0 siblings, 0 replies; 62+ messages in thread
From: malc @ 2009-09-10 23:11 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, Juan Quintela

On Fri, 11 Sep 2009, Paolo Bonzini wrote:

> 
> > Obviously I am not a expert on function calls, but if an architecture is
> > limiting the number of functions you can call ->  Darwin will do his job.
> 
> Besides, the next version of GCC will support link-time optimization and
> cross-module inlining.  There is really no excuse to add more abstractions if
> it helps.

Nice slip there.

-- 
mailto:av1474@comtv.ru

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-10 23:10                   ` malc
@ 2009-09-10 23:33                     ` Juan Quintela
  2009-09-11  5:49                     ` Amit Shah
                                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-10 23:33 UTC (permalink / raw)
  To: malc; +Cc: qemu-devel

malc <av1474@comtv.ru> wrote:
> On Thu, 10 Sep 2009, Anthony Liguori wrote:
>
>> malc wrote:
>> > On Thu, 10 Sep 2009, Anthony Liguori wrote:
>> > 
>> >   
>> > > malc wrote:
>> > >     
>> > > > My problem with this patch is that it is completely pointless, touches
>> > > > a gob of places and the fact that you apparently never seen what a
>> > > > function call entails on PPC64 (any ABI).
>> > > >         
>> > > But there is nothing to suggest this variable is every in the fast path so
>> > > any overhead argument is unfounded.
>> > > 
>> > > More importantly, using a function to access this variable gives us the
>> > > ability to change how the behavior is implemented without touching a gob
>> > > of
>> > > places.
>> > > 
>> > >     
>> > 
>> > Untill such an ability is needed, the patch adds nothing,
>> 
>> Except that it eliminates the possibility of misusing the interface and
>> setting it somewhere it shouldn't be.
>> 
>> It makes the code more defensive because you cannot accidentally use it like
>> it's a local variable.  The key bit of the patch is:
>> 
>> -int64_t ticks_per_sec;
>> +static int64_t ticks_per_sec;
>> 
>> 
>> That is *always* a worthwhile change to make.  We need more patches like this.
>> 
>
> And generalizations are always true.

So?

> Anyhow, i'm explicitly against the
> patch, so first obtain the express acknowledgment from the leaders,
> otherwise i'll revert it should it go in.

Now playing the commit access card.

At this point I retire for the discussion, as clearly I am not one of
the leaders to revert your revert back.

Later, Juan.

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-10 23:10                   ` malc
  2009-09-10 23:33                     ` Juan Quintela
@ 2009-09-11  5:49                     ` Amit Shah
  2009-09-11 13:00                     ` Markus Armbruster
  2009-09-11 15:34                     ` Anthony Liguori
  3 siblings, 0 replies; 62+ messages in thread
From: Amit Shah @ 2009-09-11  5:49 UTC (permalink / raw)
  To: malc; +Cc: qemu-devel, Juan Quintela

On (Fri) Sep 11 2009 [03:10:59], malc wrote:
> 
> And generalizations are always true. Anyhow, i'm explicitly against the
> patch, so first obtain the express acknowledgment from the leaders,
> otherwise i'll revert it should it go in.

Sad that it has come to this. qemu is a community project, not a project
where "leaders" choose what's better for the community.

I don't disagree with the notion that if there's one person objecting to
a change, we should have a discussion and either get everyone onboard or
make changes for the general good.

But this "leader" card has been played in the past too and it's very
disturbing. It only works to fracture the community and if qemu has to
move forward, the committers have to realise it's not a dictatorship
that has to have the last word.

		Amit

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-10  1:04 ` [Qemu-devel] [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function Juan Quintela
  2009-09-10  1:20   ` malc
@ 2009-09-11  9:04   ` Jan Kiszka
  2009-09-11  9:31     ` Juan Quintela
  1 sibling, 1 reply; 62+ messages in thread
From: Jan Kiszka @ 2009-09-11  9:04 UTC (permalink / raw)
  To: Juan Quintela; +Cc: qemu-devel

Juan Quintela wrote:
> Signed-off-by: Juan Quintela <quintela@redhat.com>

[...]

> diff --git a/vl.c b/vl.c
> index 448ec6c..33abef2 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -186,7 +186,7 @@ enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
>  static DisplayState *display_state;
>  DisplayType display_type = DT_DEFAULT;
>  const char* keyboard_layout = NULL;
> -int64_t ticks_per_sec;
> +static int64_t ticks_per_sec;
>  ram_addr_t ram_size;
>  int nb_nics;
>  NICInfo nd_table[MAX_NICS];
> @@ -1032,6 +1032,11 @@ int64_t qemu_get_clock(QEMUClock *clock)
>      }
>  }
> 
> +int64_t get_ticks_per_sec(void)
> +{
> +    return ticks_per_sec;
> +}
> +

This refactoring would be even more useful if that one became

static inline int64_t get_ticks_per_sec(void)
{
    return QEMU_CLOCK_BASE;
}

Right now we don't have a use for the ticks_per_sec /variable/, it's
always constant. Your interface does not prevent changing this in the
future, though, which is just like it should be.

Jan

-- 
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-11  9:04   ` Jan Kiszka
@ 2009-09-11  9:31     ` Juan Quintela
  2009-09-11  9:37       ` Jan Kiszka
  0 siblings, 1 reply; 62+ messages in thread
From: Juan Quintela @ 2009-09-11  9:31 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: qemu-devel

Jan Kiszka <jan.kiszka@siemens.com> wrote:
> Juan Quintela wrote:
>> Signed-off-by: Juan Quintela <quintela@redhat.com>
>
> [...]
>
>> diff --git a/vl.c b/vl.c
>> index 448ec6c..33abef2 100644
>> --- a/vl.c
>> +++ b/vl.c
>> @@ -186,7 +186,7 @@ enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
>>  static DisplayState *display_state;
>>  DisplayType display_type = DT_DEFAULT;
>>  const char* keyboard_layout = NULL;
>> -int64_t ticks_per_sec;
>> +static int64_t ticks_per_sec;
>>  ram_addr_t ram_size;
>>  int nb_nics;
>>  NICInfo nd_table[MAX_NICS];
>> @@ -1032,6 +1032,11 @@ int64_t qemu_get_clock(QEMUClock *clock)
>>      }
>>  }
>> 
>> +int64_t get_ticks_per_sec(void)
>> +{
>> +    return ticks_per_sec;
>> +}
>> +
>
> This refactoring would be even more useful if that one became
>
> static inline int64_t get_ticks_per_sec(void)
> {
>     return QEMU_CLOCK_BASE;
> }
>
> Right now we don't have a use for the ticks_per_sec /variable/, it's
> always constant. Your interface does not prevent changing this in the
> future, though, which is just like it should be.

I liked this one on top.

Thanks, Juan.

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-11  9:31     ` Juan Quintela
@ 2009-09-11  9:37       ` Jan Kiszka
  2009-09-11 10:15         ` Juan Quintela
  0 siblings, 1 reply; 62+ messages in thread
From: Jan Kiszka @ 2009-09-11  9:37 UTC (permalink / raw)
  To: Juan Quintela; +Cc: qemu-devel

Juan Quintela wrote:
> Jan Kiszka <jan.kiszka@siemens.com> wrote:
>> Juan Quintela wrote:
>>> Signed-off-by: Juan Quintela <quintela@redhat.com>
>> [...]
>>
>>> diff --git a/vl.c b/vl.c
>>> index 448ec6c..33abef2 100644
>>> --- a/vl.c
>>> +++ b/vl.c
>>> @@ -186,7 +186,7 @@ enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
>>>  static DisplayState *display_state;
>>>  DisplayType display_type = DT_DEFAULT;
>>>  const char* keyboard_layout = NULL;
>>> -int64_t ticks_per_sec;
>>> +static int64_t ticks_per_sec;
>>>  ram_addr_t ram_size;
>>>  int nb_nics;
>>>  NICInfo nd_table[MAX_NICS];
>>> @@ -1032,6 +1032,11 @@ int64_t qemu_get_clock(QEMUClock *clock)
>>>      }
>>>  }
>>>
>>> +int64_t get_ticks_per_sec(void)
>>> +{
>>> +    return ticks_per_sec;
>>> +}
>>> +
>> This refactoring would be even more useful if that one became
>>
>> static inline int64_t get_ticks_per_sec(void)
>> {
>>     return QEMU_CLOCK_BASE;
>> }
>>
>> Right now we don't have a use for the ticks_per_sec /variable/, it's
>> always constant. Your interface does not prevent changing this in the
>> future, though, which is just like it should be.
> 
> I liked this one on top.

Why?

Jan

-- 
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-11  9:37       ` Jan Kiszka
@ 2009-09-11 10:15         ` Juan Quintela
  2009-09-11 10:26           ` Jan Kiszka
  0 siblings, 1 reply; 62+ messages in thread
From: Juan Quintela @ 2009-09-11 10:15 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: qemu-devel

Jan Kiszka <jan.kiszka@siemens.com> wrote:
> Juan Quintela wrote:
>> Jan Kiszka <jan.kiszka@siemens.com> wrote:
>>> Juan Quintela wrote:
>>>> Signed-off-by: Juan Quintela <quintela@redhat.com>
>>> [...]
>>>
>>>> diff --git a/vl.c b/vl.c
>>>> index 448ec6c..33abef2 100644
>>>> --- a/vl.c
>>>> +++ b/vl.c
>>>> @@ -186,7 +186,7 @@ enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
>>>>  static DisplayState *display_state;
>>>>  DisplayType display_type = DT_DEFAULT;
>>>>  const char* keyboard_layout = NULL;
>>>> -int64_t ticks_per_sec;
>>>> +static int64_t ticks_per_sec;
>>>>  ram_addr_t ram_size;
>>>>  int nb_nics;
>>>>  NICInfo nd_table[MAX_NICS];
>>>> @@ -1032,6 +1032,11 @@ int64_t qemu_get_clock(QEMUClock *clock)
>>>>      }
>>>>  }
>>>>
>>>> +int64_t get_ticks_per_sec(void)
>>>> +{
>>>> +    return ticks_per_sec;
>>>> +}
>>>> +
>>> This refactoring would be even more useful if that one became
>>>
>>> static inline int64_t get_ticks_per_sec(void)
>>> {
>>>     return QEMU_CLOCK_BASE;
>>> }
>>>
>>> Right now we don't have a use for the ticks_per_sec /variable/, it's
>>> always constant. Your interface does not prevent changing this in the
>>> future, though, which is just like it should be.
>> 
>> I liked this one on top.
>
> Why?

Because that is how we use it.  Mine is refactoring, yours is changing
behavior.  With my patch, it is still possible to change ticks_per_sec
(not that this is a good idea, but that is how the code is today).  With
yours, you remove that feature.  I fully agree with your change.
In my book that are _two_ patches.

Later, Juan.

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-11 10:15         ` Juan Quintela
@ 2009-09-11 10:26           ` Jan Kiszka
  0 siblings, 0 replies; 62+ messages in thread
From: Jan Kiszka @ 2009-09-11 10:26 UTC (permalink / raw)
  To: Juan Quintela; +Cc: qemu-devel

Juan Quintela wrote:
> Jan Kiszka <jan.kiszka@siemens.com> wrote:
>> Juan Quintela wrote:
>>> Jan Kiszka <jan.kiszka@siemens.com> wrote:
>>>> Juan Quintela wrote:
>>>>> Signed-off-by: Juan Quintela <quintela@redhat.com>
>>>> [...]
>>>>
>>>>> diff --git a/vl.c b/vl.c
>>>>> index 448ec6c..33abef2 100644
>>>>> --- a/vl.c
>>>>> +++ b/vl.c
>>>>> @@ -186,7 +186,7 @@ enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
>>>>>  static DisplayState *display_state;
>>>>>  DisplayType display_type = DT_DEFAULT;
>>>>>  const char* keyboard_layout = NULL;
>>>>> -int64_t ticks_per_sec;
>>>>> +static int64_t ticks_per_sec;
>>>>>  ram_addr_t ram_size;
>>>>>  int nb_nics;
>>>>>  NICInfo nd_table[MAX_NICS];
>>>>> @@ -1032,6 +1032,11 @@ int64_t qemu_get_clock(QEMUClock *clock)
>>>>>      }
>>>>>  }
>>>>>
>>>>> +int64_t get_ticks_per_sec(void)
>>>>> +{
>>>>> +    return ticks_per_sec;
>>>>> +}
>>>>> +
>>>> This refactoring would be even more useful if that one became
>>>>
>>>> static inline int64_t get_ticks_per_sec(void)
>>>> {
>>>>     return QEMU_CLOCK_BASE;
>>>> }
>>>>
>>>> Right now we don't have a use for the ticks_per_sec /variable/, it's
>>>> always constant. Your interface does not prevent changing this in the
>>>> future, though, which is just like it should be.
>>> I liked this one on top.
>> Why?
> 
> Because that is how we use it.  Mine is refactoring, yours is changing
> behavior.  With my patch, it is still possible to change ticks_per_sec
> (not that this is a good idea, but that is how the code is today).  With
> yours, you remove that feature.  I fully agree with your change.
> In my book that are _two_ patches.

Ah, ok, misunderstanding on my side (I'm a bit slow today). Will file a
patch on top of yours.

Jan

-- 
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-10 23:10                   ` malc
  2009-09-10 23:33                     ` Juan Quintela
  2009-09-11  5:49                     ` Amit Shah
@ 2009-09-11 13:00                     ` Markus Armbruster
  2009-09-11 15:34                     ` Anthony Liguori
  3 siblings, 0 replies; 62+ messages in thread
From: Markus Armbruster @ 2009-09-11 13:00 UTC (permalink / raw)
  To: malc; +Cc: qemu-devel, Juan Quintela

malc <av1474@comtv.ru> writes:

> And generalizations are always true. Anyhow, i'm explicitly against the
> patch, so first obtain the express acknowledgment from the leaders,
> otherwise i'll revert it should it go in.

In a healthy development community, differences of opinion on technical
matters should be settled by force of argument, not by commit
privileges.  Commit privileges may have to be invoked to terminate an
argument that is clearly not going anywhere.  Often unavoidable when the
argumnt is about matters of taste, like indentation style.

In my opinion, your threat to revert a patch should it be committed by
one of your commit-privileged fellows is uncalled for at this stage of
the discussion.  Such heavy-handed use of the privilege sends a signal
to the unprivileged they're not worthy.  And it risks some of the
unprivileged get that signal loud and clear, and go away.

With privilege comes responsibility.

Off my soapbox, thanks for listening.

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] Re: [PATCH 03/26] Remove SaveVM v2 support
  2009-09-10 18:22         ` Anthony Liguori
@ 2009-09-11 14:05           ` Stefano Stabellini
  2009-09-11 14:28             ` Juan Quintela
  0 siblings, 1 reply; 62+ messages in thread
From: Stefano Stabellini @ 2009-09-11 14:05 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Juan Quintela, qemu-devel, Stefano Stabellini

On Thu, 10 Sep 2009, Anthony Liguori wrote:
> Practically speaking, we only have the ability to support back to 
> 0.10.0.  We simply didn't have the necessary infrastructure in place to 
> support anything older than that.
> v3 of the savevm protocol came before 0.10.0 so there's no need for us 
> to every support v2 or v1 of the protocol.
> 
> There are some major changes happen to the savevm infrastructure for 
> 0.12.0.  I'd suggest that instead of not removing v2, we remove it, 
> finish up the changes, then you can look at re-adding support for it.
> 
> Some of the features of v2 may be difficult to carry forward (like the 
> savevm section sizes).
> 
> And FWIW, I don't necessarily think we'll see a v4 for 0.12.0.  I'm not 
> convinced it's needed and/or useful.
> 

I gave a better look at the code and the situation is not as bad as I
thought: the important code for us is not much the single
function qemu_loadvm_state_v2 that can easily be replaced and\or
rewritten but all the per device state loading functions in C, that
fortunately are shared between v2 and v3.
I am still unhappy with removing support for v2 and I am inclined to
consider it a regression but as long as you keep those functions in I am
reasonably happy.

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 03/26] Remove SaveVM v2 support
  2009-09-11 14:05           ` Stefano Stabellini
@ 2009-09-11 14:28             ` Juan Quintela
  2009-09-11 15:32               ` Stefano Stabellini
  0 siblings, 1 reply; 62+ messages in thread
From: Juan Quintela @ 2009-09-11 14:28 UTC (permalink / raw)
  To: Stefano Stabellini; +Cc: qemu-devel

Stefano Stabellini <stefano.stabellini@eu.citrix.com> wrote:
> On Thu, 10 Sep 2009, Anthony Liguori wrote:
>> Practically speaking, we only have the ability to support back to 
>> 0.10.0.  We simply didn't have the necessary infrastructure in place to 
>> support anything older than that.
>> v3 of the savevm protocol came before 0.10.0 so there's no need for us 
>> to every support v2 or v1 of the protocol.
>> 
>> There are some major changes happen to the savevm infrastructure for 
>> 0.12.0.  I'd suggest that instead of not removing v2, we remove it, 
>> finish up the changes, then you can look at re-adding support for it.
>> 
>> Some of the features of v2 may be difficult to carry forward (like the 
>> savevm section sizes).
>> 
>> And FWIW, I don't necessarily think we'll see a v4 for 0.12.0.  I'm not 
>> convinced it's needed and/or useful.
>> 
>
> I gave a better look at the code and the situation is not as bad as I
> thought: the important code for us is not much the single
> function qemu_loadvm_state_v2 that can easily be replaced and\or
> rewritten but all the per device state loading functions in C, that
> fortunately are shared between v2 and v3.
> I am still unhappy with removing support for v2 and I am inclined to
> consider it a regression but as long as you keep those functions in I am
> reasonably happy.

I think we can't call that a regression:

Old in the past SaveVM State v2 is created.

Everything works for a while.

At some later point SaveVM State v3 is created.

Things continue to work fo a while.

After this while (In April of this year ram support for V2 got broken, when I fixed
it, I found that VGA got garbled and ide didn't work either).

Things didn't work for at least 5 months, I haven't seen a complaint.

Removing something that hasn't work during 5 months and nobody
complained is supposed to be a regression?

Now: We have v2 support on tree, that is not working, haven't worked for
a long time, and there is not a chance to load an image from the old
past.  What is better?  Remove the old non working code.  Or spend time
debugging why it stopped working and fixing it?  Notice that it is also
important that nobody complained that they were unable to load the old images.

Later, Juan.

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 03/26] Remove SaveVM v2 support
  2009-09-11 14:28             ` Juan Quintela
@ 2009-09-11 15:32               ` Stefano Stabellini
  2009-09-11 15:37                 ` Anthony Liguori
  2009-09-11 15:48                 ` Juan Quintela
  0 siblings, 2 replies; 62+ messages in thread
From: Stefano Stabellini @ 2009-09-11 15:32 UTC (permalink / raw)
  To: Juan Quintela; +Cc: qemu-devel, Stefano Stabellini

On Fri, 11 Sep 2009, Juan Quintela wrote:
> I think we can't call that a regression:
> 
> Old in the past SaveVM State v2 is created.
> 
> Everything works for a while.
> 
> At some later point SaveVM State v3 is created.
> 
> Things continue to work fo a while.
> 
> After this while (In April of this year ram support for V2 got broken, when I fixed
> it, I found that VGA got garbled and ide didn't work either).
> 
> Things didn't work for at least 5 months, I haven't seen a complaint.
> 
> Removing something that hasn't work during 5 months and nobody
> complained is supposed to be a regression?
> 
> Now: We have v2 support on tree, that is not working, haven't worked for
> a long time, and there is not a chance to load an image from the old
> past.  What is better?  Remove the old non working code.  Or spend time
> debugging why it stopped working and fixing it?  Notice that it is also
> important that nobody complained that they were unable to load the old images.
> 

No one complained because the people affected by this issue probably
don't follow qemu development so closely to have realized that their old
images won't work anymore.
I do believe that fixing v2 compatibility is important for a large
number of qemu users (including kvm and xen).

That said, I don't want to fight over this more than necessary, so as
long as you keep the per device loading functions in C we can maintain
v2 compatibility downstream if upstream is not interested.

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-10 23:10                   ` malc
                                       ` (2 preceding siblings ...)
  2009-09-11 13:00                     ` Markus Armbruster
@ 2009-09-11 15:34                     ` Anthony Liguori
  2009-09-11 15:55                       ` Juan Quintela
                                         ` (2 more replies)
  3 siblings, 3 replies; 62+ messages in thread
From: Anthony Liguori @ 2009-09-11 15:34 UTC (permalink / raw)
  To: malc; +Cc: qemu-devel, Juan Quintela

[-- Attachment #1: Type: text/plain, Size: 547 bytes --]

malc wrote:
> And generalizations are always true. Anyhow, i'm explicitly against the
> patch, so first obtain the express acknowledgment from the leaders,
> otherwise i'll revert it should it go in.
>   

I'm adding the following patch to Juan's series.  The result is that 
get_ticks_per_sec() should be optimized to a literal value.  The result 
being that uses of it are faster than they were before (not it should 
matter).

I think the result of this patch is that the refactoring is an 
undeniable improvement.

Regards,

Anthony Liguori



[-- Attachment #2: get-ticks-per-sec.patch --]
[-- Type: text/x-patch, Size: 3203 bytes --]

commit 1c7aff17af0ca9e1803b952ce455f096c5da8847
Author: Anthony Liguori <aliguori@us.ibm.com>
Date:   Fri Sep 11 10:28:26 2009 -0500

    Make get_ticks_per_sec() a static inline
    
    ticks_per_sec is a constant.  There's no need to store it as a variable as it
    never changes since our time is based on units.
    
    Convert get_ticks_per_sec() to a static inline and move the constant into
    qemu-timer.h.  Remove all references to QEMU_TIMER_BASE so that we consistently
    use this interface.
    
    Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

diff --git a/qemu-timer.h b/qemu-timer.h
index 00b166d..e44c334 100644
--- a/qemu-timer.h
+++ b/qemu-timer.h
@@ -26,7 +26,10 @@ void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time);
 int qemu_timer_pending(QEMUTimer *ts);
 int qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time);
 
-int64_t get_ticks_per_sec(void);
+static inline int64_t get_ticks_per_sec(void)
+{
+    return 1000000000LL;
+}
 
 void qemu_get_timer(QEMUFile *f, QEMUTimer *ts);
 void qemu_put_timer(QEMUFile *f, QEMUTimer *ts);
diff --git a/vl.c b/vl.c
index 6052b1c..c3c874d 100644
--- a/vl.c
+++ b/vl.c
@@ -528,8 +528,6 @@ uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)
 /***********************************************************/
 /* real time host monotonic timer */
 
-#define QEMU_TIMER_BASE 1000000000LL
-
 #ifdef WIN32
 
 static int64_t clock_freq;
@@ -550,7 +548,7 @@ static int64_t get_clock(void)
 {
     LARGE_INTEGER ti;
     QueryPerformanceCounter(&ti);
-    return muldiv64(ti.QuadPart, QEMU_TIMER_BASE, clock_freq);
+    return muldiv64(ti.QuadPart, get_ticks_per_sec(), clock_freq);
 }
 
 #else
@@ -758,7 +756,7 @@ static void rtc_stop_timer(struct qemu_alarm_timer *t);
    fairly approximate, so ignore small variation.
    When the guest is idle real and virtual time will be aligned in
    the IO wait loop.  */
-#define ICOUNT_WOBBLE (QEMU_TIMER_BASE / 10)
+#define ICOUNT_WOBBLE (get_ticks_per_sec() / 10)
 
 static void icount_adjust(void)
 {
@@ -800,7 +798,7 @@ static void icount_adjust_rt(void * opaque)
 static void icount_adjust_vm(void * opaque)
 {
     qemu_mod_timer(icount_vm_timer,
-                   qemu_get_clock(vm_clock) + QEMU_TIMER_BASE / 10);
+                   qemu_get_clock(vm_clock) + get_ticks_per_sec() / 10);
     icount_adjust();
 }
 
@@ -816,7 +814,7 @@ static void init_icount_adjust(void)
                    qemu_get_clock(rt_clock) + 1000);
     icount_vm_timer = qemu_new_timer(vm_clock, icount_adjust_vm, NULL);
     qemu_mod_timer(icount_vm_timer,
-                   qemu_get_clock(vm_clock) + QEMU_TIMER_BASE / 10);
+                   qemu_get_clock(vm_clock) + get_ticks_per_sec() / 10);
 }
 
 static struct qemu_alarm_timer alarm_timers[] = {
@@ -1036,15 +1034,10 @@ int64_t qemu_get_clock(QEMUClock *clock)
     }
 }
 
-int64_t get_ticks_per_sec(void)
-{
-    return timers_state.ticks_per_sec;
-}
-
 static void init_timers(void)
 {
     init_get_clock();
-    timers_state.ticks_per_sec = QEMU_TIMER_BASE;
+    timers_state.ticks_per_sec = get_ticks_per_sec();
     rt_clock = qemu_new_clock(QEMU_TIMER_REALTIME);
     vm_clock = qemu_new_clock(QEMU_TIMER_VIRTUAL);
 }

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 03/26] Remove SaveVM v2 support
  2009-09-11 15:32               ` Stefano Stabellini
@ 2009-09-11 15:37                 ` Anthony Liguori
  2009-09-11 15:48                 ` Juan Quintela
  1 sibling, 0 replies; 62+ messages in thread
From: Anthony Liguori @ 2009-09-11 15:37 UTC (permalink / raw)
  To: Stefano Stabellini; +Cc: qemu-devel, Juan Quintela

Stefano Stabellini wrote:
> No one complained because the people affected by this issue probably
> don't follow qemu development so closely to have realized that their old
> images won't work anymore.
> I do believe that fixing v2 compatibility is important for a large
> number of qemu users (including kvm and xen).
>   

kvm never supported live migration with v2.  As I think I mentioned in 
another note, I don't want to burden the VMState refactoring with 
supporting a format that qemu doesn't support upstream.  That said, if 
you want to add back a version of it that makes use of the new 
infrastructure, I would be willing to take that.

In fact, if you're willing to do the cleanup work along with Juan, we 
can avoid removing it.

> That said, I don't want to fight over this more than necessary, so as
> long as you keep the per device loading functions in C we can maintain
> v2 compatibility downstream if upstream is not interested.
>   

The per device loading functions will be switching to VMState.

Regards,

Anthony Liguori

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 03/26] Remove SaveVM v2 support
  2009-09-11 15:32               ` Stefano Stabellini
  2009-09-11 15:37                 ` Anthony Liguori
@ 2009-09-11 15:48                 ` Juan Quintela
  2009-09-11 17:59                   ` Stefano Stabellini
  2009-09-17 11:40                   ` Stefano Stabellini
  1 sibling, 2 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-11 15:48 UTC (permalink / raw)
  To: Stefano Stabellini; +Cc: qemu-devel

Stefano Stabellini <stefano.stabellini@eu.citrix.com> wrote:
> On Fri, 11 Sep 2009, Juan Quintela wrote:
>> I think we can't call that a regression:
>> 
>> Old in the past SaveVM State v2 is created.
>> 
>> Everything works for a while.
>> 
>> At some later point SaveVM State v3 is created.
>> 
>> Things continue to work fo a while.
>> 
>> After this while (In April of this year ram support for V2 got broken, when I fixed
>> it, I found that VGA got garbled and ide didn't work either).
>> 
>> Things didn't work for at least 5 months, I haven't seen a complaint.
>> 
>> Removing something that hasn't work during 5 months and nobody
>> complained is supposed to be a regression?
>> 
>> Now: We have v2 support on tree, that is not working, haven't worked for
>> a long time, and there is not a chance to load an image from the old
>> past.  What is better?  Remove the old non working code.  Or spend time
>> debugging why it stopped working and fixing it?  Notice that it is also
>> important that nobody complained that they were unable to load the old images.
>> 
>
> No one complained because the people affected by this issue probably
> don't follow qemu development so closely to have realized that their old
> images won't work anymore.
> I do believe that fixing v2 compatibility is important for a large
> number of qemu users (including kvm and xen).

About this, nobody is wanting to remove useful features.  I was removing
things that didn't work.  The best plan of action if you want v2 support
on tree is to fix it.  Do what I did:

This commit introduces SaveVM v3
commit 9366f4186025e1d8fc3bebd41fb714521c170b6f
Author: aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>
Date:   Mon Oct 6 14:53:52 2008 +0000

    Introduce v3 of savevm protocol

I checkout previous commit, savevm one machine. Go to the present and
try to load it -> RAM don't work.

Search what commit broke it:

commit 94a6b54fd6d2d3321066cb4db7abeeb417af9365
Author: pbrook <pbrook@c046a42c-6fe2-441c-8c8c-71466251a162>
Date:   Sat Apr 11 17:15:54 2009 +0000

    Implement dynamic guest ram allocation.

Went to the previous one, to see if this was the only broken thing.
And found that ide and vga was broken at that point.

I stopped searching there.
You get that image to load, and I try not to break it with VMState
changes.  Can you (or anybody else) got v2 to life?  If it is working,
and you can use it, I don't want to break its support.  But if it has
been broken for ages and nobody steps it to fix it -> removing is only
useful thing that I can think of doing.

> That said, I don't want to fight over this more than necessary, so as
> long as you keep the per device loading functions in C we can maintain
> v2 compatibility downstream if upstream is not interested.

Instead of complaining, we can start doing things productively.
Can you do a list of the older (device, version) that you are interested
in?  If we have such a list, we can see how feasible it is maintaing
support for them.

Later, Juan.

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-11 15:34                     ` Anthony Liguori
@ 2009-09-11 15:55                       ` Juan Quintela
  2009-09-11 15:58                       ` Jan Kiszka
  2009-11-09 16:29                       ` Paul Brook
  2 siblings, 0 replies; 62+ messages in thread
From: Juan Quintela @ 2009-09-11 15:55 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: qemu-devel

Anthony Liguori <anthony@codemonkey.ws> wrote:
> malc wrote:
>> And generalizations are always true. Anyhow, i'm explicitly against the
>> patch, so first obtain the express acknowledgment from the leaders,
>> otherwise i'll revert it should it go in.
>>   
>
> I'm adding the following patch to Juan's series.  The result is that
> get_ticks_per_sec() should be optimized to a literal value.  The
> result being that uses of it are faster than they were before (not it
> should matter).
>
> I think the result of this patch is that the refactoring is an
> undeniable improvement.
>
> Regards,
>
> Anthony Liguori

Nice.

Acked-by: Juan Quintela <quintela@redhat.com>

>
> commit 1c7aff17af0ca9e1803b952ce455f096c5da8847
> Author: Anthony Liguori <aliguori@us.ibm.com>
> Date:   Fri Sep 11 10:28:26 2009 -0500
>
>     Make get_ticks_per_sec() a static inline
>     
>     ticks_per_sec is a constant.  There's no need to store it as a variable as it
>     never changes since our time is based on units.
>     
>     Convert get_ticks_per_sec() to a static inline and move the constant into
>     qemu-timer.h.  Remove all references to QEMU_TIMER_BASE so that we consistently
>     use this interface.
>     
>     Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
>
> diff --git a/qemu-timer.h b/qemu-timer.h
> index 00b166d..e44c334 100644
> --- a/qemu-timer.h
> +++ b/qemu-timer.h
> @@ -26,7 +26,10 @@ void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time);
>  int qemu_timer_pending(QEMUTimer *ts);
>  int qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time);
>  
> -int64_t get_ticks_per_sec(void);
> +static inline int64_t get_ticks_per_sec(void)
> +{
> +    return 1000000000LL;
> +}
>  
>  void qemu_get_timer(QEMUFile *f, QEMUTimer *ts);
>  void qemu_put_timer(QEMUFile *f, QEMUTimer *ts);
> diff --git a/vl.c b/vl.c
> index 6052b1c..c3c874d 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -528,8 +528,6 @@ uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)
>  /***********************************************************/
>  /* real time host monotonic timer */
>  
> -#define QEMU_TIMER_BASE 1000000000LL
> -
>  #ifdef WIN32
>  
>  static int64_t clock_freq;
> @@ -550,7 +548,7 @@ static int64_t get_clock(void)
>  {
>      LARGE_INTEGER ti;
>      QueryPerformanceCounter(&ti);
> -    return muldiv64(ti.QuadPart, QEMU_TIMER_BASE, clock_freq);
> +    return muldiv64(ti.QuadPart, get_ticks_per_sec(), clock_freq);
>  }
>  
>  #else
> @@ -758,7 +756,7 @@ static void rtc_stop_timer(struct qemu_alarm_timer *t);
>     fairly approximate, so ignore small variation.
>     When the guest is idle real and virtual time will be aligned in
>     the IO wait loop.  */
> -#define ICOUNT_WOBBLE (QEMU_TIMER_BASE / 10)
> +#define ICOUNT_WOBBLE (get_ticks_per_sec() / 10)
>  
>  static void icount_adjust(void)
>  {
> @@ -800,7 +798,7 @@ static void icount_adjust_rt(void * opaque)
>  static void icount_adjust_vm(void * opaque)
>  {
>      qemu_mod_timer(icount_vm_timer,
> -                   qemu_get_clock(vm_clock) + QEMU_TIMER_BASE / 10);
> +                   qemu_get_clock(vm_clock) + get_ticks_per_sec() / 10);
>      icount_adjust();
>  }
>  
> @@ -816,7 +814,7 @@ static void init_icount_adjust(void)
>                     qemu_get_clock(rt_clock) + 1000);
>      icount_vm_timer = qemu_new_timer(vm_clock, icount_adjust_vm, NULL);
>      qemu_mod_timer(icount_vm_timer,
> -                   qemu_get_clock(vm_clock) + QEMU_TIMER_BASE / 10);
> +                   qemu_get_clock(vm_clock) + get_ticks_per_sec() / 10);
>  }
>  
>  static struct qemu_alarm_timer alarm_timers[] = {
> @@ -1036,15 +1034,10 @@ int64_t qemu_get_clock(QEMUClock *clock)
>      }
>  }
>  
> -int64_t get_ticks_per_sec(void)
> -{
> -    return timers_state.ticks_per_sec;
> -}
> -
>  static void init_timers(void)
>  {
>      init_get_clock();
> -    timers_state.ticks_per_sec = QEMU_TIMER_BASE;
> +    timers_state.ticks_per_sec = get_ticks_per_sec();
>      rt_clock = qemu_new_clock(QEMU_TIMER_REALTIME);
>      vm_clock = qemu_new_clock(QEMU_TIMER_VIRTUAL);
>  }

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-11 15:34                     ` Anthony Liguori
  2009-09-11 15:55                       ` Juan Quintela
@ 2009-09-11 15:58                       ` Jan Kiszka
  2009-11-09 16:29                       ` Paul Brook
  2 siblings, 0 replies; 62+ messages in thread
From: Jan Kiszka @ 2009-09-11 15:58 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: qemu-devel, Juan Quintela

Anthony Liguori wrote:
> malc wrote:
>> And generalizations are always true. Anyhow, i'm explicitly against the
>> patch, so first obtain the express acknowledgment from the leaders,
>> otherwise i'll revert it should it go in.
>>   
> 
> I'm adding the following patch to Juan's series.  The result is that
> get_ticks_per_sec() should be optimized to a literal value.  The result
> being that uses of it are faster than they were before (not it should
> matter).

Perfect!

> 
> I think the result of this patch is that the refactoring is an
> undeniable improvement.
> 
> Regards,
> 
> Anthony Liguori
> 
> 

Jan

-- 
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 03/26] Remove SaveVM v2 support
  2009-09-11 15:48                 ` Juan Quintela
@ 2009-09-11 17:59                   ` Stefano Stabellini
  2009-09-17 11:40                   ` Stefano Stabellini
  1 sibling, 0 replies; 62+ messages in thread
From: Stefano Stabellini @ 2009-09-11 17:59 UTC (permalink / raw)
  To: Juan Quintela; +Cc: qemu-devel, Stefano Stabellini

On Fri, 11 Sep 2009, Juan Quintela wrote:
> About this, nobody is wanting to remove useful features.  I was removing
> things that didn't work.  The best plan of action if you want v2 support
> on tree is to fix it.  Do what I did:
> 
> This commit introduces SaveVM v3
> commit 9366f4186025e1d8fc3bebd41fb714521c170b6f
> Author: aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>
> Date:   Mon Oct 6 14:53:52 2008 +0000
> 
>     Introduce v3 of savevm protocol
> 
> I checkout previous commit, savevm one machine. Go to the present and
> try to load it -> RAM don't work.
> 
> Search what commit broke it:
> 
> commit 94a6b54fd6d2d3321066cb4db7abeeb417af9365
> Author: pbrook <pbrook@c046a42c-6fe2-441c-8c8c-71466251a162>
> Date:   Sat Apr 11 17:15:54 2009 +0000
> 
>     Implement dynamic guest ram allocation.
> 
> Went to the previous one, to see if this was the only broken thing.
> And found that ide and vga was broken at that point.
> 
> I stopped searching there.
> You get that image to load, and I try not to break it with VMState
> changes.  Can you (or anybody else) got v2 to life?  If it is working,
> and you can use it, I don't want to break its support.  But if it has
> been broken for ages and nobody steps it to fix it -> removing is only
> useful thing that I can think of doing.

I really want to thank you for understanding; Ian and\or me will try to
fix this issue as soon as we can.


> > That said, I don't want to fight over this more than necessary, so as
> > long as you keep the per device loading functions in C we can maintain
> > v2 compatibility downstream if upstream is not interested.
> 
> Instead of complaining, we can start doing things productively.
> Can you do a list of the older (device, version) that you are interested
> in?  If we have such a list, we can see how feasible it is maintaing
> support for them.
> 

The list is not very long, and you'll find that most devices still have
the same version number:

I440FX version 2 (now is 3)
PIIX3 version 2 (now is 3)
cirrus_vga version 2 (now is 2)
vga version 2 (now is 2)
mc146818rtc version 1
serial version 2 (now is 3)
rtl8139 version 3 (now is 4)
ide version 2 (now is 3)
pckbd version 3 (now is 3)
ps2kbd version 3  (now is 3)
ps2mouse version 2  (now is 2)
dma version 1
fdc version 2  (now is 2)
UHCI usb controller version 1
gpe version 1
pcislots version 1
piix4acpi version 1

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] Re: [PATCH 03/26] Remove SaveVM v2 support
  2009-09-11 15:48                 ` Juan Quintela
  2009-09-11 17:59                   ` Stefano Stabellini
@ 2009-09-17 11:40                   ` Stefano Stabellini
  1 sibling, 0 replies; 62+ messages in thread
From: Stefano Stabellini @ 2009-09-17 11:40 UTC (permalink / raw)
  To: Juan Quintela; +Cc: Ian Jackson, qemu-devel, Stefano Stabellini

[-- Attachment #1: Type: text/plain, Size: 2511 bytes --]

On Fri, 11 Sep 2009, Juan Quintela wrote:
> About this, nobody is wanting to remove useful features.  I was removing
> things that didn't work.  The best plan of action if you want v2 support
> on tree is to fix it.  Do what I did:
> 
> This commit introduces SaveVM v3
> commit 9366f4186025e1d8fc3bebd41fb714521c170b6f
> Author: aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>
> Date:   Mon Oct 6 14:53:52 2008 +0000
> 
>     Introduce v3 of savevm protocol
> 
> I checkout previous commit, savevm one machine. Go to the present and
> try to load it -> RAM don't work.
> 
> Search what commit broke it:
> 
> commit 94a6b54fd6d2d3321066cb4db7abeeb417af9365
> Author: pbrook <pbrook@c046a42c-6fe2-441c-8c8c-71466251a162>
> Date:   Sat Apr 11 17:15:54 2009 +0000
> 
>     Implement dynamic guest ram allocation.
> 
> Went to the previous one, to see if this was the only broken thing.
> And found that ide and vga was broken at that point.
> 
> I stopped searching there.
> You get that image to load, and I try not to break it with VMState
> changes.  Can you (or anybody else) got v2 to life?  If it is working,
> and you can use it, I don't want to break its support.  But if it has
> been broken for ages and nobody steps it to fix it -> removing is only
> useful thing that I can think of doing.

I didn't have much time to work on this but I thought it would be a
good idea to give an update on the situation.

The two patches I am attaching to this email fix the ide v1 state loading
problem and the v2 ram loading problem (you have to make sure that the
ram size given from the command line is the same of the saved image).
They apply to CS 799f1f2325a1136a84d6f0ea94d891ef33656af2 that is right
before "ram: remove support for loading v1" and "ram: Remove SaveVM
Version 2 support".

I was able to save and restore qemu guests in graphical mode with no issues.
There is still a font corruption problem that may be the vga issue you
were reporting. The vga state is saved and loaded correctly but the
fonts come up all zeroed after resume and I am still not sure why, it
might be a videram saving problem.

Reverting "Remove SaveVM v2 support" and "ram: Remove SaveVM Version 2
support" and applying these patches on the latest CS doesn't give the
results you would expect: qemu segfaults resuming the cirrus vga state
that may be a symptom of a problem introduced by the vmstate changes in
cirrus vga.

I'll be away for a week or two but I think IanJ will keep working on this.

Cheers,

Stefano

[-- Attachment #2: Type: text/plain, Size: 836 bytes --]

diff --git a/vl.c b/vl.c
index 0446769..3188672 100644
--- a/vl.c
+++ b/vl.c
@@ -3038,7 +3038,7 @@ static int ram_load_dead(QEMUFile *f, void *opaque)
 
     if (ram_decompress_open(s, f) < 0)
         return -EINVAL;
-    for(i = 0; i < last_ram_offset; i+= BDRV_HASH_BLOCK_SIZE) {
+    for(i = 0; i < ram_size; i+= BDRV_HASH_BLOCK_SIZE) {
         if (ram_decompress_buf(s, buf, 1) < 0) {
             fprintf(stderr, "Error while reading ram block header\n");
             goto error;
@@ -3069,7 +3069,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
         return ram_load_v1(f, opaque);
 
     if (version_id == 2) {
-        if (qemu_get_be32(f) != last_ram_offset)
+        if (qemu_get_be32(f) != ram_size)
             return -EINVAL;
         return ram_load_dead(f, opaque);
     }

[-- Attachment #3: Type: text/plain, Size: 1064 bytes --]

diff --git a/hw/ide/pci.c b/hw/ide/pci.c
index 607472b..a5c112a 100644
--- a/hw/ide/pci.c
+++ b/hw/ide/pci.c
@@ -307,8 +307,6 @@ static int pci_ide_load(QEMUFile* f, void *opaque, int version_id)
     PCIIDEState *d = opaque;
     int ret, i;
 
-    if (version_id != 2 && version_id != 3)
-        return -EINVAL;
     ret = pci_device_load(&d->dev, f);
     if (ret < 0)
         return ret;
@@ -319,10 +317,12 @@ static int pci_ide_load(QEMUFile* f, void *opaque, int version_id)
         qemu_get_8s(f, &bm->cmd);
         qemu_get_8s(f, &bm->status);
         qemu_get_be32s(f, &bm->addr);
-        qemu_get_sbe64s(f, &bm->sector_num);
-        qemu_get_be32s(f, &bm->nsector);
-        qemu_get_8s(f, &ifidx);
-        bm->unit = ifidx & 1;
+        if (version_id > 1) {
+            qemu_get_sbe64s(f, &bm->sector_num);
+            qemu_get_be32s(f, &bm->nsector);
+            qemu_get_8s(f, &ifidx);
+            bm->unit = ifidx & 1;
+        }
         /* XXX: if a transfer is pending, we do not save it yet */
     }
 

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function
  2009-09-11 15:34                     ` Anthony Liguori
  2009-09-11 15:55                       ` Juan Quintela
  2009-09-11 15:58                       ` Jan Kiszka
@ 2009-11-09 16:29                       ` Paul Brook
  2 siblings, 0 replies; 62+ messages in thread
From: Paul Brook @ 2009-11-09 16:29 UTC (permalink / raw)
  To: qemu-devel; +Cc: Juan Quintela

On Friday 11 September 2009, Anthony Liguori wrote:
> malc wrote:
> > And generalizations are always true. Anyhow, i'm explicitly against the
> > patch, so first obtain the express acknowledgment from the leaders,
> > otherwise i'll revert it should it go in.
> 
> I'm adding the following patch to Juan's series.  The result is that
> get_ticks_per_sec() should be optimized to a literal value.  The result
> being that uses of it are faster than they were before (not it should
> matter).

Having this as a function/variable is completely misleading. It is and always 
will be 1000000000. You'd be better off using QEMU_TIMER_BASE directly.

Paul

^ permalink raw reply	[flat|nested] 62+ messages in thread

end of thread, other threads:[~2009-11-09 16:29 UTC | newest]

Thread overview: 62+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-10  1:04 [Qemu-devel] [PATCH 00/26] VMState: port several pc devices to vmstate Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 01/26] ram: remove support for loading v1 Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 02/26] ram: Remove SaveVM Version 2 support Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 03/26] Remove SaveVM v2 support Juan Quintela
2009-09-10 17:41   ` Stefano Stabellini
2009-09-10 17:43     ` [Qemu-devel] " Juan Quintela
2009-09-10 18:15       ` Stefano Stabellini
2009-09-10 18:22         ` Anthony Liguori
2009-09-11 14:05           ` Stefano Stabellini
2009-09-11 14:28             ` Juan Quintela
2009-09-11 15:32               ` Stefano Stabellini
2009-09-11 15:37                 ` Anthony Liguori
2009-09-11 15:48                 ` Juan Quintela
2009-09-11 17:59                   ` Stefano Stabellini
2009-09-17 11:40                   ` Stefano Stabellini
2009-09-10  1:04 ` [Qemu-devel] [PATCH 04/26] timers: remove useless check Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function Juan Quintela
2009-09-10  1:20   ` malc
2009-09-10  1:57     ` [Qemu-devel] " Juan Quintela
2009-09-10  2:21       ` malc
2009-09-10 16:44         ` Juan Quintela
2009-09-10 17:02           ` malc
2009-09-10 17:38             ` Anthony Liguori
2009-09-10 21:31               ` malc
2009-09-10 22:08                 ` Anthony Liguori
2009-09-10 23:10                   ` malc
2009-09-10 23:33                     ` Juan Quintela
2009-09-11  5:49                     ` Amit Shah
2009-09-11 13:00                     ` Markus Armbruster
2009-09-11 15:34                     ` Anthony Liguori
2009-09-11 15:55                       ` Juan Quintela
2009-09-11 15:58                       ` Jan Kiszka
2009-11-09 16:29                       ` Paul Brook
2009-09-10 17:39             ` Juan Quintela
2009-09-10 22:16               ` Paolo Bonzini
2009-09-10 23:11                 ` malc
2009-09-11  9:04   ` Jan Kiszka
2009-09-11  9:31     ` Juan Quintela
2009-09-11  9:37       ` Jan Kiszka
2009-09-11 10:15         ` Juan Quintela
2009-09-11 10:26           ` Jan Kiszka
2009-09-10  1:04 ` [Qemu-devel] [PATCH 06/26] timers: Createt TimersState and put all timers state there Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 07/26] timers: move them to VMState Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 08/26] vmstate: add sensible arguments to vmstate_unregister() Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 09/26] vmstate: rename run_after_load() -> post_load() Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 10/26] vmstate: Add pre_load() hook Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 11/26] vmstate: Add pre/post_save() hooks Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 12/26] vmstate: port cpu_comon Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 13/26] vmstate: port fw_cfg device Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 14/26] vmstate: port i8259 device Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 15/26] vmstate: add support for uint8_t equal Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 16/26] vmstate: port fdc device Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 17/26] vmstate: add support for arrays of uint16_t Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 18/26] vmstate: port dma device Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 19/26] vmstate: port vmmouse device Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 20/26] vmstate: port pckbd device Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 21/26] vmstate: add uint64 array support Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 22/26] vmstate: port ioapic device Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 23/26] hpet: it is imposible that qemu_timer field is NULL at this point Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 24/26] vmstate: port hpet device Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 25/26] vmstate: port serial device Juan Quintela
2009-09-10  1:04 ` [Qemu-devel] [PATCH 26/26] vmstate: port cirrus_vga device Juan Quintela

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.