Skip to content

Commit 0a2c666

Browse files
visitorckwYuryNorov
authored andcommitted
lib/test_bitops: Add benchmark test for fns()
Introduce a benchmark test for the fns(). It measures the total time taken by fns() to process 10,000 test data generated using get_random_bytes() for each n in the range [0, BITS_PER_LONG). example: test_bitops: fns: 7637268 ns CC: Andrew Morton <akpm@linux-foundation.org> CC: Rasmus Villemoes <linux@rasmusvillemoes.dk> CC: David Laight <David.Laight@aculab.com> Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com> Suggested-by: Yury Norov <yury.norov@gmail.com> Signed-off-by: Yury Norov <yury.norov@gmail.com>
1 parent efe3a85 commit 0a2c666

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lib/test_bitops.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
77

8+
#include <linux/cleanup.h>
89
#include <linux/init.h>
910
#include <linux/module.h>
1011
#include <linux/printk.h>
12+
#include <linux/slab.h>
1113

1214
/* a tiny module only meant to test
1315
*
@@ -50,6 +52,30 @@ static unsigned long order_comb_long[][2] = {
5052
};
5153
#endif
5254

55+
static int __init test_fns(void)
56+
{
57+
static volatile __always_used unsigned long tmp __initdata;
58+
unsigned long *buf __free(kfree) = NULL;
59+
unsigned int i, n;
60+
ktime_t time;
61+
62+
buf = kmalloc_array(10000, sizeof(unsigned long), GFP_KERNEL);
63+
if (!buf)
64+
return -ENOMEM;
65+
66+
get_random_bytes(buf, 10000 * sizeof(unsigned long));
67+
time = ktime_get();
68+
69+
for (n = 0; n < BITS_PER_LONG; n++)
70+
for (i = 0; i < 10000; i++)
71+
tmp = fns(buf[i], n);
72+
73+
time = ktime_get() - time;
74+
pr_err("fns: %18llu ns\n", time);
75+
76+
return 0;
77+
}
78+
5379
static int __init test_bitops_startup(void)
5480
{
5581
int i, bit_set;
@@ -94,6 +120,8 @@ static int __init test_bitops_startup(void)
94120
if (bit_set != BITOPS_LAST)
95121
pr_err("ERROR: FOUND SET BIT %d\n", bit_set);
96122

123+
test_fns();
124+
97125
pr_info("Completed bitops test\n");
98126

99127
return 0;

0 commit comments

Comments
 (0)