lib/rbtree_test.c: make input module parameters
[email protected]
maintainerPATCH 69/126 lib/rbtree_test.c: make input module parameters
From: Davidlohr Bueso <[email protected]>
Subject: lib/rbtree_test.c: make input module parameters
Allows for more flexible debugging.
Signed-off-by Davidlohr Bueso <[email protected]>
Signed-off-by Andrew Morton <[email protected]>
---
lib/rbtree_test.c | 55 +++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 21 deletions(-)
lib/rbtree_test.c renamed from lib/rbtree_test.c~lib-rbtree_testc-make-input-module-parameters +34 -21
@@ -1,11 +1,18 @@#include <linux/module.h> +#include <linux/moduleparam.h> #include <linux/rbtree_augmented.h> #include <linux/random.h> +#include <linux/slab.h> #include <asm/timex.h> -#define NODES 100 -#define PERF_LOOPS 100000 -#define CHECK_LOOPS 100 +#define __param (type, name, init, msg) \ + static type name = init; \ + 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 {u32 key;
@@ -17,7 +24,7 @@ struct test_node { };static struct rb_root root =RB_ROOT ; -static struct test_node nodes[NODES ]; +static struct test_node *nodes =NULL ;static struct rnd_state rnd;
@@ -95,7 +102,7 @@ static void erase_augmented(struct test_static void init (void ) {int i; -for (i =0 ; i <NODES ; i++) { +for (i =0 ; i < nnodes; i++) { nodes[i].key =prandom_u32_state (&rnd); nodes[i].val =prandom_u32_state (&rnd); }
@@ -177,6 +184,10 @@ static int __init rbtree_test_init(void)int i, j;cycles_t time1, time2, time; + nodes =kmalloc (nnodes *sizeof (*nodes),GFP_KERNEL ); +if (!nodes) +return -ENOMEM ; +printk (KERN_ALERT "rbtree testing" );prandom_seed_state (&rnd,3141592653589793238ULL );
@@ -184,27 +195,27 @@ static int __init rbtree_test_init(void) time1 =get_cycles (); -for (i =0 ; i <PERF_LOOPS ; i++) { -for (j =0 ; j <NODES ; j++) +for (i =0 ; i < perf_loops; i++) { +for (j =0 ; j < nnodes; j++)insert (nodes + j, &root); -for (j =0 ; j <NODES ; j++) +for (j =0 ; j < nnodes; j++)erase (nodes + j, &root); } time2 =get_cycles (); time = time2 - time1; - time =div_u64 (time,PERF_LOOPS ); + time =div_u64 (time, perf_loops);printk (" -> %llu cycles\n" , (unsigned long long )time); -for (i =0 ; i <CHECK_LOOPS ; i++) { +for (i =0 ; i < check_loops; i++) {init (); -for (j =0 ; j <NODES ; j++) { +for (j =0 ; j < nnodes; j++) {check (j);insert (nodes + j, &root); } -for (j =0 ; j <NODES ; j++) { -check (NODES - j); +for (j =0 ; j < nnodes; j++) { +check (nnodes - j);erase (nodes + j, &root); }check (0 );
@@ -216,32 +227,34 @@ static int __init rbtree_test_init(void) time1 =get_cycles (); -for (i =0 ; i <PERF_LOOPS ; i++) { -for (j =0 ; j <NODES ; j++) +for (i =0 ; i < perf_loops; i++) { +for (j =0 ; j < nnodes; j++)insert_augmented (nodes + j, &root); -for (j =0 ; j <NODES ; j++) +for (j =0 ; j < nnodes; j++)erase_augmented (nodes + j, &root); } time2 =get_cycles (); time = time2 - time1; - time =div_u64 (time,PERF_LOOPS ); + time =div_u64 (time, perf_loops);printk (" -> %llu cycles\n" , (unsigned long long )time); -for (i =0 ; i <CHECK_LOOPS ; i++) { +for (i =0 ; i < check_loops; i++) {init (); -for (j =0 ; j <NODES ; j++) { +for (j =0 ; j < nnodes; j++) {check_augmented (j);insert_augmented (nodes + j, &root); } -for (j =0 ; j <NODES ; j++) { -check_augmented (NODES - j); +for (j =0 ; j < nnodes; j++) { +check_augmented (nnodes - j);erase_augmented (nodes + j, &root); }check_augmented (0 ); } +kfree (nodes); +return -EAGAIN ;/* Fail will directly unload the module */ }
_