diff options
Diffstat (limited to 'lib/raid6')
-rw-r--r-- | lib/raid6/Makefile | 2 | ||||
-rw-r--r-- | lib/raid6/algos.c | 127 | ||||
-rw-r--r-- | lib/raid6/mktables.c | 25 | ||||
-rw-r--r-- | lib/raid6/recov.c | 15 | ||||
-rw-r--r-- | lib/raid6/recov_ssse3.c | 335 | ||||
-rw-r--r-- | lib/raid6/test/Makefile | 2 | ||||
-rw-r--r-- | lib/raid6/test/test.c | 32 | ||||
-rw-r--r-- | lib/raid6/x86.h | 15 |
8 files changed, 491 insertions, 62 deletions
diff --git a/lib/raid6/Makefile b/lib/raid6/Makefile index 8a38102770f3..de06dfe165b8 100644 --- a/lib/raid6/Makefile +++ b/lib/raid6/Makefile | |||
@@ -1,6 +1,6 @@ | |||
1 | obj-$(CONFIG_RAID6_PQ) += raid6_pq.o | 1 | obj-$(CONFIG_RAID6_PQ) += raid6_pq.o |
2 | 2 | ||
3 | raid6_pq-y += algos.o recov.o tables.o int1.o int2.o int4.o \ | 3 | raid6_pq-y += algos.o recov.o recov_ssse3.o tables.o int1.o int2.o int4.o \ |
4 | int8.o int16.o int32.o altivec1.o altivec2.o altivec4.o \ | 4 | int8.o int16.o int32.o altivec1.o altivec2.o altivec4.o \ |
5 | altivec8.o mmx.o sse1.o sse2.o | 5 | altivec8.o mmx.o sse1.o sse2.o |
6 | hostprogs-y += mktables | 6 | hostprogs-y += mktables |
diff --git a/lib/raid6/algos.c b/lib/raid6/algos.c index 8b02f60ffc86..589f5f50ad2e 100644 --- a/lib/raid6/algos.c +++ b/lib/raid6/algos.c | |||
@@ -17,11 +17,11 @@ | |||
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include <linux/raid/pq.h> | 19 | #include <linux/raid/pq.h> |
20 | #include <linux/module.h> | ||
21 | #ifndef __KERNEL__ | 20 | #ifndef __KERNEL__ |
22 | #include <sys/mman.h> | 21 | #include <sys/mman.h> |
23 | #include <stdio.h> | 22 | #include <stdio.h> |
24 | #else | 23 | #else |
24 | #include <linux/module.h> | ||
25 | #include <linux/gfp.h> | 25 | #include <linux/gfp.h> |
26 | #if !RAID6_USE_EMPTY_ZERO_PAGE | 26 | #if !RAID6_USE_EMPTY_ZERO_PAGE |
27 | /* In .bss so it's zeroed */ | 27 | /* In .bss so it's zeroed */ |
@@ -34,10 +34,6 @@ struct raid6_calls raid6_call; | |||
34 | EXPORT_SYMBOL_GPL(raid6_call); | 34 | EXPORT_SYMBOL_GPL(raid6_call); |
35 | 35 | ||
36 | const struct raid6_calls * const raid6_algos[] = { | 36 | const struct raid6_calls * const raid6_algos[] = { |
37 | &raid6_intx1, | ||
38 | &raid6_intx2, | ||
39 | &raid6_intx4, | ||
40 | &raid6_intx8, | ||
41 | #if defined(__ia64__) | 37 | #if defined(__ia64__) |
42 | &raid6_intx16, | 38 | &raid6_intx16, |
43 | &raid6_intx32, | 39 | &raid6_intx32, |
@@ -61,6 +57,24 @@ const struct raid6_calls * const raid6_algos[] = { | |||
61 | &raid6_altivec4, | 57 | &raid6_altivec4, |
62 | &raid6_altivec8, | 58 | &raid6_altivec8, |
63 | #endif | 59 | #endif |
60 | &raid6_intx1, | ||
61 | &raid6_intx2, | ||
62 | &raid6_intx4, | ||
63 | &raid6_intx8, | ||
64 | NULL | ||
65 | }; | ||
66 | |||
67 | void (*raid6_2data_recov)(int, size_t, int, int, void **); | ||
68 | EXPORT_SYMBOL_GPL(raid6_2data_recov); | ||
69 | |||
70 | void (*raid6_datap_recov)(int, size_t, int, void **); | ||
71 | EXPORT_SYMBOL_GPL(raid6_datap_recov); | ||
72 | |||
73 | const struct raid6_recov_calls *const raid6_recov_algos[] = { | ||
74 | #if (defined(__i386__) || defined(__x86_64__)) && !defined(__arch_um__) | ||
75 | &raid6_recov_ssse3, | ||
76 | #endif | ||
77 | &raid6_recov_intx1, | ||
64 | NULL | 78 | NULL |
65 | }; | 79 | }; |
66 | 80 | ||
@@ -72,59 +86,55 @@ const struct raid6_calls * const raid6_algos[] = { | |||
72 | #define time_before(x, y) ((x) < (y)) | 86 | #define time_before(x, y) ((x) < (y)) |
73 | #endif | 87 | #endif |
74 | 88 | ||
75 | /* Try to pick the best algorithm */ | 89 | static inline const struct raid6_recov_calls *raid6_choose_recov(void) |
76 | /* This code uses the gfmul table as convenient data set to abuse */ | ||
77 | |||
78 | int __init raid6_select_algo(void) | ||
79 | { | 90 | { |
80 | const struct raid6_calls * const * algo; | 91 | const struct raid6_recov_calls *const *algo; |
81 | const struct raid6_calls * best; | 92 | const struct raid6_recov_calls *best; |
82 | char *syndromes; | ||
83 | void *dptrs[(65536/PAGE_SIZE)+2]; | ||
84 | int i, disks; | ||
85 | unsigned long perf, bestperf; | ||
86 | int bestprefer; | ||
87 | unsigned long j0, j1; | ||
88 | 93 | ||
89 | disks = (65536/PAGE_SIZE)+2; | 94 | for (best = NULL, algo = raid6_recov_algos; *algo; algo++) |
90 | for ( i = 0 ; i < disks-2 ; i++ ) { | 95 | if (!best || (*algo)->priority > best->priority) |
91 | dptrs[i] = ((char *)raid6_gfmul) + PAGE_SIZE*i; | 96 | if (!(*algo)->valid || (*algo)->valid()) |
92 | } | 97 | best = *algo; |
93 | 98 | ||
94 | /* Normal code - use a 2-page allocation to avoid D$ conflict */ | 99 | if (best) { |
95 | syndromes = (void *) __get_free_pages(GFP_KERNEL, 1); | 100 | raid6_2data_recov = best->data2; |
101 | raid6_datap_recov = best->datap; | ||
96 | 102 | ||
97 | if ( !syndromes ) { | 103 | printk("raid6: using %s recovery algorithm\n", best->name); |
98 | printk("raid6: Yikes! No memory available.\n"); | 104 | } else |
99 | return -ENOMEM; | 105 | printk("raid6: Yikes! No recovery algorithm found!\n"); |
100 | } | ||
101 | 106 | ||
102 | dptrs[disks-2] = syndromes; | 107 | return best; |
103 | dptrs[disks-1] = syndromes + PAGE_SIZE; | 108 | } |
109 | |||
110 | static inline const struct raid6_calls *raid6_choose_gen( | ||
111 | void *(*const dptrs)[(65536/PAGE_SIZE)+2], const int disks) | ||
112 | { | ||
113 | unsigned long perf, bestperf, j0, j1; | ||
114 | const struct raid6_calls *const *algo; | ||
115 | const struct raid6_calls *best; | ||
104 | 116 | ||
105 | bestperf = 0; bestprefer = 0; best = NULL; | 117 | for (bestperf = 0, best = NULL, algo = raid6_algos; *algo; algo++) { |
118 | if (!best || (*algo)->prefer >= best->prefer) { | ||
119 | if ((*algo)->valid && !(*algo)->valid()) | ||
120 | continue; | ||
106 | 121 | ||
107 | for ( algo = raid6_algos ; *algo ; algo++ ) { | ||
108 | if ( !(*algo)->valid || (*algo)->valid() ) { | ||
109 | perf = 0; | 122 | perf = 0; |
110 | 123 | ||
111 | preempt_disable(); | 124 | preempt_disable(); |
112 | j0 = jiffies; | 125 | j0 = jiffies; |
113 | while ( (j1 = jiffies) == j0 ) | 126 | while ((j1 = jiffies) == j0) |
114 | cpu_relax(); | 127 | cpu_relax(); |
115 | while (time_before(jiffies, | 128 | while (time_before(jiffies, |
116 | j1 + (1<<RAID6_TIME_JIFFIES_LG2))) { | 129 | j1 + (1<<RAID6_TIME_JIFFIES_LG2))) { |
117 | (*algo)->gen_syndrome(disks, PAGE_SIZE, dptrs); | 130 | (*algo)->gen_syndrome(disks, PAGE_SIZE, *dptrs); |
118 | perf++; | 131 | perf++; |
119 | } | 132 | } |
120 | preempt_enable(); | 133 | preempt_enable(); |
121 | 134 | ||
122 | if ( (*algo)->prefer > bestprefer || | 135 | if (perf > bestperf) { |
123 | ((*algo)->prefer == bestprefer && | ||
124 | perf > bestperf) ) { | ||
125 | best = *algo; | ||
126 | bestprefer = best->prefer; | ||
127 | bestperf = perf; | 136 | bestperf = perf; |
137 | best = *algo; | ||
128 | } | 138 | } |
129 | printk("raid6: %-8s %5ld MB/s\n", (*algo)->name, | 139 | printk("raid6: %-8s %5ld MB/s\n", (*algo)->name, |
130 | (perf*HZ) >> (20-16+RAID6_TIME_JIFFIES_LG2)); | 140 | (perf*HZ) >> (20-16+RAID6_TIME_JIFFIES_LG2)); |
@@ -139,9 +149,46 @@ int __init raid6_select_algo(void) | |||
139 | } else | 149 | } else |
140 | printk("raid6: Yikes! No algorithm found!\n"); | 150 | printk("raid6: Yikes! No algorithm found!\n"); |
141 | 151 | ||
152 | return best; | ||
153 | } | ||
154 | |||
155 | |||
156 | /* Try to pick the best algorithm */ | ||
157 | /* This code uses the gfmul table as convenient data set to abuse */ | ||
158 | |||
159 | int __init raid6_select_algo(void) | ||
160 | { | ||
161 | const int disks = (65536/PAGE_SIZE)+2; | ||
162 | |||
163 | const struct raid6_calls *gen_best; | ||
164 | const struct raid6_recov_calls *rec_best; | ||
165 | char *syndromes; | ||
166 | void *dptrs[(65536/PAGE_SIZE)+2]; | ||
167 | int i; | ||
168 | |||
169 | for (i = 0; i < disks-2; i++) | ||
170 | dptrs[i] = ((char *)raid6_gfmul) + PAGE_SIZE*i; | ||
171 | |||
172 | /* Normal code - use a 2-page allocation to avoid D$ conflict */ | ||
173 | syndromes = (void *) __get_free_pages(GFP_KERNEL, 1); | ||
174 | |||
175 | if (!syndromes) { | ||
176 | printk("raid6: Yikes! No memory available.\n"); | ||
177 | return -ENOMEM; | ||
178 | } | ||
179 | |||
180 | dptrs[disks-2] = syndromes; | ||
181 | dptrs[disks-1] = syndromes + PAGE_SIZE; | ||
182 | |||
183 | /* select raid gen_syndrome function */ | ||
184 | gen_best = raid6_choose_gen(&dptrs, disks); | ||
185 | |||
186 | /* select raid recover functions */ | ||
187 | rec_best = raid6_choose_recov(); | ||
188 | |||
142 | free_pages((unsigned long)syndromes, 1); | 189 | free_pages((unsigned long)syndromes, 1); |
143 | 190 | ||
144 | return best ? 0 : -EINVAL; | 191 | return gen_best && rec_best ? 0 : -EINVAL; |
145 | } | 192 | } |
146 | 193 | ||
147 | static void raid6_exit(void) | 194 | static void raid6_exit(void) |
diff --git a/lib/raid6/mktables.c b/lib/raid6/mktables.c index 8a3780902cec..39787db588b0 100644 --- a/lib/raid6/mktables.c +++ b/lib/raid6/mktables.c | |||
@@ -81,6 +81,31 @@ int main(int argc, char *argv[]) | |||
81 | printf("EXPORT_SYMBOL(raid6_gfmul);\n"); | 81 | printf("EXPORT_SYMBOL(raid6_gfmul);\n"); |
82 | printf("#endif\n"); | 82 | printf("#endif\n"); |
83 | 83 | ||
84 | /* Compute vector multiplication table */ | ||
85 | printf("\nconst u8 __attribute__((aligned(256)))\n" | ||
86 | "raid6_vgfmul[256][32] =\n" | ||
87 | "{\n"); | ||
88 | for (i = 0; i < 256; i++) { | ||
89 | printf("\t{\n"); | ||
90 | for (j = 0; j < 16; j += 8) { | ||
91 | printf("\t\t"); | ||
92 | for (k = 0; k < 8; k++) | ||
93 | printf("0x%02x,%c", gfmul(i, j + k), | ||
94 | (k == 7) ? '\n' : ' '); | ||
95 | } | ||
96 | for (j = 0; j < 16; j += 8) { | ||
97 | printf("\t\t"); | ||
98 | for (k = 0; k < 8; k++) | ||
99 | printf("0x%02x,%c", gfmul(i, (j + k) << 4), | ||
100 | (k == 7) ? '\n' : ' '); | ||
101 | } | ||
102 | printf("\t},\n"); | ||
103 | } | ||
104 | printf("};\n"); | ||
105 | printf("#ifdef __KERNEL__\n"); | ||
106 | printf("EXPORT_SYMBOL(raid6_vgfmul);\n"); | ||
107 | printf("#endif\n"); | ||
108 | |||
84 | /* Compute power-of-2 table (exponent) */ | 109 | /* Compute power-of-2 table (exponent) */ |
85 | v = 1; | 110 | v = 1; |
86 | printf("\nconst u8 __attribute__((aligned(256)))\n" | 111 | printf("\nconst u8 __attribute__((aligned(256)))\n" |
diff --git a/lib/raid6/recov.c b/lib/raid6/recov.c index fe275d7b6b36..1805a5cc5daa 100644 --- a/lib/raid6/recov.c +++ b/lib/raid6/recov.c | |||
@@ -22,7 +22,7 @@ | |||
22 | #include <linux/raid/pq.h> | 22 | #include <linux/raid/pq.h> |
23 | 23 | ||
24 | /* Recover two failed data blocks. */ | 24 | /* Recover two failed data blocks. */ |
25 | void raid6_2data_recov(int disks, size_t bytes, int faila, int failb, | 25 | void raid6_2data_recov_intx1(int disks, size_t bytes, int faila, int failb, |
26 | void **ptrs) | 26 | void **ptrs) |
27 | { | 27 | { |
28 | u8 *p, *q, *dp, *dq; | 28 | u8 *p, *q, *dp, *dq; |
@@ -64,10 +64,9 @@ void raid6_2data_recov(int disks, size_t bytes, int faila, int failb, | |||
64 | p++; q++; | 64 | p++; q++; |
65 | } | 65 | } |
66 | } | 66 | } |
67 | EXPORT_SYMBOL_GPL(raid6_2data_recov); | ||
68 | 67 | ||
69 | /* Recover failure of one data block plus the P block */ | 68 | /* Recover failure of one data block plus the P block */ |
70 | void raid6_datap_recov(int disks, size_t bytes, int faila, void **ptrs) | 69 | void raid6_datap_recov_intx1(int disks, size_t bytes, int faila, void **ptrs) |
71 | { | 70 | { |
72 | u8 *p, *q, *dq; | 71 | u8 *p, *q, *dq; |
73 | const u8 *qmul; /* Q multiplier table */ | 72 | const u8 *qmul; /* Q multiplier table */ |
@@ -96,7 +95,15 @@ void raid6_datap_recov(int disks, size_t bytes, int faila, void **ptrs) | |||
96 | q++; dq++; | 95 | q++; dq++; |
97 | } | 96 | } |
98 | } | 97 | } |
99 | EXPORT_SYMBOL_GPL(raid6_datap_recov); | 98 | |
99 | |||
100 | const struct raid6_recov_calls raid6_recov_intx1 = { | ||
101 | .data2 = raid6_2data_recov_intx1, | ||
102 | .datap = raid6_datap_recov_intx1, | ||
103 | .valid = NULL, | ||
104 | .name = "intx1", | ||
105 | .priority = 0, | ||
106 | }; | ||
100 | 107 | ||
101 | #ifndef __KERNEL__ | 108 | #ifndef __KERNEL__ |
102 | /* Testing only */ | 109 | /* Testing only */ |
diff --git a/lib/raid6/recov_ssse3.c b/lib/raid6/recov_ssse3.c new file mode 100644 index 000000000000..37ae61930559 --- /dev/null +++ b/lib/raid6/recov_ssse3.c | |||
@@ -0,0 +1,335 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2012 Intel Corporation | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License | ||
6 | * as published by the Free Software Foundation; version 2 | ||
7 | * of the License. | ||
8 | */ | ||
9 | |||
10 | #if (defined(__i386__) || defined(__x86_64__)) && !defined(__arch_um__) | ||
11 | |||
12 | #include <linux/raid/pq.h> | ||
13 | #include "x86.h" | ||
14 | |||
15 | static int raid6_has_ssse3(void) | ||
16 | { | ||
17 | return boot_cpu_has(X86_FEATURE_XMM) && | ||
18 | boot_cpu_has(X86_FEATURE_XMM2) && | ||
19 | boot_cpu_has(X86_FEATURE_SSSE3); | ||
20 | } | ||
21 | |||
22 | void raid6_2data_recov_ssse3(int disks, size_t bytes, int faila, int failb, | ||
23 | void **ptrs) | ||
24 | { | ||
25 | u8 *p, *q, *dp, *dq; | ||
26 | const u8 *pbmul; /* P multiplier table for B data */ | ||
27 | const u8 *qmul; /* Q multiplier table (for both) */ | ||
28 | static const u8 __aligned(16) x0f[16] = { | ||
29 | 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, | ||
30 | 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f}; | ||
31 | |||
32 | p = (u8 *)ptrs[disks-2]; | ||
33 | q = (u8 *)ptrs[disks-1]; | ||
34 | |||
35 | /* Compute syndrome with zero for the missing data pages | ||
36 | Use the dead data pages as temporary storage for | ||
37 | delta p and delta q */ | ||
38 | dp = (u8 *)ptrs[faila]; | ||
39 | ptrs[faila] = (void *)raid6_empty_zero_page; | ||
40 | ptrs[disks-2] = dp; | ||
41 | dq = (u8 *)ptrs[failb]; | ||
42 | ptrs[failb] = (void *)raid6_empty_zero_page; | ||
43 | ptrs[disks-1] = dq; | ||
44 | |||
45 | raid6_call.gen_syndrome(disks, bytes, ptrs); | ||
46 | |||
47 | /* Restore pointer table */ | ||
48 | ptrs[faila] = dp; | ||
49 | ptrs[failb] = dq; | ||
50 | ptrs[disks-2] = p; | ||
51 | ptrs[disks-1] = q; | ||
52 | |||
53 | /* Now, pick the proper data tables */ | ||
54 | pbmul = raid6_vgfmul[raid6_gfexi[failb-faila]]; | ||
55 | qmul = raid6_vgfmul[raid6_gfinv[raid6_gfexp[faila] ^ | ||
56 | raid6_gfexp[failb]]]; | ||
57 | |||
58 | kernel_fpu_begin(); | ||
59 | |||
60 | asm volatile("movdqa %0,%%xmm7" : : "m" (x0f[0])); | ||
61 | |||
62 | #ifdef CONFIG_X86_64 | ||
63 | asm volatile("movdqa %0,%%xmm6" : : "m" (qmul[0])); | ||
64 | asm volatile("movdqa %0,%%xmm14" : : "m" (pbmul[0])); | ||
65 | asm volatile("movdqa %0,%%xmm15" : : "m" (pbmul[16])); | ||
66 | #endif | ||
67 | |||
68 | /* Now do it... */ | ||
69 | while (bytes) { | ||
70 | #ifdef CONFIG_X86_64 | ||
71 | /* xmm6, xmm14, xmm15 */ | ||
72 | |||
73 | asm volatile("movdqa %0,%%xmm1" : : "m" (q[0])); | ||
74 | asm volatile("movdqa %0,%%xmm9" : : "m" (q[16])); | ||
75 | asm volatile("movdqa %0,%%xmm0" : : "m" (p[0])); | ||
76 | asm volatile("movdqa %0,%%xmm8" : : "m" (p[16])); | ||
77 | asm volatile("pxor %0,%%xmm1" : : "m" (dq[0])); | ||
78 | asm volatile("pxor %0,%%xmm9" : : "m" (dq[16])); | ||
79 | asm volatile("pxor %0,%%xmm0" : : "m" (dp[0])); | ||
80 | asm volatile("pxor %0,%%xmm8" : : "m" (dp[16])); | ||
81 | |||
82 | /* xmm0/8 = px */ | ||
83 | |||
84 | asm volatile("movdqa %xmm6,%xmm4"); | ||
85 | asm volatile("movdqa %0,%%xmm5" : : "m" (qmul[16])); | ||
86 | asm volatile("movdqa %xmm6,%xmm12"); | ||
87 | asm volatile("movdqa %xmm5,%xmm13"); | ||
88 | asm volatile("movdqa %xmm1,%xmm3"); | ||
89 | asm volatile("movdqa %xmm9,%xmm11"); | ||
90 | asm volatile("movdqa %xmm0,%xmm2"); /* xmm2/10 = px */ | ||
91 | asm volatile("movdqa %xmm8,%xmm10"); | ||
92 | asm volatile("psraw $4,%xmm1"); | ||
93 | asm volatile("psraw $4,%xmm9"); | ||
94 | asm volatile("pand %xmm7,%xmm3"); | ||
95 | asm volatile("pand %xmm7,%xmm11"); | ||
96 | asm volatile("pand %xmm7,%xmm1"); | ||
97 | asm volatile("pand %xmm7,%xmm9"); | ||
98 | asm volatile("pshufb %xmm3,%xmm4"); | ||
99 | asm volatile("pshufb %xmm11,%xmm12"); | ||
100 | asm volatile("pshufb %xmm1,%xmm5"); | ||
101 | asm volatile("pshufb %xmm9,%xmm13"); | ||
102 | asm volatile("pxor %xmm4,%xmm5"); | ||
103 | asm volatile("pxor %xmm12,%xmm13"); | ||
104 | |||
105 | /* xmm5/13 = qx */ | ||
106 | |||
107 | asm volatile("movdqa %xmm14,%xmm4"); | ||
108 | asm volatile("movdqa %xmm15,%xmm1"); | ||
109 | asm volatile("movdqa %xmm14,%xmm12"); | ||
110 | asm volatile("movdqa %xmm15,%xmm9"); | ||
111 | asm volatile("movdqa %xmm2,%xmm3"); | ||
112 | asm volatile("movdqa %xmm10,%xmm11"); | ||
113 | asm volatile("psraw $4,%xmm2"); | ||
114 | asm volatile("psraw $4,%xmm10"); | ||
115 | asm volatile("pand %xmm7,%xmm3"); | ||
116 | asm volatile("pand %xmm7,%xmm11"); | ||
117 | asm volatile("pand %xmm7,%xmm2"); | ||
118 | asm volatile("pand %xmm7,%xmm10"); | ||
119 | asm volatile("pshufb %xmm3,%xmm4"); | ||
120 | asm volatile("pshufb %xmm11,%xmm12"); | ||
121 | asm volatile("pshufb %xmm2,%xmm1"); | ||
122 | asm volatile("pshufb %xmm10,%xmm9"); | ||
123 | asm volatile("pxor %xmm4,%xmm1"); | ||
124 | asm volatile("pxor %xmm12,%xmm9"); | ||
125 | |||
126 | /* xmm1/9 = pbmul[px] */ | ||
127 | asm volatile("pxor %xmm5,%xmm1"); | ||
128 | asm volatile("pxor %xmm13,%xmm9"); | ||
129 | /* xmm1/9 = db = DQ */ | ||
130 | asm volatile("movdqa %%xmm1,%0" : "=m" (dq[0])); | ||
131 | asm volatile("movdqa %%xmm9,%0" : "=m" (dq[16])); | ||
132 | |||
133 | asm volatile("pxor %xmm1,%xmm0"); | ||
134 | asm volatile("pxor %xmm9,%xmm8"); | ||
135 | asm volatile("movdqa %%xmm0,%0" : "=m" (dp[0])); | ||
136 | asm volatile("movdqa %%xmm8,%0" : "=m" (dp[16])); | ||
137 | |||
138 | bytes -= 32; | ||
139 | p += 32; | ||
140 | q += 32; | ||
141 | dp += 32; | ||
142 | dq += 32; | ||
143 | #else | ||
144 | asm volatile("movdqa %0,%%xmm1" : : "m" (*q)); | ||
145 | asm volatile("movdqa %0,%%xmm0" : : "m" (*p)); | ||
146 | asm volatile("pxor %0,%%xmm1" : : "m" (*dq)); | ||
147 | asm volatile("pxor %0,%%xmm0" : : "m" (*dp)); | ||
148 | |||
149 | /* 1 = dq ^ q | ||
150 | * 0 = dp ^ p | ||
151 | */ | ||
152 | asm volatile("movdqa %0,%%xmm4" : : "m" (qmul[0])); | ||
153 | asm volatile("movdqa %0,%%xmm5" : : "m" (qmul[16])); | ||
154 | |||
155 | asm volatile("movdqa %xmm1,%xmm3"); | ||
156 | asm volatile("psraw $4,%xmm1"); | ||
157 | asm volatile("pand %xmm7,%xmm3"); | ||
158 | asm volatile("pand %xmm7,%xmm1"); | ||
159 | asm volatile("pshufb %xmm3,%xmm4"); | ||
160 | asm volatile("pshufb %xmm1,%xmm5"); | ||
161 | asm volatile("pxor %xmm4,%xmm5"); | ||
162 | |||
163 | asm volatile("movdqa %xmm0,%xmm2"); /* xmm2 = px */ | ||
164 | |||
165 | /* xmm5 = qx */ | ||
166 | |||
167 | asm volatile("movdqa %0,%%xmm4" : : "m" (pbmul[0])); | ||
168 | asm volatile("movdqa %0,%%xmm1" : : "m" (pbmul[16])); | ||
169 | asm volatile("movdqa %xmm2,%xmm3"); | ||
170 | asm volatile("psraw $4,%xmm2"); | ||
171 | asm volatile("pand %xmm7,%xmm3"); | ||
172 | asm volatile("pand %xmm7,%xmm2"); | ||
173 | asm volatile("pshufb %xmm3,%xmm4"); | ||
174 | asm volatile("pshufb %xmm2,%xmm1"); | ||
175 | asm volatile("pxor %xmm4,%xmm1"); | ||
176 | |||
177 | /* xmm1 = pbmul[px] */ | ||
178 | asm volatile("pxor %xmm5,%xmm1"); | ||
179 | /* xmm1 = db = DQ */ | ||
180 | asm volatile("movdqa %%xmm1,%0" : "=m" (*dq)); | ||
181 | |||
182 | asm volatile("pxor %xmm1,%xmm0"); | ||
183 | asm volatile("movdqa %%xmm0,%0" : "=m" (*dp)); | ||
184 | |||
185 | bytes -= 16; | ||
186 | p += 16; | ||
187 | q += 16; | ||
188 | dp += 16; | ||
189 | dq += 16; | ||
190 | #endif | ||
191 | } | ||
192 | |||
193 | kernel_fpu_end(); | ||
194 | } | ||
195 | |||
196 | |||
197 | void raid6_datap_recov_ssse3(int disks, size_t bytes, int faila, void **ptrs) | ||
198 | { | ||
199 | u8 *p, *q, *dq; | ||
200 | const u8 *qmul; /* Q multiplier table */ | ||
201 | static const u8 __aligned(16) x0f[16] = { | ||
202 | 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, | ||
203 | 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f}; | ||
204 | |||
205 | p = (u8 *)ptrs[disks-2]; | ||
206 | q = (u8 *)ptrs[disks-1]; | ||
207 | |||
208 | /* Compute syndrome with zero for the missing data page | ||
209 | Use the dead data page as temporary storage for delta q */ | ||
210 | dq = (u8 *)ptrs[faila]; | ||
211 | ptrs[faila] = (void *)raid6_empty_zero_page; | ||
212 | ptrs[disks-1] = dq; | ||
213 | |||
214 | raid6_call.gen_syndrome(disks, bytes, ptrs); | ||
215 | |||
216 | /* Restore pointer table */ | ||
217 | ptrs[faila] = dq; | ||
218 | ptrs[disks-1] = q; | ||
219 | |||
220 | /* Now, pick the proper data tables */ | ||
221 | qmul = raid6_vgfmul[raid6_gfinv[raid6_gfexp[faila]]]; | ||
222 | |||
223 | kernel_fpu_begin(); | ||
224 | |||
225 | asm volatile("movdqa %0, %%xmm7" : : "m" (x0f[0])); | ||
226 | |||
227 | while (bytes) { | ||
228 | #ifdef CONFIG_X86_64 | ||
229 | asm volatile("movdqa %0, %%xmm3" : : "m" (dq[0])); | ||
230 | asm volatile("movdqa %0, %%xmm4" : : "m" (dq[16])); | ||
231 | asm volatile("pxor %0, %%xmm3" : : "m" (q[0])); | ||
232 | asm volatile("movdqa %0, %%xmm0" : : "m" (qmul[0])); | ||
233 | |||
234 | /* xmm3 = q[0] ^ dq[0] */ | ||
235 | |||
236 | asm volatile("pxor %0, %%xmm4" : : "m" (q[16])); | ||
237 | asm volatile("movdqa %0, %%xmm1" : : "m" (qmul[16])); | ||
238 | |||
239 | /* xmm4 = q[16] ^ dq[16] */ | ||
240 | |||
241 | asm volatile("movdqa %xmm3, %xmm6"); | ||
242 | asm volatile("movdqa %xmm4, %xmm8"); | ||
243 | |||
244 | /* xmm4 = xmm8 = q[16] ^ dq[16] */ | ||
245 | |||
246 | asm volatile("psraw $4, %xmm3"); | ||
247 | asm volatile("pand %xmm7, %xmm6"); | ||
248 | asm volatile("pand %xmm7, %xmm3"); | ||
249 | asm volatile("pshufb %xmm6, %xmm0"); | ||
250 | asm volatile("pshufb %xmm3, %xmm1"); | ||
251 | asm volatile("movdqa %0, %%xmm10" : : "m" (qmul[0])); | ||
252 | asm volatile("pxor %xmm0, %xmm1"); | ||
253 | asm volatile("movdqa %0, %%xmm11" : : "m" (qmul[16])); | ||
254 | |||
255 | /* xmm1 = qmul[q[0] ^ dq[0]] */ | ||
256 | |||
257 | asm volatile("psraw $4, %xmm4"); | ||
258 | asm volatile("pand %xmm7, %xmm8"); | ||
259 | asm volatile("pand %xmm7, %xmm4"); | ||
260 | asm volatile("pshufb %xmm8, %xmm10"); | ||
261 | asm volatile("pshufb %xmm4, %xmm11"); | ||
262 | asm volatile("movdqa %0, %%xmm2" : : "m" (p[0])); | ||
263 | asm volatile("pxor %xmm10, %xmm11"); | ||
264 | asm volatile("movdqa %0, %%xmm12" : : "m" (p[16])); | ||
265 | |||
266 | /* xmm11 = qmul[q[16] ^ dq[16]] */ | ||
267 | |||
268 | asm volatile("pxor %xmm1, %xmm2"); | ||
269 | |||
270 | /* xmm2 = p[0] ^ qmul[q[0] ^ dq[0]] */ | ||
271 | |||
272 | asm volatile("pxor %xmm11, %xmm12"); | ||
273 | |||
274 | /* xmm12 = p[16] ^ qmul[q[16] ^ dq[16]] */ | ||
275 | |||
276 | asm volatile("movdqa %%xmm1, %0" : "=m" (dq[0])); | ||
277 | asm volatile("movdqa %%xmm11, %0" : "=m" (dq[16])); | ||
278 | |||
279 | asm volatile("movdqa %%xmm2, %0" : "=m" (p[0])); | ||
280 | asm volatile("movdqa %%xmm12, %0" : "=m" (p[16])); | ||
281 | |||
282 | bytes -= 32; | ||
283 | p += 32; | ||
284 | q += 32; | ||
285 | dq += 32; | ||
286 | |||
287 | #else | ||
288 | asm volatile("movdqa %0, %%xmm3" : : "m" (dq[0])); | ||
289 | asm volatile("movdqa %0, %%xmm0" : : "m" (qmul[0])); | ||
290 | asm volatile("pxor %0, %%xmm3" : : "m" (q[0])); | ||
291 | asm volatile("movdqa %0, %%xmm1" : : "m" (qmul[16])); | ||
292 | |||
293 | /* xmm3 = *q ^ *dq */ | ||
294 | |||
295 | asm volatile("movdqa %xmm3, %xmm6"); | ||
296 | asm volatile("movdqa %0, %%xmm2" : : "m" (p[0])); | ||
297 | asm volatile("psraw $4, %xmm3"); | ||
298 | asm volatile("pand %xmm7, %xmm6"); | ||
299 | asm volatile("pand %xmm7, %xmm3"); | ||
300 | asm volatile("pshufb %xmm6, %xmm0"); | ||
301 | asm volatile("pshufb %xmm3, %xmm1"); | ||
302 | asm volatile("pxor %xmm0, %xmm1"); | ||
303 | |||
304 | /* xmm1 = qmul[*q ^ *dq */ | ||
305 | |||
306 | asm volatile("pxor %xmm1, %xmm2"); | ||
307 | |||
308 | /* xmm2 = *p ^ qmul[*q ^ *dq] */ | ||
309 | |||
310 | asm volatile("movdqa %%xmm1, %0" : "=m" (dq[0])); | ||
311 | asm volatile("movdqa %%xmm2, %0" : "=m" (p[0])); | ||
312 | |||
313 | bytes -= 16; | ||
314 | p += 16; | ||
315 | q += 16; | ||
316 | dq += 16; | ||
317 | #endif | ||
318 | } | ||
319 | |||
320 | kernel_fpu_end(); | ||
321 | } | ||
322 | |||
323 | const struct raid6_recov_calls raid6_recov_ssse3 = { | ||
324 | .data2 = raid6_2data_recov_ssse3, | ||
325 | .datap = raid6_datap_recov_ssse3, | ||
326 | .valid = raid6_has_ssse3, | ||
327 | #ifdef CONFIG_X86_64 | ||
328 | .name = "ssse3x2", | ||
329 | #else | ||
330 | .name = "ssse3x1", | ||
331 | #endif | ||
332 | .priority = 1, | ||
333 | }; | ||
334 | |||
335 | #endif | ||
diff --git a/lib/raid6/test/Makefile b/lib/raid6/test/Makefile index aa651697b6dc..c76151d94764 100644 --- a/lib/raid6/test/Makefile +++ b/lib/raid6/test/Makefile | |||
@@ -23,7 +23,7 @@ RANLIB = ranlib | |||
23 | all: raid6.a raid6test | 23 | all: raid6.a raid6test |
24 | 24 | ||
25 | raid6.a: int1.o int2.o int4.o int8.o int16.o int32.o mmx.o sse1.o sse2.o \ | 25 | raid6.a: int1.o int2.o int4.o int8.o int16.o int32.o mmx.o sse1.o sse2.o \ |
26 | altivec1.o altivec2.o altivec4.o altivec8.o recov.o algos.o \ | 26 | altivec1.o altivec2.o altivec4.o altivec8.o recov.o recov_ssse3.o algos.o \ |
27 | tables.o | 27 | tables.o |
28 | rm -f $@ | 28 | rm -f $@ |
29 | $(AR) cq $@ $^ | 29 | $(AR) cq $@ $^ |
diff --git a/lib/raid6/test/test.c b/lib/raid6/test/test.c index 7a930318b17d..5a485b7a7d3c 100644 --- a/lib/raid6/test/test.c +++ b/lib/raid6/test/test.c | |||
@@ -90,25 +90,35 @@ static int test_disks(int i, int j) | |||
90 | int main(int argc, char *argv[]) | 90 | int main(int argc, char *argv[]) |
91 | { | 91 | { |
92 | const struct raid6_calls *const *algo; | 92 | const struct raid6_calls *const *algo; |
93 | const struct raid6_recov_calls *const *ra; | ||
93 | int i, j; | 94 | int i, j; |
94 | int err = 0; | 95 | int err = 0; |
95 | 96 | ||
96 | makedata(); | 97 | makedata(); |
97 | 98 | ||
98 | for (algo = raid6_algos; *algo; algo++) { | 99 | for (ra = raid6_recov_algos; *ra; ra++) { |
99 | if (!(*algo)->valid || (*algo)->valid()) { | 100 | if ((*ra)->valid && !(*ra)->valid()) |
100 | raid6_call = **algo; | 101 | continue; |
102 | raid6_2data_recov = (*ra)->data2; | ||
103 | raid6_datap_recov = (*ra)->datap; | ||
101 | 104 | ||
102 | /* Nuke syndromes */ | 105 | printf("using recovery %s\n", (*ra)->name); |
103 | memset(data[NDISKS-2], 0xee, 2*PAGE_SIZE); | ||
104 | 106 | ||
105 | /* Generate assumed good syndrome */ | 107 | for (algo = raid6_algos; *algo; algo++) { |
106 | raid6_call.gen_syndrome(NDISKS, PAGE_SIZE, | 108 | if (!(*algo)->valid || (*algo)->valid()) { |
107 | (void **)&dataptrs); | 109 | raid6_call = **algo; |
108 | 110 | ||
109 | for (i = 0; i < NDISKS-1; i++) | 111 | /* Nuke syndromes */ |
110 | for (j = i+1; j < NDISKS; j++) | 112 | memset(data[NDISKS-2], 0xee, 2*PAGE_SIZE); |
111 | err += test_disks(i, j); | 113 | |
114 | /* Generate assumed good syndrome */ | ||
115 | raid6_call.gen_syndrome(NDISKS, PAGE_SIZE, | ||
116 | (void **)&dataptrs); | ||
117 | |||
118 | for (i = 0; i < NDISKS-1; i++) | ||
119 | for (j = i+1; j < NDISKS; j++) | ||
120 | err += test_disks(i, j); | ||
121 | } | ||
112 | } | 122 | } |
113 | printf("\n"); | 123 | printf("\n"); |
114 | } | 124 | } |
diff --git a/lib/raid6/x86.h b/lib/raid6/x86.h index cb2a8c91c886..d55d63232c55 100644 --- a/lib/raid6/x86.h +++ b/lib/raid6/x86.h | |||
@@ -35,24 +35,29 @@ static inline void kernel_fpu_end(void) | |||
35 | { | 35 | { |
36 | } | 36 | } |
37 | 37 | ||
38 | #define __aligned(x) __attribute__((aligned(x))) | ||
39 | |||
38 | #define X86_FEATURE_MMX (0*32+23) /* Multimedia Extensions */ | 40 | #define X86_FEATURE_MMX (0*32+23) /* Multimedia Extensions */ |
39 | #define X86_FEATURE_FXSR (0*32+24) /* FXSAVE and FXRSTOR instructions | 41 | #define X86_FEATURE_FXSR (0*32+24) /* FXSAVE and FXRSTOR instructions |
40 | * (fast save and restore) */ | 42 | * (fast save and restore) */ |
41 | #define X86_FEATURE_XMM (0*32+25) /* Streaming SIMD Extensions */ | 43 | #define X86_FEATURE_XMM (0*32+25) /* Streaming SIMD Extensions */ |
42 | #define X86_FEATURE_XMM2 (0*32+26) /* Streaming SIMD Extensions-2 */ | 44 | #define X86_FEATURE_XMM2 (0*32+26) /* Streaming SIMD Extensions-2 */ |
45 | #define X86_FEATURE_XMM3 (4*32+ 0) /* "pni" SSE-3 */ | ||
46 | #define X86_FEATURE_SSSE3 (4*32+ 9) /* Supplemental SSE-3 */ | ||
47 | #define X86_FEATURE_AVX (4*32+28) /* Advanced Vector Extensions */ | ||
43 | #define X86_FEATURE_MMXEXT (1*32+22) /* AMD MMX extensions */ | 48 | #define X86_FEATURE_MMXEXT (1*32+22) /* AMD MMX extensions */ |
44 | 49 | ||
45 | /* Should work well enough on modern CPUs for testing */ | 50 | /* Should work well enough on modern CPUs for testing */ |
46 | static inline int boot_cpu_has(int flag) | 51 | static inline int boot_cpu_has(int flag) |
47 | { | 52 | { |
48 | u32 eax = (flag >> 5) ? 0x80000001 : 1; | 53 | u32 eax = (flag & 0x20) ? 0x80000001 : 1; |
49 | u32 edx; | 54 | u32 ecx, edx; |
50 | 55 | ||
51 | asm volatile("cpuid" | 56 | asm volatile("cpuid" |
52 | : "+a" (eax), "=d" (edx) | 57 | : "+a" (eax), "=d" (edx), "=c" (ecx) |
53 | : : "ecx", "ebx"); | 58 | : : "ebx"); |
54 | 59 | ||
55 | return (edx >> (flag & 31)) & 1; | 60 | return ((flag & 0x80 ? ecx : edx) >> (flag & 31)) & 1; |
56 | } | 61 | } |
57 | 62 | ||
58 | #endif /* ndef __KERNEL__ */ | 63 | #endif /* ndef __KERNEL__ */ |