public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Levi Yun <ppbuk5246@gmail.com>
To: akpm@linux-foundation.org, yury.norov@gmail.com,
	andriy.shevchenko@linux.intel.com,
	richard.weiyang@linux.alibaba.com, christian.brauner@ubuntu.com,
	arnd@arndb.de, jpoimboe@redhat.com, changbin.du@intel.com,
	rdunlap@infradead.org, masahiroy@kernel.org,
	gregkh@linuxfoundation.org, peterz@infradead.org,
	peter.enderborg@sony.com, krzk@kernel.org,
	brendanhiggins@google.com, keescook@chromium.org,
	broonie@kernel.org, matti.vaittinen@fi.rohmeurope.com,
	mhiramat@kernel.org, jpa@git.mail.kapsi.fi,
	nivedita@alum.mit.edu, glider@google.com, orson.zhai@unisoc.com,
	takahiro.akashi@linaro.org, clm@fb.com, josef@toxicpanda.com,
	dsterba@suse.com, dushistov@mail.ru
Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
	linux-btrfs@vger.kernel.org
Subject: [PATCH v2 5/8] lib/find_bit_bench.c: Add find_last_zero_bit.
Date: Sun, 6 Dec 2020 15:49:05 +0900	[thread overview]
Message-ID: <20201206064905.GA6183@ubuntu> (raw)

Add bench test of find_last_zero_bit.

Also, this patch fix the unmatched iterations value with
find_next_bit and find_last_bit which happen when
the last bit set or not,
Let suppose, 4096 bitmap size and 4095 bit is set only.
In this case former find_next_bit returns iterations count as 0.
But find_last_bit returns it as 1.
This unmatched return value makes some confusion.
So we fix it.

Signed-off-by: Levi Yun <ppbuk5246@gmail.com>
---
 lib/find_bit_benchmark.c | 51 +++++++++++++++++++++++++++++-----------
 1 file changed, 37 insertions(+), 14 deletions(-)

