diff options
author | Yury Norov <ynorov@caviumnetworks.com> | 2018-02-06 18:38:31 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-02-06 21:32:44 -0500 |
commit | 15ff67bf85c6c02ab7d850deea0199516e8f16a0 (patch) | |
tree | 69383df4c252a1e4dd6ce7a58ba30b891e348e43 /lib/find_bit_benchmark.c | |
parent | dceeb3e7fd5cdafb6b8f70321fc4d994c95c3554 (diff) |
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>
Diffstat (limited to 'lib/find_bit_benchmark.c')
-rw-r--r-- | lib/find_bit_benchmark.c | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/lib/find_bit_benchmark.c b/lib/find_bit_benchmark.c index f4394a36f9aa..67b19233c28f 100644 --- a/lib/find_bit_benchmark.c +++ b/lib/find_bit_benchmark.c | |||
@@ -43,16 +43,15 @@ static DECLARE_BITMAP(bitmap, BITMAP_LEN) __initdata; | |||
43 | static int __init test_find_first_bit(void *bitmap, unsigned long len) | 43 | static int __init test_find_first_bit(void *bitmap, unsigned long len) |
44 | { | 44 | { |
45 | unsigned long i, cnt; | 45 | unsigned long i, cnt; |
46 | cycles_t cycles; | 46 | ktime_t time; |
47 | 47 | ||
48 | cycles = get_cycles(); | 48 | time = ktime_get(); |
49 | for (cnt = i = 0; i < len; cnt++) { | 49 | for (cnt = i = 0; i < len; cnt++) { |
50 | i = find_first_bit(bitmap, len); | 50 | i = find_first_bit(bitmap, len); |
51 | __clear_bit(i, bitmap); | 51 | __clear_bit(i, bitmap); |
52 | } | 52 | } |
53 | cycles = get_cycles() - cycles; | 53 | time = ktime_get() - time; |
54 | pr_err("find_first_bit:\t\t%llu cycles,\t%ld iterations\n", | 54 | pr_err("find_first_bit: %18llu ns, %6ld iterations\n", time, cnt); |
55 | (u64)cycles, cnt); | ||
56 | 55 | ||
57 | return 0; | 56 | return 0; |
58 | } | 57 | } |
@@ -60,14 +59,13 @@ static int __init test_find_first_bit(void *bitmap, unsigned long len) | |||
60 | static int __init test_find_next_bit(const void *bitmap, unsigned long len) | 59 | static int __init test_find_next_bit(const void *bitmap, unsigned long len) |
61 | { | 60 | { |
62 | unsigned long i, cnt; | 61 | unsigned long i, cnt; |
63 | cycles_t cycles; | 62 | ktime_t time; |
64 | 63 | ||
65 | cycles = get_cycles(); | 64 | time = ktime_get(); |
66 | for (cnt = i = 0; i < BITMAP_LEN; cnt++) | 65 | for (cnt = i = 0; i < BITMAP_LEN; cnt++) |
67 | i = find_next_bit(bitmap, BITMAP_LEN, i) + 1; | 66 | i = find_next_bit(bitmap, BITMAP_LEN, i) + 1; |
68 | cycles = get_cycles() - cycles; | 67 | time = ktime_get() - time; |
69 | pr_err("find_next_bit:\t\t%llu cycles,\t%ld iterations\n", | 68 | pr_err("find_next_bit: %18llu ns, %6ld iterations\n", time, cnt); |
70 | (u64)cycles, cnt); | ||
71 | 69 | ||
72 | return 0; | 70 | return 0; |
73 | } | 71 | } |
@@ -75,14 +73,13 @@ static int __init test_find_next_bit(const void *bitmap, unsigned long len) | |||
75 | static int __init test_find_next_zero_bit(const void *bitmap, unsigned long len) | 73 | static int __init test_find_next_zero_bit(const void *bitmap, unsigned long len) |
76 | { | 74 | { |
77 | unsigned long i, cnt; | 75 | unsigned long i, cnt; |
78 | cycles_t cycles; | 76 | ktime_t time; |
79 | 77 | ||
80 | cycles = get_cycles(); | 78 | time = ktime_get(); |
81 | for (cnt = i = 0; i < BITMAP_LEN; cnt++) | 79 | for (cnt = i = 0; i < BITMAP_LEN; cnt++) |
82 | i = find_next_zero_bit(bitmap, len, i) + 1; | 80 | i = find_next_zero_bit(bitmap, len, i) + 1; |
83 | cycles = get_cycles() - cycles; | 81 | time = ktime_get() - time; |
84 | pr_err("find_next_zero_bit:\t%llu cycles,\t%ld iterations\n", | 82 | pr_err("find_next_zero_bit: %18llu ns, %6ld iterations\n", time, cnt); |
85 | (u64)cycles, cnt); | ||
86 | 83 | ||
87 | return 0; | 84 | return 0; |
88 | } | 85 | } |
@@ -90,9 +87,9 @@ static int __init test_find_next_zero_bit(const void *bitmap, unsigned long len) | |||
90 | static int __init test_find_last_bit(const void *bitmap, unsigned long len) | 87 | static int __init test_find_last_bit(const void *bitmap, unsigned long len) |
91 | { | 88 | { |
92 | unsigned long l, cnt = 0; | 89 | unsigned long l, cnt = 0; |
93 | cycles_t cycles; | 90 | ktime_t time; |
94 | 91 | ||
95 | cycles = get_cycles(); | 92 | time = ktime_get(); |
96 | do { | 93 | do { |
97 | cnt++; | 94 | cnt++; |
98 | l = find_last_bit(bitmap, len); | 95 | l = find_last_bit(bitmap, len); |
@@ -100,9 +97,8 @@ static int __init test_find_last_bit(const void *bitmap, unsigned long len) | |||
100 | break; | 97 | break; |
101 | len = l; | 98 | len = l; |
102 | } while (len); | 99 | } while (len); |
103 | cycles = get_cycles() - cycles; | 100 | time = ktime_get() - time; |
104 | pr_err("find_last_bit:\t\t%llu cycles,\t%ld iterations\n", | 101 | pr_err("find_last_bit: %18llu ns, %6ld iterations\n", time, cnt); |
105 | (u64)cycles, cnt); | ||
106 | 102 | ||
107 | return 0; | 103 | return 0; |
108 | } | 104 | } |
@@ -132,13 +128,12 @@ static int __init find_bit_test(void) | |||
132 | test_find_last_bit(bitmap, BITMAP_LEN); | 128 | test_find_last_bit(bitmap, BITMAP_LEN); |
133 | test_find_first_bit(bitmap, BITMAP_LEN); | 129 | test_find_first_bit(bitmap, BITMAP_LEN); |
134 | 130 | ||
135 | return 0; | 131 | /* |
132 | * Everything is OK. Return error just to let user run benchmark | ||
133 | * again without annoying rmmod. | ||
134 | */ | ||
135 | return -EINVAL; | ||
136 | } | 136 | } |
137 | module_init(find_bit_test); | 137 | module_init(find_bit_test); |
138 | 138 | ||
139 | static void __exit test_find_bit_cleanup(void) | ||
140 | { | ||
141 | } | ||
142 | module_exit(test_find_bit_cleanup); | ||
143 | |||
144 | MODULE_LICENSE("GPL"); | 139 | MODULE_LICENSE("GPL"); |