diff options
author | Konstantin Khlebnikov <koct9i@gmail.com> | 2016-12-14 18:08:14 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-12-14 19:04:09 -0500 |
commit | cfa40bcfd6fed7010b1633bf127ed8571d3b607e (patch) | |
tree | 1d51776664d8465ac4c45a22072a5c13239cf5c2 | |
parent | ba20cd60c97945f0de9fe313f869b3a5855e1503 (diff) |
radix tree test suite: benchmark for iterator
This adds simple benchmark for iterator similar to one I've used for
commit 78c1d78488a3 ("radix-tree: introduce bit-optimized iterator")
Building with make BENCHMARK=1 set radix tree order to 6, this allows to
get performance comparable to in kernel performance.
Link: http://lkml.kernel.org/r/1480369871-5271-43-git-send-email-mawilcox@linuxonhyperv.com
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
Tested-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: Matthew Wilcox <mawilcox@microsoft.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | tools/testing/radix-tree/Makefile | 6 | ||||
-rw-r--r-- | tools/testing/radix-tree/benchmark.c | 98 | ||||
-rw-r--r-- | tools/testing/radix-tree/linux/kernel.h | 4 | ||||
-rw-r--r-- | tools/testing/radix-tree/main.c | 2 | ||||
-rw-r--r-- | tools/testing/radix-tree/test.h | 1 |
5 files changed, 110 insertions, 1 deletions
diff --git a/tools/testing/radix-tree/Makefile b/tools/testing/radix-tree/Makefile index 3c338dc3b162..08283a841066 100644 --- a/tools/testing/radix-tree/Makefile +++ b/tools/testing/radix-tree/Makefile | |||
@@ -4,7 +4,11 @@ LDFLAGS += -lpthread -lurcu | |||
4 | TARGETS = main | 4 | TARGETS = main |
5 | OFILES = main.o radix-tree.o linux.o test.o tag_check.o find_next_bit.o \ | 5 | OFILES = main.o radix-tree.o linux.o test.o tag_check.o find_next_bit.o \ |
6 | regression1.o regression2.o regression3.o multiorder.o \ | 6 | regression1.o regression2.o regression3.o multiorder.o \ |
7 | iteration_check.o | 7 | iteration_check.o benchmark.o |
8 | |||
9 | ifdef BENCHMARK | ||
10 | CFLAGS += -DBENCHMARK=1 | ||
11 | endif | ||
8 | 12 | ||
9 | targets: $(TARGETS) | 13 | targets: $(TARGETS) |
10 | 14 | ||
diff --git a/tools/testing/radix-tree/benchmark.c b/tools/testing/radix-tree/benchmark.c new file mode 100644 index 000000000000..215ca86c7605 --- /dev/null +++ b/tools/testing/radix-tree/benchmark.c | |||
@@ -0,0 +1,98 @@ | |||
1 | /* | ||
2 | * benchmark.c: | ||
3 | * Author: Konstantin Khlebnikov <koct9i@gmail.com> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms and conditions of the GNU General Public License, | ||
7 | * version 2, as published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
12 | * more details. | ||
13 | */ | ||
14 | #include <linux/radix-tree.h> | ||
15 | #include <linux/slab.h> | ||
16 | #include <linux/errno.h> | ||
17 | #include <time.h> | ||
18 | #include "test.h" | ||
19 | |||
20 | #define NSEC_PER_SEC 1000000000L | ||
21 | |||
22 | static long long benchmark_iter(struct radix_tree_root *root, bool tagged) | ||
23 | { | ||
24 | volatile unsigned long sink = 0; | ||
25 | struct radix_tree_iter iter; | ||
26 | struct timespec start, finish; | ||
27 | long long nsec; | ||
28 | int l, loops = 1; | ||
29 | void **slot; | ||
30 | |||
31 | #ifdef BENCHMARK | ||
32 | again: | ||
33 | #endif | ||
34 | clock_gettime(CLOCK_MONOTONIC, &start); | ||
35 | for (l = 0; l < loops; l++) { | ||
36 | if (tagged) { | ||
37 | radix_tree_for_each_tagged(slot, root, &iter, 0, 0) | ||
38 | sink ^= (unsigned long)slot; | ||
39 | } else { | ||
40 | radix_tree_for_each_slot(slot, root, &iter, 0) | ||
41 | sink ^= (unsigned long)slot; | ||
42 | } | ||
43 | } | ||
44 | clock_gettime(CLOCK_MONOTONIC, &finish); | ||
45 | |||
46 | nsec = (finish.tv_sec - start.tv_sec) * NSEC_PER_SEC + | ||
47 | (finish.tv_nsec - start.tv_nsec); | ||
48 | |||
49 | #ifdef BENCHMARK | ||
50 | if (loops == 1 && nsec * 5 < NSEC_PER_SEC) { | ||
51 | loops = NSEC_PER_SEC / nsec / 4 + 1; | ||
52 | goto again; | ||
53 | } | ||
54 | #endif | ||
55 | |||
56 | nsec /= loops; | ||
57 | return nsec; | ||
58 | } | ||
59 | |||
60 | static void benchmark_size(unsigned long size, unsigned long step, int order) | ||
61 | { | ||
62 | RADIX_TREE(tree, GFP_KERNEL); | ||
63 | long long normal, tagged; | ||
64 | unsigned long index; | ||
65 | |||
66 | for (index = 0 ; index < size ; index += step) { | ||
67 | item_insert_order(&tree, index, order); | ||
68 | radix_tree_tag_set(&tree, index, 0); | ||
69 | } | ||
70 | |||
71 | tagged = benchmark_iter(&tree, true); | ||
72 | normal = benchmark_iter(&tree, false); | ||
73 | |||
74 | printf("Size %ld, step %6ld, order %d tagged %10lld ns, normal %10lld ns\n", | ||
75 | size, step, order, tagged, normal); | ||
76 | |||
77 | item_kill_tree(&tree); | ||
78 | rcu_barrier(); | ||
79 | } | ||
80 | |||
81 | void benchmark(void) | ||
82 | { | ||
83 | unsigned long size[] = {1 << 10, 1 << 20, 0}; | ||
84 | unsigned long step[] = {1, 2, 7, 15, 63, 64, 65, | ||
85 | 128, 256, 512, 12345, 0}; | ||
86 | int c, s; | ||
87 | |||
88 | printf("starting benchmarks\n"); | ||
89 | printf("RADIX_TREE_MAP_SHIFT = %d\n", RADIX_TREE_MAP_SHIFT); | ||
90 | |||
91 | for (c = 0; size[c]; c++) | ||
92 | for (s = 0; step[s]; s++) | ||
93 | benchmark_size(size[c], step[s], 0); | ||
94 | |||
95 | for (c = 0; size[c]; c++) | ||
96 | for (s = 0; step[s]; s++) | ||
97 | benchmark_size(size[c], step[s] << 9, 9); | ||
98 | } | ||
diff --git a/tools/testing/radix-tree/linux/kernel.h b/tools/testing/radix-tree/linux/kernel.h index be98a47b4e1b..dbe4b92806b8 100644 --- a/tools/testing/radix-tree/linux/kernel.h +++ b/tools/testing/radix-tree/linux/kernel.h | |||
@@ -10,7 +10,11 @@ | |||
10 | #include "../../include/linux/compiler.h" | 10 | #include "../../include/linux/compiler.h" |
11 | #include "../../../include/linux/kconfig.h" | 11 | #include "../../../include/linux/kconfig.h" |
12 | 12 | ||
13 | #ifdef BENCHMARK | ||
14 | #define RADIX_TREE_MAP_SHIFT 6 | ||
15 | #else | ||
13 | #define RADIX_TREE_MAP_SHIFT 3 | 16 | #define RADIX_TREE_MAP_SHIFT 3 |
17 | #endif | ||
14 | 18 | ||
15 | #ifndef NULL | 19 | #ifndef NULL |
16 | #define NULL 0 | 20 | #define NULL 0 |
diff --git a/tools/testing/radix-tree/main.c b/tools/testing/radix-tree/main.c index 2eb694994497..f1d1e3bd9464 100644 --- a/tools/testing/radix-tree/main.c +++ b/tools/testing/radix-tree/main.c | |||
@@ -352,6 +352,8 @@ int main(int argc, char **argv) | |||
352 | /* Free any remaining preallocated nodes */ | 352 | /* Free any remaining preallocated nodes */ |
353 | radix_tree_cpu_dead(0); | 353 | radix_tree_cpu_dead(0); |
354 | 354 | ||
355 | benchmark(); | ||
356 | |||
355 | sleep(1); | 357 | sleep(1); |
356 | printf("after sleep(1): %d allocated, preempt %d\n", | 358 | printf("after sleep(1): %d allocated, preempt %d\n", |
357 | nr_allocated, preempt_count); | 359 | nr_allocated, preempt_count); |
diff --git a/tools/testing/radix-tree/test.h b/tools/testing/radix-tree/test.h index 5d2fad05b263..215ab77a56e3 100644 --- a/tools/testing/radix-tree/test.h +++ b/tools/testing/radix-tree/test.h | |||
@@ -28,6 +28,7 @@ void item_kill_tree(struct radix_tree_root *root); | |||
28 | void tag_check(void); | 28 | void tag_check(void); |
29 | void multiorder_checks(void); | 29 | void multiorder_checks(void); |
30 | void iteration_test(void); | 30 | void iteration_test(void); |
31 | void benchmark(void); | ||
31 | 32 | ||
32 | struct item * | 33 | struct item * |
33 | item_tag_set(struct radix_tree_root *root, unsigned long index, int tag); | 34 | item_tag_set(struct radix_tree_root *root, unsigned long index, int tag); |