Skip to contentSkip to conversation

Add AVX512F optimization option and buffer_zero_avx512()

PATCH Applied Robert Hoo 3 participants 5 messages Feb 29, 2020 – Mar 6, 2020

lore
Share & tools
lore

Robert Hoo

author
#0 lore raw

v4 cover Add AVX512F optimization option and buffer_zero_avx512()

1) Introduce {enable,disable}-avx512f configure option

2) Implement new buffer_zero_avx512() with AVX512F instructions

Changes in v4:
In init_cpuid_cache(), stringently test AVX512F OS level enablement.

Changes in v3:
In init_accel(), init length_to_accel value in every accel case, because in unit test, it will be invoked several times with different accel cases. (Thanks Richard's careful review)

Changes in v2:
1. Fixes wrong definition of CACHE_SSE2 in v1.
2. Fixes not handle <256 length case in buffer_zero_avx512() implementaion. (Follow Richard's suggestion: handle the case in select_accel_fn(), and have a global variable alongside buffer_accel)
3. Changes avx512f configuration option's default status to disabled.
4. Ran 'make check-unit' on this patch, on both a Ivybridge machine and a CascadeLake machine.

Robert Hoo (2):
configure: add configure option avx512f_opt
util: add util function buffer_zero_avx512()

 configure            | 41 +++++++++++++++++++++++++++++
 include/qemu/cpuid.h |  3 +++
 util/bufferiszero.c  | 74 +++++++++++++++++++++++++++++++++++++++++++++-------
 3 files changed, 108 insertions(+), 10 deletions(-)
Signature · 1 line
1.8.3.1
author
#2 lore raw

PATCH v4 2/2 util: add util function buffer_zero_avx512()

And intialize buffer_is_zero() with it, when Intel AVX512F is available on host.

This function utilizes Intel AVX512 fundamental instructions which is faster than its implementation with AVX2 (in my unit test, with 4K buffer, on CascadeLake SP, ~36% faster, buffer_zero_avx512() V.S. buffer_zero_avx2()).

---
 include/qemu/cpuid.h |  3 +++
 util/bufferiszero.c  | 74 +++++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 67 insertions(+), 10 deletions(-)
include/qemu/cpuid.h +3 -0
index 6930170..09fc245 100644
@@ -45,6 +45,9 @@
 #ifndef bit_AVX2
 #define bit_AVX2        (1 << 5)
 #endif
+#ifndef bit_AVX512F
+#define bit_AVX512F        (1 << 16)
+#endif
 #ifndef bit_BMI2
 #define bit_BMI2        (1 << 8)
 #endif
util/bufferiszero.c +64 -10

141 lines not on this page · raw message

Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH v4 1/2 configure: add configure option avx512f_opt

In reply to Robert Hoo

If it is enabled, config-host.mak will have CONFIG_AVX512F_OPT defined.

AVX512F instruction set is available since Intel Skylake, and can be enabled in compiling with -mavx512f.
More info:
https://software.intel.com/sites/default/files/managed/c5/15/architecture-instruction-set-extensions-programming-reference.pdf

---
 configure | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
configure +41 -0
index d57261e..a0b41ce 100755
@@ -1395,6 +1395,11 @@ for opt do
   ;;
   --enable-avx2) avx2_opt="yes"
   ;;
+  --disable-avx512f) avx512f_opt="no"
+  ;;
+  --enable-avx512f) avx512f_opt="yes"
+  ;;
+
   --enable-glusterfs) glusterfs="yes"
   ;;
   --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
@@ -1825,6 +1830,7 @@ disabled with --disable-FEATURE, default is enabled if available:
   tcmalloc        tcmalloc support
   jemalloc        jemalloc support
   avx2            AVX2 optimization support
+  avx512f         AVX512F optimization support
   replication     replication support
   opengl          opengl support
   virglrenderer   virgl rendering support
@@ -5518,6 +5524,36 @@ EOF
   fi
 fi
 
