Skip to contentSkip to conversation

raid6/altivec: Add vpermxor implementation for raid6 Q syndrome

PATCH Superseded Matt Brown 3 participants 3 messages Apr 6, 2017 – Apr 10, 2017 MD RAID

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Matt Brown

author
#0 lore raw

PATCH v2 1/1 raid6/altivec: Add vpermxor implementation for raid6 Q syndrome

The raid6 Q syndrome check has been optimised using the vpermxor instruction. This instruction was made available with POWER8, ISA version 2.07. It allows for both vperm and vxor instructions to be done in a single instruction. This has been tested for correctness on a ppc64le vm with a basic RAID6 setup containing 5 drives.

The performance benchmarks are from the raid6test in the /lib/raid6/test directory. These results are from an IBM Firestone machine with ppc64le architecture. The benchmark results show a 35% speed increase over the best existing algorithm for powerpc (altivec). The raid6test has also been run on a big-endian ppc64 vm to ensure it also works for big-endian architectures.

Performance benchmarks:

	raid6: altivecx4 gen() 18773 MB/s
	raid6: altivecx8 gen() 19438 MB/s

	raid6: vpermxor4 gen() 25112 MB/s
	raid6: vpermxor8 gen() 26279 MB/s

Bugs fixed:
- A small bug in pq.h regarding a missing and mismatched ifdef statement
- Fixed test/Makefile to correctly build test on ppc

---
mpe I assume you are ok to take this patch, most of the other ppc raid patches have gone through you.

Changelog:
v2
- added reference to raid6 paper
- shortened asm lines
- removed redundant Makefile line
- fixed test/Makefile bug

---
 include/linux/raid/pq.h |   4 ++
 lib/raid6/Makefile      |  27 ++++++++++++-
 lib/raid6/algos.c       |   4 ++
 lib/raid6/altivec.uc    |   3 ++
 lib/raid6/test/Makefile |  26 +++++++++---
 lib/raid6/vpermxor.uc   | 104 ++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 161 insertions(+), 7 deletions(-)
 create mode 100644 lib/raid6/vpermxor.uc
include/linux/raid/pq.h +4 -0
index 4d57bba..3df9aa6 100644
@@ -107,6 +107,10 @@ extern const struct raid6_calls raid6_avx512x2;
 extern const struct raid6_calls raid6_avx512x4;
 extern const struct raid6_calls raid6_tilegx8;
 extern const struct raid6_calls raid6_s390vx8;
