diff options
author | Davidlohr Bueso <dave@stgolabs.net> | 2017-07-10 18:51:46 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-07-10 19:32:35 -0400 |
commit | a54dae0338b7f01eb0f9c7571fb9b74f791d1c6b (patch) | |
tree | a0a49d7bfaefa64d534708f7422a4d5f99741547 /lib/interval_tree_test.c | |
parent | 0f789b67647205b77dee56fcc27a7d8de3fcd52e (diff) |
lib/interval_tree_test.c: make test options module parameters
Allows for more flexible debugging.
Link: http://lkml.kernel.org/r/20170518174936.20265-3-dave@stgolabs.net
Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/interval_tree_test.c')
-rw-r--r-- | lib/interval_tree_test.c | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/lib/interval_tree_test.c b/lib/interval_tree_test.c index 245900b98c8e..1093f0496d5e 100644 --- a/lib/interval_tree_test.c +++ b/lib/interval_tree_test.c | |||
@@ -1,16 +1,25 @@ | |||
1 | #include <linux/module.h> | 1 | #include <linux/module.h> |
2 | #include <linux/moduleparam.h> | ||
2 | #include <linux/interval_tree.h> | 3 | #include <linux/interval_tree.h> |
3 | #include <linux/random.h> | 4 | #include <linux/random.h> |
5 | #include <linux/slab.h> | ||
4 | #include <asm/timex.h> | 6 | #include <asm/timex.h> |
5 | 7 | ||
6 | #define NODES 100 | 8 | #define __param(type, name, init, msg) \ |
7 | #define PERF_LOOPS 100000 | 9 | static type name = init; \ |
8 | #define SEARCHES 100 | 10 | module_param(name, type, 0444); \ |
9 | #define SEARCH_LOOPS 10000 | 11 | MODULE_PARM_DESC(name, msg); |
12 | |||
13 | __param(int, nnodes, 100, "Number of nodes in the interval tree"); | ||
14 | __param(int, perf_loops, 100000, "Number of iterations modifying the tree"); | ||
15 | |||
16 | __param(int, nsearches, 100, "Number of searches to the interval tree"); | ||
17 | __param(int, search_loops, 10000, "Number of iterations searching the tree"); | ||
18 | |||
10 | 19 | ||
11 | static struct rb_root root = RB_ROOT; | 20 | static struct rb_root root = RB_ROOT; |
12 | static struct interval_tree_node nodes[NODES]; | 21 | static struct interval_tree_node *nodes = NULL; |
13 | static u32 queries[SEARCHES]; | 22 | static u32 *queries = NULL; |
14 | 23 | ||
15 | static struct rnd_state rnd; | 24 | static struct rnd_state rnd; |
16 | 25 | ||
@@ -29,7 +38,8 @@ search(unsigned long query, struct rb_root *root) | |||
29 | static void init(void) | 38 | static void init(void) |
30 | { | 39 | { |
31 | int i; | 40 | int i; |
32 | for (i = 0; i < NODES; i++) { | 41 | |
42 | for (i = 0; i < nnodes; i++) { | ||
33 | u32 a = prandom_u32_state(&rnd); | 43 | u32 a = prandom_u32_state(&rnd); |
34 | u32 b = prandom_u32_state(&rnd); | 44 | u32 b = prandom_u32_state(&rnd); |
35 | if (a <= b) { | 45 | if (a <= b) { |
@@ -40,7 +50,7 @@ static void init(void) | |||
40 | nodes[i].last = a; | 50 | nodes[i].last = a; |
41 | } | 51 | } |
42 | } | 52 | } |
43 | for (i = 0; i < SEARCHES; i++) | 53 | for (i = 0; i < nsearches; i++) |
44 | queries[i] = prandom_u32_state(&rnd); | 54 | queries[i] = prandom_u32_state(&rnd); |
45 | } | 55 | } |
46 | 56 | ||
@@ -50,6 +60,16 @@ static int interval_tree_test_init(void) | |||
50 | unsigned long results; | 60 | unsigned long results; |
51 | cycles_t time1, time2, time; | 61 | cycles_t time1, time2, time; |
52 | 62 | ||
63 | nodes = kmalloc(nnodes * sizeof(struct interval_tree_node), GFP_KERNEL); | ||
64 | if (!nodes) | ||
65 | return -ENOMEM; | ||
66 | |||
67 | queries = kmalloc(nsearches * sizeof(int), GFP_KERNEL); | ||
68 | if (!queries) { | ||
69 | kfree(nodes); | ||
70 | return -ENOMEM; | ||
71 | } | ||
72 | |||
53 | printk(KERN_ALERT "interval tree insert/remove"); | 73 | printk(KERN_ALERT "interval tree insert/remove"); |
54 | 74 | ||
55 | prandom_seed_state(&rnd, 3141592653589793238ULL); | 75 | prandom_seed_state(&rnd, 3141592653589793238ULL); |
@@ -57,39 +77,42 @@ static int interval_tree_test_init(void) | |||
57 | 77 | ||
58 | time1 = get_cycles(); | 78 | time1 = get_cycles(); |
59 | 79 | ||
60 | for (i = 0; i < PERF_LOOPS; i++) { | 80 | for (i = 0; i < perf_loops; i++) { |
61 | for (j = 0; j < NODES; j++) | 81 | for (j = 0; j < nnodes; j++) |
62 | interval_tree_insert(nodes + j, &root); | 82 | interval_tree_insert(nodes + j, &root); |
63 | for (j = 0; j < NODES; j++) | 83 | for (j = 0; j < nnodes; j++) |
64 | interval_tree_remove(nodes + j, &root); | 84 | interval_tree_remove(nodes + j, &root); |
65 | } | 85 | } |
66 | 86 | ||
67 | time2 = get_cycles(); | 87 | time2 = get_cycles(); |
68 | time = time2 - time1; | 88 | time = time2 - time1; |
69 | 89 | ||
70 | time = div_u64(time, PERF_LOOPS); | 90 | time = div_u64(time, perf_loops); |
71 | printk(" -> %llu cycles\n", (unsigned long long)time); | 91 | printk(" -> %llu cycles\n", (unsigned long long)time); |
72 | 92 | ||
73 | printk(KERN_ALERT "interval tree search"); | 93 | printk(KERN_ALERT "interval tree search"); |
74 | 94 | ||
75 | for (j = 0; j < NODES; j++) | 95 | for (j = 0; j < nnodes; j++) |
76 | interval_tree_insert(nodes + j, &root); | 96 | interval_tree_insert(nodes + j, &root); |
77 | 97 | ||
78 | time1 = get_cycles(); | 98 | time1 = get_cycles(); |
79 | 99 | ||
80 | results = 0; | 100 | results = 0; |
81 | for (i = 0; i < SEARCH_LOOPS; i++) | 101 | for (i = 0; i < search_loops; i++) |
82 | for (j = 0; j < SEARCHES; j++) | 102 | for (j = 0; j < nsearches; j++) |
83 | results += search(queries[j], &root); | 103 | results += search(queries[j], &root); |
84 | 104 | ||
85 | time2 = get_cycles(); | 105 | time2 = get_cycles(); |
86 | time = time2 - time1; | 106 | time = time2 - time1; |
87 | 107 | ||
88 | time = div_u64(time, SEARCH_LOOPS); | 108 | time = div_u64(time, search_loops); |
89 | results = div_u64(results, SEARCH_LOOPS); | 109 | results = div_u64(results, search_loops); |
90 | printk(" -> %llu cycles (%lu results)\n", | 110 | printk(" -> %llu cycles (%lu results)\n", |
91 | (unsigned long long)time, results); | 111 | (unsigned long long)time, results); |
92 | 112 | ||
113 | kfree(queries); | ||
114 | kfree(nodes); | ||
115 | |||
93 | return -EAGAIN; /* Fail will directly unload the module */ | 116 | return -EAGAIN; /* Fail will directly unload the module */ |
94 | } | 117 | } |
95 | 118 | ||