diff --git a/lib/find_bit_benchmark.c b/lib/find_bit_benchmark.c
index 5637c5711db9..007371169008 100644
--- a/lib/find_bit_benchmark.c
+++ b/lib/find_bit_benchmark.c
@@ -35,14 +35,14 @@ static DECLARE_BITMAP(bitmap2, BITMAP_LEN) __initdata;
  */
 static int __init test_find_first_bit(void *bitmap, unsigned long len)
 {
-	unsigned long i, cnt;
+	unsigned long i = 0, cnt = 0;
 	ktime_t time;
 
 	time = ktime_get();
-	for (cnt = i = 0; i < len; cnt++) {
+	do {
 		i = find_first_bit(bitmap, len);
 		__clear_bit(i, bitmap);
-	}
+	} while (i++ < len && ++cnt);
 	time = ktime_get() - time;
 	pr_err("find_first_bit:     %18llu ns, %6ld iterations\n", time, cnt);
 
@@ -51,12 +51,13 @@ static int __init test_find_first_bit(void *bitmap, unsigned long len)
 
 static int __init test_find_next_bit(const void *bitmap, unsigned long len)
 {
-	unsigned long i, cnt;
+	unsigned long i = 0, cnt = 0;
 	ktime_t time;
 
 	time = ktime_get();
-	for (cnt = i = 0; i < BITMAP_LEN; cnt++)
-		i = find_next_bit(bitmap, BITMAP_LEN, i) + 1;
+	do {
+		i = find_next_bit(bitmap, BITMAP_LEN, i);
+	} while (i++ < BITMAP_LEN && ++cnt);
 	time = ktime_get() - time;
 	pr_err("find_next_bit:      %18llu ns, %6ld iterations\n", time, cnt);
 
@@ -65,12 +66,13 @@ static int __init test_find_next_bit(const void *bitmap, unsigned long len)
 
 static int __init test_find_next_zero_bit(const void *bitmap, unsigned long len)
 {
-	unsigned long i, cnt;
+	unsigned long i = 0, cnt = 0;
 	ktime_t time;
 
 	time = ktime_get();
-	for (cnt = i = 0; i < BITMAP_LEN; cnt++)
-		i = find_next_zero_bit(bitmap, len, i) + 1;
+	do {
+		i = find_next_zero_bit(bitmap, len, i);
+	} while (i++ < BITMAP_LEN && ++cnt);
 	time = ktime_get() - time;
 	pr_err("find_next_zero_bit: %18llu ns, %6ld iterations\n", time, cnt);
 
@@ -84,27 +86,46 @@ static int __init test_find_last_bit(const void *bitmap, unsigned long len)
 
 	time = ktime_get();
 	do {
-		cnt++;
 		l = find_last_bit(bitmap, len);
 		if (l >= len)
 			break;
 		len = l;
-	} while (len);
+	} while (len >= 0 && ++cnt); /**< to find real 0 bit set. */
 	time = ktime_get() - time;
 	pr_err("find_last_bit:      %18llu ns, %6ld iterations\n", time, cnt);
 
 	return 0;
 }
 
+static int __init test_find_last_zero_bit(const void *bitmap, unsigned long len)
+{
+	unsigned long l, cnt = 0;
+	ktime_t time;
+
+	time = ktime_get();
+	do {
+		l = find_last_zero_bit(bitmap, len);
+		if (l >= len)
+			break;
+		len = l;
+	} while (len >= 0 && ++cnt); /**< to find real 0 bit set. */
+	time = ktime_get() - time;
+	pr_err("find_last_zero_bit:      %18llu ns, %6ld iterations\n", time, cnt);
+
+	return 0;
+}
+
+
 static int __init test_find_next_and_bit(const void *bitmap,
 		const void *bitmap2, unsigned long len)
 {
-	unsigned long i, cnt;
+	unsigned long i, cnt = 0;
 	ktime_t time;
 
 	time = ktime_get();
-	for (cnt = i = 0; i < BITMAP_LEN; cnt++)
-		i = find_next_and_bit(bitmap, bitmap2, BITMAP_LEN, i + 1);
+	do {
+		i = find_next_and_bit(bitmap, bitmap2, BITMAP_LEN, i);
+	} while (i++ < BITMAP_LEN && ++cnt);
 	time = ktime_get() - time;
 	pr_err("find_next_and_bit:  %18llu ns, %6ld iterations\n", time, cnt);
 
@@ -123,6 +144,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_last_zero_bit(bitmap, BITMAP_LEN);
 
 	/*
 	 * test_find_first_bit() may take some time, so
@@ -144,6 +166,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_last_zero_bit(bitmap, BITMAP_LEN);
 	test_find_first_bit(bitmap, BITMAP_LEN);
 	test_find_next_and_bit(bitmap, bitmap2, BITMAP_LEN);
 
-- 
2.27.0

                 reply	other threads:[~2020-12-06  6:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20201206064905.GA6183@ubuntu \
    --to=ppbuk5246@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=brendanhiggins@google.com \
    --cc=broonie@kernel.org \
    --cc=changbin.du@intel.com \
    --cc=christian.brauner@ubuntu.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=dushistov@mail.ru \
    --cc=glider@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=josef@toxicpanda.com \
    --cc=jpa@git.mail.kapsi.fi \
    --cc=jpoimboe@redhat.com \
    --cc=keescook@chromium.org \
    --cc=krzk@kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=matti.vaittinen@fi.rohmeurope.com \
    --cc=mhiramat@kernel.org \
    --cc=nivedita@alum.mit.edu \
    --cc=orson.zhai@unisoc.com \
    --cc=peter.enderborg@sony.com \
    --cc=peterz@infradead.org \
    --cc=rdunlap@infradead.org \
    --cc=richard.weiyang@linux.alibaba.com \
    --cc=takahiro.akashi@linaro.org \
    --cc=yury.norov@gmail.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