aboutsummaryrefslogtreecommitdiffstats
path: root/lib/interval_tree_test.c
diff options
context:
space:
mode:
authorDavidlohr Bueso <dave@stgolabs.net>2017-07-10 18:51:52 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-07-10 19:32:35 -0400
commitc46ecce431ebe6b1a9551d1f530eb432dae5c39b (patch)
treedcbf05825ef1ab89f8e51381681763f911298d34 /lib/interval_tree_test.c
parenta8ec14d4f6aa8e245efacc992c8ee6ea0464ce2a (diff)
lib/interval_tree_test.c: allow full tree search
... such that a user can specify visiting all the nodes in the tree (intersects with the world). This is a nice opposite from the very basic default query which is a single point. Link: http://lkml.kernel.org/r/20170518174936.20265-5-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.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/interval_tree_test.c b/lib/interval_tree_test.c
index 0fef6364a958..df495fe81421 100644
--- a/lib/interval_tree_test.c
+++ b/lib/interval_tree_test.c
@@ -15,6 +15,7 @@ __param(int, perf_loops, 100000, "Number of iterations modifying the tree");
15 15
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__param(bool, search_all, false, "Searches will iterate all nodes in the tree");
18 19
19__param(uint, max_endpoint, ~0, "Largest value for the interval's endpoint"); 20__param(uint, max_endpoint, ~0, "Largest value for the interval's endpoint");
20 21
@@ -25,13 +26,13 @@ static u32 *queries = NULL;
25static struct rnd_state rnd; 26static struct rnd_state rnd;
26 27
27static inline unsigned long 28static inline unsigned long
28search(unsigned long query, struct rb_root *root) 29search(struct rb_root *root, unsigned long start, unsigned long last)
29{ 30{
30 struct interval_tree_node *node; 31 struct interval_tree_node *node;
31 unsigned long results = 0; 32 unsigned long results = 0;
32 33
33 for (node = interval_tree_iter_first(root, query, query); node; 34 for (node = interval_tree_iter_first(root, start, last); node;
34 node = interval_tree_iter_next(node, query, query)) 35 node = interval_tree_iter_next(node, start, last))
35 results++; 36 results++;
36 return results; 37 return results;
37} 38}
@@ -102,8 +103,12 @@ static int interval_tree_test_init(void)
102 103
103 results = 0; 104 results = 0;
104 for (i = 0; i < search_loops; i++) 105 for (i = 0; i < search_loops; i++)
105 for (j = 0; j < nsearches; j++) 106 for (j = 0; j < nsearches; j++) {
106 results += search(queries[j], &root); 107 unsigned long start = search_all ? 0 : queries[j];
108 unsigned long last = search_all ? max_endpoint : queries[j];
109
110 results += search(&root, start, last);
111 }
107 112
108 time2 = get_cycles(); 113 time2 = get_cycles();
109 time = time2 - time1; 114 time = time2 - time1;