From: Paolo Bonzini <pbonzini@redhat.com>
To: Wen Congyang <wency@cn.fujitsu.com>,
qemu devel <qemu-devel@nongnu.org>, Fam Zheng <famz@redhat.com>,
Max Reitz <mreitz@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
Lai Jiangshan <laijs@cn.fujitsu.com>,
qemu block <qemu-block@nongnu.org>,
Jiang Yunhong <yunhong.jiang@intel.com>,
Dong Eddie <eddie.dong@intel.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
Gonglei <arei.gonglei@huawei.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Yang Hongyang <yanghy@cn.fujitsu.com>,
zhanghailiang <zhang.zhanghailiang@huawei.com>
Subject: Re: [Qemu-devel] [PATCH COLO v3 10/14] util/hbitmap: Add an API to reset all set bits in hbitmap
Date: Fri, 03 Apr 2015 13:05:20 +0200 [thread overview]
Message-ID: <551E73F0.5060704@redhat.com> (raw)
In-Reply-To: <1428055280-12015-11-git-send-email-wency@cn.fujitsu.com>
On 03/04/2015 12:01, Wen Congyang wrote:
> Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
> include/qemu/hbitmap.h | 8 ++++++++
> tests/test-hbitmap.c | 39 +++++++++++++++++++++++++++++++++++++++
> util/hbitmap.c | 16 ++++++++++++++++
> 3 files changed, 63 insertions(+)
>
> diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h
> index 550d7ce..95a55e4 100644
> --- a/include/qemu/hbitmap.h
> +++ b/include/qemu/hbitmap.h
> @@ -109,6 +109,14 @@ void hbitmap_set(HBitmap *hb, uint64_t start, uint64_t count);
> void hbitmap_reset(HBitmap *hb, uint64_t start, uint64_t count);
>
> /**
> + * hbitmap_reset_all:
> + * @hb: HBitmap to operate on.
> + *
> + * Reset all bits in an HBitmap.
> + */
> +void hbitmap_reset_all(HBitmap *hb);
> +
> +/**
> * hbitmap_get:
> * @hb: HBitmap to operate on.
> * @item: Bit to query (0-based).
> diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c
> index 8c902f2..1f0078a 100644
> --- a/tests/test-hbitmap.c
> +++ b/tests/test-hbitmap.c
> @@ -11,6 +11,7 @@
>
> #include <glib.h>
> #include <stdarg.h>
> +#include <string.h>
> #include "qemu/hbitmap.h"
>
> #define LOG_BITS_PER_LONG (BITS_PER_LONG == 32 ? 5 : 6)
> @@ -143,6 +144,23 @@ static void hbitmap_test_reset(TestHBitmapData *data,
> }
> }
>
> +static void hbitmap_test_reset_all(TestHBitmapData *data)
> +{
> + size_t n;
> +
> + hbitmap_reset_all(data->hb);
> +
> + n = (data->size + BITS_PER_LONG - 1) / BITS_PER_LONG;
> + if (n == 0) {
> + n = 1;
> + }
> + memset(data->bits, 0, n * sizeof(unsigned long));
> +
> + if (data->granularity == 0) {
> + hbitmap_test_check(data, 0);
> + }
> +}
> +
> static void hbitmap_test_check_get(TestHBitmapData *data)
> {
> uint64_t count = 0;
> @@ -323,6 +341,26 @@ static void test_hbitmap_reset(TestHBitmapData *data,
> hbitmap_test_set(data, L3 / 2, L3);
> }
>
> +static void test_hbitmap_reset_all(TestHBitmapData *data,
> + const void *unused)
> +{
> + hbitmap_test_init(data, L3 * 2, 0);
> + hbitmap_test_set(data, L1 - 1, L1 + 2);
> + hbitmap_test_reset_all(data);
> + hbitmap_test_set(data, 0, L1 * 3);
> + hbitmap_test_reset_all(data);
> + hbitmap_test_set(data, L2, L1);
> + hbitmap_test_reset_all(data);
> + hbitmap_test_set(data, L2, L3 - L2 + 1);
> + hbitmap_test_reset_all(data);
> + hbitmap_test_set(data, L3 - 1, 3);
> + hbitmap_test_reset_all(data);
> + hbitmap_test_set(data, 0, L3 * 2);
> + hbitmap_test_reset_all(data);
> + hbitmap_test_set(data, L3 / 2, L3);
> + hbitmap_test_reset_all(data);
> +}
> +
> static void test_hbitmap_granularity(TestHBitmapData *data,
> const void *unused)
> {
> @@ -394,6 +432,7 @@ int main(int argc, char **argv)
> hbitmap_test_add("/hbitmap/set/overlap", test_hbitmap_set_overlap);
> hbitmap_test_add("/hbitmap/reset/empty", test_hbitmap_reset_empty);
> hbitmap_test_add("/hbitmap/reset/general", test_hbitmap_reset);
> + hbitmap_test_add("/hbitmap/reset/all", test_hbitmap_reset_all);
> hbitmap_test_add("/hbitmap/granularity", test_hbitmap_granularity);
> g_test_run();
>
> diff --git a/util/hbitmap.c b/util/hbitmap.c
> index ab13971..acce93c 100644
> --- a/util/hbitmap.c
> +++ b/util/hbitmap.c
> @@ -353,6 +353,22 @@ void hbitmap_reset(HBitmap *hb, uint64_t start, uint64_t count)
> hb_reset_between(hb, HBITMAP_LEVELS - 1, start, last);
> }
>
> +void hbitmap_reset_all(HBitmap *hb)
> +{
> + uint64_t size = hb->size;
> + unsigned int i;
> +
> + /* Same as hbitmap_alloc() except memset() */
> + for (i = HBITMAP_LEVELS; --i >= 1; ) {
> + size = MAX((size + BITS_PER_LONG - 1) >> BITS_PER_LEVEL, 1);
> + memset(hb->levels[i], 0, size * sizeof(unsigned long));
> + }
> +
> + assert(size == 1);
> + hb->levels[0][0] = 1UL << (BITS_PER_LONG - 1);
> + hb->count = 0;
> +}
> +
> bool hbitmap_get(const HBitmap *hb, uint64_t item)
> {
> /* Compute position and bit in the last layer. */
>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
next prev parent reply other threads:[~2015-04-03 11:05 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-03 10:01 [Qemu-devel] [PATCH COLO v3 00/14] Block replication for continuous checkpoints Wen Congyang
2015-04-03 10:01 ` [Qemu-devel] [PATCH COLO v3 01/14] docs: block replication's description Wen Congyang
2015-04-20 15:30 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-04-21 1:25 ` Wen Congyang
2015-04-21 15:28 ` Paolo Bonzini
2015-04-22 9:18 ` Stefan Hajnoczi
2015-04-22 9:28 ` Wen Congyang
2015-04-23 9:55 ` Stefan Hajnoczi
2015-04-23 10:11 ` Wen Congyang
2015-04-22 9:31 ` Kevin Wolf
2015-04-22 10:12 ` [Qemu-devel] " Paolo Bonzini
2015-04-23 9:00 ` Kevin Wolf
2015-04-23 9:14 ` Wen Congyang
2015-04-23 10:05 ` Paolo Bonzini
2015-04-23 10:17 ` Kevin Wolf
2015-04-23 10:33 ` Paolo Bonzini
2015-04-23 10:40 ` Kevin Wolf
2015-04-23 10:44 ` Paolo Bonzini
2015-04-23 11:35 ` Wen Congyang
2015-04-23 11:36 ` Kevin Wolf
2015-04-23 11:53 ` Paolo Bonzini
2015-04-23 12:05 ` Dr. David Alan Gilbert
2015-04-23 12:11 ` Paolo Bonzini
2015-04-23 12:19 ` Dr. David Alan Gilbert
2015-04-23 12:23 ` Paolo Bonzini
2015-04-24 2:01 ` Fam Zheng
2015-04-24 2:16 ` Wen Congyang
2015-04-24 7:47 ` Paolo Bonzini
2015-04-24 7:55 ` Wen Congyang
2015-04-24 8:58 ` Dr. David Alan Gilbert
2015-04-24 9:04 ` Paolo Bonzini
2015-04-24 9:38 ` Wen Congyang
2015-04-24 9:36 ` Paolo Bonzini
2015-04-24 9:53 ` Wen Congyang
2015-04-24 10:03 ` Paolo Bonzini
2015-04-27 9:37 ` Stefan Hajnoczi
2015-04-29 8:29 ` Paolo Bonzini
2015-04-29 8:37 ` Gonglei
2015-04-30 14:56 ` Stefan Hajnoczi
2015-05-05 15:23 ` Dr. David Alan Gilbert
2015-05-06 2:26 ` Dong, Eddie
2015-05-06 2:49 ` Fam Zheng
2015-05-08 8:42 ` Stefan Hajnoczi
2015-05-08 9:34 ` Dr. David Alan Gilbert
2015-05-08 9:39 ` Kevin Wolf
2015-05-08 9:55 ` Dr. David Alan Gilbert
2015-04-23 9:26 ` Paolo Bonzini
2015-04-23 9:37 ` Kevin Wolf
2015-04-23 9:41 ` Wen Congyang
2015-04-22 9:29 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-04-22 9:42 ` Wen Congyang
2015-04-22 10:39 ` [Qemu-devel] " Dr. David Alan Gilbert
2015-04-03 10:01 ` [Qemu-devel] [PATCH COLO v3 02/14] quorum: allow ignoring child errors Wen Congyang
2015-04-03 10:01 ` [Qemu-devel] [PATCH COLO v3 03/14] NBD client: connect to nbd server later Wen Congyang
2015-04-03 10:01 ` [Qemu-devel] [PATCH COLO v3 04/14] Add new block driver interfaces to control block replication Wen Congyang
2015-04-22 12:56 ` Eric Blake
2015-04-03 10:01 ` [Qemu-devel] [PATCH COLO v3 05/14] quorum: implement block driver interfaces for " Wen Congyang
2015-04-03 10:01 ` [Qemu-devel] [PATCH COLO v3 06/14] NBD client: " Wen Congyang
2015-04-03 10:01 ` [Qemu-devel] [PATCH COLO v3 07/14] allow writing to the backing file Wen Congyang
2015-04-03 10:01 ` [Qemu-devel] [PATCH COLO v3 08/14] Allow creating backup jobs when opening BDS Wen Congyang
2015-04-03 11:06 ` Paolo Bonzini
2015-04-03 10:01 ` [Qemu-devel] [PATCH COLO v3 09/14] block: Parse "backing_reference" option to reference existing BDS Wen Congyang
2015-04-03 10:01 ` [Qemu-devel] [PATCH COLO v3 10/14] util/hbitmap: Add an API to reset all set bits in hbitmap Wen Congyang
2015-04-03 11:05 ` Paolo Bonzini [this message]
2015-05-01 16:47 ` [Qemu-devel] [Qemu-block] " John Snow
2015-05-07 2:20 ` Wen Congyang
2015-05-07 18:32 ` John Snow
2015-05-08 0:59 ` Wen Congyang
2015-04-03 10:01 ` [Qemu-devel] [PATCH COLO v3 11/14] Backup: clear all bitmap when doing block checkpoint Wen Congyang
2015-04-03 11:09 ` Paolo Bonzini
2015-04-07 1:45 ` Wen Congyang
2015-04-03 10:01 ` [Qemu-devel] [PATCH COLO v3 12/14] qcow2: support colo Wen Congyang
2015-04-03 10:01 ` [Qemu-devel] [PATCH COLO v3 13/14] skip nbd_target when starting block replication Wen Congyang
2015-04-03 10:01 ` [Qemu-devel] [PATCH COLO v3 14/14] Don't allow a disk use backing reference target Wen Congyang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=551E73F0.5060704@redhat.com \
--to=pbonzini@redhat.com \
--cc=arei.gonglei@huawei.com \
--cc=dgilbert@redhat.com \
--cc=eddie.dong@intel.com \
--cc=famz@redhat.com \
--cc=kwolf@redhat.com \
--cc=laijs@cn.fujitsu.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=wency@cn.fujitsu.com \
--cc=yanghy@cn.fujitsu.com \
--cc=yunhong.jiang@intel.com \
--cc=zhang.zhanghailiang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).