aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/radix-tree/benchmark.c
diff options
context:
space:
mode:
authorRehas Sachdeva <aquannie@gmail.com>2017-02-26 16:17:00 -0500
committerMatthew Wilcox <mawilcox@microsoft.com>2017-03-07 13:18:20 -0500
commit0d4a41c1a0335dc515c6e7fabd447263b57f6457 (patch)
tree48a11b5f0ddb777f21f0897fd7bb710e8e7c0631 /tools/testing/radix-tree/benchmark.c
parentc629a344accd15022dd6d87fa28c8e22f978fbda (diff)
radix tree test suite: Add performance benchmarks
Add performance benchmarks for radix tree insertion, tagging and deletion. Signed-off-by: Rehas Sachdeva <aquannie@gmail.com> Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
Diffstat (limited to 'tools/testing/radix-tree/benchmark.c')
-rw-r--r--tools/testing/radix-tree/benchmark.c82
1 files changed, 75 insertions, 7 deletions
diff --git a/tools/testing/radix-tree/benchmark.c b/tools/testing/radix-tree/benchmark.c
index 9b09ddfe462f..35741b9c2a4a 100644
--- a/tools/testing/radix-tree/benchmark.c
+++ b/tools/testing/radix-tree/benchmark.c
@@ -17,6 +17,9 @@
17#include <time.h> 17#include <time.h>
18#include "test.h" 18#include "test.h"
19 19
20#define for_each_index(i, base, order) \
21 for (i = base; i < base + (1 << order); i++)
22
20#define NSEC_PER_SEC 1000000000L 23#define NSEC_PER_SEC 1000000000L
21 24
22static long long benchmark_iter(struct radix_tree_root *root, bool tagged) 25static long long benchmark_iter(struct radix_tree_root *root, bool tagged)
@@ -57,22 +60,87 @@ again:
57 return nsec; 60 return nsec;
58} 61}
59 62
63static void benchmark_insert(struct radix_tree_root *root,
64 unsigned long size, unsigned long step, int order)
65{
66 struct timespec start, finish;
67 unsigned long index;
68 long long nsec;
69
70 clock_gettime(CLOCK_MONOTONIC, &start);
71
72 for (index = 0 ; index < size ; index += step)
73 item_insert_order(root, index, order);
74
75 clock_gettime(CLOCK_MONOTONIC, &finish);
76
77 nsec = (finish.tv_sec - start.tv_sec) * NSEC_PER_SEC +
78 (finish.tv_nsec - start.tv_nsec);
79
80 printv(2, "Size: %8ld, step: %8ld, order: %d, insertion: %15lld ns\n",
81 size, step, order, nsec);
82}
83
84static void benchmark_tagging(struct radix_tree_root *root,
85 unsigned long size, unsigned long step, int order)
86{
87 struct timespec start, finish;
88 unsigned long index;
89 long long nsec;
90
91 clock_gettime(CLOCK_MONOTONIC, &start);
92
93 for (index = 0 ; index < size ; index += step)
94 radix_tree_tag_set(root, index, 0);
95
96 clock_gettime(CLOCK_MONOTONIC, &finish);
97
98 nsec = (finish.tv_sec - start.tv_sec) * NSEC_PER_SEC +
99 (finish.tv_nsec - start.tv_nsec);
100
101 printv(2, "Size: %8ld, step: %8ld, order: %d, tagging: %17lld ns\n",
102 size, step, order, nsec);
103}
104
105static void benchmark_delete(struct radix_tree_root *root,
106 unsigned long size, unsigned long step, int order)
107{
108 struct timespec start, finish;
109 unsigned long index, i;
110 long long nsec;
111
112 clock_gettime(CLOCK_MONOTONIC, &start);
113
114 for (index = 0 ; index < size ; index += step)
115 for_each_index(i, index, order)
116 item_delete(root, i);
117
118 clock_gettime(CLOCK_MONOTONIC, &finish);
119
120 nsec = (finish.tv_sec - start.tv_sec) * NSEC_PER_SEC +
121 (finish.tv_nsec - start.tv_nsec);
122
123 printv(2, "Size: %8ld, step: %8ld, order: %d, deletion: %16lld ns\n",
124 size, step, order, nsec);
125}
126
60static void benchmark_size(unsigned long size, unsigned long step, int order) 127static void benchmark_size(unsigned long size, unsigned long step, int order)
61{ 128{
62 RADIX_TREE(tree, GFP_KERNEL); 129 RADIX_TREE(tree, GFP_KERNEL);
63 long long normal, tagged; 130 long long normal, tagged;
64 unsigned long index;
65 131
66 for (index = 0 ; index < size ; index += step) { 132 benchmark_insert(&tree, size, step, order);
67 item_insert_order(&tree, index, order); 133 benchmark_tagging(&tree, size, step, order);
68 radix_tree_tag_set(&tree, index, 0);
69 }
70 134
71 tagged = benchmark_iter(&tree, true); 135 tagged = benchmark_iter(&tree, true);
72 normal = benchmark_iter(&tree, false); 136 normal = benchmark_iter(&tree, false);
73 137
74 printv(2, "Size %ld, step %6ld, order %d tagged %10lld ns, normal %10lld ns\n", 138 printv(2, "Size: %8ld, step: %8ld, order: %d, tagged iteration: %8lld ns\n",
75 size, step, order, tagged, normal); 139 size, step, order, tagged);
140 printv(2, "Size: %8ld, step: %8ld, order: %d, normal iteration: %8lld ns\n",
141 size, step, order, normal);
142
143 benchmark_delete(&tree, size, step, order);
76 144
77 item_kill_tree(&tree); 145 item_kill_tree(&tree);
78 rcu_barrier(); 146 rcu_barrier();