* [Qemu-devel] [PATCH v2] util/hbitmap: Add an API to reset all set bits in hbitmap
@ 2015-05-22 1:29 Wen Congyang
2015-05-27 8:01 ` Wen Congyang
2015-06-19 11:54 ` Stefan Hajnoczi
0 siblings, 2 replies; 3+ messages in thread
From: Wen Congyang @ 2015-05-22 1:29 UTC (permalink / raw)
To: qemu-devl, Paolo Bonzini, John Snow; +Cc: Kevin Wolf, Gonglei, zhanghailiang
The function bdrv_clear_dirty_bitmap() is updated to use
faster hbitmap_reset_all() call.
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>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
---
block.c | 2 +-
include/qemu/hbitmap.h | 8 ++++++++
tests/test-hbitmap.c | 38 ++++++++++++++++++++++++++++++++++++++
util/hbitmap.c | 13 +++++++++++++
4 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/block.c b/block.c
index 7904098..49d472f 100644
--- a/block.c
+++ b/block.c
@@ -3309,7 +3309,7 @@ void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap,
void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap)
{
assert(bdrv_dirty_bitmap_enabled(bitmap));
- hbitmap_reset(bitmap->bitmap, 0, bitmap->size);
+ hbitmap_reset_all(bitmap->bitmap);
}
void bdrv_set_dirty(BlockDriverState *bs, int64_t cur_sector,
diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h
index f0a85f8..bb94a00 100644
--- a/include/qemu/hbitmap.h
+++ b/include/qemu/hbitmap.h
@@ -132,6 +132,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 9f41b5f..161eeb4 100644
--- a/tests/test-hbitmap.c
+++ b/tests/test-hbitmap.c
@@ -184,6 +184,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;
@@ -364,6 +381,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)
{
@@ -627,6 +664,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);
hbitmap_test_add("/hbitmap/truncate/nop", test_hbitmap_truncate_nop);
diff --git a/util/hbitmap.c b/util/hbitmap.c
index a10c7ae..50b888f 100644
--- a/util/hbitmap.c
+++ b/util/hbitmap.c
@@ -356,6 +356,19 @@ 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)
+{
+ unsigned int i;
+
+ /* Same as hbitmap_alloc() except for memset() instead of malloc() */
+ for (i = HBITMAP_LEVELS; --i >= 1; ) {
+ memset(hb->levels[i], 0, hb->sizes[i] * sizeof(unsigned long));
+ }
+
+ 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. */
--
2.1.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] util/hbitmap: Add an API to reset all set bits in hbitmap
2015-05-22 1:29 [Qemu-devel] [PATCH v2] util/hbitmap: Add an API to reset all set bits in hbitmap Wen Congyang
@ 2015-05-27 8:01 ` Wen Congyang
2015-06-19 11:54 ` Stefan Hajnoczi
1 sibling, 0 replies; 3+ messages in thread
From: Wen Congyang @ 2015-05-27 8:01 UTC (permalink / raw)
To: qemu-devl, Paolo Bonzini, John Snow; +Cc: Kevin Wolf, Gonglei, zhanghailiang
Hi, Paolo, Kevin
Who will take this patch?
Thanks
Wen Congyang
On 05/22/2015 09:29 AM, Wen Congyang wrote:
> The function bdrv_clear_dirty_bitmap() is updated to use
> faster hbitmap_reset_all() call.
>
> 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>
> Acked-by: Paolo Bonzini <pbonzini@redhat.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> Reviewed-by: John Snow <jsnow@redhat.com>
> ---
> block.c | 2 +-
> include/qemu/hbitmap.h | 8 ++++++++
> tests/test-hbitmap.c | 38 ++++++++++++++++++++++++++++++++++++++
> util/hbitmap.c | 13 +++++++++++++
> 4 files changed, 60 insertions(+), 1 deletion(-)
>
> diff --git a/block.c b/block.c
> index 7904098..49d472f 100644
> --- a/block.c
> +++ b/block.c
> @@ -3309,7 +3309,7 @@ void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap,
> void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap)
> {
> assert(bdrv_dirty_bitmap_enabled(bitmap));
> - hbitmap_reset(bitmap->bitmap, 0, bitmap->size);
> + hbitmap_reset_all(bitmap->bitmap);
> }
>
> void bdrv_set_dirty(BlockDriverState *bs, int64_t cur_sector,
> diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h
> index f0a85f8..bb94a00 100644
> --- a/include/qemu/hbitmap.h
> +++ b/include/qemu/hbitmap.h
> @@ -132,6 +132,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 9f41b5f..161eeb4 100644
> --- a/tests/test-hbitmap.c
> +++ b/tests/test-hbitmap.c
> @@ -184,6 +184,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;
> @@ -364,6 +381,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)
> {
> @@ -627,6 +664,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);
>
> hbitmap_test_add("/hbitmap/truncate/nop", test_hbitmap_truncate_nop);
> diff --git a/util/hbitmap.c b/util/hbitmap.c
> index a10c7ae..50b888f 100644
> --- a/util/hbitmap.c
> +++ b/util/hbitmap.c
> @@ -356,6 +356,19 @@ 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)
> +{
> + unsigned int i;
> +
> + /* Same as hbitmap_alloc() except for memset() instead of malloc() */
> + for (i = HBITMAP_LEVELS; --i >= 1; ) {
> + memset(hb->levels[i], 0, hb->sizes[i] * sizeof(unsigned long));
> + }
> +
> + 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. */
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] util/hbitmap: Add an API to reset all set bits in hbitmap
2015-05-22 1:29 [Qemu-devel] [PATCH v2] util/hbitmap: Add an API to reset all set bits in hbitmap Wen Congyang
2015-05-27 8:01 ` Wen Congyang
@ 2015-06-19 11:54 ` Stefan Hajnoczi
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2015-06-19 11:54 UTC (permalink / raw)
To: Wen Congyang
Cc: Kevin Wolf, zhanghailiang, qemu-devl, Gonglei, Paolo Bonzini,
John Snow
[-- Attachment #1: Type: text/plain, Size: 823 bytes --]
On Fri, May 22, 2015 at 09:29:46AM +0800, Wen Congyang wrote:
> The function bdrv_clear_dirty_bitmap() is updated to use
> faster hbitmap_reset_all() call.
>
> 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>
> Acked-by: Paolo Bonzini <pbonzini@redhat.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> Reviewed-by: John Snow <jsnow@redhat.com>
> ---
> block.c | 2 +-
> include/qemu/hbitmap.h | 8 ++++++++
> tests/test-hbitmap.c | 38 ++++++++++++++++++++++++++++++++++++++
> util/hbitmap.c | 13 +++++++++++++
> 4 files changed, 60 insertions(+), 1 deletion(-)
Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block
Stefan
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-06-19 11:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-22 1:29 [Qemu-devel] [PATCH v2] util/hbitmap: Add an API to reset all set bits in hbitmap Wen Congyang
2015-05-27 8:01 ` Wen Congyang
2015-06-19 11:54 ` Stefan Hajnoczi
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).