+##########################################
+# avx512f optimization requirement check
+#
+# There is no point enabling this if cpuid.h is not usable,
+# since we won't be able to select the new routines.
+# by default, it is turned off.
+# if user explicitly want to enable it, check environment
+
+if test "$cpuid_h" = "yes" && test "$avx512f_opt" = "yes"; then
+  cat > $TMPC << EOF
+#pragma GCC push_options
+#pragma GCC target("avx512f")
+#include <cpuid.h>
+#include <immintrin.h>
+static int bar(void *a) {
+    __m512i x = *(__m512i *)a;
+    return _mm512_test_epi64_mask(x, x);
+}
+int main(int argc, char *argv[])
+{
+	return bar(argv[0]);
+}
+EOF
+  if ! compile_object "" ; then
+    avx512f_opt="no"
+  fi
+else
+  avx512f_opt="no"
+fi
+
 ########################################
 # check if __[u]int128_t is usable.
 
@@ -6650,6 +6686,7 @@ echo "libxml2           $libxml2"
 echo "tcmalloc support  $tcmalloc"
 echo "jemalloc support  $jemalloc"
 echo "avx2 optimization $avx2_opt"
+echo "avx512f optimization $avx512f_opt"
 echo "replication support $replication"
 echo "VxHS block device $vxhs"
 echo "bochs support     $bochs"
@@ -7200,6 +7237,10 @@ if test "$avx2_opt" = "yes" ; then
   echo "CONFIG_AVX2_OPT=y" >> $config_host_mak
 fi
 
+if test "$avx512f_opt" = "yes" ; then
+  echo "CONFIG_AVX512F_OPT=y" >> $config_host_mak
+fi
+
 if test "$lzo" = "yes" ; then
   echo "CONFIG_LZO=y" >> $config_host_mak
 fi
Signature · 1 line
1.8.3.1
Reviewed-by on v4 2/2
#3 lore raw

Re: [PATCH v4 2/2] util: add util function buffer_zero_avx512()

In reply to Robert Hoo
Quoted 8 lines · Robert Hoo

And intialize buffer_is_zero() with it, when Intel AVX512F is available on host.

This function utilizes Intel AVX512 fundamental instructions which is faster than its implementation with AVX2 (in my unit test, with 4K buffer, on CascadeLake SP, ~36% faster, buffer_zero_avx512() V.S. buffer_zero_avx2()).

Quoted 5 lines
---
 include/qemu/cpuid.h |  3 +++
 util/bufferiszero.c  | 74 +++++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 67 insertions(+), 10 deletions(-)

r~

#4 lore raw
In reply to Robert Hoo
Quoted 22 lines · Robert Hoo

1) Introduce {enable,disable}-avx512f configure option

2) Implement new buffer_zero_avx512() with AVX512F instructions

Changes in v4:
In init_cpuid_cache(), stringently test AVX512F OS level enablement.

Changes in v3:
In init_accel(), init length_to_accel value in every accel case, because in unit test, it will be invoked several times with different accel cases. (Thanks Richard's careful review)

Changes in v2:
1. Fixes wrong definition of CACHE_SSE2 in v1.
2. Fixes not handle <256 length case in buffer_zero_avx512() implementaion. (Follow Richard's suggestion: handle the case in select_accel_fn(), and have a global variable alongside buffer_accel)
3. Changes avx512f configuration option's default status to disabled.
4. Ran 'make check-unit' on this patch, on both a Ivybridge machine and a CascadeLake machine.

Quoted 9 lines

Robert Hoo (2):
configure: add configure option avx512f_opt
util: add util function buffer_zero_avx512()

 configure            | 41 +++++++++++++++++++++++++++++
 include/qemu/cpuid.h |  3 +++
 util/bufferiszero.c  | 74 +++++++++++++++++++++++++++++++++++++++++++++-------
 3 files changed, 108 insertions(+), 10 deletions(-)

Queued, thanks.

Paolo