From patchwork Sun Oct 28 14:59:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mitsyanko X-Patchwork-Id: 194705 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3C3962C0086 for ; Mon, 29 Oct 2012 02:00:47 +1100 (EST) Received: from localhost ([::1]:41134 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TSUM1-0001de-Dt for incoming@patchwork.ozlabs.org; Sun, 28 Oct 2012 11:00:45 -0400 Received: from eggs.gnu.org ([208.118.235.92]:59316) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TSULg-0000uH-Oh for qemu-devel@nongnu.org; Sun, 28 Oct 2012 11:00:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TSULa-0004IS-T0 for qemu-devel@nongnu.org; Sun, 28 Oct 2012 11:00:22 -0400 Received: from mail-lb0-f173.google.com ([209.85.217.173]:44921) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TSULa-00043O-6C for qemu-devel@nongnu.org; Sun, 28 Oct 2012 11:00:18 -0400 Received: by mail-lb0-f173.google.com with SMTP id gj3so2485050lbb.4 for ; Sun, 28 Oct 2012 08:00:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=fcwp7K7jVXcaDWE+k9QJZ39DfYC2GV6QQiP4aakiD7g=; b=THF+AFp+vHNkGa4TOK9EWtYQJqWb4MMbn0VUIybKKYu8Haz4fCEiL2bXEoq+biqCwv SoZGVrlj/hCthnFRrxJRrMLQsO7ZM+e92Nmy7ORN3NMpE8PDCgAiKcMKC0frXWT89MNQ 9y7epbjqytZNmmze9+NwHIPekLpOr8GZOwa/LEeobMw+ELgp8Vul3/3ASIwncrsJ3MfN 3LUDl1FEpwDzppNhgJyyqdJK7dm7cgmZeuaEVQ96vM05Cke0l6bTx+WesnXJ/q8+k57u 3CzEV9YTUh3LOm8WHSNJ5bNXWcbNq9s+jmgX9ZyM9t7NtJYxyRbYWraCHhVaFjPvbHR/ v7cQ== Received: by 10.112.103.38 with SMTP id ft6mr894247lbb.54.1351436402871; Sun, 28 Oct 2012 08:00:02 -0700 (PDT) Received: from localhost ([77.41.56.77]) by mx.google.com with ESMTPS id nr2sm2164615lab.5.2012.10.28.08.00.01 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 28 Oct 2012 08:00:02 -0700 (PDT) From: Igor Mitsyanko To: qemu-devel@nongnu.org Date: Sun, 28 Oct 2012 18:59:47 +0400 Message-Id: <1351436388-3636-3-git-send-email-i.mitsyanko@samsung.com> X-Mailer: git-send-email 1.8.0.msysgit.0 In-Reply-To: <1351436388-3636-1-git-send-email-i.mitsyanko@samsung.com> References: <1351436388-3636-1-git-send-email-i.mitsyanko@samsung.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.217.173 Cc: kwolf@redhat.com, peter.maydell@linaro.org, benoit.canet@gmail.com, wdongxu@linux.vnet.ibm.com, stefanha@linux.vnet.ibm.com, e.voevodin@samsung.com, armbru@redhat.com, andrew.zaborowski@intel.com, kyungmin.park@samsung.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH V5 2/3] vmstate: Add support for saving/loading bitmaps X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Peter Maydell Add support for saving/loading bitmap.h bitmaps in vmstate. Signed-off-by: Peter Maydell Tested-by: Igor Mitsyanko Reviewed-by: Juan Quintela --- savevm.c | 41 +++++++++++++++++++++++++++++++++++++++++ vmstate.h | 13 +++++++++++++ 2 files changed, 54 insertions(+) diff --git a/savevm.c b/savevm.c index b080d37..43d3d1b 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 @@ -1132,6 +1133,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 c9c320e..623af0a 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 int32_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