]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
ma_xa_benchmark: Initial push
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 5 Feb 2019 17:30:13 +0000 (12:30 -0500)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Wed, 31 Jul 2019 14:52:39 +0000 (10:52 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
include/linux/maple_tree.h
lib/maple_tree.c
lib/test_maple_tree.c
lib/xarray.c
tools/testing/radix-tree/.gitignore
tools/testing/radix-tree/Makefile
tools/testing/radix-tree/linux.c
tools/testing/radix-tree/ma_xa_benchmark.c [new file with mode: 0644]

index 3de603ee86310e3857513c645edafa4808982639..5481cf0186a741f533f3a4534b206946369aa793 100644 (file)
@@ -240,4 +240,5 @@ void *mas_find(struct ma_state *, unsigned long max);
 
 bool mas_nomem(struct ma_state *, gfp_t);
 void mas_pause(struct ma_state *);
+void maple_tree_init(void);
 #endif
index bf062e01f4cddbe8bed5c7a18b7f921c5f5c8512..83600a0ba7d39cd2bd5c0a8d33461f0252a0be3b 100644 (file)
@@ -1294,4 +1294,10 @@ void mt_set_non_kernel(unsigned int val)
 {
        kmem_cache_set_non_kernel(maple_node_cache, val);
 }
+
+extern unsigned long kmem_cache_get_alloc(struct kmem_cache *);
+unsigned long mt_get_alloc_size(void)
+{
+       return kmem_cache_get_alloc(maple_node_cache);
+}
 #endif
index 418556a3976a3f10ccca35866db18d2cbdce4c84..721087b9f8fd71afdaa967943b6250efc8e1ff74 100644 (file)
@@ -207,8 +207,12 @@ static noinline void check_seq(struct maple_tree *mt, unsigned long max,
                }
                check_load(mt, i + 1, NULL);
        }
-       if (verbose)
+       if (verbose) {
+               rcu_barrier();
                mt_dump(mt);
+               printk(" seq test of 0-%lu used %luK in %d allocations\n",
+                       max, mt_get_alloc_size()/1024, nr_allocated);
+       }
        mtree_destroy(mt);
 }
 
index 446b956c918888d06dfca776d00aed8f3c2e54de..999302144839d64381804ec1d9b9d769635fbaf4 100644 (file)
@@ -2057,4 +2057,10 @@ void xa_dump(const struct xarray *xa)
                shift = xa_to_node(entry)->shift + XA_CHUNK_SHIFT;
        xa_dump_entry(entry, 0, shift);
 }
+
+extern unsigned long kmem_cache_get_alloc(struct kmem_cache *);
+unsigned long xa_get_alloc_size(void)
+{
+       return kmem_cache_get_alloc(radix_tree_node_cachep);
+}
 #endif
index 0a26b3850a46d6e0997a4c70c7639d66a1baf2e0..85216f7d7b1527f68c1b65987a2f82d4aa67ceaf 100644 (file)
@@ -6,3 +6,4 @@ multiorder
 radix-tree.c
 xarray
 maple
+ma_xa_benchmark
index 0aad7e2ec4c9faab9c2c467b38007e7fb5448d63..018f7c3426fa86ab42b58d9d2a08cf2901b2b17c 100644 (file)
@@ -4,7 +4,7 @@ CFLAGS += -I. -I../../include -g -Og -Wall -D_LGPL_SOURCE -fsanitize=address \
          -fsanitize=undefined
 LDFLAGS += -fsanitize=address -fsanitize=undefined
 LDLIBS+= -lpthread -lurcu
-TARGETS = main idr-test multiorder xarray maple
+TARGETS = main idr-test multiorder xarray maple ma_xa_benchmark
 CORE_OFILES := xarray.o radix-tree.o idr.o linux.o test.o find_bit.o bitmap.o maple.o
 OFILES = main.o $(CORE_OFILES) regression1.o regression2.o regression3.o \
         regression4.o \
@@ -30,6 +30,8 @@ xarray: $(CORE_OFILES)
 
 maple: $(CORE_OFILES)
 
+ma_xa_benchmark: ma_xa_benchmark.o $(CORE_OFILES)
+
 multiorder: multiorder.o $(CORE_OFILES)
 
 clean:
