From patchwork Thu Aug 9 11:54:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 10618 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 0181823E56 for ; Thu, 9 Aug 2012 11:54:30 +0000 (UTC) Received: from mail-yx0-f180.google.com (mail-yx0-f180.google.com [209.85.213.180]) by fiordland.canonical.com (Postfix) with ESMTP id 9D112A189C8 for ; Thu, 9 Aug 2012 11:54:30 +0000 (UTC) Received: by yenq6 with SMTP id q6so309387yen.11 for ; Thu, 09 Aug 2012 04:54:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:x-gm-message-state; bh=3BgWh+VjbpuIA1mj0vfneqCuBDIuXbiS20jnubQUjN8=; b=NymQqebFYOhOmfiBVX7L2I0IWoAyuHQNqQeAcXwh71NVLwut2J93HrMw30q/nSfqkT MRfP/AW/5BqoiqtdzFAbapSz1k7BueMnDTzm0Yvzs4IRH3E7l7ZGkMqe9ouyunZQWy8J JlcLy0Ntzq+pX7P9N4+WFzA6xmfFWaFjb8H1JyRPEyKFA3qKJyThUkfU3pSx8yu9/4GR 8Lvo+nF/EQ2aAYemm8Hd4tuceoHYoehuT5O8UNAAcp1VS4HygJId3cVlvDCr4Zkiw7Jf jSxKr9ZQdu6+IeLI7b7TpF4BrL0+b7NGYHDipgc97wAPsB1xnQNNiFI+q5nzeqST7G8a /Nyg== Received: by 10.50.159.135 with SMTP id xc7mr738887igb.9.1344513269633; Thu, 09 Aug 2012 04:54:29 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.200 with SMTP id ew8csp4718igc; Thu, 9 Aug 2012 04:54:28 -0700 (PDT) Received: by 10.14.194.198 with SMTP id m46mr26985511een.13.1344513268309; Thu, 09 Aug 2012 04:54:28 -0700 (PDT) Received: from mnementh.archaic.org.uk (1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id f45si465377eep.57.2012.08.09.04.54.27 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 09 Aug 2012 04:54:28 -0700 (PDT) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Authentication-Results: mx.google.com; spf=neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1SzRJn-0005yy-PN; Thu, 09 Aug 2012 12:54:23 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Igor Mitsyanko , Juan Quintela Subject: [PATCH] vmstate: Add support for saving/loading bitmaps Date: Thu, 9 Aug 2012 12:54:23 +0100 Message-Id: <1344513263-22971-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 X-Gm-Message-State: ALoCoQmvu9jJRscd/TswUY/YS9lS+Fec4QQ05wGinshW0MyJxCPtTeH0lXd2DEDbiPo0ExVkEcLH Add support for saving/loading bitmap.h bitmaps in vmstate. Signed-off-by: Peter Maydell Tested-by: Igor Mitsyanko Reviewed-by: Juan Quintela --- 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