mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-12-29 17:25:38 +00:00
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>
This commit is contained in:
parent
efe3a85eab
commit
0a2c6664e5
@ -5,9 +5,11 @@
|
|||||||
|
|
||||||
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
||||||
|
|
||||||
|
#include <linux/cleanup.h>
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/printk.h>
|
#include <linux/printk.h>
|
||||||
|
#include <linux/slab.h>
|
||||||
|
|
||||||
/* a tiny module only meant to test
|
/* a tiny module only meant to test
|
||||||
*
|
*
|
||||||
@ -50,6 +52,30 @@ static unsigned long order_comb_long[][2] = {
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static int __init test_fns(void)
|
||||||
|
{
|
||||||
|
static volatile __always_used unsigned long tmp __initdata;
|
||||||
|
unsigned long *buf __free(kfree) = NULL;
|
||||||
|
unsigned int i, n;
|
||||||
|
ktime_t time;
|
||||||
|
|
||||||
|
buf = kmalloc_array(10000, sizeof(unsigned long), GFP_KERNEL);
|
||||||
|
if (!buf)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
get_random_bytes(buf, 10000 * sizeof(unsigned long));
|
||||||
|
time = ktime_get();
|
||||||
|
|
||||||
|
for (n = 0; n < BITS_PER_LONG; n++)
|
||||||
|
for (i = 0; i < 10000; i++)
|
||||||
|
tmp = fns(buf[i], n);
|
||||||
|
|
||||||
|
time = ktime_get() - time;
|
||||||
|
pr_err("fns: %18llu ns\n", time);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int __init test_bitops_startup(void)
|
static int __init test_bitops_startup(void)
|
||||||
{
|
{
|
||||||
int i, bit_set;
|
int i, bit_set;
|
||||||
@ -94,6 +120,8 @@ static int __init test_bitops_startup(void)
|
|||||||
if (bit_set != BITOPS_LAST)
|
if (bit_set != BITOPS_LAST)
|
||||||
pr_err("ERROR: FOUND SET BIT %d\n", bit_set);
|
pr_err("ERROR: FOUND SET BIT %d\n", bit_set);
|
||||||
|
|
||||||
|
test_fns();
|
||||||
|
|
||||||
pr_info("Completed bitops test\n");
|
pr_info("Completed bitops test\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user