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

selftests/powerpc: Fix generation of vector instructions/types in context_switch

Currently it doesn't appear the resulting binary actually uses any
Altivec or VSX instructions the solution is to explicitly tell GCC to
use vector instructions and use vector types in the code.

Part of this this issue can be GCC version specific:

GCC 4.9.x is happy to use Altivec and VSX instructions if altivec.h is
includedi (and possibly if vector types are used), this also means that
4.9.x will use VSX instructions even if only -maltivec is passed. It is
also possible that Altivec instructions will be used even without
-maltivec or -mabi=altivec.

GCC 5.2.x complains about the lack of -maltivec parameter if altivec.h
is included and will not use VSX unless -mvsx is present on commandline.

GCC 5.3.0 has a regression that means __attribute__((__target__("no-vsx"))
fails to build. A fix is targeted for 5.4.

Furthermore LTO (Link Time Optimisation) doesn't play well with
__attribute__((__target__("no-vsx")), LTO can cause GCC to forget about
the attribute and compile with VSX instructions regardless. Be wary when
enabling -flfo for this test.

Signed-off-by: Cyril Bur <cyrilbur@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

authored by

Cyril Bur and committed by
Michael Ellerman
f2418ae8 94fa56a9

+9 -3
+1
tools/testing/selftests/powerpc/benchmarks/Makefile
··· 7 7 $(TEST_PROGS): ../harness.c 8 8 9 9 context_switch: ../utils.c 10 + context_switch: CFLAGS += -maltivec -mvsx -mabi=altivec 10 11 context_switch: LDLIBS += -lpthread 11 12 12 13 include ../../lib.mk
+8 -3
tools/testing/selftests/powerpc/benchmarks/context_switch.c
··· 25 25 #include <sys/types.h> 26 26 #include <sys/shm.h> 27 27 #include <linux/futex.h> 28 - 28 + #ifdef __powerpc__ 29 + #include <altivec.h> 30 + #endif 29 31 #include "../utils.h" 30 32 31 33 static unsigned int timeout = 30; ··· 39 37 double fp; 40 38 41 39 static int touch_vector = 1; 42 - typedef int v4si __attribute__ ((vector_size (16))); 43 - v4si a, b, c; 40 + vector int a, b, c; 44 41 45 42 #ifdef __powerpc__ 46 43 static int touch_altivec = 1; 47 44 45 + /* 46 + * Note: LTO (Link Time Optimisation) doesn't play well with this function 47 + * attribute. Be very careful enabling LTO for this test. 48 + */ 48 49 static void __attribute__((__target__("no-vsx"))) altivec_touch_fn(void) 49 50 { 50 51 c = a + b;