From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:44205) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Szryg-0001BB-7d for qemu-devel@nongnu.org; Fri, 10 Aug 2012 12:22:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Szryc-0006Ph-Ue for qemu-devel@nongnu.org; Fri, 10 Aug 2012 12:22:22 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:16140) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Szryc-0006PC-OL for qemu-devel@nongnu.org; Fri, 10 Aug 2012 12:22:18 -0400 Received: from eusync3.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0M8J00IYGS5UPO00@mailout2.w1.samsung.com> for qemu-devel@nongnu.org; Fri, 10 Aug 2012 17:22:42 +0100 (BST) Received: from [106.109.9.232] by eusync3.samsung.com (Oracle Communications Messaging Server 7u4-23.01(7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0M8J0049QS53EB10@eusync3.samsung.com> for qemu-devel@nongnu.org; Fri, 10 Aug 2012 17:22:16 +0100 (BST) Date: Fri, 10 Aug 2012 20:22:15 +0400 From: Igor Mitsyanko In-reply-to: <1344513263-22971-1-git-send-email-peter.maydell@linaro.org> Message-id: <50253537.1070003@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=windows-1252; format=flowed Content-transfer-encoding: QUOTED-PRINTABLE References: <1344513263-22971-1-git-send-email-peter.maydell@linaro.org> Subject: Re: [Qemu-devel] [PATCH] vmstate: Add support for saving/loading bitmaps List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Juan Quintela , qemu-devel@nongnu.org, patches@linaro.org 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 > --- > 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" > =20 > #define SELF_ANNOUNCE_ROUNDS 5 > =20 > @@ -1159,6 +1160,46 @@ const VMStateInfo vmstate_info_unused_buffer= =3D { > .put =3D put_unused_buffer, > }; > =20 > +/* bitmaps (as defined by bitmap.h). Note that size here is the si= ze > + * 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 form= at > + * is an array of 'unsigned long', which may be either 32 or 64 bi= ts. > + */ > +/* 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 =3D pv; > + int i, idx =3D 0; > + for (i =3D 0; i < BITS_TO_U64S(size); i++) { > + uint64_t w =3D qemu_get_be64(f); > + bmp[idx++] =3D w; > + if (sizeof(unsigned long) =3D=3D 4 && idx < BITS_TO_LONGS(= size)) { > + bmp[idx++] =3D w >> 32; > + } > + } > + return 0; > +} > + > +static void put_bitmap(QEMUFile *f, void *pv, size_t size) > +{ > + unsigned long *bmp =3D pv; > + int i, idx =3D 0; > + for (i =3D 0; i < BITS_TO_U64S(size); i++) { > + uint64_t w =3D bmp[idx++]; > + if (sizeof(unsigned long) =3D=3D 4 && idx < BITS_TO_LONGS(= size)) { > + w |=3D ((uint64_t)bmp[idx++]) << 32; > + } > + qemu_put_be64(f, w); > + } > +} > + > +const VMStateInfo vmstate_info_bitmap =3D { > + .name =3D "bitmap", > + .get =3D get_bitmap, > + .put =3D 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; > =20 > #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_b= uffer; > .flags =3D VMS_BUFFER, = \ > } > =20 > +/* _field_size should be a uint32_t field in the _state struct giv= ing the "..should be an int32_t.." > + * size of the bitmap _field in bits. > + */ > +#define VMSTATE_BITMAP(_field, _state, _version, _field_size) { = \ > + .name =3D (stringify(_field)), = \ > + .version_id =3D (_version), = \ > + .size_offset =3D vmstate_offset_value(_state, _field_size, in= t32_t),\ > + .info =3D &vmstate_info_bitmap, = \ > + .flags =3D VMS_VBUFFER|VMS_POINTER, = \ > + .offset =3D 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 64bi= t=20 little endian host and vice versa. Haven=92t tested with=20 bigendian-littleendian migration since I don't have a bigendian machi= ne=20 at my disposal. Tested-by: Igor Mitsyanko