]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
radix tree test suite: benchmark for iterator
authorKonstantin Khlebnikov <koct9i@gmail.com>
Wed, 14 Dec 2016 23:08:14 +0000 (15:08 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 15 Dec 2016 00:04:09 +0000 (16:04 -0800)
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>
tools/testing/radix-tree/Makefile
tools/testing/radix-tree/benchmark.c [new file with mode: 0644]
tools/testing/radix-tree/linux/kernel.h
tools/testing/radix-tree/main.c
tools/testing/radix-tree/test.h

index 3c338dc3b162be900efa93055b4b5d7205eeddcf..08283a8410669be9d847d173620802feacc54b62 100644 (file)
@@ -4,7 +4,11 @@ LDFLAGS += -lpthread -lurcu
 TARGETS = main
 OFILES = main.o radix-tree.o linux.o test.o tag_check.o find_next_bit.o \
         regression1.o regression2.o regression3.o multiorder.o \
-        iteration_check.o
+        iteration_check.o benchmark.o
+
+ifdef BENCHMARK
+       CFLAGS += -DBENCHMARK=1
+endif
 
 targets: $(TARGETS)
 
diff --git a/tools/testing/radix-tree/benchmark.c b/tools/testing/radix-tree/benchmark.c
new file mode 100644 (file)
index 0000000..215ca86
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * benchmark.c:
+ * Author: Konstantin Khlebnikov <koct9i@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+#include <linux/radix-tree.h>
+#include <linux/slab.h>
+#include <linux/errno.h>
+#include <time.h>
+#include "test.h"
+
+#define NSEC_PER_SEC   1000000000L
+
+static long long benchmark_iter(struct radix_tree_root *root, bool tagged)
+{
+       volatile unsigned long sink = 0;
+       struct radix_tree_iter iter;
+       struct timespec start, finish;
+       long long nsec;
+       int l, loops = 1;
+       void **slot;
+
+#ifdef BENCHMARK
+again:
+#endif
+       clock_gettime(CLOCK_MONOTONIC, &start);
+       for (l = 0; l < loops; l++) {
+               if (tagged) {
+                       radix_tree_for_each_tagged(slot, root, &iter, 0, 0)
+                               sink ^= (unsigned long)slot;
+               } else {
+                       radix_tree_for_each_slot(slot, root, &iter, 0)
+                               sink ^= (unsigned long)slot;
+               }
+       }
+       clock_gettime(CLOCK_MONOTONIC, &finish);
+
+       nsec = (finish.tv_sec - start.tv_sec) * NSEC_PER_SEC +
+              (finish.tv_nsec - start.tv_nsec);
+
+#ifdef BENCHMARK
+       if (loops == 1 && nsec * 5 < NSEC_PER_SEC) {
+               loops = NSEC_PER_SEC / nsec / 4 + 1;
+               goto again;
+       }
+#endif
+
+       nsec /= loops;
+       return nsec;
+}
+
+static void benchmark_size(unsigned long size, unsigned long step, int order)
+{
+       RADIX_TREE(tree, GFP_KERNEL);
+       long long normal, tagged;
+       unsigned long index;
+
+       for (index = 0 ; index < size ; index += step) {
+               item_insert_order(&tree, index, order);
+               radix_tree_tag_set(&tree, index, 0);
+       }
+
+       tagged = benchmark_iter(&tree, true);
+       normal = benchmark_iter(&tree, false);
+
+       printf("Size %ld, step %6ld, order %d tagged %10lld ns, normal %10lld ns\n",
+               size, step, order, tagged, normal);
+
+       item_kill_tree(&tree);
+       rcu_barrier();
+}
+
+void benchmark(void)
+{
+       unsigned long size[] = {1 << 10, 1 << 20, 0};
+       unsigned long step[] = {1, 2, 7, 15, 63, 64, 65,
+                               128, 256, 512, 12345, 0};
+       int c, s;
+
+       printf("starting benchmarks\n");
+       printf("RADIX_TREE_MAP_SHIFT = %d\n", RADIX_TREE_MAP_SHIFT);
+
+       for (c = 0; size[c]; c++)
+               for (s = 0; step[s]; s++)
+                       benchmark_size(size[c], step[s], 0);
+
+       for (c = 0; size[c]; c++)
+               for (s = 0; step[s]; s++)
+                       benchmark_size(size[c], step[s] << 9, 9);
+}
index be98a47b4e1b3be99b32c856d1dddf6a97c1e62e..dbe4b92806b822488f15fb023fb9292953819bd3 100644 (file)
 #include "../../include/linux/compiler.h"
 #include "../../../include/linux/kconfig.h"
 
+#ifdef BENCHMARK
+#define RADIX_TREE_MAP_SHIFT   6
+#else
 #define RADIX_TREE_MAP_SHIFT   3
+#endif
 
 #ifndef NULL
 #define NULL   0
index 2eb6949944977f7688c1fffe258dc0f05781e470..f1d1e3bd9464fec18d2538e144e0f96689baf584 100644 (file)
@@ -352,6 +352,8 @@ int main(int argc, char **argv)
        /* Free any remaining preallocated nodes */
        radix_tree_cpu_dead(0);
 
+       benchmark();
+
        sleep(1);
        printf("after sleep(1): %d allocated, preempt %d\n",
                nr_allocated, preempt_count);
index 5d2fad05b263cc28b95cb3a53b12a1a68ca9cca1..215ab77a56e385747d480d09de4c4d850b182304 100644 (file)
@@ -28,6 +28,7 @@ void item_kill_tree(struct radix_tree_root *root);
 void tag_check(void);
 void multiorder_checks(void);
 void iteration_test(void);
+void benchmark(void);
 
 struct item *
 item_tag_set(struct radix_tree_root *root, unsigned long index, int tag);