[{"id":1774812,"web_url":"http://patchwork.ozlabs.org/comment/1774812/","msgid":"<23eacf8d-8f80-f912-9b77-c955f8100a5f@virtuozzo.com>","list_archive_url":null,"date":"2017-09-25T15:38:44","subject":"Re: [Qemu-devel] [PATCH 11/18] hbitmap: Add @advance param to\n\thbitmap_iter_next()","submitter":{"id":66592,"url":"http://patchwork.ozlabs.org/api/people/66592/","name":"Vladimir Sementsov-Ogievskiy","email":"vsementsov@virtuozzo.com"},"content":"13.09.2017 21:19, Max Reitz wrote:\n> This new parameter allows the caller to just query the next dirty\n> position without moving the iterator.\n>\n> Signed-off-by: Max Reitz <mreitz@redhat.com>\n> ---\n>   include/qemu/hbitmap.h |  4 +++-\n>   block/dirty-bitmap.c   |  2 +-\n>   tests/test-hbitmap.c   | 26 +++++++++++++-------------\n>   util/hbitmap.c         | 10 +++++++---\n>   4 files changed, 24 insertions(+), 18 deletions(-)\n>\n> diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h\n> index d3a74a21fc..6a52575ad5 100644\n> --- a/include/qemu/hbitmap.h\n> +++ b/include/qemu/hbitmap.h\n> @@ -316,11 +316,13 @@ void hbitmap_free_meta(HBitmap *hb);\n>   /**\n>    * hbitmap_iter_next:\n>    * @hbi: HBitmapIter to operate on.\n> + * @advance: If true, advance the iterator.  Otherwise, the next call\n> + *           of this function will return the same result.\n\nit's not quit right, as hbitmap iterator allows concurrent resetting of \nbits, and in\nthis case next call may return some other result. (see f63ea4e92bad1db)\n\n>    *\n>    * Return the next bit that is set in @hbi's associated HBitmap,\n>    * or -1 if all remaining bits are zero.\n>    */\n> -int64_t hbitmap_iter_next(HBitmapIter *hbi);\n> +int64_t hbitmap_iter_next(HBitmapIter *hbi, bool advance);\n>   \n>   /**\n>    * hbitmap_iter_next_word:\n> diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c\n> index 30462d4f9a..aee57cf8c8 100644\n> --- a/block/dirty-bitmap.c\n> +++ b/block/dirty-bitmap.c\n> @@ -547,7 +547,7 @@ void bdrv_dirty_iter_free(BdrvDirtyBitmapIter *iter)\n>   \n>   int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter)\n>   {\n> -    return hbitmap_iter_next(&iter->hbi);\n> +    return hbitmap_iter_next(&iter->hbi, true);\n>   }\n>   \n>   /* Called within bdrv_dirty_bitmap_lock..unlock */\n> diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c\n> index 1acb353889..e6d4d563cb 100644\n> --- a/tests/test-hbitmap.c\n> +++ b/tests/test-hbitmap.c\n> @@ -46,7 +46,7 @@ static void hbitmap_test_check(TestHBitmapData *data,\n>   \n>       i = first;\n>       for (;;) {\n> -        next = hbitmap_iter_next(&hbi);\n> +        next = hbitmap_iter_next(&hbi, true);\n>           if (next < 0) {\n>               next = data->size;\n>           }\n> @@ -435,25 +435,25 @@ static void test_hbitmap_iter_granularity(TestHBitmapData *data,\n>       /* Note that hbitmap_test_check has to be invoked manually in this test.  */\n>       hbitmap_test_init(data, 131072 << 7, 7);\n>       hbitmap_iter_init(&hbi, data->hb, 0);\n> -    g_assert_cmpint(hbitmap_iter_next(&hbi), <, 0);\n> +    g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0);\n>   \n>       hbitmap_test_set(data, ((L2 + L1 + 1) << 7) + 8, 8);\n>       hbitmap_iter_init(&hbi, data->hb, 0);\n> -    g_assert_cmpint(hbitmap_iter_next(&hbi), ==, (L2 + L1 + 1) << 7);\n> -    g_assert_cmpint(hbitmap_iter_next(&hbi), <, 0);\n> +    g_assert_cmpint(hbitmap_iter_next(&hbi, true), ==, (L2 + L1 + 1) << 7);\n> +    g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0);\n>   \n>       hbitmap_iter_init(&hbi, data->hb, (L2 + L1 + 2) << 7);\n> -    g_assert_cmpint(hbitmap_iter_next(&hbi), <, 0);\n> +    g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0);\n>   \n>       hbitmap_test_set(data, (131072 << 7) - 8, 8);\n>       hbitmap_iter_init(&hbi, data->hb, 0);\n> -    g_assert_cmpint(hbitmap_iter_next(&hbi), ==, (L2 + L1 + 1) << 7);\n> -    g_assert_cmpint(hbitmap_iter_next(&hbi), ==, 131071 << 7);\n> -    g_assert_cmpint(hbitmap_iter_next(&hbi), <, 0);\n> +    g_assert_cmpint(hbitmap_iter_next(&hbi, true), ==, (L2 + L1 + 1) << 7);\n> +    g_assert_cmpint(hbitmap_iter_next(&hbi, true), ==, 131071 << 7);\n> +    g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0);\n>   \n>       hbitmap_iter_init(&hbi, data->hb, (L2 + L1 + 2) << 7);\n> -    g_assert_cmpint(hbitmap_iter_next(&hbi), ==, 131071 << 7);\n> -    g_assert_cmpint(hbitmap_iter_next(&hbi), <, 0);\n> +    g_assert_cmpint(hbitmap_iter_next(&hbi, true), ==, 131071 << 7);\n> +    g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0);\n>   }\n>   \n>   static void hbitmap_test_set_boundary_bits(TestHBitmapData *data, ssize_t diff)\n> @@ -893,7 +893,7 @@ static void test_hbitmap_serialize_zeroes(TestHBitmapData *data,\n>       for (i = 0; i < num_positions; i++) {\n>           hbitmap_deserialize_zeroes(data->hb, positions[i], min_l1, true);\n>           hbitmap_iter_init(&iter, data->hb, 0);\n> -        next = hbitmap_iter_next(&iter);\n> +        next = hbitmap_iter_next(&iter, true);\n>           if (i == num_positions - 1) {\n>               g_assert_cmpint(next, ==, -1);\n>           } else {\n> @@ -919,10 +919,10 @@ static void test_hbitmap_iter_and_reset(TestHBitmapData *data,\n>   \n>       hbitmap_iter_init(&hbi, data->hb, BITS_PER_LONG - 1);\n>   \n> -    hbitmap_iter_next(&hbi);\n> +    hbitmap_iter_next(&hbi, true);\n>   \n>       hbitmap_reset_all(data->hb);\n> -    hbitmap_iter_next(&hbi);\n> +    hbitmap_iter_next(&hbi, true);\n>   }\n>   \n>   int main(int argc, char **argv)\n> diff --git a/util/hbitmap.c b/util/hbitmap.c\n> index 21535cc90b..96525983ce 100644\n> --- a/util/hbitmap.c\n> +++ b/util/hbitmap.c\n> @@ -141,7 +141,7 @@ unsigned long hbitmap_iter_skip_words(HBitmapIter *hbi)\n>       return cur;\n>   }\n>   \n> -int64_t hbitmap_iter_next(HBitmapIter *hbi)\n> +int64_t hbitmap_iter_next(HBitmapIter *hbi, bool advance)\n>   {\n>       unsigned long cur = hbi->cur[HBITMAP_LEVELS - 1] &\n>               hbi->hb->levels[HBITMAP_LEVELS - 1][hbi->pos];\n> @@ -154,8 +154,12 @@ int64_t hbitmap_iter_next(HBitmapIter *hbi)\n>           }\n>       }\n>   \n> -    /* The next call will resume work from the next bit.  */\n> -    hbi->cur[HBITMAP_LEVELS - 1] = cur & (cur - 1);\n> +    if (advance) {\n> +        /* The next call will resume work from the next bit.  */\n> +        hbi->cur[HBITMAP_LEVELS - 1] = cur & (cur - 1);\n> +    } else {\n> +        hbi->cur[HBITMAP_LEVELS - 1] = cur;\n> +    }\n>       item = ((uint64_t)hbi->pos << BITS_PER_LEVEL) + ctzl(cur);\n>   \n>       return item << hbi->granularity;","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3y17YZ6lx9z9s7c\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 26 Sep 2017 01:39:30 +1000 (AEST)","from localhost ([::1]:43092 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dwVTl-0004oT-2l\n\tfor incoming@patchwork.ozlabs.org; Mon, 25 Sep 2017 11:39:29 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:41405)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <vsementsov@virtuozzo.com>) id 1dwVTC-0004mV-IV\n\tfor qemu-devel@nongnu.org; Mon, 25 Sep 2017 11:38:55 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <vsementsov@virtuozzo.com>) id 1dwVTB-0005aA-6z\n\tfor qemu-devel@nongnu.org; Mon, 25 Sep 2017 11:38:54 -0400","from mailhub.sw.ru ([195.214.232.25]:17512 helo=relay.sw.ru)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <vsementsov@virtuozzo.com>)\n\tid 1dwVTA-0005ZQ-Qi\n\tfor qemu-devel@nongnu.org; Mon, 25 Sep 2017 11:38:53 -0400","from [172.16.24.243] (msk-vpn.virtuozzo.com [195.214.232.6])\n\tby relay.sw.ru (8.13.4/8.13.4) with ESMTP id v8PFcisp027303;\n\tMon, 25 Sep 2017 18:38:44 +0300 (MSK)"],"To":"Max Reitz <mreitz@redhat.com>, qemu-block@nongnu.org","References":"<20170913181910.29688-1-mreitz@redhat.com>\n\t<20170913181910.29688-12-mreitz@redhat.com>","From":"Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>","Message-ID":"<23eacf8d-8f80-f912-9b77-c955f8100a5f@virtuozzo.com>","Date":"Mon, 25 Sep 2017 18:38:44 +0300","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<20170913181910.29688-12-mreitz@redhat.com>","Content-Type":"text/plain; charset=utf-8; format=flowed","Content-Transfer-Encoding":"7bit","Content-Language":"en-US","X-detected-operating-system":"by eggs.gnu.org: OpenBSD 3.x [fuzzy]","X-Received-From":"195.214.232.25","Subject":"Re: [Qemu-devel] [PATCH 11/18] hbitmap: Add @advance param to\n\thbitmap_iter_next()","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Kevin Wolf <kwolf@redhat.com>, John Snow <jsnow@redhat.com>,\n\tFam Zheng <famz@redhat.com>, qemu-devel@nongnu.org,\n\tStefan Hajnoczi <stefanha@redhat.com>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1774966,"web_url":"http://patchwork.ozlabs.org/comment/1774966/","msgid":"<37272a30-5dd5-f5a4-8137-b4e87e8571d7@redhat.com>","list_archive_url":null,"date":"2017-09-25T20:40:03","subject":"Re: [Qemu-devel] [PATCH 11/18] hbitmap: Add @advance param to\n\thbitmap_iter_next()","submitter":{"id":36836,"url":"http://patchwork.ozlabs.org/api/people/36836/","name":"Max Reitz","email":"mreitz@redhat.com"},"content":"On 2017-09-25 17:38, Vladimir Sementsov-Ogievskiy wrote:\n> 13.09.2017 21:19, Max Reitz wrote:\n>> This new parameter allows the caller to just query the next dirty\n>> position without moving the iterator.\n>>\n>> Signed-off-by: Max Reitz <mreitz@redhat.com>\n>> ---\n>>   include/qemu/hbitmap.h |  4 +++-\n>>   block/dirty-bitmap.c   |  2 +-\n>>   tests/test-hbitmap.c   | 26 +++++++++++++-------------\n>>   util/hbitmap.c         | 10 +++++++---\n>>   4 files changed, 24 insertions(+), 18 deletions(-)\n>>\n>> diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h\n>> index d3a74a21fc..6a52575ad5 100644\n>> --- a/include/qemu/hbitmap.h\n>> +++ b/include/qemu/hbitmap.h\n>> @@ -316,11 +316,13 @@ void hbitmap_free_meta(HBitmap *hb);\n>>   /**\n>>    * hbitmap_iter_next:\n>>    * @hbi: HBitmapIter to operate on.\n>> + * @advance: If true, advance the iterator.  Otherwise, the next call\n>> + *           of this function will return the same result.\n> \n> it's not quit right, as hbitmap iterator allows concurrent resetting of\n> bits, and in\n> this case next call may return some other result. (see f63ea4e92bad1db)\n\nAh, right!  I think it should still be useful for what I (currently)\nneed in patch 12, I would just need a different description then.\n\n(Like \"...will return the same result (if that position is still dirty).\")\n\nMax","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx09.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx09.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=mreitz@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3y1GFN2PkBz9t2Q\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 26 Sep 2017 06:40:52 +1000 (AEST)","from localhost ([::1]:44203 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dwaBL-0004iT-SR\n\tfor incoming@patchwork.ozlabs.org; Mon, 25 Sep 2017 16:40:47 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:60338)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <mreitz@redhat.com>) id 1dwaAz-0004fl-HV\n\tfor qemu-devel@nongnu.org; Mon, 25 Sep 2017 16:40:26 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <mreitz@redhat.com>) id 1dwaAy-00076a-Pc\n\tfor qemu-devel@nongnu.org; Mon, 25 Sep 2017 16:40:25 -0400","from mx1.redhat.com ([209.132.183.28]:37274)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <mreitz@redhat.com>)\n\tid 1dwaAs-000754-CV; Mon, 25 Sep 2017 16:40:18 -0400","from smtp.corp.redhat.com\n\t(int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id AD991CD18D;\n\tMon, 25 Sep 2017 20:40:14 +0000 (UTC)","from dresden.str.redhat.com (ovpn-204-55.brq.redhat.com\n\t[10.40.204.55])\n\tby smtp.corp.redhat.com (Postfix) with ESMTPS id 3EC497838A;\n\tMon, 25 Sep 2017 20:40:05 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com AD991CD18D","To":"Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,\n\tqemu-block@nongnu.org","References":"<20170913181910.29688-1-mreitz@redhat.com>\n\t<20170913181910.29688-12-mreitz@redhat.com>\n\t<23eacf8d-8f80-f912-9b77-c955f8100a5f@virtuozzo.com>","From":"Max Reitz <mreitz@redhat.com>","Message-ID":"<37272a30-5dd5-f5a4-8137-b4e87e8571d7@redhat.com>","Date":"Mon, 25 Sep 2017 22:40:03 +0200","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<23eacf8d-8f80-f912-9b77-c955f8100a5f@virtuozzo.com>","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\";\n\tboundary=\"Brs0J46Fjlj2mSPNH8ECJH9W0KJCQanBf\"","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.13","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.38]);\n\tMon, 25 Sep 2017 20:40:15 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","X-Content-Filtered-By":"Mailman/MimeDel 2.1.21","Subject":"Re: [Qemu-devel] [PATCH 11/18] hbitmap: Add @advance param to\n\thbitmap_iter_next()","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Kevin Wolf <kwolf@redhat.com>, John Snow <jsnow@redhat.com>,\n\tFam Zheng <famz@redhat.com>, qemu-devel@nongnu.org,\n\tStefan Hajnoczi <stefanha@redhat.com>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}}]