@@ -55,6 +57,8 @@ xarray.o: ../../../lib/xarray.c ../../../lib/test_xarray.c
 
 maple.o: ../../../lib/maple_tree.c ../../../lib/test_maple_tree.c
 
+ma_xa_benchmark.o:
+
 generated/map-shift.h:
        @if ! grep -qws $(SHIFT) generated/map-shift.h; then            \
                echo "#define XA_CHUNK_SHIFT $(SHIFT)" >                \
index c9937c9f002ea4182894b7425bdcbc558f41dcf1..54f3d6cea0ebaa0a3dc2beb064a87aa7becbc709 100644 (file)
@@ -32,6 +32,10 @@ void kmem_cache_set_non_kernel(struct kmem_cache *cachep, unsigned int val)
        cachep->non_kernel = val;
 }
 
+unsigned long kmem_cache_get_alloc(struct kmem_cache *cachep)
+{
+       return cachep->size * nr_allocated;
+}
 void *kmem_cache_alloc(struct kmem_cache *cachep, int gfp)
 {
        void *p;
diff --git a/tools/testing/radix-tree/ma_xa_benchmark.c b/tools/testing/radix-tree/ma_xa_benchmark.c
new file mode 100644 (file)
index 0000000..91f2ae7
--- /dev/null
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * ma_rdx_time.c: userspace time test of maple tree and radix tree.
+ * Copyright (c) 2019 Liam R. Howlett <Liam.Howlett@Oracle.com>
+ */
+
+#define MT_DEBUG
+#define XA_DEBUG
+#include "test.h"
+#include <time.h>
+
+#define module_init(x)
+#define module_exit(x)
+#define MODULE_AUTHOR(x)
+#define MODULE_LICENSE(x)
+#define dump_stack()   assert(0)
+
+#include <linux/maple_tree.h>
+#include <linux/xarray.h>
+
+
+
+extern unsigned long xa_get_alloc_size(void);
+extern unsigned long mt_get_alloc_size(void);
+
+int __weak main(void)
+{
+       clock_t start, end;
+       double xa_t, mt_t;
+       unsigned long xa_m, mt_m;
+       void *entry;
+       unsigned long i, max = 100000;
+
+
+       radix_tree_init();
+       DEFINE_XARRAY(xa);
+       entry = &xa;
+
+       start = clock();
+       for (i = 0; i <= max; i++) {
+               xa_store(&xa, i, entry, GFP_KERNEL);
+       }
+       end = clock();
+
+       for (i = 0; i <= max; i++) {
+               BUG_ON(entry != xa_load(&xa, i));
+       }
+       /*  xarray first */
+       xa_t = ((double) (end - start)) / CLOCKS_PER_SEC;
+       xa_m = xa_get_alloc_size();
+       printk("xa %lu inserts: %fs using %luK in %d allocations\n",
+               max, xa_t, xa_m/1024, nr_allocated);
+
+
+       xa_destroy(&xa);
+       radix_tree_cpu_dead(1);
+       rcu_barrier();
+       BUG_ON(nr_allocated);
+
+       /* Maple Tree tests*/
+       maple_tree_init();
+       DEFINE_MTREE(mt);
+
+       start = clock();
+       for (i = 0; i <= max; i++) {
+               mtree_insert(&mt, i, entry, GFP_KERNEL);
+       }
+       end = clock();
+       for (i = 0; i <= max; i++) {
+               BUG_ON(entry != mtree_load(&mt, i));
+       }
+
+       /*  xarray first */
+       mt_t = ((double) (end - start)) / CLOCKS_PER_SEC;
+       mt_m = mt_get_alloc_size();
+       printk("mt %lu inserts: %fs using %luK in %d allocations\n",
+               max, mt_t, mt_m/1024, nr_allocated);
+       mtree_destroy(&mt);
+       printk(" Delta : %f (%f%%)\n", xa_t - mt_t, (xa_t - mt_t)/(xa_t + mt_t) * 100);
+       rcu_barrier();
+       if (nr_allocated)
+               printf("nr_allocated = %d\n", nr_allocated);
+       printk("Done\n");
+       return 0;
+}