| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* -*- linux-c -*- ------------------------------------------------------- * |
|---|
| 2 | 3 | * |
|---|
| 3 | 4 | * Copyright 2002 H. Peter Anvin - All Rights Reserved |
|---|
| 4 | | - * |
|---|
| 5 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 6 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 7 | | - * the Free Software Foundation, Inc., 53 Temple Place Ste 330, |
|---|
| 8 | | - * Boston MA 02111-1307, USA; either version 2 of the License, or |
|---|
| 9 | | - * (at your option) any later version; incorporated herein by reference. |
|---|
| 10 | 5 | * |
|---|
| 11 | 6 | * ----------------------------------------------------------------------- */ |
|---|
| 12 | 7 | |
|---|
| .. | .. |
|---|
| 34 | 29 | EXPORT_SYMBOL_GPL(raid6_call); |
|---|
| 35 | 30 | |
|---|
| 36 | 31 | const struct raid6_calls * const raid6_algos[] = { |
|---|
| 37 | | -#if defined(__ia64__) |
|---|
| 38 | | - &raid6_intx16, |
|---|
| 39 | | - &raid6_intx32, |
|---|
| 40 | | -#endif |
|---|
| 41 | 32 | #if defined(__i386__) && !defined(__arch_um__) |
|---|
| 42 | | - &raid6_mmxx1, |
|---|
| 43 | | - &raid6_mmxx2, |
|---|
| 44 | | - &raid6_sse1x1, |
|---|
| 45 | | - &raid6_sse1x2, |
|---|
| 46 | | - &raid6_sse2x1, |
|---|
| 47 | | - &raid6_sse2x2, |
|---|
| 48 | | -#ifdef CONFIG_AS_AVX2 |
|---|
| 49 | | - &raid6_avx2x1, |
|---|
| 50 | | - &raid6_avx2x2, |
|---|
| 51 | | -#endif |
|---|
| 52 | 33 | #ifdef CONFIG_AS_AVX512 |
|---|
| 53 | | - &raid6_avx512x1, |
|---|
| 54 | 34 | &raid6_avx512x2, |
|---|
| 35 | + &raid6_avx512x1, |
|---|
| 55 | 36 | #endif |
|---|
| 37 | + &raid6_avx2x2, |
|---|
| 38 | + &raid6_avx2x1, |
|---|
| 39 | + &raid6_sse2x2, |
|---|
| 40 | + &raid6_sse2x1, |
|---|
| 41 | + &raid6_sse1x2, |
|---|
| 42 | + &raid6_sse1x1, |
|---|
| 43 | + &raid6_mmxx2, |
|---|
| 44 | + &raid6_mmxx1, |
|---|
| 56 | 45 | #endif |
|---|
| 57 | 46 | #if defined(__x86_64__) && !defined(__arch_um__) |
|---|
| 58 | | - &raid6_sse2x1, |
|---|
| 59 | | - &raid6_sse2x2, |
|---|
| 60 | | - &raid6_sse2x4, |
|---|
| 61 | | -#ifdef CONFIG_AS_AVX2 |
|---|
| 62 | | - &raid6_avx2x1, |
|---|
| 63 | | - &raid6_avx2x2, |
|---|
| 64 | | - &raid6_avx2x4, |
|---|
| 65 | | -#endif |
|---|
| 66 | 47 | #ifdef CONFIG_AS_AVX512 |
|---|
| 67 | | - &raid6_avx512x1, |
|---|
| 68 | | - &raid6_avx512x2, |
|---|
| 69 | 48 | &raid6_avx512x4, |
|---|
| 49 | + &raid6_avx512x2, |
|---|
| 50 | + &raid6_avx512x1, |
|---|
| 70 | 51 | #endif |
|---|
| 52 | + &raid6_avx2x4, |
|---|
| 53 | + &raid6_avx2x2, |
|---|
| 54 | + &raid6_avx2x1, |
|---|
| 55 | + &raid6_sse2x4, |
|---|
| 56 | + &raid6_sse2x2, |
|---|
| 57 | + &raid6_sse2x1, |
|---|
| 71 | 58 | #endif |
|---|
| 72 | 59 | #ifdef CONFIG_ALTIVEC |
|---|
| 73 | | - &raid6_altivec1, |
|---|
| 74 | | - &raid6_altivec2, |
|---|
| 75 | | - &raid6_altivec4, |
|---|
| 76 | | - &raid6_altivec8, |
|---|
| 77 | | - &raid6_vpermxor1, |
|---|
| 78 | | - &raid6_vpermxor2, |
|---|
| 79 | | - &raid6_vpermxor4, |
|---|
| 80 | 60 | &raid6_vpermxor8, |
|---|
| 61 | + &raid6_vpermxor4, |
|---|
| 62 | + &raid6_vpermxor2, |
|---|
| 63 | + &raid6_vpermxor1, |
|---|
| 64 | + &raid6_altivec8, |
|---|
| 65 | + &raid6_altivec4, |
|---|
| 66 | + &raid6_altivec2, |
|---|
| 67 | + &raid6_altivec1, |
|---|
| 81 | 68 | #endif |
|---|
| 82 | 69 | #if defined(CONFIG_S390) |
|---|
| 83 | 70 | &raid6_s390vx8, |
|---|
| 84 | 71 | #endif |
|---|
| 85 | | - &raid6_intx1, |
|---|
| 86 | | - &raid6_intx2, |
|---|
| 87 | | - &raid6_intx4, |
|---|
| 88 | | - &raid6_intx8, |
|---|
| 89 | 72 | #ifdef CONFIG_KERNEL_MODE_NEON |
|---|
| 90 | | - &raid6_neonx1, |
|---|
| 91 | | - &raid6_neonx2, |
|---|
| 92 | | - &raid6_neonx4, |
|---|
| 93 | 73 | &raid6_neonx8, |
|---|
| 74 | + &raid6_neonx4, |
|---|
| 75 | + &raid6_neonx2, |
|---|
| 76 | + &raid6_neonx1, |
|---|
| 94 | 77 | #endif |
|---|
| 78 | +#if defined(__ia64__) |
|---|
| 79 | + &raid6_intx32, |
|---|
| 80 | + &raid6_intx16, |
|---|
| 81 | +#endif |
|---|
| 82 | + &raid6_intx8, |
|---|
| 83 | + &raid6_intx4, |
|---|
| 84 | + &raid6_intx2, |
|---|
| 85 | + &raid6_intx1, |
|---|
| 95 | 86 | NULL |
|---|
| 96 | 87 | }; |
|---|
| 97 | 88 | |
|---|
| .. | .. |
|---|
| 102 | 93 | EXPORT_SYMBOL_GPL(raid6_datap_recov); |
|---|
| 103 | 94 | |
|---|
| 104 | 95 | const struct raid6_recov_calls *const raid6_recov_algos[] = { |
|---|
| 96 | +#ifdef CONFIG_X86 |
|---|
| 105 | 97 | #ifdef CONFIG_AS_AVX512 |
|---|
| 106 | 98 | &raid6_recov_avx512, |
|---|
| 107 | 99 | #endif |
|---|
| 108 | | -#ifdef CONFIG_AS_AVX2 |
|---|
| 109 | 100 | &raid6_recov_avx2, |
|---|
| 110 | | -#endif |
|---|
| 111 | | -#ifdef CONFIG_AS_SSSE3 |
|---|
| 112 | 101 | &raid6_recov_ssse3, |
|---|
| 113 | 102 | #endif |
|---|
| 114 | 103 | #ifdef CONFIG_S390 |
|---|
| .. | .. |
|---|
| 128 | 117 | #define RAID6_TIME_JIFFIES_LG2 9 |
|---|
| 129 | 118 | #define time_before(x, y) ((x) < (y)) |
|---|
| 130 | 119 | #endif |
|---|
| 120 | + |
|---|
| 121 | +#define RAID6_TEST_DISKS 8 |
|---|
| 122 | +#define RAID6_TEST_DISKS_ORDER 3 |
|---|
| 131 | 123 | |
|---|
| 132 | 124 | static inline const struct raid6_recov_calls *raid6_choose_recov(void) |
|---|
| 133 | 125 | { |
|---|
| .. | .. |
|---|
| 151 | 143 | } |
|---|
| 152 | 144 | |
|---|
| 153 | 145 | static inline const struct raid6_calls *raid6_choose_gen( |
|---|
| 154 | | - void *(*const dptrs)[(65536/PAGE_SIZE)+2], const int disks) |
|---|
| 146 | + void *(*const dptrs)[RAID6_TEST_DISKS], const int disks) |
|---|
| 155 | 147 | { |
|---|
| 156 | 148 | unsigned long perf, bestgenperf, bestxorperf, j0, j1; |
|---|
| 157 | 149 | int start = (disks>>1)-1, stop = disks-3; /* work on the second half of the disks */ |
|---|
| .. | .. |
|---|
| 162 | 154 | if (!best || (*algo)->prefer >= best->prefer) { |
|---|
| 163 | 155 | if ((*algo)->valid && !(*algo)->valid()) |
|---|
| 164 | 156 | continue; |
|---|
| 157 | + |
|---|
| 158 | + if (!IS_ENABLED(CONFIG_RAID6_PQ_BENCHMARK)) { |
|---|
| 159 | + best = *algo; |
|---|
| 160 | + break; |
|---|
| 161 | + } |
|---|
| 165 | 162 | |
|---|
| 166 | 163 | perf = 0; |
|---|
| 167 | 164 | |
|---|
| .. | .. |
|---|
| 181 | 178 | best = *algo; |
|---|
| 182 | 179 | } |
|---|
| 183 | 180 | pr_info("raid6: %-8s gen() %5ld MB/s\n", (*algo)->name, |
|---|
| 184 | | - (perf*HZ) >> (20-16+RAID6_TIME_JIFFIES_LG2)); |
|---|
| 181 | + (perf * HZ * (disks-2)) >> |
|---|
| 182 | + (20 - PAGE_SHIFT + RAID6_TIME_JIFFIES_LG2)); |
|---|
| 185 | 183 | |
|---|
| 186 | 184 | if (!(*algo)->xor_syndrome) |
|---|
| 187 | 185 | continue; |
|---|
| .. | .. |
|---|
| 204 | 202 | bestxorperf = perf; |
|---|
| 205 | 203 | |
|---|
| 206 | 204 | pr_info("raid6: %-8s xor() %5ld MB/s\n", (*algo)->name, |
|---|
| 207 | | - (perf*HZ) >> (20-16+RAID6_TIME_JIFFIES_LG2+1)); |
|---|
| 205 | + (perf * HZ * (disks-2)) >> |
|---|
| 206 | + (20 - PAGE_SHIFT + RAID6_TIME_JIFFIES_LG2 + 1)); |
|---|
| 208 | 207 | } |
|---|
| 209 | 208 | } |
|---|
| 210 | 209 | |
|---|
| 211 | 210 | if (best) { |
|---|
| 212 | | - pr_info("raid6: using algorithm %s gen() %ld MB/s\n", |
|---|
| 213 | | - best->name, |
|---|
| 214 | | - (bestgenperf*HZ) >> (20-16+RAID6_TIME_JIFFIES_LG2)); |
|---|
| 215 | | - if (best->xor_syndrome) |
|---|
| 216 | | - pr_info("raid6: .... xor() %ld MB/s, rmw enabled\n", |
|---|
| 217 | | - (bestxorperf*HZ) >> (20-16+RAID6_TIME_JIFFIES_LG2+1)); |
|---|
| 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); |
|---|
| 218 | 223 | raid6_call = *best; |
|---|
| 219 | 224 | } else |
|---|
| 220 | 225 | pr_err("raid6: Yikes! No algorithm found!\n"); |
|---|
| .. | .. |
|---|
| 228 | 233 | |
|---|
| 229 | 234 | int __init raid6_select_algo(void) |
|---|
| 230 | 235 | { |
|---|
| 231 | | - const int disks = (65536/PAGE_SIZE)+2; |
|---|
| 236 | + const int disks = RAID6_TEST_DISKS; |
|---|
| 232 | 237 | |
|---|
| 233 | 238 | const struct raid6_calls *gen_best; |
|---|
| 234 | 239 | const struct raid6_recov_calls *rec_best; |
|---|
| 235 | | - char *syndromes; |
|---|
| 236 | | - void *dptrs[(65536/PAGE_SIZE)+2]; |
|---|
| 237 | | - int i; |
|---|
| 240 | + char *disk_ptr, *p; |
|---|
| 241 | + void *dptrs[RAID6_TEST_DISKS]; |
|---|
| 242 | + int i, cycle; |
|---|
| 238 | 243 | |
|---|
| 239 | | - for (i = 0; i < disks-2; i++) |
|---|
| 240 | | - dptrs[i] = ((char *)raid6_gfmul) + PAGE_SIZE*i; |
|---|
| 241 | | - |
|---|
| 242 | | - /* Normal code - use a 2-page allocation to avoid D$ conflict */ |
|---|
| 243 | | - syndromes = (void *) __get_free_pages(GFP_KERNEL, 1); |
|---|
| 244 | | - |
|---|
| 245 | | - if (!syndromes) { |
|---|
| 244 | + /* prepare the buffer and fill it circularly with gfmul table */ |
|---|
| 245 | + disk_ptr = (char *)__get_free_pages(GFP_KERNEL, RAID6_TEST_DISKS_ORDER); |
|---|
| 246 | + if (!disk_ptr) { |
|---|
| 246 | 247 | pr_err("raid6: Yikes! No memory available.\n"); |
|---|
| 247 | 248 | return -ENOMEM; |
|---|
| 248 | 249 | } |
|---|
| 249 | 250 | |
|---|
| 250 | | - dptrs[disks-2] = syndromes; |
|---|
| 251 | | - dptrs[disks-1] = syndromes + PAGE_SIZE; |
|---|
| 251 | + p = disk_ptr; |
|---|
| 252 | + for (i = 0; i < disks; i++) |
|---|
| 253 | + dptrs[i] = p + PAGE_SIZE * i; |
|---|
| 254 | + |
|---|
| 255 | + cycle = ((disks - 2) * PAGE_SIZE) / 65536; |
|---|
| 256 | + for (i = 0; i < cycle; i++) { |
|---|
| 257 | + memcpy(p, raid6_gfmul, 65536); |
|---|
| 258 | + p += 65536; |
|---|
| 259 | + } |
|---|
| 260 | + |
|---|
| 261 | + if ((disks - 2) * PAGE_SIZE % 65536) |
|---|
| 262 | + memcpy(p, raid6_gfmul, (disks - 2) * PAGE_SIZE % 65536); |
|---|
| 252 | 263 | |
|---|
| 253 | 264 | /* select raid gen_syndrome function */ |
|---|
| 254 | 265 | gen_best = raid6_choose_gen(&dptrs, disks); |
|---|
| .. | .. |
|---|
| 256 | 267 | /* select raid recover functions */ |
|---|
| 257 | 268 | rec_best = raid6_choose_recov(); |
|---|
| 258 | 269 | |
|---|
| 259 | | - free_pages((unsigned long)syndromes, 1); |
|---|
| 270 | + free_pages((unsigned long)disk_ptr, RAID6_TEST_DISKS_ORDER); |
|---|
| 260 | 271 | |
|---|
| 261 | 272 | return gen_best && rec_best ? 0 : -EINVAL; |
|---|
| 262 | 273 | } |
|---|