Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lib/find_bit_benchmark: avoid clearing randomly filled bitmap in test_find_first_bit()

test_find_first_bit() searches for a set bit from the beginning of the
test bitmap and clears it repeatedly, eventually clearing the entire
bitmap.

After test_find_first_bit() is executed, test_find_first_and_bit() and
test_find_next_and_bit() are executed without randomly reinitializing the
cleared bitmap.

In the first phase (testing find_bit() with a random-filled bitmap),
test_find_first_bit() only operates on 1/10 of the entire size of the
testing bitmap, so this isn't a big problem.

However, in the second phase (testing find_bit() with a sparse bitmap),
test_find_first_bit() clears the entire test bitmap, so the subsequent
test_find_first_and_bit() and test_find_next_and_bit() will not find any
set bits. This is probably not the intended benchmark.

To fix this issue, test_find_first_bit() operates on a duplicated bitmap
and does not clear the original test bitmap.
The same is already done in test_find_first_and_bit().

While we're at it, add const qualifiers to the bitmap pointer arguments
in the test functions.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Yury Norov <ynorov@nvidia.com>

authored by

Akinobu Mita and committed by
Yury Norov
6c88ba56 a6766437

+9 -6
+9 -6
lib/find_bit_benchmark.c
··· 30 30 static DECLARE_BITMAP(bitmap2, BITMAP_LEN) __initdata; 31 31 32 32 /* 33 - * This is Schlemiel the Painter's algorithm. It should be called after 34 - * all other tests for the same bitmap because it sets all bits of bitmap to 1. 33 + * This is Schlemiel the Painter's algorithm. 35 34 */ 36 - static int __init test_find_first_bit(void *bitmap, unsigned long len) 35 + static int __init test_find_first_bit(const void *bitmap, unsigned long len) 37 36 { 37 + static DECLARE_BITMAP(cp, BITMAP_LEN) __initdata; 38 38 unsigned long i, cnt; 39 39 ktime_t time; 40 40 41 + bitmap_copy(cp, bitmap, BITMAP_LEN); 42 + 41 43 time = ktime_get(); 42 44 for (cnt = i = 0; i < len; cnt++) { 43 - i = find_first_bit(bitmap, len); 44 - __clear_bit(i, bitmap); 45 + i = find_first_bit(cp, len); 46 + __clear_bit(i, cp); 45 47 } 46 48 time = ktime_get() - time; 47 49 pr_err("find_first_bit: %18llu ns, %6ld iterations\n", time, cnt); ··· 51 49 return 0; 52 50 } 53 51 54 - static int __init test_find_first_and_bit(void *bitmap, const void *bitmap2, unsigned long len) 52 + static int __init test_find_first_and_bit(const void *bitmap, const void *bitmap2, 53 + unsigned long len) 55 54 { 56 55 static DECLARE_BITMAP(cp, BITMAP_LEN) __initdata; 57 56 unsigned long i, cnt;