From nobody Fri May 17 10:44:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1582979834; cv=none; d=zohomail.com; s=zohoarc; b=aVql/ixDAzFAKzYAHMKmGH/Vp28axPQr5O2CG15QIbC1GXEGltmxZT6MR/1ffedQrAvVynVgM5IVxh2ksFDSO7IriIzLAB4j7rN/CyDQ+afUtdtS0qzs9eeiITRpsAE2pcmMzhb3idJPrnGrNeB7lsqlIaJCU4/qjB08Q0Lo65A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582979834; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=GZ/JsRxGPz/Efye1I2jW8nIclY+notRgotXzPRNYQ+Q=; b=I/uC7Ezf7uaMMtt5G82smq8ZlJcU6uYjz3BUuH382j0aiVbNlpUfA5N+1NogQohDTeDwSIcE4tNkGS7m99b+TDC9QVfR4bI7ucv1XeTVJKCj3jlZW0PS5z5GyBaWWXsFeeEFbkAy0DRimentuPDxXkh/NysIWVye5lIjpbCU9Aw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582979834054761.5456926126989; Sat, 29 Feb 2020 04:37:14 -0800 (PST) Received: from localhost ([::1]:60116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j81Mm-0006ti-E6 for importer@patchew.org; Sat, 29 Feb 2020 07:37:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59158) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j81KX-0004eO-A2 for qemu-devel@nongnu.org; Sat, 29 Feb 2020 07:34:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j81KW-00080e-1U for qemu-devel@nongnu.org; Sat, 29 Feb 2020 07:34:53 -0500 Received: from mga17.intel.com ([192.55.52.151]:29708) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j81KV-000807-Q6 for qemu-devel@nongnu.org; Sat, 29 Feb 2020 07:34:51 -0500 Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Feb 2020 04:34:50 -0800 Received: from sqa-gate.sh.intel.com (HELO robert-ivt.tsp.org) ([10.239.48.212]) by orsmga006.jf.intel.com with ESMTP; 29 Feb 2020 04:34:48 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,499,1574150400"; d="scan'208";a="242654293" From: Robert Hoo To: qemu-devel@nongnu.org, pbonzini@redhat.com, richard.henderson@linaro.org, laurent@vivier.eu, philmd@redhat.com, berrange@redhat.com Subject: [PATCH v4 1/2] configure: add configure option avx512f_opt Date: Sat, 29 Feb 2020 20:34:34 +0800 Message-Id: <1582979675-22550-2-git-send-email-robert.hu@linux.intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1582979675-22550-1-git-send-email-robert.hu@linux.intel.com> References: <1582979675-22550-1-git-send-email-robert.hu@linux.intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.151 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: robert.hu@intel.com, chao.p.peng@intel.com, Robert Hoo Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If it is enabled, config-host.mak will have CONFIG_AVX512F_OPT defined. AVX512F instruction set is available since Intel Skylake, and can be enable= d in compiling with -mavx512f. More info: https://software.intel.com/sites/default/files/managed/c5/15/architecture-i= nstruction-set-extensions-programming-reference.pdf Signed-off-by: Robert Hoo Reviewed-by: Richard Henderson --- configure | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/configure b/configure index d57261e..a0b41ce 100755 --- a/configure +++ b/configure @@ -1395,6 +1395,11 @@ for opt do ;; --enable-avx2) avx2_opt=3D"yes" ;; + --disable-avx512f) avx512f_opt=3D"no" + ;; + --enable-avx512f) avx512f_opt=3D"yes" + ;; + --enable-glusterfs) glusterfs=3D"yes" ;; --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane) @@ -1825,6 +1830,7 @@ disabled with --disable-FEATURE, default is enabled i= f 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 =20 +########################################## +# 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" =3D "yes" && test "$avx512f_opt" =3D "yes"; then + cat > $TMPC << EOF +#pragma GCC push_options +#pragma GCC target("avx512f") +#include +#include +static int bar(void *a) { + __m512i x =3D *(__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=3D"no" + fi +else + avx512f_opt=3D"no" +fi + ######################################## # check if __[u]int128_t is usable. =20 @@ -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" =3D "yes" ; then echo "CONFIG_AVX2_OPT=3Dy" >> $config_host_mak fi =20 +if test "$avx512f_opt" =3D "yes" ; then + echo "CONFIG_AVX512F_OPT=3Dy" >> $config_host_mak +fi + if test "$lzo" =3D "yes" ; then echo "CONFIG_LZO=3Dy" >> $config_host_mak fi --=20 1.8.3.1 From nobody Fri May 17 10:44:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1582979776; cv=none; d=zohomail.com; s=zohoarc; b=Pld5UYHmxA9aFEAsEQGCcHxywIGP1IDEak1CFc5W8we2b4/45BPDZv6LHGdkmX7rOkrJAjW6eXraT+qfk3cGVxqO4CT8u3fWrcPHYzOl2bRTqnzv2E24CeMS9ri32lKYdUUMhrGfoaMgqWqXMhNq2Xo7AZ+urMmXSJhwVzNQWD4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582979776; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=57A4L5eU7ux7LXMY9GabC2KAHj7EEnFOCuJTA9D9Uy8=; b=FmNuqWTBvyRIDN4E3OvCGeUSuEK1EdqccTUp4X9TQ7FVmb4t1qKI70fOZDXzHRyexFa8u8pnguA9A0vxKpiqpjFH815vG3U/TzH6NEAM6O+5s097HfmVwk5H5474i/nRYiYMbUYDlnONxpuy3OGZdJbTe1uOqik5sQVxNW9CfOw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582979776420824.4399491822696; Sat, 29 Feb 2020 04:36:16 -0800 (PST) Received: from localhost ([::1]:60108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j81Lr-0005e3-5f for importer@patchew.org; Sat, 29 Feb 2020 07:36:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59175) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j81KZ-0004ec-IW for qemu-devel@nongnu.org; Sat, 29 Feb 2020 07:34:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j81KY-00081T-AG for qemu-devel@nongnu.org; Sat, 29 Feb 2020 07:34:55 -0500 Received: from mga17.intel.com ([192.55.52.151]:29711) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j81KY-000815-2S for qemu-devel@nongnu.org; Sat, 29 Feb 2020 07:34:54 -0500 Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Feb 2020 04:34:53 -0800 Received: from sqa-gate.sh.intel.com (HELO robert-ivt.tsp.org) ([10.239.48.212]) by orsmga006.jf.intel.com with ESMTP; 29 Feb 2020 04:34:50 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,499,1574150400"; d="scan'208";a="242654297" From: Robert Hoo To: qemu-devel@nongnu.org, pbonzini@redhat.com, richard.henderson@linaro.org, laurent@vivier.eu, philmd@redhat.com, berrange@redhat.com Subject: [PATCH v4 2/2] util: add util function buffer_zero_avx512() Date: Sat, 29 Feb 2020 20:34:35 +0800 Message-Id: <1582979675-22550-3-git-send-email-robert.hu@linux.intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1582979675-22550-1-git-send-email-robert.hu@linux.intel.com> References: <1582979675-22550-1-git-send-email-robert.hu@linux.intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.151 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: robert.hu@intel.com, chao.p.peng@intel.com, Robert Hoo Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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()). Signed-off-by: Robert Hoo Reviewed-by: Richard Henderson --- include/qemu/cpuid.h | 3 +++ util/bufferiszero.c | 74 +++++++++++++++++++++++++++++++++++++++++++++---= ---- 2 files changed, 67 insertions(+), 10 deletions(-) diff --git a/include/qemu/cpuid.h b/include/qemu/cpuid.h index 6930170..09fc245 100644 --- a/include/qemu/cpuid.h +++ b/include/qemu/cpuid.h @@ -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 diff --git a/util/bufferiszero.c b/util/bufferiszero.c index bfb2605..b6eab0c 100644 --- a/util/bufferiszero.c +++ b/util/bufferiszero.c @@ -63,11 +63,11 @@ buffer_zero_int(const void *buf, size_t len) } } =20 -#if defined(CONFIG_AVX2_OPT) || defined(__SSE2__) +#if defined(CONFIG_AVX512F_OPT) || defined(CONFIG_AVX2_OPT) || defined(__S= SE2__) /* Do not use push_options pragmas unnecessarily, because clang * does not support them. */ -#ifdef CONFIG_AVX2_OPT +#if defined(CONFIG_AVX512F_OPT) || defined(CONFIG_AVX2_OPT) #pragma GCC push_options #pragma GCC target("sse2") #endif @@ -104,7 +104,7 @@ buffer_zero_sse2(const void *buf, size_t len) =20 return _mm_movemask_epi8(_mm_cmpeq_epi8(t, zero)) =3D=3D 0xFFFF; } -#ifdef CONFIG_AVX2_OPT +#if defined(CONFIG_AVX512F_OPT) || defined(CONFIG_AVX2_OPT) #pragma GCC pop_options #endif =20 @@ -187,18 +187,54 @@ buffer_zero_avx2(const void *buf, size_t len) #pragma GCC pop_options #endif /* CONFIG_AVX2_OPT */ =20 +#ifdef CONFIG_AVX512F_OPT +#pragma GCC push_options +#pragma GCC target("avx512f") +#include + +static bool +buffer_zero_avx512(const void *buf, size_t len) +{ + /* Begin with an unaligned head of 64 bytes. */ + __m512i t =3D _mm512_loadu_si512(buf); + __m512i *p =3D (__m512i *)(((uintptr_t)buf + 5 * 64) & -64); + __m512i *e =3D (__m512i *)(((uintptr_t)buf + len) & -64); + + /* Loop over 64-byte aligned blocks of 256. */ + while (p <=3D e) { + __builtin_prefetch(p); + if (unlikely(_mm512_test_epi64_mask(t, t))) { + return false; + } + t =3D p[-4] | p[-3] | p[-2] | p[-1]; + p +=3D 4; + } + + t |=3D _mm512_loadu_si512(buf + len - 4 * 64); + t |=3D _mm512_loadu_si512(buf + len - 3 * 64); + t |=3D _mm512_loadu_si512(buf + len - 2 * 64); + t |=3D _mm512_loadu_si512(buf + len - 1 * 64); + + return !_mm512_test_epi64_mask(t, t); + +} +#pragma GCC pop_options +#endif + + /* Note that for test_buffer_is_zero_next_accel, the most preferred * ISA must have the least significant bit. */ -#define CACHE_AVX2 1 -#define CACHE_SSE4 2 -#define CACHE_SSE2 4 +#define CACHE_AVX512F 1 +#define CACHE_AVX2 2 +#define CACHE_SSE4 4 +#define CACHE_SSE2 8 =20 /* Make sure that these variables are appropriately initialized when * SSE2 is enabled on the compiler command-line, but the compiler is * too old to support CONFIG_AVX2_OPT. */ -#ifdef CONFIG_AVX2_OPT +#if defined(CONFIG_AVX512F_OPT) || defined(CONFIG_AVX2_OPT) # define INIT_CACHE 0 # define INIT_ACCEL buffer_zero_int #else @@ -211,25 +247,35 @@ buffer_zero_avx2(const void *buf, size_t len) =20 static unsigned cpuid_cache =3D INIT_CACHE; static bool (*buffer_accel)(const void *, size_t) =3D INIT_ACCEL; +static int length_to_accel; =20 static void init_accel(unsigned cache) { bool (*fn)(const void *, size_t) =3D buffer_zero_int; if (cache & CACHE_SSE2) { fn =3D buffer_zero_sse2; + length_to_accel =3D 64; } #ifdef CONFIG_AVX2_OPT if (cache & CACHE_SSE4) { fn =3D buffer_zero_sse4; + length_to_accel =3D 64; } if (cache & CACHE_AVX2) { fn =3D buffer_zero_avx2; + length_to_accel =3D 64; + } +#endif +#ifdef CONFIG_AVX512F_OPT + if (cache & CACHE_AVX512F) { + fn =3D buffer_zero_avx512; + length_to_accel =3D 256; } #endif buffer_accel =3D fn; } =20 -#ifdef CONFIG_AVX2_OPT +#if defined(CONFIG_AVX512F_OPT) || defined(CONFIG_AVX2_OPT) #include "qemu/cpuid.h" =20 static void __attribute__((constructor)) init_cpuid_cache(void) @@ -252,9 +298,17 @@ static void __attribute__((constructor)) init_cpuid_ca= che(void) int bv; __asm("xgetbv" : "=3Da"(bv), "=3Dd"(d) : "c"(0)); __cpuid_count(7, 0, a, b, c, d); - if ((bv & 6) =3D=3D 6 && (b & bit_AVX2)) { + if ((bv & 0x6) =3D=3D 0x6 && (b & bit_AVX2)) { cache |=3D CACHE_AVX2; } + /* 0xe6: + * XCR0[7:5] =3D 111b (OPMASK state, upper 256-bit of ZMM0-ZMM= 15 + * and ZMM16-ZMM31 state are enabled by OS) + * XCR0[2:1] =3D 11b (XMM state and YMM state are enabled by O= S) + */ + if ((bv & 0xe6) =3D=3D 0xe6 && (b & bit_AVX512F)) { + cache |=3D CACHE_AVX512F; + } } } cpuid_cache =3D cache; @@ -277,7 +331,7 @@ bool test_buffer_is_zero_next_accel(void) =20 static bool select_accel_fn(const void *buf, size_t len) { - if (likely(len >=3D 64)) { + if (likely(len >=3D length_to_accel)) { return buffer_accel(buf, len); } return buffer_zero_int(buf, len); --=20 1.8.3.1