net/virtio: fix AVX512 datapath selection
authorMaxime Coquelin <maxime.coquelin@redhat.com>
Mon, 11 May 2020 14:47:20 +0000 (16:47 +0200)
committerFerruh Yigit <ferruh.yigit@intel.com>
Mon, 11 May 2020 21:04:33 +0000 (23:04 +0200)
The AVX512 packed ring datapath selection was only done
at build time, but it should also be checked at runtime
that the CPU supports it.

This patch add a CPU flags check so that non-vectorized
path is selected at runtime if AVX512 is not supported.

Also in meson build enable vectorization only for relevant file, not for
all driver.

Fixes: ccb10995c2ad ("net/virtio: add election for vectorized path")

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Maxime Coquelin <maxime.coquelin@redhat.com>
drivers/net/virtio/meson.build
drivers/net/virtio/virtio_ethdev.c

index 5cc529f..3fd6051 100644 (file)
@@ -11,8 +11,14 @@ deps += ['kvargs', 'bus_pci']
 if arch_subdir == 'x86'
        if not machine_args.contains('-mno-avx512f')
                if cc.has_argument('-mavx512f') and cc.has_argument('-mavx512vl') and cc.has_argument('-mavx512bw')
-                       cflags += ['-mavx512f', '-mavx512bw', '-mavx512vl']
                        cflags += ['-DCC_AVX512_SUPPORT']
+                       virtio_avx512_lib = static_library('virtio_avx512_lib',
+                                             'virtio_rxtx_packed_avx.c',
+                                             dependencies: [static_rte_ethdev,
+                                               static_rte_kvargs, static_rte_bus_pci],
+                                             include_directories: includes,
+                                             c_args: [cflags, '-mavx512f', '-mavx512bw', '-mavx512vl'])
+                       objs += virtio_avx512_lib.extract_objects('virtio_rxtx_packed_avx.c')
                        if (toolchain == 'gcc' and cc.version().version_compare('>=8.3.0'))
                                cflags += '-DVHOST_GCC_UNROLL_PRAGMA'
                        elif (toolchain == 'clang' and cc.version().version_compare('>=3.7.0'))
@@ -20,7 +26,6 @@ if arch_subdir == 'x86'
                        elif (toolchain == 'icc' and cc.version().version_compare('>=16.0.0'))
                                cflags += '-DVHOST_ICC_UNROLL_PRAGMA'
                        endif
-                       sources += files('virtio_rxtx_packed_avx.c')
                endif
        endif
        sources += files('virtio_rxtx_simple_sse.c')
index 312871c..49ccef1 100644 (file)
@@ -1965,8 +1965,10 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
                        PMD_DRV_LOG(INFO,
                                "building environment do not support packed ring vectorized");
 #else
-                       hw->use_vec_rx = 1;
-                       hw->use_vec_tx = 1;
+                       if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F)) {
+                               hw->use_vec_rx = 1;
+                               hw->use_vec_tx = 1;
+                       }
 #endif
                }
        }