build: rework x86 CPU variants 81/26781/5
authorDamjan Marion <damarion@cisco.com>
Wed, 29 Apr 2020 19:28:15 +0000 (21:28 +0200)
committerDamjan Marion <damarion@cisco.com>
Thu, 30 Apr 2020 11:25:29 +0000 (13:25 +0200)
Type: improvement
Change-Id: Ief243f88e654e578ef9b8060fcf535b364aececb
Signed-off-by: Damjan Marion <damarion@cisco.com>
13 files changed:
Makefile
build-data/packages/libmemif.mk
build-data/packages/sample-plugin.mk
build-data/packages/vom.mk
build-data/packages/vpp.mk
extras/rpm/vpp.spec
src/CMakeLists.txt
src/cmake/cpu.cmake
src/vlib/node_cli.c
src/vppinfra/cpu.h
src/vppinfra/string.h
src/vppinfra/vector.h
test/test_node_variants.py

index 4a547b7..bf9cfcc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -59,11 +59,6 @@ else ifeq ($(filter rhel centos fedora opensuse opensuse-leap opensuse-tumblewee
 PKG=rpm
 endif
 
-# on ubuntu 18.04 prefer gcc-8 if it is installed and CC  is not set
-ifeq ($(OS_VERSION_ID)-$(CC)-$(shell which gcc-8 > /dev/null; echo $$?),18.04-cc-0)
-       CC = gcc-8
-endif
-
 # +libganglia1-dev if building the gmond plugin
 
 DEB_DEPENDS  = curl build-essential autoconf automake ccache
@@ -86,7 +81,7 @@ ifeq ($(OS_VERSION_ID),16.04)
 else ifeq ($(OS_VERSION_ID),18.04)
        DEB_DEPENDS += python-dev
        DEB_DEPENDS += libssl-dev
-       DEB_DEPENDS += gcc-8 clang-9
+       DEB_DEPENDS += clang-9
 else ifeq ($(OS_VERSION_ID),20.04)
        LIBFFI=libffi7
 else ifeq ($(OS_ID)-$(OS_VERSION_ID),debian-8)
@@ -132,7 +127,7 @@ else
        RPM_DEPENDS += python36-ply  # for vppapigen
        RPM_DEPENDS += python3-devel python3-pip
        RPM_DEPENDS += python-virtualenv python36-jsonschema
-       RPM_DEPENDS += devtoolset-7
+       RPM_DEPENDS += devtoolset-9
        RPM_DEPENDS += cmake3
        RPM_DEPENDS_GROUPS = 'Development Tools'
 endif
index 9bce09b..acc0d64 100644 (file)
@@ -27,8 +27,8 @@ libmemif_cmake_args += -DCMAKE_SHARED_LINKER_FLAGS="$($(TAG)_TAG_LDFLAGS)"
 libmemif_cmake_args += -DCMAKE_PREFIX_PATH:PATH="$(PACKAGE_INSTALL_DIR)/../vpp"
 
 # Use devtoolset on centos 7
-ifneq ($(wildcard /opt/rh/devtoolset-7/enable),)
-libmemif_cmake_args += -DCMAKE_PROGRAM_PATH:PATH="/opt/rh/devtoolset-7/root/bin"
+ifneq ($(wildcard /opt/rh/devtoolset-9/enable),)
+libmemif_cmake_args += -DCMAKE_PROGRAM_PATH:PATH="/opt/rh/devtoolset-9/root/bin"
 endif
 
 libmemif_configure = \
index 7785567..34188f9 100644 (file)
@@ -31,8 +31,8 @@ sample-plugin_cmake_args += -DCMAKE_SHARED_LINKER_FLAGS="$($(TAG)_TAG_LDFLAGS)"
 sample-plugin_cmake_args += -DCMAKE_PREFIX_PATH:PATH="$(PACKAGE_INSTALL_DIR)/../vpp"
 
 # Use devtoolset on centos 7
-ifneq ($(wildcard /opt/rh/devtoolset-7/enable),)
-sample-plugin_cmake_args += -DCMAKE_PROGRAM_PATH:PATH="/opt/rh/devtoolset-7/root/bin"
+ifneq ($(wildcard /opt/rh/devtoolset-9/enable),)
+sample-plugin_cmake_args += -DCMAKE_PROGRAM_PATH:PATH="/opt/rh/devtoolset-9/root/bin"
 endif
 
 sample-plugin_configure = \
index fefd49a..f284473 100644 (file)
@@ -28,8 +28,8 @@ vom_cmake_args += -DCMAKE_SHARED_LINKER_FLAGS="$($(TAG)_TAG_LDFLAGS)"
 vom_cmake_args += -DCMAKE_PREFIX_PATH:PATH="$(PACKAGE_INSTALL_DIR)/../vpp"
 
 # Use devtoolset on centos 7
-ifneq ($(wildcard /opt/rh/devtoolset-7/enable),)
-vom_cmake_args += -DCMAKE_PROGRAM_PATH:PATH="/opt/rh/devtoolset-7/root/bin"
+ifneq ($(wildcard /opt/rh/devtoolset-9/enable),)
+vom_cmake_args += -DCMAKE_PROGRAM_PATH:PATH="/opt/rh/devtoolset-9/root/bin"
 endif
 
 vom_configure = \
index 6571cd2..bbff1ba 100644 (file)
@@ -37,8 +37,8 @@ endif
 endif
 
 # Use devtoolset on centos 7
-ifneq ($(wildcard /opt/rh/devtoolset-7/enable),)
-vpp_cmake_args += -DCMAKE_PROGRAM_PATH:PATH="/opt/rh/devtoolset-7/root/bin"
+ifneq ($(wildcard /opt/rh/devtoolset-9/enable),)
+vpp_cmake_args += -DCMAKE_PROGRAM_PATH:PATH="/opt/rh/devtoolset-9/root/bin"
 endif
 
 ifneq ($(VPP_EXTRA_CMAKE_ARGS),)
index 726c9c4..f2de430 100644 (file)
@@ -68,7 +68,7 @@ BuildRequires: mbedtls-devel mbedtls
 BuildREquires: openssl-devel
 BuildRequires: python36-devel
 %if 0%{rhel} == 7
-BuildRequires: devtoolset-7-toolchain
+BuildRequires: devtoolset-9-toolchain
 BuildRequires: cmake3
 BuildRequires: glibc-static, yum-utils
 %else
@@ -177,7 +177,7 @@ groupadd -f -r vpp
 
 %build
 %if 0%{rhel} < 8
-. /opt/rh/devtoolset-7/enable
+. /opt/rh/devtoolset-9/enable
 %endif
 %if %{with aesni}
     make bootstrap
index 16ae7d5..1564fd0 100644 (file)
@@ -13,7 +13,7 @@
 
 cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
 
-set(CMAKE_C_COMPILER_NAMES clang-9 cc)
+set(CMAKE_C_COMPILER_NAMES clang-10 clang-9 gcc-9 cc)
 
 project(vpp C)
 
index 0ce8bea..0e47f33 100644 (file)
@@ -76,17 +76,21 @@ endif()
 ##############################################################################
 if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
   set(CMAKE_C_FLAGS "-march=corei7 -mtune=corei7-avx ${CMAKE_C_FLAGS}")
-  check_c_compiler_flag("-march=core-avx2" compiler_flag_march_core_avx2)
-  if(compiler_flag_march_core_avx2)
-    list(APPEND MARCH_VARIANTS "avx2\;-march=core-avx2 -mtune=core-avx2")
+  check_c_compiler_flag("-march=haswell" compiler_flag_march_haswell)
+  if(compiler_flag_march_haswell)
+    list(APPEND MARCH_VARIANTS "hsw\;-march=haswell -mtune=haswell")
   endif()
   if (GNU_ASSEMBLER_AVX512_BUG)
      message(WARNING "AVX-512 multiarch variant(s) disabled due to GNU Assembler bug")
   else()
+    check_c_compiler_flag("-mprefer-vector-width=256" compiler_flag_mprefer_vector_width)
     check_c_compiler_flag("-march=skylake-avx512" compiler_flag_march_skylake_avx512)
     check_c_compiler_flag("-march=icelake-client" compiler_flag_march_icelake_client)
-    if(compiler_flag_march_skylake_avx512)
-      list(APPEND MARCH_VARIANTS "avx512\;-march=skylake-avx512 -mtune=skylake-avx512")
+    if(compiler_flag_march_skylake_avx512 AND compiler_flag_mprefer_vector_width)
+      list(APPEND MARCH_VARIANTS "skx\;-march=skylake-avx512 -mtune=skylake-avx512 -mprefer-vector-width=256")
+    endif()
+    if(compiler_flag_march_icelake_client AND compiler_flag_mprefer_vector_width)
+      list(APPEND MARCH_VARIANTS "icl\;-march=icelake-client -mtune=icelake-client -mprefer-vector-width=512")
     endif()
   endif()
 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)")
index 750f69e..7cfc4a3 100644 (file)
@@ -623,7 +623,7 @@ show_node (vlib_main_t * vm, unformat_input_t * input,
          if (vec_len (s) == 0)
            s = format (s, "\n    %-15s  %=8s  %6s",
                        "Name", "Priority", "Active");
-         s = format (s, "\n    %-15s  %=8u  %=6s", fnr->name, fnr->priority,
+         s = format (s, "\n    %-15s  %8d  %=6s", fnr->name, fnr->priority,
                      fnr->function == n->function ? "yes" : "");
          fnr = fnr->next_registration;
        }
index 7bd5dfe..dc73c90 100644 (file)
@@ -132,6 +132,9 @@ _ (x86_aes,  1, ecx, 25)  \
 _ (sha,      7, ebx, 29)  \
 _ (vaes,     7, ecx, 9)   \
 _ (vpclmulqdq, 7, ecx, 10)   \
+_ (avx512_vnni, 7, ecx, 11)   \
+_ (avx512_bitalg, 7, ecx, 12)   \
+_ (avx512_vpopcntdq, 7, ecx, 14)   \
 _ (invariant_tsc, 0x80000007, edx, 8)
 
 
@@ -245,15 +248,23 @@ clib_cpu_supports_aes ()
 }
 
 static inline int
-clib_cpu_march_priority_avx512 ()
+clib_cpu_march_priority_icl ()
+{
+  if (clib_cpu_supports_avx512_bitalg ())
+    return 200;
+  return -1;
+}
+
+static inline int
+clib_cpu_march_priority_skx ()
 {
   if (clib_cpu_supports_avx512f ())
-    return 20;
+    return 100;
   return -1;
 }
 
 static inline int
-clib_cpu_march_priority_avx2 ()
+clib_cpu_march_priority_hsw ()
 {
   if (clib_cpu_supports_avx2 ())
     return 50;
index a3db926..3dafe89 100644 (file)
@@ -71,7 +71,7 @@ void clib_memswap (void *_a, void *_b, uword bytes);
  * so don't let it anywhere near them.
  */
 #ifndef __COVERITY__
-#if __AVX512F__
+#if __AVX512BITALG__
 #include <vppinfra/memcpy_avx512.h>
 #elif __AVX2__
 #include <vppinfra/memcpy_avx2.h>
index 906d8d8..8b08db2 100644 (file)
@@ -66,7 +66,7 @@
 #endif
 #endif
 
-#if defined (__AVX512F__)
+#if defined (__AVX512BITALG__)
 #define CLIB_HAVE_VEC512
 #endif
 
@@ -168,7 +168,10 @@ typedef u64 u64x _vector_size (8);
 #include <vppinfra/vector_avx2.h>
 #endif
 
-#if defined (__AVX512F__)
+#if defined (__AVX512BITALG__)
+/* Due to power level transition issues, we don't preffer AVX-512 on
+   Skylake X and CascadeLake CPUs, AVX512BITALG is introduced on
+   icelake CPUs  */
 #include <vppinfra/vector_avx512.h>
 #endif
 
index 8298dc8..3632910 100644 (file)
@@ -67,48 +67,73 @@ class TestNodeVariant(VppTestCase):
         self.assertEqual(variant_info[0], variant)
 
 
-class TestAVX512Variant(TestNodeVariant):
-    """ Test avx512 Node Variants """
+class TestICLVariant(TestNodeVariant):
+    """ Test icl Node Variants """
 
-    VARIANT = "avx512"
-    LINUX_VARIANT = VARIANT + "f"
+    VARIANT = "icl"
+    LINUX_VARIANT = "avx512_bitalg"
 
     @classmethod
     def setUpConstants(cls):
-        super(TestAVX512Variant, cls).setUpConstants(cls.VARIANT)
+        super(TestICLVariant, cls).setUpConstants(cls.VARIANT)
 
     @classmethod
     def setUpClass(cls):
-        super(TestAVX512Variant, cls).setUpClass()
+        super(TestICLVariant, cls).setUpClass()
 
     @classmethod
     def tearDownClass(cls):
-        super(TestAVX512Variant, cls).tearDownClass()
+        super(TestICLVariant, cls).tearDownClass()
 
     @unittest.skipUnless(skipVariant(LINUX_VARIANT),
                          VARIANT + " not a supported variant, skip.")
-    def test_avx512(self):
+    def test_icl(self):
         self.checkVariant(self.VARIANT)
 
 
-class TestAVX2Variant(TestNodeVariant):
+class TestSKXVariant(TestNodeVariant):
+    """ Test skx Node Variants """
+
+    VARIANT = "skx"
+    LINUX_VARIANT = "avx512f"
+
+    @classmethod
+    def setUpConstants(cls):
+        super(TestSKXVariant, cls).setUpConstants(cls.VARIANT)
+
+    @classmethod
+    def setUpClass(cls):
+        super(TestSKXVariant, cls).setUpClass()
+
+    @classmethod
+    def tearDownClass(cls):
+        super(TestSKXVariant, cls).tearDownClass()
+
+    @unittest.skipUnless(skipVariant(LINUX_VARIANT),
+                         VARIANT + " not a supported variant, skip.")
+    def test_skx(self):
+        self.checkVariant(self.VARIANT)
+
+
+class TestHSWVariant(TestNodeVariant):
     """ Test avx2 Node Variants """
 
-    VARIANT = "avx2"
+    VARIANT = "hsw"
+    LINUX_VARIANT = "avx2"
 
     @classmethod
     def setUpConstants(cls):
-        super(TestAVX2Variant, cls).setUpConstants(cls.VARIANT)
+        super(TestHSWVariant, cls).setUpConstants(cls.VARIANT)
 
     @classmethod
     def setUpClass(cls):
-        super(TestAVX2Variant, cls).setUpClass()
+        super(TestHSWVariant, cls).setUpClass()
 
     @classmethod
     def tearDownClass(cls):
-        super(TestAVX2Variant, cls).tearDownClass()
+        super(TestHSWVariant, cls).tearDownClass()
 
-    @unittest.skipUnless(skipVariant(VARIANT),
+    @unittest.skipUnless(skipVariant(LINUX_VARIANT),
                          VARIANT + " not a supported variant, skip.")
-    def test_avx2(self):
+    def test_hsw(self):
         self.checkVariant(self.VARIANT)