hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/lib/raid6/algos.c
....@@ -1,12 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* -*- linux-c -*- ------------------------------------------------------- *
23 *
34 * 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.
105 *
116 * ----------------------------------------------------------------------- */
127
....@@ -34,64 +29,60 @@
3429 EXPORT_SYMBOL_GPL(raid6_call);
3530
3631 const struct raid6_calls * const raid6_algos[] = {
37
-#if defined(__ia64__)
38
- &raid6_intx16,
39
- &raid6_intx32,
40
-#endif
4132 #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
5233 #ifdef CONFIG_AS_AVX512
53
- &raid6_avx512x1,
5434 &raid6_avx512x2,
35
+ &raid6_avx512x1,
5536 #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,
5645 #endif
5746 #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
6647 #ifdef CONFIG_AS_AVX512
67
- &raid6_avx512x1,
68
- &raid6_avx512x2,
6948 &raid6_avx512x4,
49
+ &raid6_avx512x2,
50
+ &raid6_avx512x1,
7051 #endif
52
+ &raid6_avx2x4,
53
+ &raid6_avx2x2,
54
+ &raid6_avx2x1,
55
+ &raid6_sse2x4,
56
+ &raid6_sse2x2,
57
+ &raid6_sse2x1,
7158 #endif
7259 #ifdef CONFIG_ALTIVEC
73
- &raid6_altivec1,
74
- &raid6_altivec2,
75
- &raid6_altivec4,
76
- &raid6_altivec8,
77
- &raid6_vpermxor1,
78
- &raid6_vpermxor2,
79
- &raid6_vpermxor4,
8060 &raid6_vpermxor8,
61
+ &raid6_vpermxor4,
62
+ &raid6_vpermxor2,
63
+ &raid6_vpermxor1,
64
+ &raid6_altivec8,
65
+ &raid6_altivec4,
66
+ &raid6_altivec2,
67
+ &raid6_altivec1,
8168 #endif
8269 #if defined(CONFIG_S390)
8370 &raid6_s390vx8,
8471 #endif
85
- &raid6_intx1,
86
- &raid6_intx2,
87
- &raid6_intx4,
88
- &raid6_intx8,
8972 #ifdef CONFIG_KERNEL_MODE_NEON
90
- &raid6_neonx1,
91
- &raid6_neonx2,
92
- &raid6_neonx4,
9373 &raid6_neonx8,
74
+ &raid6_neonx4,
75
+ &raid6_neonx2,
76
+ &raid6_neonx1,
9477 #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,
9586 NULL
9687 };
9788
....@@ -102,13 +93,11 @@
10293 EXPORT_SYMBOL_GPL(raid6_datap_recov);
10394
10495 const struct raid6_recov_calls *const raid6_recov_algos[] = {
96
+#ifdef CONFIG_X86
10597 #ifdef CONFIG_AS_AVX512
10698 &raid6_recov_avx512,
10799 #endif
108
-#ifdef CONFIG_AS_AVX2
109100 &raid6_recov_avx2,
110
-#endif
111
-#ifdef CONFIG_AS_SSSE3
112101 &raid6_recov_ssse3,
113102 #endif
114103 #ifdef CONFIG_S390
....@@ -128,6 +117,9 @@
128117 #define RAID6_TIME_JIFFIES_LG2 9
129118 #define time_before(x, y) ((x) < (y))
130119 #endif
120
+
121
+#define RAID6_TEST_DISKS 8
122
+#define RAID6_TEST_DISKS_ORDER 3
131123
132124 static inline const struct raid6_recov_calls *raid6_choose_recov(void)
133125 {
....@@ -151,7 +143,7 @@
151143 }
152144
153145 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)
155147 {
156148 unsigned long perf, bestgenperf, bestxorperf, j0, j1;
157149 int start = (disks>>1)-1, stop = disks-3; /* work on the second half of the disks */
....@@ -162,6 +154,11 @@
162154 if (!best || (*algo)->prefer >= best->prefer) {
163155 if ((*algo)->valid && !(*algo)->valid())
164156 continue;
157
+
158
+ if (!IS_ENABLED(CONFIG_RAID6_PQ_BENCHMARK)) {
159
+ best = *algo;
160
+ break;
161
+ }
165162
166163 perf = 0;
167164
....@@ -181,7 +178,8 @@
181178 best = *algo;
182179 }
183180 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));
185183
186184 if (!(*algo)->xor_syndrome)
187185 continue;
....@@ -204,17 +202,24 @@
204202 bestxorperf = perf;
205203
206204 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));
208207 }
209208 }
210209
211210 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);
218223 raid6_call = *best;
219224 } else
220225 pr_err("raid6: Yikes! No algorithm found!\n");
....@@ -228,27 +233,33 @@
228233
229234 int __init raid6_select_algo(void)
230235 {
231
- const int disks = (65536/PAGE_SIZE)+2;
236
+ const int disks = RAID6_TEST_DISKS;
232237
233238 const struct raid6_calls *gen_best;
234239 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;
238243
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) {
246247 pr_err("raid6: Yikes! No memory available.\n");
247248 return -ENOMEM;
248249 }
249250
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);
252263
253264 /* select raid gen_syndrome function */
254265 gen_best = raid6_choose_gen(&dptrs, disks);
....@@ -256,7 +267,7 @@
256267 /* select raid recover functions */
257268 rec_best = raid6_choose_recov();
258269
259
- free_pages((unsigned long)syndromes, 1);
270
+ free_pages((unsigned long)disk_ptr, RAID6_TEST_DISKS_ORDER);
260271
261272 return gen_best && rec_best ? 0 : -EINVAL;
262273 }