* [Qemu-devel] [PATCH] vmstate: Add support for saving/loading bitmaps
@ 2012-08-09 11:54 Peter Maydell
2012-08-10 16:22 ` Igor Mitsyanko
2012-08-13 11:12 ` Juan Quintela
0 siblings, 2 replies; 5+ messages in thread
From: Peter Maydell @ 2012-08-09 11:54 UTC (permalink / raw)
To: qemu-devel; +Cc: Juan Quintela, Igor Mitsyanko, patches
Add support for saving/loading bitmap.h bitmaps in vmstate.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
This will be needed for saving/restoring the bitmap in sd.c which
is introduced by Igor's latest patchset; the relevant VMSTATE line is:
VMSTATE_BITMAP(wp_groups, SDState, 1, wpgrps_size),
(and you'll need to make wpgrps_size an int32_t, not uint32_t).
Igor: I've only tested this fairly lightly, you'll probably want to
do things like testing save on 32 bit and load on 64 bit and
vice-versa.
savevm.c | 41 +++++++++++++++++++++++++++++++++++++++++
vmstate.h | 13 +++++++++++++
2 files changed, 54 insertions(+)
diff --git a/savevm.c b/savevm.c
index 6e82b2d..0e2de97 100644
--- a/savevm.c
+++ b/savevm.c
@@ -86,6 +86,7 @@
#include "memory.h"
#include "qmp-commands.h"
#include "trace.h"
+#include "bitops.h"
#define SELF_ANNOUNCE_ROUNDS 5
@@ -1159,6 +1160,46 @@ const VMStateInfo vmstate_info_unused_buffer = {
.put = put_unused_buffer,
};
+/* bitmaps (as defined by bitmap.h). Note that size here is the size
+ * of the bitmap in bits. The on-the-wire format of a bitmap is 64
+ * bit words with the bits in big endian order. The in-memory format
+ * is an array of 'unsigned long', which may be either 32 or 64 bits.
+ */
+/* This is the number of 64 bit words sent over the wire */
+#define BITS_TO_U64S(nr) DIV_ROUND_UP(nr, 64)
+static int get_bitmap(QEMUFile *f, void *pv, size_t size)
+{
+ unsigned long *bmp = pv;
+ int i, idx = 0;
+ for (i = 0; i < BITS_TO_U64S(size); i++) {
+ uint64_t w = qemu_get_be64(f);
+ bmp[idx++] = w;
+ if (sizeof(unsigned long) == 4 && idx < BITS_TO_LONGS(size)) {
+ bmp[idx++] = w >> 32;
+ }
+ }
+ return 0;
+}
+
+static void put_bitmap(QEMUFile *f, void *pv, size_t size)
+{
+ unsigned long *bmp = pv;
+ int i, idx = 0;
+ for (i = 0; i < BITS_TO_U64S(size); i++) {
+ uint64_t w = bmp[idx++];
+ if (sizeof(unsigned long) == 4 && idx < BITS_TO_LONGS(size)) {
+ w |= ((uint64_t)bmp[idx++]) << 32;
+ }
+ qemu_put_be64(f, w);
+ }
+}
+
+const VMStateInfo vmstate_info_bitmap = {
+ .name = "bitmap",
+ .get = get_bitmap,
+ .put = put_bitmap,
+};
+
typedef struct CompatEntry {
char idstr[256];
int instance_id;
diff --git a/vmstate.h b/vmstate.h
index 5bd2b76..c45f46e 100644
--- a/vmstate.h
+++ b/vmstate.h
@@ -139,6 +139,7 @@ extern const VMStateInfo vmstate_info_uint64;
extern const VMStateInfo vmstate_info_timer;
extern const VMStateInfo vmstate_info_buffer;
extern const VMStateInfo vmstate_info_unused_buffer;
+extern const VMStateInfo vmstate_info_bitmap;
#define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
#define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
@@ -411,6 +412,18 @@ extern const VMStateInfo vmstate_info_unused_buffer;
.flags = VMS_BUFFER, \
}
+/* _field_size should be a uint32_t field in the _state struct giving the
+ * size of the bitmap _field in bits.
+ */
+#define VMSTATE_BITMAP(_field, _state, _version, _field_size) { \
+ .name = (stringify(_field)), \
+ .version_id = (_version), \
+ .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\
+ .info = &vmstate_info_bitmap, \
+ .flags = VMS_VBUFFER|VMS_POINTER, \
+ .offset = offsetof(_state, _field), \
+}
+
/* _f : field name
_f_n : num of elements field_name
_n : num of elements
--
1.7.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] vmstate: Add support for saving/loading bitmaps
2012-08-09 11:54 [Qemu-devel] [PATCH] vmstate: Add support for saving/loading bitmaps Peter Maydell
@ 2012-08-10 16:22 ` Igor Mitsyanko
2012-08-10 16:30 ` Peter Maydell
2012-08-13 11:12 ` Juan Quintela
1 sibling, 1 reply; 5+ messages in thread
From: Igor Mitsyanko @ 2012-08-10 16:22 UTC (permalink / raw)
To: Peter Maydell; +Cc: Juan Quintela, qemu-devel, patches
On 08/09/2012 03:54 PM, Peter Maydell wrote:
> Add support for saving/loading bitmap.h bitmaps in vmstate.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> This will be needed for saving/restoring the bitmap in sd.c which
> is introduced by Igor's latest patchset; the relevant VMSTATE line is:
> VMSTATE_BITMAP(wp_groups, SDState, 1, wpgrps_size),
> (and you'll need to make wpgrps_size an int32_t, not uint32_t).
>
> Igor: I've only tested this fairly lightly, you'll probably want to
> do things like testing save on 32 bit and load on 64 bit and
> vice-versa.
>
> savevm.c | 41 +++++++++++++++++++++++++++++++++++++++++
> vmstate.h | 13 +++++++++++++
> 2 files changed, 54 insertions(+)
>
> diff --git a/savevm.c b/savevm.c
> index 6e82b2d..0e2de97 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -86,6 +86,7 @@
> #include "memory.h"
> #include "qmp-commands.h"
> #include "trace.h"
> +#include "bitops.h"
>
> #define SELF_ANNOUNCE_ROUNDS 5
>
> @@ -1159,6 +1160,46 @@ const VMStateInfo vmstate_info_unused_buffer = {
> .put = put_unused_buffer,
> };
>
> +/* bitmaps (as defined by bitmap.h). Note that size here is the size
> + * of the bitmap in bits. The on-the-wire format of a bitmap is 64
> + * bit words with the bits in big endian order. The in-memory format
> + * is an array of 'unsigned long', which may be either 32 or 64 bits.
> + */
> +/* This is the number of 64 bit words sent over the wire */
> +#define BITS_TO_U64S(nr) DIV_ROUND_UP(nr, 64)
> +static int get_bitmap(QEMUFile *f, void *pv, size_t size)
> +{
> + unsigned long *bmp = pv;
> + int i, idx = 0;
> + for (i = 0; i < BITS_TO_U64S(size); i++) {
> + uint64_t w = qemu_get_be64(f);
> + bmp[idx++] = w;
> + if (sizeof(unsigned long) == 4 && idx < BITS_TO_LONGS(size)) {
> + bmp[idx++] = w >> 32;
> + }
> + }
> + return 0;
> +}
> +
> +static void put_bitmap(QEMUFile *f, void *pv, size_t size)
> +{
> + unsigned long *bmp = pv;
> + int i, idx = 0;
> + for (i = 0; i < BITS_TO_U64S(size); i++) {
> + uint64_t w = bmp[idx++];
> + if (sizeof(unsigned long) == 4 && idx < BITS_TO_LONGS(size)) {
> + w |= ((uint64_t)bmp[idx++]) << 32;
> + }
> + qemu_put_be64(f, w);
> + }
> +}
> +
> +const VMStateInfo vmstate_info_bitmap = {
> + .name = "bitmap",
> + .get = get_bitmap,
> + .put = put_bitmap,
> +};
> +
> typedef struct CompatEntry {
> char idstr[256];
> int instance_id;
> diff --git a/vmstate.h b/vmstate.h
> index 5bd2b76..c45f46e 100644
> --- a/vmstate.h
> +++ b/vmstate.h
> @@ -139,6 +139,7 @@ extern const VMStateInfo vmstate_info_uint64;
> extern const VMStateInfo vmstate_info_timer;
> extern const VMStateInfo vmstate_info_buffer;
> extern const VMStateInfo vmstate_info_unused_buffer;
> +extern const VMStateInfo vmstate_info_bitmap;
>
> #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
> #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
> @@ -411,6 +412,18 @@ extern const VMStateInfo vmstate_info_unused_buffer;
> .flags = VMS_BUFFER, \
> }
>
> +/* _field_size should be a uint32_t field in the _state struct giving the
"..should be an int32_t.."
> + * size of the bitmap _field in bits.
> + */
> +#define VMSTATE_BITMAP(_field, _state, _version, _field_size) { \
> + .name = (stringify(_field)), \
> + .version_id = (_version), \
> + .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\
> + .info = &vmstate_info_bitmap, \
> + .flags = VMS_VBUFFER|VMS_POINTER, \
> + .offset = offsetof(_state, _field), \
> +}
> +
> /* _f : field name
> _f_n : num of elements field_name
> _n : num of elements
I've successfully tested this patch with migration from 32bit to 64bit
little endian host and vice versa. Haven’t tested with
bigendian-littleendian migration since I don't have a bigendian machine
at my disposal.
Tested-by: Igor Mitsyanko <i.mitsyanko@samsung.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] vmstate: Add support for saving/loading bitmaps
2012-08-10 16:22 ` Igor Mitsyanko
@ 2012-08-10 16:30 ` Peter Maydell
2012-08-10 16:35 ` Igor Mitsyanko
0 siblings, 1 reply; 5+ messages in thread
From: Peter Maydell @ 2012-08-10 16:30 UTC (permalink / raw)
To: Igor Mitsyanko; +Cc: Juan Quintela, qemu-devel, patches
On 10 August 2012 17:22, Igor Mitsyanko <i.mitsyanko@samsung.com> wrote:
> On 08/09/2012 03:54 PM, Peter Maydell wrote:
>> --- a/vmstate.h
>> +++ b/vmstate.h
>> @@ -139,6 +139,7 @@ extern const VMStateInfo vmstate_info_uint64;
>> extern const VMStateInfo vmstate_info_timer;
>> extern const VMStateInfo vmstate_info_buffer;
>> extern const VMStateInfo vmstate_info_unused_buffer;
>> +extern const VMStateInfo vmstate_info_bitmap;
>> #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
>> #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
>> @@ -411,6 +412,18 @@ extern const VMStateInfo vmstate_info_unused_buffer;
>> .flags = VMS_BUFFER, \
>> }
>> +/* _field_size should be a uint32_t field in the _state struct giving
>> the
>
>
> "..should be an int32_t.."
Er, yes. This patch should probably go in as part of your series
to add save/load to sd.c -- could you just fix this when you resend
the patch as part of that, please?
thanks
-- PMM
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] vmstate: Add support for saving/loading bitmaps
2012-08-10 16:30 ` Peter Maydell
@ 2012-08-10 16:35 ` Igor Mitsyanko
0 siblings, 0 replies; 5+ messages in thread
From: Igor Mitsyanko @ 2012-08-10 16:35 UTC (permalink / raw)
To: Peter Maydell; +Cc: Juan Quintela, qemu-devel, patches
On 08/10/2012 08:30 PM, Peter Maydell wrote:
> On 10 August 2012 17:22, Igor Mitsyanko <i.mitsyanko@samsung.com> wrote:
>> On 08/09/2012 03:54 PM, Peter Maydell wrote:
>>> --- a/vmstate.h
>>> +++ b/vmstate.h
>>> @@ -139,6 +139,7 @@ extern const VMStateInfo vmstate_info_uint64;
>>> extern const VMStateInfo vmstate_info_timer;
>>> extern const VMStateInfo vmstate_info_buffer;
>>> extern const VMStateInfo vmstate_info_unused_buffer;
>>> +extern const VMStateInfo vmstate_info_bitmap;
>>> #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
>>> #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
>>> @@ -411,6 +412,18 @@ extern const VMStateInfo vmstate_info_unused_buffer;
>>> .flags = VMS_BUFFER, \
>>> }
>>> +/* _field_size should be a uint32_t field in the _state struct giving
>>> the
>>
>> "..should be an int32_t.."
> Er, yes. This patch should probably go in as part of your series
> to add save/load to sd.c -- could you just fix this when you resend
> the patch as part of that, please?
>
> thanks
> -- PMM
>
sure
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] vmstate: Add support for saving/loading bitmaps
2012-08-09 11:54 [Qemu-devel] [PATCH] vmstate: Add support for saving/loading bitmaps Peter Maydell
2012-08-10 16:22 ` Igor Mitsyanko
@ 2012-08-13 11:12 ` Juan Quintela
1 sibling, 0 replies; 5+ messages in thread
From: Juan Quintela @ 2012-08-13 11:12 UTC (permalink / raw)
To: Peter Maydell; +Cc: Igor Mitsyanko, qemu-devel, patches
Peter Maydell <peter.maydell@linaro.org> wrote:
> Add support for saving/loading bitmap.h bitmaps in vmstate.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> This will be needed for saving/restoring the bitmap in sd.c which
> is introduced by Igor's latest patchset; the relevant VMSTATE line is:
> VMSTATE_BITMAP(wp_groups, SDState, 1, wpgrps_size),
> (and you'll need to make wpgrps_size an int32_t, not uint32_t).
>
> Igor: I've only tested this fairly lightly, you'll probably want to
> do things like testing save on 32 bit and load on 64 bit and
> vice-versa.
>
> savevm.c | 41 +++++++++++++++++++++++++++++++++++++++++
> vmstate.h | 13 +++++++++++++
> 2 files changed, 54 insertions(+)
Reviewed-by: Juan Quintela <quintela@redhat.com>
I haven't tested it, but Igor did, so O;-)
I can add it to my next pull request, or let it on Igor one that is the
one using it. Both ways work for me.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-08-13 11:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-09 11:54 [Qemu-devel] [PATCH] vmstate: Add support for saving/loading bitmaps Peter Maydell
2012-08-10 16:22 ` Igor Mitsyanko
2012-08-10 16:30 ` Peter Maydell
2012-08-10 16:35 ` Igor Mitsyanko
2012-08-13 11:12 ` Juan Quintela
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).