diff options
author | Davidlohr Bueso <dave@stgolabs.net> | 2017-07-10 18:51:49 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-07-10 19:32:35 -0400 |
commit | a8ec14d4f6aa8e245efacc992c8ee6ea0464ce2a (patch) | |
tree | eb6eaca9080f9cbdb6d17af2ebf64c80175daa52 /lib | |
parent | a54dae0338b7f01eb0f9c7571fb9b74f791d1c6b (diff) |
lib/interval_tree_test.c: allow users to limit scope of endpoint
Add a 'max_endpoint' parameter such that users may easily limit the size
of the intervals that are randomly generated.
Link: http://lkml.kernel.org/r/20170518174936.20265-4-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')
-rw-r--r-- | lib/interval_tree_test.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/interval_tree_test.c b/lib/interval_tree_test.c index 1093f0496d5e..0fef6364a958 100644 --- a/lib/interval_tree_test.c +++ b/lib/interval_tree_test.c | |||
@@ -16,6 +16,7 @@ __param(int, perf_loops, 100000, "Number of iterations modifying the tree"); | |||
16 | __param(int, nsearches, 100, "Number of searches to the interval tree"); | 16 | __param(int, nsearches, 100, "Number of searches to the interval tree"); |
17 | __param(int, search_loops, 10000, "Number of iterations searching the tree"); | 17 | __param(int, search_loops, 10000, "Number of iterations searching the tree"); |
18 | 18 | ||
19 | __param(uint, max_endpoint, ~0, "Largest value for the interval's endpoint"); | ||
19 | 20 | ||
20 | static struct rb_root root = RB_ROOT; | 21 | static struct rb_root root = RB_ROOT; |
21 | static struct interval_tree_node *nodes = NULL; | 22 | static struct interval_tree_node *nodes = NULL; |
@@ -40,18 +41,20 @@ static void init(void) | |||
40 | int i; | 41 | int i; |
41 | 42 | ||
42 | for (i = 0; i < nnodes; i++) { | 43 | for (i = 0; i < nnodes; i++) { |
43 | u32 a = prandom_u32_state(&rnd); | 44 | u32 b = (prandom_u32_state(&rnd) >> 4) % max_endpoint; |
44 | u32 b = prandom_u32_state(&rnd); | 45 | u32 a = (prandom_u32_state(&rnd) >> 4) % b; |
45 | if (a <= b) { | 46 | |
46 | nodes[i].start = a; | 47 | nodes[i].start = a; |
47 | nodes[i].last = b; | 48 | nodes[i].last = b; |
48 | } else { | ||
49 | nodes[i].start = b; | ||
50 | nodes[i].last = a; | ||
51 | } | ||
52 | } | 49 | } |
50 | |||
51 | /* | ||
52 | * Limit the search scope to what the user defined. | ||
53 | * Otherwise we are merely measuring empty walks, | ||
54 | * which is pointless. | ||
55 | */ | ||
53 | for (i = 0; i < nsearches; i++) | 56 | for (i = 0; i < nsearches; i++) |
54 | queries[i] = prandom_u32_state(&rnd); | 57 | queries[i] = (prandom_u32_state(&rnd) >> 4) % max_endpoint; |
55 | } | 58 | } |
56 | 59 | ||
57 | static int interval_tree_test_init(void) | 60 | static int interval_tree_test_init(void) |