From: Yury Norov <yury.norov@gmail.com>
To: Yi Sun <yi.sun@unisoc.com>
Cc: yury.norov@gmail.com, 279644543@qq.com, mina86@mina86.com,
mnazarewicz@gmail.com, akpm@linux-foundation.org,
akinobu.mita@gmail.com, linux-kernel@vger.kernel.org,
tjmercier@google.com, qiang.zhao@freescale.com,
scottwood@freescale.com, fvdl@google.com, tglx@kernel.org,
song@kernel.org, hch@lst.de, minchan@kernel.org,
jstultz@google.com
Subject: Re: [PATCH v6 1/2] lib: bitmap: add tests for bitmap_find_next_zero_area_off()
Date: Thu, 18 Jun 2026 13:31:13 -0400 [thread overview]
Message-ID: <ajQrYZomFpVmcw3v@yury> (raw)
In-Reply-To: <20260618133518.4079981-2-yi.sun@unisoc.com>
On Thu, Jun 18, 2026 at 09:35:17PM +0800, Yi Sun wrote:
> Add functional and performance tests
> for bitmap_find_next_zero_area_off().
>
> performance tests partial output:
> Start testing find_bit() with random-filled bitmap
> [ 0.310073] bitmap_find_next_zero_area_off: 852731 ns, 1154 iterations
> [ 0.311435] find_next_bit: 1356654 ns, 163975 iterations
> Start testing find_bit() with sparse bitmap
> [ 0.316267] bitmap_find_next_zero_area_off: 4426808 ns, 322479 iterations
> [ 0.316292] find_next_bit: 15154 ns, 656 iterations
>
> Signed-off-by: Yi Sun <yi.sun@unisoc.com>
> ---
> lib/find_bit_benchmark.c | 31 ++++++++++++++++++++++++-------
> lib/test_bitmap.c | 38 ++++++++++++++++++++++++++++++++++++++
> 2 files changed, 62 insertions(+), 7 deletions(-)
>
> diff --git a/lib/find_bit_benchmark.c b/lib/find_bit_benchmark.c
> index 00d9dc61cd46..cde7c09de05c 100644
> --- a/lib/find_bit_benchmark.c
> +++ b/lib/find_bit_benchmark.c
> @@ -46,7 +46,7 @@ static int __init test_find_first_bit(const void *bitmap, unsigned long len)
> __clear_bit(i, cp);
> }
> time = ktime_get() - time;
> - pr_err("find_first_bit: %18llu ns, %6ld iterations\n", time, cnt);
> + pr_err("find_first_bit: %14llu ns, %6ld iterations\n", time, cnt);
No need to change the existing code. Just add your test and make sure
it looks aligned with the existing format.
>
> return 0;
> }
> @@ -66,7 +66,7 @@ static int __init test_find_first_and_bit(const void *bitmap, const void *bitmap
> __clear_bit(i, cp);
> }
> time = ktime_get() - time;
> - pr_err("find_first_and_bit: %18llu ns, %6ld iterations\n", time, cnt);
> + pr_err("find_first_and_bit: %14llu ns, %6ld iterations\n", time, cnt);
>
> return 0;
> }
> @@ -80,7 +80,7 @@ static int __init test_find_next_bit(const void *bitmap, unsigned long len)
> for (cnt = i = 0; i < BITMAP_LEN; cnt++)
> i = find_next_bit(bitmap, BITMAP_LEN, i) + 1;
> time = ktime_get() - time;
> - pr_err("find_next_bit: %18llu ns, %6ld iterations\n", time, cnt);
> + pr_err("find_next_bit: %14llu ns, %6ld iterations\n", time, cnt);
>
> return 0;
> }
> @@ -94,7 +94,7 @@ static int __init test_find_next_zero_bit(const void *bitmap, unsigned long len)
> for (cnt = i = 0; i < BITMAP_LEN; cnt++)
> i = find_next_zero_bit(bitmap, len, i) + 1;
> time = ktime_get() - time;
> - pr_err("find_next_zero_bit: %18llu ns, %6ld iterations\n", time, cnt);
> + pr_err("find_next_zero_bit: %14llu ns, %6ld iterations\n", time, cnt);
>
> return 0;
> }
> @@ -113,7 +113,7 @@ static int __init test_find_last_bit(const void *bitmap, unsigned long len)
> len = l;
> } while (len);
> time = ktime_get() - time;
> - pr_err("find_last_bit: %18llu ns, %6ld iterations\n", time, cnt);
> + pr_err("find_last_bit: %14llu ns, %6ld iterations\n", time, cnt);
>
> return 0;
> }
> @@ -129,7 +129,7 @@ static int __init test_find_nth_bit(const unsigned long *bitmap, unsigned long l
> WARN_ON(l >= len);
> }
> time = ktime_get() - time;
> - pr_err("find_nth_bit: %18llu ns, %6ld iterations\n", time, w);
> + pr_err("find_nth_bit: %14llu ns, %6ld iterations\n", time, w);
>
> return 0;
> }
> @@ -144,7 +144,22 @@ static int __init test_find_next_and_bit(const void *bitmap,
> for (cnt = i = 0; i < BITMAP_LEN; cnt++)
> i = find_next_and_bit(bitmap, bitmap2, BITMAP_LEN, i + 1);
> time = ktime_get() - time;
> - pr_err("find_next_and_bit: %18llu ns, %6ld iterations\n", time, cnt);
> + pr_err("find_next_and_bit: %14llu ns, %6ld iterations\n", time, cnt);
> +
> + return 0;
> +}
> +
> +static int __init
> +test_bitmap_find_next_zero_area_off(unsigned long *bitmap, unsigned long len)
> +{
> + unsigned long i, cnt;
> + ktime_t time;
> +
> + time = ktime_get();
> + for (cnt = i = 0; i < BITMAP_LEN; cnt++)
> + i = bitmap_find_next_zero_area_off(bitmap, BITMAP_LEN, i, 8, 0, 0) + 1;
> + time = ktime_get() - time;
> + pr_err("bitmap_find_next_zero_area_off: %14llu ns, %6ld iterations\n", time, cnt);
>
> return 0;
> }
> @@ -158,6 +173,7 @@ static int __init find_bit_test(void)
> get_random_bytes(bitmap, sizeof(bitmap));
> get_random_bytes(bitmap2, sizeof(bitmap2));
>
> + test_bitmap_find_next_zero_area_off(bitmap, BITMAP_LEN);
> test_find_next_bit(bitmap, BITMAP_LEN);
> test_find_next_zero_bit(bitmap, BITMAP_LEN);
> test_find_last_bit(bitmap, BITMAP_LEN);
> @@ -181,6 +197,7 @@ static int __init find_bit_test(void)
> __set_bit(get_random_u32_below(BITMAP_LEN), bitmap2);
> }
>
> + test_bitmap_find_next_zero_area_off(bitmap, BITMAP_LEN);
> test_find_next_bit(bitmap, BITMAP_LEN);
> test_find_next_zero_bit(bitmap, BITMAP_LEN);
> test_find_last_bit(bitmap, BITMAP_LEN);
> diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
> index 69813c10e6c0..8665df77c960 100644
> --- a/lib/test_bitmap.c
> +++ b/lib/test_bitmap.c
> @@ -234,6 +234,43 @@ static void __init test_find_nth_bit(void)
> }
> }
>
> +static void __init
> +test_bitmap_find_next_zero_area_off(void)
> +{
> + DECLARE_BITMAP(bmap, 192);
> +
> + bitmap_set(bmap, 0, 192);
> +
> + bitmap_clear(bmap, 0, 8);
> + __clear_bit(50, bmap);
> + bitmap_clear(bmap, 60, 18);
> + __set_bit(69, bmap);
> + __clear_bit(80, bmap);
> + bitmap_clear(bmap, 100, 10);
> + __clear_bit(120, bmap);
> + bitmap_clear(bmap, 145, 8);
> + bitmap_clear(bmap, 160, 32);
> +
> + expect_eq_uint(0,
> + bitmap_find_next_zero_area_off(bmap, 192, 0, 8, 0, 0));
> + expect_eq_uint(0,
> + bitmap_find_next_zero_area_off(bmap, 192, 0, 8, 3, 0));
> + expect_eq_uint(163,
> + bitmap_find_next_zero_area_off(bmap, 192, 0, 8, 3, 1));
> + expect_eq_uint(60,
> + bitmap_find_next_zero_area_off(bmap, 192, 1, 8, 0, 0));
> + expect_eq_uint(160,
> + bitmap_find_next_zero_area_off(bmap, 192, 1, 8, 7, 0));
> + expect_eq_uint(60,
> + bitmap_find_next_zero_area_off(bmap, 192, 1, 8, 7, 4));
> + expect_eq_uint(100,
> + bitmap_find_next_zero_area_off(bmap, 192, 0, 10, 0, 0));
> + expect_eq_uint(160,
> + bitmap_find_next_zero_area_off(bmap, 192, 0, 32, 0, 0));
> + expect_eq_uint(1,
> + !!(bitmap_find_next_zero_area_off(bmap, 192, 0, 33, 0, 0) >= 192));
> +}
> +
> static void __init test_fill_set(void)
> {
> DECLARE_BITMAP(bmap, 1024);
> @@ -1559,6 +1596,7 @@ static void __init selftest(void)
> test_for_each_clear_bitrange_from();
> test_for_each_set_clump8();
> test_for_each_set_bit_wrap();
> + test_bitmap_find_next_zero_area_off();
> }
>
> KSTM_MODULE_LOADERS(test_bitmap);
> --
> 2.34.1
next prev parent reply other threads:[~2026-06-18 17:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-18 13:35 [PATCH v6 0/2] Improve the performance of bitmap_find_next_zero_area_off() Yi Sun
2026-06-18 13:35 ` [PATCH v6 1/2] lib: bitmap: add tests for bitmap_find_next_zero_area_off() Yi Sun
2026-06-18 17:31 ` Yury Norov [this message]
2026-06-18 13:35 ` [PATCH v6 2/2] lib: bitmap: optimize bitmap_find_next_zero_area_off() Yi Sun
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=ajQrYZomFpVmcw3v@yury \
--to=yury.norov@gmail.com \
--cc=279644543@qq.com \
--cc=akinobu.mita@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=fvdl@google.com \
--cc=hch@lst.de \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mina86@mina86.com \
--cc=minchan@kernel.org \
--cc=mnazarewicz@gmail.com \
--cc=qiang.zhao@freescale.com \
--cc=scottwood@freescale.com \
--cc=song@kernel.org \
--cc=tglx@kernel.org \
--cc=tjmercier@google.com \
--cc=yi.sun@unisoc.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.