+extern const struct raid6_calls raid6_vpermxor1;
+extern const struct raid6_calls raid6_vpermxor2;
+extern const struct raid6_calls raid6_vpermxor4;
+extern const struct raid6_calls raid6_vpermxor8;
 
 struct raid6_recov_calls {
 	void (*data2)(int, size_t, int, int, void **);
lib/raid6/Makefile +26 -1
index 3057011..7775aad 100644
@@ -4,7 +4,8 @@ raid6_pq-y	+= algos.o recov.o tables.o int1.o int2.o int4.o \
 		   int8.o int16.o int32.o
 
 raid6_pq-$(CONFIG_X86) += recov_ssse3.o recov_avx2.o mmx.o sse1.o sse2.o avx2.o avx512.o recov_avx512.o
-raid6_pq-$(CONFIG_ALTIVEC) += altivec1.o altivec2.o altivec4.o altivec8.o
+raid6_pq-$(CONFIG_ALTIVEC) += altivec1.o altivec2.o altivec4.o altivec8.o \
+				vpermxor1.o vpermxor2.o vpermxor4.o vpermxor8.o
 raid6_pq-$(CONFIG_KERNEL_MODE_NEON) += neon.o neon1.o neon2.o neon4.o neon8.o
 raid6_pq-$(CONFIG_TILEGX) += tilegx8.o
 raid6_pq-$(CONFIG_S390) += s390vx8.o recov_s390xc.o
@@ -88,6 +89,30 @@ $(obj)/altivec8.c:   UNROLL := 8
 $(obj)/altivec8.c:   $(src)/altivec.uc $(src)/unroll.awk FORCE
 	$(call if_changed,unroll)
 
+CFLAGS_vpermxor1.o += $(altivec_flags)
+targets += vpermxor1.c
+$(obj)/vpermxor1.c: UNROLL := 1
+$(obj)/vpermxor1.c: $(src)/vpermxor.uc $(src)/unroll.awk FORCE
+	$(call if_changed,unroll)
+
+CFLAGS_vpermxor2.o += $(altivec_flags)
+targets += vpermxor2.c
+$(obj)/vpermxor2.c: UNROLL := 2
+$(obj)/vpermxor2.c: $(src)/vpermxor.uc $(src)/unroll.awk FORCE
+	$(call if_changed,unroll)
+
+CFLAGS_vpermxor4.o += $(altivec_flags)
+targets += vpermxor4.c
+$(obj)/vpermxor4.c: UNROLL := 4
+$(obj)/vpermxor4.c: $(src)/vpermxor.uc $(src)/unroll.awk FORCE
+	$(call if_changed,unroll)
+
+CFLAGS_vpermxor8.o += $(altivec_flags)
+targets += vpermxor8.c
+$(obj)/vpermxor8.c: UNROLL := 8
+$(obj)/vpermxor8.c: $(src)/vpermxor.uc $(src)/unroll.awk FORCE
+	$(call if_changed,unroll)
+
 CFLAGS_neon1.o += $(NEON_FLAGS)
 targets += neon1.c
 $(obj)/neon1.c:   UNROLL := 1
lib/raid6/algos.c +4 -0
index 7857049..edd4f69 100644
@@ -74,6 +74,10 @@ const struct raid6_calls * const raid6_algos[] = {
 	&raid6_altivec2,
 	&raid6_altivec4,
 	&raid6_altivec8,
+	&raid6_vpermxor1,
+	&raid6_vpermxor2,
+	&raid6_vpermxor4,
+	&raid6_vpermxor8,
 #endif
 #if defined(CONFIG_TILEGX)
 	&raid6_tilegx8,
lib/raid6/altivec.uc +3 -0
index 682aae8..d20ed0d 100644
@@ -24,10 +24,13 @@
 
 #include <linux/raid/pq.h>
 
+#ifdef CONFIG_ALTIVEC
+
 #include <altivec.h>
 #ifdef __KERNEL__
 # include <asm/cputable.h>
 # include <asm/switch_to.h>
+#endif /* __KERNEL__ */
 
 /*
  * This is the C data type to use.  We use a vector of
lib/raid6/test/Makefile +20 -6
index 2c7b60e..b9503a3 100644
@@ -43,11 +43,13 @@ else ifeq ($(HAS_NEON),yes)
         OBJS   += neon.o neon1.o neon2.o neon4.o neon8.o
         CFLAGS += -DCONFIG_KERNEL_MODE_NEON=1
 else
-        HAS_ALTIVEC := $(shell printf '\#include <altivec.h>\nvector int a;\n' |\
-                         gcc -c -x c - >&/dev/null && \
-                         rm ./-.o && echo yes)
-        ifeq ($(HAS_ALTIVEC),yes)
-                OBJS += altivec1.o altivec2.o altivec4.o altivec8.o
+	 HAS_ALTIVEC := $(shell printf '\#include <altivec.h>\nvector int a;\n' |\
+			 gcc -c -x c - >/dev/null && rm ./-.o && echo yes)
+	 ifeq ($(HAS_ALTIVEC),yes)
+		CFLAGS += -I../../../arch/powerpc/include
+		CFLAGS += -DCONFIG_ALTIVEC
+		OBJS += altivec1.o altivec2.o altivec4.o altivec8.o \
+			vpermxor1.o vpermxor2.o vpermxor4.o vpermxor8.o
         endif
 endif
 ifeq ($(ARCH),tilegx)
@@ -97,6 +99,18 @@ altivec4.c: altivec.uc ../unroll.awk
 altivec8.c: altivec.uc ../unroll.awk
 	$(AWK) ../unroll.awk -vN=8 < altivec.uc > $@
 
+vpermxor1.c: vpermxor.uc ../unroll.awk
+	$(AWK) ../unroll.awk -vN=1 < vpermxor.uc > $@
+
+vpermxor2.c: vpermxor.uc ../unroll.awk
+	$(AWK) ../unroll.awk -vN=2 < vpermxor.uc > $@
+
+vpermxor4.c: vpermxor.uc ../unroll.awk
+	$(AWK) ../unroll.awk -vN=4 < vpermxor.uc > $@
+
+vpermxor8.c: vpermxor.uc ../unroll.awk
+	$(AWK) ../unroll.awk -vN=8 < vpermxor.uc > $@
+
 int1.c: int.uc ../unroll.awk
 	$(AWK) ../unroll.awk -vN=1 < int.uc > $@
 
@@ -122,7 +136,7 @@ tables.c: mktables
 	./mktables > tables.c
 
 clean:
-	rm -f *.o *.a mktables mktables.c *.uc int*.c altivec*.c neon*.c tables.c raid6test
+	rm -f *.o *.a mktables mktables.c *.uc int*.c altivec*.c vpermxor*.c neon*.c tables.c raid6test
 	rm -f tilegx*.c
 
 spotless: clean
lib/raid6/vpermxor.uc new file +104 -0

104 lines not on this page · raw message

Signature · 1 line
2.9.3
Reviewed-by on v2 1/1
#1 lore raw

Hi Matt,

Thanks for answering my questions and doing those fixes.

Quoted 5 lines

Bugs fixed:
- A small bug in pq.h regarding a missing and mismatched ifdef statement
- Fixed test/Makefile to correctly build test on ppc

I think this commit should be labelled:

Fixes 4f8c55c5ad49 ("lib/raid6: build proper files on corresponding arch")

mpe can probably add that when he merges - no need to do a new version :)

Quoted 5 lines

else

lib/raid6/test/Makefile +0 -4
-        HAS_ALTIVEC := $(shell printf '\#include <altivec.h>\nvector int a;\n' |\
-                         gcc -c -x c - >&/dev/null && \
-                         rm ./-.o && echo yes)
-        ifeq ($(HAS_ALTIVEC),yes)

lib/raid6/test/Makefile else ifeq ($(HAS_NEON),yes) · line 54

Quoted 10 lines
lib/raid6/test/Makefile +7 -1
-                OBJS += altivec1.o altivec2.o altivec4.o altivec8.o
+	 HAS_ALTIVEC := $(shell printf '\#include <altivec.h>\nvector int a;\n' |\
+			 gcc -c -x c - >/dev/null && rm ./-.o && echo yes)
+	 ifeq ($(HAS_ALTIVEC),yes)
+		CFLAGS += -I../../../arch/powerpc/include
+		CFLAGS += -DCONFIG_ALTIVEC
+		OBJS += altivec1.o altivec2.o altivec4.o altivec8.o \
+			vpermxor1.o vpermxor2.o vpermxor4.o vpermxor8.o
         endif
 endif

Looks like vim has replaced spaces with tabs here. Not sure how much we care...

lib/raid6/test/Makefile altivec4.c: altivec.uc ../unroll.awk · line 101

Quoted 5 lines

ifeq ($(ARCH),tilegx)

lib/raid6/test/Makefile +0 -0
@@ -97,6 +99,18 @@ altivec4.c: altivec.uc ../unroll.awk
 altivec8.c: altivec.uc ../unroll.awk
 	$(AWK) ../unroll.awk -vN=8 < altivec.uc > $@
 

... especially seeing as tabs are already used in the file here!

Quoted 7 lines
lib/raid6/test/Makefile +7 -0
+vpermxor1.c: vpermxor.uc ../unroll.awk
+	$(AWK) ../unroll.awk -vN=1 < vpermxor.uc > $@
+
+vpermxor2.c: vpermxor.uc ../unroll.awk
+	$(AWK) ../unroll.awk -vN=2 < vpermxor.uc > $@
+
+vpermxor4.c: vpermxor.uc ../unroll.awk

lib/raid6/test/Makefile altivec4.c: altivec.uc ../unroll.awk

Quoted 10 lines
lib/raid6/test/Makefile +7 -0
+	$(AWK) ../unroll.awk -vN=4 < vpermxor.uc > $@
+
+vpermxor8.c: vpermxor.uc ../unroll.awk
+	$(AWK) ../unroll.awk -vN=8 < vpermxor.uc > $@
+
 int1.c: int.uc ../unroll.awk
 	$(AWK) ../unroll.awk -vN=1 < int.uc > $@
 
+			/*Q syndrome */
+	/* Check if CPU has both altivec and the vpermxor instruction*/

Very trivial nit: for future patches please make sure you have spaces between the beginning/end of a comment and the comment.

lib/raid6/vpermxor.uc line 89

Quoted 3 lines
lib/raid6/vpermxor.uc new file +3 -0
+# ifdef __KERNEL__
+	return (cpu_has_feature(CONFIG_ALTIVEC) &&
+		cpu_has_feature(CPU_FTR_ARCH_207S));

I think CPU_FTR_ARCH_207S implies Altivec? Again, not a real problem, I don't think it's really worth doing a respin for any of these, so:

Thanks for making Power faster!

Regards,
Daniel

#2 lore raw
Quoted 11 lines · Daniel Axtens

Hi Matt,

Thanks for answering my questions and doing those fixes.

Quoted 5 lines

Bugs fixed:
- A small bug in pq.h regarding a missing and mismatched ifdef statement
- Fixed test/Makefile to correctly build test on ppc

Quoted 4 lines

I think this commit should be labelled:

Fixes 4f8c55c5ad49 ("lib/raid6: build proper files on corresponding arch")

mpe can probably add that when he merges - no need to do a new version :)

Please send a separate patch which does that fix.

Quoted 9 lines
Quoted 9 lines

else

lib/raid6/test/Makefile +3 -5
-        HAS_ALTIVEC := $(shell printf '\#include <altivec.h>\nvector int a;\n' |\
-                         gcc -c -x c - >&/dev/null && \
-                         rm ./-.o && echo yes)
-        ifeq ($(HAS_ALTIVEC),yes)
-                OBJS += altivec1.o altivec2.o altivec4.o altivec8.o
+	 HAS_ALTIVEC := $(shell printf '\#include <altivec.h>\nvector int a;\n' |\
+			 gcc -c -x c - >/dev/null && rm ./-.o && echo yes)
+	 ifeq ($(HAS_ALTIVEC),yes)
Quoted 8 lines

lib/raid6/test/Makefile else ifeq ($(HAS_NEON),yes) · line 54

Quoted 6 lines
lib/raid6/test/Makefile +4 -0
+		CFLAGS += -I../../../arch/powerpc/include
+		CFLAGS += -DCONFIG_ALTIVEC
+		OBJS += altivec1.o altivec2.o altivec4.o altivec8.o \
+			vpermxor1.o vpermxor2.o vpermxor4.o vpermxor8.o
         endif
 endif

Looks like vim has replaced spaces with tabs here. Not sure how much we care...

We care at least because it makes the diff look bigger than it really is, if I'm reading it right the first three lines haven't actually changed.

Quoted 5 lines

lib/raid6/test/Makefile altivec4.c: altivec.uc ../unroll.awk · line 101

Quoted 4 lines
lib/raid6/test/Makefile +0 -0
@@ -97,6 +99,18 @@ altivec4.c: altivec.uc ../unroll.awk
 altivec8.c: altivec.uc ../unroll.awk
 	$(AWK) ../unroll.awk -vN=8 < altivec.uc > $@
 

... especially seeing as tabs are already used in the file here!

It's a Makefile! Tabs have meaning :)

Quoted 4 lines

lib/raid6/vpermxor.uc line 89

Quoted 3 lines
lib/raid6/vpermxor.uc new file +3 -0
+# ifdef __KERNEL__
+	return (cpu_has_feature(CONFIG_ALTIVEC) &&
+		cpu_has_feature(CPU_FTR_ARCH_207S));

I think CPU_FTR_ARCH_207S implies Altivec? Again, not a real problem,

It doesn't.

And also CONFIG_ALTIVEC is not a cpu feature!

You should be using CPU_FTR_ALTIVEC_COMP. That copes with the case where the kernel is compiled without ALTIVEC support.

cheers