From: Yury Norov <yury.norov@gmail.com>
To: linux-kernel@vger.kernel.org,
"Alexander Lobakin" <alexandr.lobakin@intel.com>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Arnd Bergmann" <arnd@arndb.de>,
"David Gow" <davidgow@google.com>,
"Eric Dumazet" <edumazet@google.com>,
"Isabella Basso" <isabbasso@riseup.net>,
"Kees Cook" <keescook@chromium.org>,
"Keith Busch" <kbusch@kernel.org>,
"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
"Marco Elver" <elver@google.com>,
"Mark Rutland" <mark.rutland@arm.com>,
"Rasmus Villemoes" <linux@rasmusvillemoes.dk>,
"Steven Rostedt" <rostedt@goodmis.org>,
"Toke Høiland-Jørgensen" <toke@redhat.com>
Cc: Yury Norov <yury.norov@gmail.com>
Subject: [PATCH 2/5] lib/bitmap: add tests for find_nth_bit()
Date: Sun, 10 Jul 2022 21:47:08 -0700 [thread overview]
Message-ID: <20220711044711.466822-3-yury.norov@gmail.com> (raw)
In-Reply-To: <20220711044711.466822-1-yury.norov@gmail.com>
Add functional and performance tests for find_nth_bit().
Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
lib/find_bit_benchmark.c | 17 +++++++++++++++++
lib/test_bitmap.c | 36 ++++++++++++++++++++++++++++++++++--
2 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/lib/find_bit_benchmark.c b/lib/find_bit_benchmark.c
index db904b57d4b8..a17a0ad0f783 100644
--- a/lib/find_bit_benchmark.c
+++ b/lib/find_bit_benchmark.c
@@ -115,6 +115,22 @@ static int __init test_find_last_bit(const void *bitmap, unsigned long len)
return 0;
}
+static int __init test_find_nth_bit(const unsigned long *bitmap, unsigned long len)
+{
+ unsigned long l, n, w = bitmap_weight(bitmap, len);
+ ktime_t time;
+
+ time = ktime_get();
+ for (n = 0; n < w; n++) {
+ l = find_nth_bit(bitmap, len, n);
+ WARN_ON(l >= len);
+ }
+ time = ktime_get() - time;
+ pr_err("find_nth_bit: %18llu ns, %6ld iterations\n", time, w);
+
+ return 0;
+}
+
static int __init test_find_next_and_bit(const void *bitmap,
const void *bitmap2, unsigned long len)
{
@@ -142,6 +158,7 @@ static int __init find_bit_test(void)
test_find_next_bit(bitmap, BITMAP_LEN);
test_find_next_zero_bit(bitmap, BITMAP_LEN);
test_find_last_bit(bitmap, BITMAP_LEN);
+ test_find_nth_bit(bitmap, BITMAP_LEN/10);
/*
* test_find_first_bit() may take some time, so
diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index 25967cfa4ab2..8ac8c1df818c 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -16,6 +16,8 @@
#include "../tools/testing/selftests/kselftest_module.h"
+#define EXP1_IN_BITS (sizeof(exp1) * 8)
+
KSTM_MODULE_GLOBALS();
static char pbl_buffer[PAGE_SIZE] __initdata;
@@ -219,6 +221,36 @@ static void __init test_zero_clear(void)
expect_eq_pbl("", bmap, 1024);
}
+static void __init test_find_nth_bit(void)
+{
+ unsigned long b, bit, cnt = 0;
+ DECLARE_BITMAP(bmap, 64 * 3);
+
+ bitmap_zero(bmap, 64 * 3);
+ __set_bit(10, bmap);
+ __set_bit(20, bmap);
+ __set_bit(30, bmap);
+ __set_bit(40, bmap);
+ __set_bit(50, bmap);
+ __set_bit(60, bmap);
+ __set_bit(80, bmap);
+ __set_bit(123, bmap);
+
+ expect_eq_uint(10, find_nth_bit(bmap, 64 * 3, 0));
+ expect_eq_uint(20, find_nth_bit(bmap, 64 * 3, 1));
+ expect_eq_uint(30, find_nth_bit(bmap, 64 * 3, 2));
+ expect_eq_uint(40, find_nth_bit(bmap, 64 * 3, 3));
+ expect_eq_uint(50, find_nth_bit(bmap, 64 * 3, 4));
+ expect_eq_uint(60, find_nth_bit(bmap, 64 * 3, 5));
+ expect_eq_uint(80, find_nth_bit(bmap, 64 * 3, 6));
+ expect_eq_uint(123, find_nth_bit(bmap, 64 * 3, 7));
+
+ for_each_set_bit(bit, exp1, EXP1_IN_BITS) {
+ b = find_nth_bit(exp1, EXP1_IN_BITS, cnt++);
+ expect_eq_uint(b, bit);
+ }
+}
+
static void __init test_fill_set(void)
{
DECLARE_BITMAP(bmap, 1024);
@@ -557,8 +589,6 @@ static void __init test_bitmap_parse(void)
}
}
-#define EXP1_IN_BITS (sizeof(exp1) * 8)
-
static void __init test_bitmap_arr32(void)
{
unsigned int nbits, next_bit;
@@ -946,6 +976,8 @@ static void __init selftest(void)
test_bitmap_cut();
test_bitmap_print_buf();
test_bitmap_const_eval();
+
+ test_find_nth_bit();
}
KSTM_MODULE_LOADERS(test_bitmap);
--
2.34.1
next prev parent reply other threads:[~2022-07-11 4:47 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-11 4:47 [PATCH v2 0/5] lib/find: add find_nth_bit() Yury Norov
2022-07-11 4:47 ` [PATCH 1/5] lib: add find_nth(,and,andnot)_bit() Yury Norov
2022-07-11 4:47 ` Yury Norov [this message]
2022-07-11 4:47 ` [PATCH 3/5] lib/bitmap: remove bitmap_ord_to_pos Yury Norov
2022-07-11 4:47 ` [PATCH 4/5] cpumask: add cpumask_nth_{,and,andnot} Yury Norov
2022-07-11 4:47 ` [PATCH 5/5] lib/nodemask: inline next_node_in() and node_random() Yury Norov
2022-07-29 3:46 ` Guenter Roeck
2022-07-29 16:48 ` Yury Norov
2022-08-13 13:15 ` Guenter Roeck
2022-08-13 13:48 ` Yury Norov
2022-08-14 18:48 ` Andy Shevchenko
2022-08-14 18:51 ` Andy Shevchenko
2022-07-11 8:55 ` [PATCH v2 0/5] lib/find: add find_nth_bit() Andy Shevchenko
2022-07-12 16:26 ` Yury Norov
2022-07-12 18:28 ` Andy Shevchenko
2022-07-13 1:46 ` Yury Norov
2022-07-15 1:04 ` Yury Norov
2022-07-21 21:14 ` Yury Norov
-- strict thread matches above, loose matches on Subject: below --
2022-07-06 18:22 [PATCH " Yury Norov
2022-07-06 18:22 ` [PATCH 2/5] lib/bitmap: add tests for find_nth_bit() Yury Norov
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=20220711044711.466822-3-yury.norov@gmail.com \
--to=yury.norov@gmail.com \
--cc=alexandr.lobakin@intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=arnd@arndb.de \
--cc=davidgow@google.com \
--cc=edumazet@google.com \
--cc=elver@google.com \
--cc=isabbasso@riseup.net \
--cc=kbusch@kernel.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=mark.rutland@arm.com \
--cc=memxor@gmail.com \
--cc=rostedt@goodmis.org \
--cc=toke@redhat.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
all inboxes | Powered by JetHome®