-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 \
maple: $(CORE_OFILES)
+ma_xa_benchmark: ma_xa_benchmark.o $(CORE_OFILES)
+
multiorder: multiorder.o $(CORE_OFILES)
clean:
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)" > \
--- /dev/null
+// 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;
+}