From 2f9148a592c6ab10f6b0b8ef45fff86c4aa24b90 Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Fri, 8 Mar 2019 13:54:13 -0500 Subject: [PATCH] ma_xa_benchmark: Update time calculations Time calculations were prone to overflow because seconds were not included. Signed-off-by: Liam R. Howlett --- tools/testing/radix-tree/ma_xa_benchmark.c | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tools/testing/radix-tree/ma_xa_benchmark.c b/tools/testing/radix-tree/ma_xa_benchmark.c index f40cb1e58399..2a6ce73d9ee1 100644 --- a/tools/testing/radix-tree/ma_xa_benchmark.c +++ b/tools/testing/radix-tree/ma_xa_benchmark.c @@ -27,13 +27,12 @@ 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; + double xa_t = 0, mt_t; + unsigned long xa_m = 0, mt_m; void *entry = &main; unsigned long i, max = 200000; struct rusage sru, eru; - /* xarray first */ radix_tree_init(); DEFINE_XARRAY(xa); @@ -44,13 +43,13 @@ int __weak main(void) } getrusage(RUSAGE_SELF, &eru); - start = sru.ru_utime.tv_usec; - end = eru.ru_utime.tv_usec; + start = sru.ru_utime.tv_usec + sru.ru_utime.tv_sec * 1000000; + end = eru.ru_utime.tv_usec + eru.ru_utime.tv_sec * 1000000; for (i = 0; i <= max; i++) { BUG_ON(entry != xa_load(&xa, i)); } rcu_barrier(); - xa_t = ((double) (end - start)) / CLOCKS_PER_SEC; + xa_t = ((double) (end - start)) / 1000000; 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); @@ -64,28 +63,29 @@ int __weak main(void) /* Maple Tree tests*/ maple_tree_init(); DEFINE_MTREE(mt); - getrusage(RUSAGE_SELF, &sru); for (i = 0; i <= max; i++) { mtree_insert(&mt, i, entry, GFP_KERNEL); } + getrusage(RUSAGE_SELF, &eru); - start = sru.ru_utime.tv_usec; - end = eru.ru_utime.tv_usec; + start = sru.ru_utime.tv_usec + sru.ru_utime.tv_sec * 1000000; + end = eru.ru_utime.tv_usec + eru.ru_utime.tv_sec * 1000000; for (i = 0; i <= max; i++) { BUG_ON(entry != mtree_load(&mt, i)); } rcu_barrier(); - mt_t = ((double) (end - start)) / CLOCKS_PER_SEC; + mt_t = ((double) (end - start))/1000000; 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); -// mt_dump(&mt); mtree_destroy(&mt); - printk(" Delta : %f (%f%% of xa time) %ldK\n", - xa_t - mt_t, mt_t/xa_t * 100, - (signed long)(xa_m - mt_m)/1024); rcu_barrier(); + printk(" Delta : %f seconds (%f%% of xa time) %ldK\n", + mt_t - xa_t, mt_t/xa_t * 100, + (signed long)(mt_m - xa_m)/1024); + rcu_barrier(); + BUG_ON(nr_allocated); return 0; } -- 2.50.1