Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lib/find_bit_benchmark.c: improvements

As suggested in review comments:
* printk: align numbers using whitespaces instead of tabs;
* return error value from init() to avoid calling rmmod if testing again;
* use ktime_get instead of get_cycles as some arches don't support it;

The output in dmesg (on QEMU arm64):
[ 38.823430] Start testing find_bit() with random-filled bitmap
[ 38.845358] find_next_bit: 20138448 ns, 163968 iterations
[ 38.856217] find_next_zero_bit: 10615328 ns, 163713 iterations
[ 38.863564] find_last_bit: 7111888 ns, 163967 iterations
[ 40.944796] find_first_bit: 2081007216 ns, 163968 iterations
[ 40.944975]
[ 40.944975] Start testing find_bit() with sparse bitmap
[ 40.945268] find_next_bit: 73216 ns, 656 iterations
[ 40.967858] find_next_zero_bit: 22461008 ns, 327025 iterations
[ 40.968047] find_last_bit: 62320 ns, 656 iterations
[ 40.978060] find_first_bit: 9889360 ns, 656 iterations

Link: http://lkml.kernel.org/r/20171124143040.a44jvhmnaiyedg2i@yury-thinkpad
Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
Tested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Clement Courbet <courbet@google.com>
Cc: Matthew Wilcox <mawilcox@microsoft.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Yury Norov and committed by
Linus Torvalds
15ff67bf dceeb3e7

+21 -26
+21 -26
lib/find_bit_benchmark.c
··· 43 43 static int __init test_find_first_bit(void *bitmap, unsigned long len) 44 44 { 45 45 unsigned long i, cnt; 46 - cycles_t cycles; 46 + ktime_t time; 47 47 48 - cycles = get_cycles(); 48 + time = ktime_get(); 49 49 for (cnt = i = 0; i < len; cnt++) { 50 50 i = find_first_bit(bitmap, len); 51 51 __clear_bit(i, bitmap); 52 52 } 53 - cycles = get_cycles() - cycles; 54 - pr_err("find_first_bit:\t\t%llu cycles,\t%ld iterations\n", 55 - (u64)cycles, cnt); 53 + time = ktime_get() - time; 54 + pr_err("find_first_bit: %18llu ns, %6ld iterations\n", time, cnt); 56 55 57 56 return 0; 58 57 } ··· 59 60 static int __init test_find_next_bit(const void *bitmap, unsigned long len) 60 61 { 61 62 unsigned long i, cnt; 62 - cycles_t cycles; 63 + ktime_t time; 63 64 64 - cycles = get_cycles(); 65 + time = ktime_get(); 65 66 for (cnt = i = 0; i < BITMAP_LEN; cnt++) 66 67 i = find_next_bit(bitmap, BITMAP_LEN, i) + 1; 67 - cycles = get_cycles() - cycles; 68 - pr_err("find_next_bit:\t\t%llu cycles,\t%ld iterations\n", 69 - (u64)cycles, cnt); 68 + time = ktime_get() - time; 69 + pr_err("find_next_bit: %18llu ns, %6ld iterations\n", time, cnt); 70 70 71 71 return 0; 72 72 } ··· 73 75 static int __init test_find_next_zero_bit(const void *bitmap, unsigned long len) 74 76 { 75 77 unsigned long i, cnt; 76 - cycles_t cycles; 78 + ktime_t time; 77 79 78 - cycles = get_cycles(); 80 + time = ktime_get(); 79 81 for (cnt = i = 0; i < BITMAP_LEN; cnt++) 80 82 i = find_next_zero_bit(bitmap, len, i) + 1; 81 - cycles = get_cycles() - cycles; 82 - pr_err("find_next_zero_bit:\t%llu cycles,\t%ld iterations\n", 83 - (u64)cycles, cnt); 83 + time = ktime_get() - time; 84 + pr_err("find_next_zero_bit: %18llu ns, %6ld iterations\n", time, cnt); 84 85 85 86 return 0; 86 87 } ··· 87 90 static int __init test_find_last_bit(const void *bitmap, unsigned long len) 88 91 { 89 92 unsigned long l, cnt = 0; 90 - cycles_t cycles; 93 + ktime_t time; 91 94 92 - cycles = get_cycles(); 95 + time = ktime_get(); 93 96 do { 94 97 cnt++; 95 98 l = find_last_bit(bitmap, len); ··· 97 100 break; 98 101 len = l; 99 102 } while (len); 100 - cycles = get_cycles() - cycles; 101 - pr_err("find_last_bit:\t\t%llu cycles,\t%ld iterations\n", 102 - (u64)cycles, cnt); 103 + time = ktime_get() - time; 104 + pr_err("find_last_bit: %18llu ns, %6ld iterations\n", time, cnt); 103 105 104 106 return 0; 105 107 } ··· 128 132 test_find_last_bit(bitmap, BITMAP_LEN); 129 133 test_find_first_bit(bitmap, BITMAP_LEN); 130 134 131 - return 0; 135 + /* 136 + * Everything is OK. Return error just to let user run benchmark 137 + * again without annoying rmmod. 138 + */ 139 + return -EINVAL; 132 140 } 133 141 module_init(find_bit_test); 134 - 135 - static void __exit test_find_bit_cleanup(void) 136 - { 137 - } 138 - module_exit(test_find_bit_cleanup); 139 142 140 143 MODULE_LICENSE("GPL");