Commit 223f8911 authored by Davidlohr Bueso's avatar Davidlohr Bueso Committed by Linus Torvalds

lib/rbtree_test.c: make input module parameters

Allows for more flexible debugging.

Link: http://lkml.kernel.org/r/20170719014603.19029-5-dave@stgolabs.netSigned-off-by: default avatarDavidlohr Bueso <dbueso@suse.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 35dc67d7
#include <linux/module.h> #include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/rbtree_augmented.h> #include <linux/rbtree_augmented.h>
#include <linux/random.h> #include <linux/random.h>
#include <linux/slab.h>
#include <asm/timex.h> #include <asm/timex.h>
#define NODES 100 #define __param(type, name, init, msg) \
#define PERF_LOOPS 100000 static type name = init; \
#define CHECK_LOOPS 100 module_param(name, type, 0444); \
MODULE_PARM_DESC(name, msg);
__param(int, nnodes, 100, "Number of nodes in the rb-tree");
__param(int, perf_loops, 100000, "Number of iterations modifying the rb-tree");
__param(int, check_loops, 100, "Number of iterations modifying and verifying the rb-tree");
struct test_node { struct test_node {
u32 key; u32 key;
...@@ -17,7 +24,7 @@ struct test_node { ...@@ -17,7 +24,7 @@ struct test_node {
}; };
static struct rb_root root = RB_ROOT; static struct rb_root root = RB_ROOT;
static struct test_node nodes[NODES]; static struct test_node *nodes = NULL;
static struct rnd_state rnd; static struct rnd_state rnd;
...@@ -95,7 +102,7 @@ static void erase_augmented(struct test_node *node, struct rb_root *root) ...@@ -95,7 +102,7 @@ static void erase_augmented(struct test_node *node, struct rb_root *root)
static void init(void) static void init(void)
{ {
int i; int i;
for (i = 0; i < NODES; i++) { for (i = 0; i < nnodes; i++) {
nodes[i].key = prandom_u32_state(&rnd); nodes[i].key = prandom_u32_state(&rnd);
nodes[i].val = prandom_u32_state(&rnd); nodes[i].val = prandom_u32_state(&rnd);
} }
...@@ -177,6 +184,10 @@ static int __init rbtree_test_init(void) ...@@ -177,6 +184,10 @@ static int __init rbtree_test_init(void)
int i, j; int i, j;
cycles_t time1, time2, time; cycles_t time1, time2, time;
nodes = kmalloc(nnodes * sizeof(*nodes), GFP_KERNEL);
if (!nodes)
return -ENOMEM;
printk(KERN_ALERT "rbtree testing"); printk(KERN_ALERT "rbtree testing");
prandom_seed_state(&rnd, 3141592653589793238ULL); prandom_seed_state(&rnd, 3141592653589793238ULL);
...@@ -184,27 +195,27 @@ static int __init rbtree_test_init(void) ...@@ -184,27 +195,27 @@ static int __init rbtree_test_init(void)
time1 = get_cycles(); time1 = get_cycles();
for (i = 0; i < PERF_LOOPS; i++) { for (i = 0; i < perf_loops; i++) {
for (j = 0; j < NODES; j++) for (j = 0; j < nnodes; j++)
insert(nodes + j, &root); insert(nodes + j, &root);
for (j = 0; j < NODES; j++) for (j = 0; j < nnodes; j++)
erase(nodes + j, &root); erase(nodes + j, &root);
} }
time2 = get_cycles(); time2 = get_cycles();
time = time2 - time1; time = time2 - time1;
time = div_u64(time, PERF_LOOPS); time = div_u64(time, perf_loops);
printk(" -> %llu cycles\n", (unsigned long long)time); printk(" -> %llu cycles\n", (unsigned long long)time);
for (i = 0; i < CHECK_LOOPS; i++) { for (i = 0; i < check_loops; i++) {
init(); init();
for (j = 0; j < NODES; j++) { for (j = 0; j < nnodes; j++) {
check(j); check(j);
insert(nodes + j, &root); insert(nodes + j, &root);
} }
for (j = 0; j < NODES; j++) { for (j = 0; j < nnodes; j++) {
check(NODES - j); check(nnodes - j);
erase(nodes + j, &root); erase(nodes + j, &root);
} }
check(0); check(0);
...@@ -216,32 +227,34 @@ static int __init rbtree_test_init(void) ...@@ -216,32 +227,34 @@ static int __init rbtree_test_init(void)
time1 = get_cycles(); time1 = get_cycles();
for (i = 0; i < PERF_LOOPS; i++) { for (i = 0; i < perf_loops; i++) {
for (j = 0; j < NODES; j++) for (j = 0; j < nnodes; j++)
insert_augmented(nodes + j, &root); insert_augmented(nodes + j, &root);
for (j = 0; j < NODES; j++) for (j = 0; j < nnodes; j++)
erase_augmented(nodes + j, &root); erase_augmented(nodes + j, &root);
} }
time2 = get_cycles(); time2 = get_cycles();
time = time2 - time1; time = time2 - time1;
time = div_u64(time, PERF_LOOPS); time = div_u64(time, perf_loops);
printk(" -> %llu cycles\n", (unsigned long long)time); printk(" -> %llu cycles\n", (unsigned long long)time);
for (i = 0; i < CHECK_LOOPS; i++) { for (i = 0; i < check_loops; i++) {
init(); init();
for (j = 0; j < NODES; j++) { for (j = 0; j < nnodes; j++) {
check_augmented(j); check_augmented(j);
insert_augmented(nodes + j, &root); insert_augmented(nodes + j, &root);
} }
for (j = 0; j < NODES; j++) { for (j = 0; j < nnodes; j++) {
check_augmented(NODES - j); check_augmented(nnodes - j);
erase_augmented(nodes + j, &root); erase_augmented(nodes + j, &root);
} }
check_augmented(0); check_augmented(0);
} }
kfree(nodes);
return -EAGAIN; /* Fail will directly unload the module */ return -EAGAIN; /* Fail will directly unload the module */
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment