aboutsummaryrefslogtreecommitdiffstats
path: root/lib/find_bit_benchmark.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/find_bit_benchmark.c')
-rw-r--r--lib/find_bit_benchmark.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/find_bit_benchmark.c b/lib/find_bit_benchmark.c
index 67b19233c28f..5985a25e6cbc 100644
--- a/lib/find_bit_benchmark.c
+++ b/lib/find_bit_benchmark.c
@@ -35,6 +35,7 @@
35#define SPARSE 500 35#define SPARSE 500
36 36
37static DECLARE_BITMAP(bitmap, BITMAP_LEN) __initdata; 37static DECLARE_BITMAP(bitmap, BITMAP_LEN) __initdata;
38static DECLARE_BITMAP(bitmap2, BITMAP_LEN) __initdata;
38 39
39/* 40/*
40 * This is Schlemiel the Painter's algorithm. It should be called after 41 * This is Schlemiel the Painter's algorithm. It should be called after
@@ -103,6 +104,22 @@ static int __init test_find_last_bit(const void *bitmap, unsigned long len)
103 return 0; 104 return 0;
104} 105}
105 106
107static int __init test_find_next_and_bit(const void *bitmap,
108 const void *bitmap2, unsigned long len)
109{
110 unsigned long i, cnt;
111 cycles_t cycles;
112
113 cycles = get_cycles();
114 for (cnt = i = 0; i < BITMAP_LEN; cnt++)
115 i = find_next_and_bit(bitmap, bitmap2, BITMAP_LEN, i+1);
116 cycles = get_cycles() - cycles;
117 pr_err("find_next_and_bit:\t\t%llu cycles, %ld iterations\n",
118 (u64)cycles, cnt);
119
120 return 0;
121}
122
106static int __init find_bit_test(void) 123static int __init find_bit_test(void)
107{ 124{
108 unsigned long nbits = BITMAP_LEN / SPARSE; 125 unsigned long nbits = BITMAP_LEN / SPARSE;
@@ -110,23 +127,29 @@ static int __init find_bit_test(void)
110 pr_err("\nStart testing find_bit() with random-filled bitmap\n"); 127 pr_err("\nStart testing find_bit() with random-filled bitmap\n");
111 128
112 get_random_bytes(bitmap, sizeof(bitmap)); 129 get_random_bytes(bitmap, sizeof(bitmap));
130 get_random_bytes(bitmap2, sizeof(bitmap2));
113 131
114 test_find_next_bit(bitmap, BITMAP_LEN); 132 test_find_next_bit(bitmap, BITMAP_LEN);
115 test_find_next_zero_bit(bitmap, BITMAP_LEN); 133 test_find_next_zero_bit(bitmap, BITMAP_LEN);
116 test_find_last_bit(bitmap, BITMAP_LEN); 134 test_find_last_bit(bitmap, BITMAP_LEN);
117 test_find_first_bit(bitmap, BITMAP_LEN); 135 test_find_first_bit(bitmap, BITMAP_LEN);
136 test_find_next_and_bit(bitmap, bitmap2, BITMAP_LEN);
118 137
119 pr_err("\nStart testing find_bit() with sparse bitmap\n"); 138 pr_err("\nStart testing find_bit() with sparse bitmap\n");
120 139
121 bitmap_zero(bitmap, BITMAP_LEN); 140 bitmap_zero(bitmap, BITMAP_LEN);
141 bitmap_zero(bitmap2, BITMAP_LEN);
122 142
123 while (nbits--) 143 while (nbits--) {
124 __set_bit(prandom_u32() % BITMAP_LEN, bitmap); 144 __set_bit(prandom_u32() % BITMAP_LEN, bitmap);
145 __set_bit(prandom_u32() % BITMAP_LEN, bitmap2);
146 }
125 147
126 test_find_next_bit(bitmap, BITMAP_LEN); 148 test_find_next_bit(bitmap, BITMAP_LEN);
127 test_find_next_zero_bit(bitmap, BITMAP_LEN); 149 test_find_next_zero_bit(bitmap, BITMAP_LEN);
128 test_find_last_bit(bitmap, BITMAP_LEN); 150 test_find_last_bit(bitmap, BITMAP_LEN);
129 test_find_first_bit(bitmap, BITMAP_LEN); 151 test_find_first_bit(bitmap, BITMAP_LEN);
152 test_find_next_and_bit(bitmap, bitmap2, BITMAP_LEN);
130 153
131 /* 154 /*
132 * Everything is OK. Return error just to let user run benchmark 155 * Everything is OK. Return error just to let user run benchmark