AVX2 configure fixes
v3 cover AVX2 configure fixes
From: "Dr. David Alan Gilbert" <[email protected]>
Hi,
This pair of patches fixes a couple of issues that we found during test.
The first is that the configure test is pessimistic when compiled with -O2, the second is that the explicit 4.9 gcc test is a bit coarse; I've removed that test but beefed up the ./configure test to actually use the avx2 intrinsics and that fails in the same way as the main code, so it works in the same way as the explicit check but allows older gcc's to work when -save-temps isn't used.
Dave
v3
Use compile_object rather than compile_prog as suggested by Peter to hopefully fail on his ccache setup.
v2
Remove the explicit version check
Split the patches
Dr. David Alan Gilbert (2):
Make avx2 configure test work with -O2
avx2 configure: Use primitives in test
configure | 17 ++++++++++++----- util/cutils.c | 8 +------- 2 files changed, 13 insertions(+), 12 deletions(-)
Signature · 1 line
2.7.4
PATCH v3 1/2 Make avx2 configure test work with -O2
From: "Dr. David Alan Gilbert" <[email protected]>
When configured with --extra-cflags=-O2 gcc optimised out the test and the readelf failed the check leaving avx2 disabled.
--- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
configure +1 -1
@@ -1784,7 +1784,7 @@ fi cat > $TMPC << EOF static void bar(void) {} static void *bar_ifunc(void) {return (void*) bar;} -static void foo(void) __attribute__((ifunc("bar_ifunc"))); +void foo(void) __attribute__((ifunc("bar_ifunc"))); int main(void) { foo(); return 0; } EOF if compile_prog "-mavx2" "" ; then
Signature · 1 line
2.7.4
PATCH v3 2/2 avx2 configure: Use primitives in test
In reply to Dr. David Alan Gilbert (git)From: "Dr. David Alan Gilbert" <[email protected]>
Use the avx2 primitives during the test, thus making sure that the compiler and assembler could actually use avx2.
This also detects the failure case on gcc 4.8.x with -save-temps and avoids the need for the gcc version check in cutils.
--- configure | 17 ++++++++++++----- util/cutils.c | 8 +------- 2 files changed, 13 insertions(+), 12 deletions(-)
configure +12 -5
@@ -1782,13 +1782,20 @@ fi # avx2 optimization requirement check cat > $TMPC << EOF -static void bar(void) {} +#pragma GCC push_options +#pragma GCC target("avx2") +#include <cpuid.h> +#include <immintrin.h> + +static int bar(void *a) { + return _mm256_movemask_epi8(_mm256_cmpeq_epi8(*(__m256i *)a, (__m256i){0})); +} static void *bar_ifunc(void) {return (void*) bar;} -void foo(void) __attribute__((ifunc("bar_ifunc"))); -int main(void) { foo(); return 0; } +int foo(void *a) __attribute__((ifunc("bar_ifunc"))); +int main(int argc, char *argv[]) { return foo(argv[0]);} EOF -if compile_prog "-mavx2" "" ; then - if readelf --syms $TMPE |grep "IFUNC.*foo" >/dev/null 2>&1; then +if compile_object "" ; then + if readelf --syms $TMPO |grep "IFUNC.*foo" >/dev/null 2>&1; then avx2_opt="yes" fi fi
util/cutils.c +1 -7
@@ -256,13 +256,7 @@ static size_t buffer_find_nonzero_offset_inner(const void *buf, size_t len)return i *sizeof (VECTYPE ); } -/* -* GCC before version 4.9 has a bug which will cause the target -* attribute work incorrectly and failed to compile in some case, -* restrict the gcc version to 4.9+ to prevent the failure. -*/ - -#if definedCONFIG_AVX2_OPT &&QEMU_GNUC_PREREQ (4 ,9 ) +#if definedCONFIG_AVX2_OPT #pragma GCC push_options#pragma GCC target("avx2")#include <cpuid.h>
Signature · 1 line
2.7.4
Paolo Bonzini
AppliedQuoted 11 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Hi,
This pair of patches fixes a couple of issues that we found during test.
The first is that the configure test is pessimistic when compiled with -O2, the second is that the explicit 4.9 gcc test is a bit coarse; I've removed that test but beefed up the ./configure test to actually use the avx2 intrinsics and that fails in the same way as the main code, so it works in the same way as the explicit check but allows older gcc's to work when -save-temps isn't used.
Quoted 5 lines
Dave
v3
Usecompile_objectrather thancompile_progas suggested by Peter to hopefully fail on his ccache setup.
Queued, thanks.
Paolo
Quoted 13 lines
v2
Remove the explicit version check
Split the patchesDr. David Alan Gilbert (2):
Make avx2 configure test work with -O2
avx2 configure: Use primitives in testconfigure | 17 ++++++++++++----- util/cutils.c | 8 +------- 2 files changed, 13 insertions(+), 12 deletions(-)
Quoted 11 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Hi,
This pair of patches fixes a couple of issues that we found during test.
The first is that the configure test is pessimistic when compiled with -O2, the second is that the explicit 4.9 gcc test is a bit coarse; I've removed that test but beefed up the ./configure test to actually use the avx2 intrinsics and that fails in the same way as the main code, so it works in the same way as the explicit check but allows older gcc's to work when -save-temps isn't used.
Quoted 5 lines
Dave
v3
Usecompile_objectrather thancompile_progas suggested by Peter to hopefully fail on his ccache setup.
I ran these patches through my build tests and it all compiled OK, so the new configure test does correctly say "no AVX" on this setup.
thanks
-- PMM
Quoted 13 lines · * Peter Maydell ([email protected]) wrote:
Quoted 11 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Hi,
This pair of patches fixes a couple of issues that we found during test.
The first is that the configure test is pessimistic when compiled with -O2, the second is that the explicit 4.9 gcc test is a bit coarse; I've removed that test but beefed up the ./configure test to actually use the avx2 intrinsics and that fails in the same way as the main code, so it works in the same way as the explicit check but allows older gcc's to work when -save-temps isn't used.
Quoted 8 lines
Quoted 5 lines
Dave
v3
Usecompile_objectrather thancompile_progas suggested by Peter to hopefully fail on his ccache setup.I ran these patches through my build tests and it all compiled OK, so the new configure test does correctly say "no AVX" on this setup.
Thanks for checking.
Dave
Quoted 3 lines
thanks
-- PMM
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH v3 2/2] avx2 configure: Use primitives in test
In reply to Dr. David Alan Gilbert (git)Quoted 7 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Use the avx2 primitives during the test, thus making sure that the compiler and assembler could actually use avx2.
This also detects the failure case on gcc 4.8.x with -save-temps and avoids the need for the gcc version check in cutils.
I'm getting a segfault when running the latest tip compiled with gcc 4.8.4 on Ubuntu 14.04 and I've bisected it to this commit.
# gcc --version gcc (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4
I'm configuring with:
# ./configure \
--static \
--disable-gtk \
--target-list=aarch64-softmmuWhen run under gdb, I get:
Program received signal SIGSEGV, Segmentation fault. buffer_find_nonzero_offset_ifunc () at ./util/cutils.c:333
333 {
(gdb) bt
#0 buffer_find_nonzero_offset_ifunc () at ./util/cutils.c:333 #1 0x0000000000939c58 in __libc_start_main () #2 0x0000000000419337 in _start ()
I confess I don't understand the intricacies here, but I'm willing to test fixes if you have any ideas for how to make this also work for my compiler without blindly excluding all gcc < 4.9.
-Aaron
Re: [Qemu-devel] [PATCH v3 2/2] avx2 configure: Use primitives in test
Quoted 26 lines · Aaron Lindsay
Quoted 7 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Use the avx2 primitives during the test, thus making sure that the compiler and assembler could actually use avx2.
This also detects the failure case on gcc 4.8.x with -save-temps and avoids the need for the gcc version check in cutils.
I'm getting a segfault when running the latest tip compiled with gcc 4.8.4 on Ubuntu 14.04 and I've bisected it to this commit.
# gcc --version gcc (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4I'm configuring with:
# ./configure \ --static \ --disable-gtk \ --target-list=aarch64-softmmuWhen run under gdb, I get:
Program received signal SIGSEGV, Segmentation fault.buffer_find_nonzero_offset_ifunc() at./util/cutils.c:333
333 {
(gdb) bt
Quoted 7 lines
#0 buffer_find_nonzero_offset_ifunc () at ./util/cutils.c:333 #1 0x0000000000939c58 in __libc_start_main () #2 0x0000000000419337 in _start ()I confess I don't understand the intricacies here, but I'm willing to test fixes if you have any ideas for how to make this also work for my compiler without blindly excluding all gcc < 4.9.
Hmm, it's possible that we have to disable ifunc together with --static.
Paolo
Re: [Qemu-devel] [PATCH v3 2/2] avx2 configure: Use primitives in test
Quoted 8 lines · Paolo Bonzini
Quoted 5 lines · Aaron Lindsay
I'm configuring with:
# ./configure \ --static \ --disable-gtk \ --target-list=aarch64-softmmuHmm, it's possible that we have to disable ifunc together with --static.
I'm still tempted to say we should just forbid building the softmmu binaries with --static, unless somebody has a serious use case for it...
thanks
-- PMM
Re: [Qemu-devel] [PATCH v3 2/2] avx2 configure: Use primitives in test
In reply to Aaron LindsayQuoted 26 lines · * Aaron Lindsay ([email protected]) wrote:
Quoted 7 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Use the avx2 primitives during the test, thus making sure that the compiler and assembler could actually use avx2.
This also detects the failure case on gcc 4.8.x with -save-temps and avoids the need for the gcc version check in cutils.
I'm getting a segfault when running the latest tip compiled with gcc 4.8.4 on Ubuntu 14.04 and I've bisected it to this commit.
# gcc --version gcc (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4I'm configuring with:
# ./configure \ --static \ --disable-gtk \ --target-list=aarch64-softmmuWhen run under gdb, I get:
Program received signal SIGSEGV, Segmentation fault.buffer_find_nonzero_offset_ifunc() at./util/cutils.c:333
333 {
(gdb) bt
Quoted 7 lines
#0 buffer_find_nonzero_offset_ifunc () at ./util/cutils.c:333 #1 0x0000000000939c58 in __libc_start_main () #2 0x0000000000419337 in _start ()I confess I don't understand the intricacies here, but I'm willing to test fixes if you have any ideas for how to make this also work for my compiler without blindly excluding all gcc < 4.9.
Does it work if you configure without the --static?
Dave
Quoted 2 lines
-Aaron
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH v3 2/2] avx2 configure: Use primitives in test
Quoted 8 lines · Dr. David Alan Gilbert
Quoted 5 lines · * Aaron Lindsay ([email protected]) wrote:
I'm configuring with:
# ./configure \ --static \ --disable-gtk \ --target-list=aarch64-softmmuDoes it work if you configure without the --static?
Yes, it works if I configure without --static.
-Aaron
Re: [Qemu-devel] [PATCH v3 2/2] avx2 configure: Use primitives in test
In reply to Peter MaydellQuoted 8 lines · Peter Maydell
Quoted 6 lines · Paolo Bonzini
Quoted 5 lines · Aaron Lindsay
I'm configuring with:
# ./configure \ --static \ --disable-gtk \ --target-list=aarch64-softmmu
Quoted 4 lines
Quoted 1 line
Hmm, it's possible that we have to disable ifunc together with --static.
I'm still tempted to say we should just forbid building the softmmu binaries with --static, unless somebody has a serious use case for it...
FWIW, we do find it convenient to be able to compile one binary capable of running on multiple systems with different (and incompatible) library versions.
-Aaron
Re: [Qemu-devel] [PATCH v3 2/2] avx2 configure: Use primitives in test
Quoted 9 lines · Aaron Lindsay
Quoted 8 lines · Peter Maydell
Quoted 6 lines · Paolo Bonzini
Quoted 5 lines · Aaron Lindsay
I'm configuring with:
# ./configure \ --static \ --disable-gtk \ --target-list=aarch64-softmmu
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Hmm, it's possible that we have to disable ifunc together with --static.
I'm still tempted to say we should just forbid building the softmmu binaries with --static, unless somebody has a serious use case for it...
FWIW, we do find it convenient to be able to compile one binary capable of running on multiple systems with different (and incompatible) library versions.
The difficulty here is that the system emulators may call functions in glibc which do dynamic resolution anyway, and so "require the shared libraries from the glibc version used for linking", to quote the linker warning. For the user-only binaries we can claim we don't make those function calls, but for softmmu we do.
thanks
-- PMM
Re: [Qemu-devel] [PATCH v3 2/2] avx2 configure: Use primitives in test
In reply to Aaron LindsayQuoted 11 lines · * Aaron Lindsay ([email protected]) wrote:
Quoted 8 lines · Dr. David Alan Gilbert
Quoted 5 lines · * Aaron Lindsay ([email protected]) wrote:
I'm configuring with:
# ./configure \ --static \ --disable-gtk \ --target-list=aarch64-softmmuDoes it work if you configure without the --static?
Yes, it works if I configure without --static.
Hmm; I wonder what the best fix is here; we could just disable it with static; it seems an easy fix assuming very few people care about the combination of avx2 performance and static, or we could try and detect the problem/old version. (it seems fine on a modern Fedora; have you tried using a modern Ubuntu?)
Dave
Quoted 2 lines
-Aaron
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH v3 2/2] avx2 configure: Use primitives in test
Quoted 11 lines · Dr. David Alan Gilbert
Quoted 10 lines · * Aaron Lindsay ([email protected]) wrote:
Quoted 8 lines · Dr. David Alan Gilbert
Quoted 5 lines · * Aaron Lindsay ([email protected]) wrote:
I'm configuring with:
# ./configure \ --static \ --disable-gtk \ --target-list=aarch64-softmmuDoes it work if you configure without the --static?
Quoted 8 lines
Quoted 1 line
Yes, it works if I configure without --static.
Hmm; I wonder what the best fix is here; we could just disable it with static; it seems an easy fix assuming very few people care about the combination of avx2 performance and static, or we could try and detect the problem/old version. (it seems fine on a modern Fedora; have you tried using a modern Ubuntu?)
That seems like a reasonable fix to me. Assuming your intention was to do this in 'configure', I'll send out a patch shortly.
Unfortunately I haven't been able to try on a 'modern' Ubuntu yet.
-Aaron
--
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH 1/1 avx2 configure: Disable if static build
This avoids a segfault like the following for at least some 4.8 versions of gcc when configured with --static if avx2 instructions are also enabled:
Program received signal SIGSEGV, Segmentation fault.
buffer_find_nonzero_offset_ifunc () at ./util/cutils.c:333
333 {
(gdb) bt
#0 buffer_find_nonzero_offset_ifunc () at ./util/cutils.c:333
#1 0x0000000000939c58 in __libc_start_main ()
#2 0x0000000000419337 in _start ()--- configure | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
configure +10 -7
@@ -1788,7 +1788,9 @@ fi ########################################## # avx2 optimization requirement check -cat > $TMPC << EOF + +if test "$static" = "no" ; then + cat > $TMPC << EOF #pragma GCC push_options #pragma GCC target("avx2") #include <cpuid.h>
@@ -1801,12 +1803,13 @@ static void *bar_ifunc(void) {return (void*) bar;} int foo(void *a) __attribute__((ifunc("bar_ifunc"))); int main(int argc, char *argv[]) { return foo(argv[0]);} EOF -if compile_object "" ; then - if has readelf; then - if readelf --syms $TMPO 2>/dev/null |grep -q "IFUNC.*foo"; then - avx2_opt="yes" - fi - fi + if compile_object "" ; then + if has readelf; then + if readelf --syms $TMPO 2>/dev/null |grep -q "IFUNC.*foo"; then + avx2_opt="yes" + fi + fi + fi fi #########################################
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [Qemu-devel] [PATCH v3 2/2] avx2 configure: Use primitives in test
In reply to Peter MaydellQuoted 19 lines · Peter Maydell
Quoted 9 lines · Aaron Lindsay
Quoted 8 lines · Peter Maydell
Quoted 6 lines · Paolo Bonzini
Quoted 5 lines · Aaron Lindsay
I'm configuring with:
# ./configure \ --static \ --disable-gtk \ --target-list=aarch64-softmmuQuoted 8 lines
Quoted 4 lines
Quoted 1 line
Hmm, it's possible that we have to disable ifunc together with --static.
I'm still tempted to say we should just forbid building the softmmu binaries with --static, unless somebody has a serious use case for it...
FWIW, we do find it convenient to be able to compile one binary capable of running on multiple systems with different (and incompatible) library versions.
Quoted 6 lines
The difficulty here is that the system emulators may call functions in glibc which do dynamic resolution anyway, and so "require the shared libraries from the glibc version used for linking", to quote the linker warning. For the user-only binaries we can claim we don't make those function calls, but for softmmu we do.
We haven't observed any problems with this approach so far, but your point is well taken. Perhaps we get what we deserve if we insist on statically compiling ;-)
-Aaron
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [Qemu-devel] [PATCH] avx2 configure: Disable if static build
In reply to Aaron LindsayQuoted 12 lines · * Aaron Lindsay ([email protected]) wrote:
This avoids a segfault like the following for at least some 4.8 versions of gcc when configured with --static if avx2 instructions are also enabled:
Program received signal SIGSEGV, Segmentation fault. buffer_find_nonzero_offset_ifunc () at ./util/cutils.c:333 333 { (gdb) bt #0 buffer_find_nonzero_offset_ifunc () at ./util/cutils.c:333 #1 0x0000000000939c58 in __libc_start_main () #2 0x0000000000419337 in _start ()
Quoted 1 line
Signed-off-by Aaron Lindsay <[email protected]>
It does look like the simplest solution to the problem;
Dave
Quoted 44 lines
--- configure | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)configure +10
-7@@ -1788,7 +1788,9 @@ fi ########################################## # avx2 optimization requirement check -cat > $TMPC << EOF + +if test "$static" = "no" ; then + cat > $TMPC << EOF #pragma GCC push_options #pragma GCC target("avx2") #include <cpuid.h>@@ -1801,12 +1803,13 @@ static void *bar_ifunc(void) {return (void*) bar;} int foo(void *a) __attribute__((ifunc("bar_ifunc"))); int main(int argc, char *argv[]) { return foo(argv[0]);} EOF -if compile_object "" ; then - if has readelf; then - if readelf --syms $TMPO 2>/dev/null |grep -q "IFUNC.*foo"; then - avx2_opt="yes" - fi - fi + if compile_object "" ; then + if has readelf; then + if readelf --syms $TMPO 2>/dev/null |grep -q "IFUNC.*foo"; then + avx2_opt="yes" + fi + fi + fi fi #########################################Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Peter Maydell
AppliedRe: [Qemu-devel] [PATCH] avx2 configure: Disable if static build
Quoted 13 lines · Dr. David Alan Gilbert
Quoted 12 lines · * Aaron Lindsay ([email protected]) wrote:
This avoids a segfault like the following for at least some 4.8 versions of gcc when configured with --static if avx2 instructions are also enabled:
Program received signal SIGSEGV, Segmentation fault. buffer_find_nonzero_offset_ifunc () at ./util/cutils.c:333 333 { (gdb) bt #0 buffer_find_nonzero_offset_ifunc () at ./util/cutils.c:333 #1 0x0000000000939c58 in __libc_start_main () #2 0x0000000000419337 in _start ()
Quoted 5 lines
Quoted 1 line
Signed-off-by Aaron Lindsay <[email protected]>It does look like the simplest solution to the problem;
Reviewed-by Dr. David Alan Gilbert <[email protected]>
Applied to master, thanks.
-- PMM