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

lib/raid6: skip benchmark of non-chosen xor_syndrome functions

In commit fe5cbc6e06c7 ("md/raid6 algorithms: delta syndrome functions")
a xor_syndrome() benchmarking was added also to the raid6_choose_gen()
function. However, the results of that benchmarking were intentionally
discarded and did not influence the choice. It picked the
xor_syndrome() variant related to the best performing gen_syndrome().

Reduce runtime of raid6_choose_gen() without modifying its outcome by
only benchmarking the xor_syndrome() of the best gen_syndrome() variant.

For a HZ=250 x86_64 system with avx2 and without avx512 this removes
5 out of 6 xor() benchmarks, saving 340ms of raid6 initialization time.

Signed-off-by: Dirk Müller <dmueller@suse.de>
Signed-off-by: Song Liu <song@kernel.org>

authored by

Dirk Müller and committed by
Song Liu
38640c48 dd3dc5f4

+40 -42
+40 -42
lib/raid6/algos.c
··· 145 145 static inline const struct raid6_calls *raid6_choose_gen( 146 146 void *(*const dptrs)[RAID6_TEST_DISKS], const int disks) 147 147 { 148 - unsigned long perf, bestgenperf, bestxorperf, j0, j1; 148 + unsigned long perf, bestgenperf, j0, j1; 149 149 int start = (disks>>1)-1, stop = disks-3; /* work on the second half of the disks */ 150 150 const struct raid6_calls *const *algo; 151 151 const struct raid6_calls *best; 152 152 153 - for (bestgenperf = 0, bestxorperf = 0, best = NULL, algo = raid6_algos; *algo; algo++) { 153 + for (bestgenperf = 0, best = NULL, algo = raid6_algos; *algo; algo++) { 154 154 if (!best || (*algo)->prefer >= best->prefer) { 155 155 if ((*algo)->valid && !(*algo)->valid()) 156 156 continue; ··· 180 180 pr_info("raid6: %-8s gen() %5ld MB/s\n", (*algo)->name, 181 181 (perf * HZ * (disks-2)) >> 182 182 (20 - PAGE_SHIFT + RAID6_TIME_JIFFIES_LG2)); 183 - 184 - if (!(*algo)->xor_syndrome) 185 - continue; 186 - 187 - perf = 0; 188 - 189 - preempt_disable(); 190 - j0 = jiffies; 191 - while ((j1 = jiffies) == j0) 192 - cpu_relax(); 193 - while (time_before(jiffies, 194 - j1 + (1<<RAID6_TIME_JIFFIES_LG2))) { 195 - (*algo)->xor_syndrome(disks, start, stop, 196 - PAGE_SIZE, *dptrs); 197 - perf++; 198 - } 199 - preempt_enable(); 200 - 201 - if (best == *algo) 202 - bestxorperf = perf; 203 - 204 - pr_info("raid6: %-8s xor() %5ld MB/s\n", (*algo)->name, 205 - (perf * HZ * (disks-2)) >> 206 - (20 - PAGE_SHIFT + RAID6_TIME_JIFFIES_LG2 + 1)); 207 183 } 208 184 } 209 185 210 - if (best) { 211 - if (IS_ENABLED(CONFIG_RAID6_PQ_BENCHMARK)) { 212 - pr_info("raid6: using algorithm %s gen() %ld MB/s\n", 213 - best->name, 214 - (bestgenperf * HZ * (disks-2)) >> 215 - (20 - PAGE_SHIFT+RAID6_TIME_JIFFIES_LG2)); 216 - if (best->xor_syndrome) 217 - pr_info("raid6: .... xor() %ld MB/s, rmw enabled\n", 218 - (bestxorperf * HZ * (disks-2)) >> 219 - (20 - PAGE_SHIFT + RAID6_TIME_JIFFIES_LG2 + 1)); 220 - } else 221 - pr_info("raid6: skip pq benchmark and using algorithm %s\n", 222 - best->name); 223 - raid6_call = *best; 224 - } else 225 - pr_err("raid6: Yikes! No algorithm found!\n"); 186 + if (!best) { 187 + pr_err("raid6: Yikes! No algorithm found!\n"); 188 + goto out; 189 + } 226 190 191 + raid6_call = *best; 192 + 193 + if (!IS_ENABLED(CONFIG_RAID6_PQ_BENCHMARK)) { 194 + pr_info("raid6: skipped pq benchmark and selected %s\n", 195 + best->name); 196 + goto out; 197 + } 198 + 199 + pr_info("raid6: using algorithm %s gen() %ld MB/s\n", 200 + best->name, 201 + (bestgenperf * HZ * (disks - 2)) >> 202 + (20 - PAGE_SHIFT + RAID6_TIME_JIFFIES_LG2)); 203 + 204 + if (best->xor_syndrome) { 205 + perf = 0; 206 + 207 + preempt_disable(); 208 + j0 = jiffies; 209 + while ((j1 = jiffies) == j0) 210 + cpu_relax(); 211 + while (time_before(jiffies, 212 + j1 + (1 << RAID6_TIME_JIFFIES_LG2))) { 213 + best->xor_syndrome(disks, start, stop, 214 + PAGE_SIZE, *dptrs); 215 + perf++; 216 + } 217 + preempt_enable(); 218 + 219 + pr_info("raid6: .... xor() %ld MB/s, rmw enabled\n", 220 + (perf * HZ * (disks - 2)) >> 221 + (20 - PAGE_SHIFT + RAID6_TIME_JIFFIES_LG2 + 1)); 222 + } 223 + 224 + out: 227 225 return best; 228 226 } 229 227