summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Marchand <david.marchand@redhat.com>2022-06-29 15:38:03 +0200
committerIlya Maximets <i.maximets@ovn.org>2022-06-29 19:01:23 +0200
commit3654d3ecb0e7c4d1b323a49336282788bc1acd4f (patch)
treebfd453cb7ff41d6588fea78b755141a64fd84bd5
parent9ae9f5b56e1a44c1c05f5cb2ad9599643285821e (diff)
downloadopenvswitch-3654d3ecb0e7c4d1b323a49336282788bc1acd4f.tar.gz
dpif-netdev: Refactor AVX512 runtime checks.
[ original commit fe171e4f109f001f07b867756a261d898f0d2cfc ] As described in the bugzilla below, cpu_has_isa code may be compiled with some AVX512 instructions in it, because cpu.c is built as part of the libopenvswitchavx512. This is a problem when this function (supposed to probe for AVX512 instructions availability) is invoked from generic OVS code, on older CPUs that don't support them. For the same reason, dpcls_subtable_avx512_gather_probe, dp_netdev_input_outer_avx512_probe, mfex_avx512_probe and mfex_avx512_vbmi_probe are potential runtime bombs and can't either be built as part of libopenvswitchavx512. Move cpu.c to be part of the "normal" libopenvswitch. And move other helpers in generic OVS code. Note: - dpcls_subtable_avx512_gather_probe is split in two, because it also needs to do its own magic, - while moving those helpers, prefer direct calls to cpu_has_isa and avoid cast to intermediate integer variables when a simple boolean is enough, Fixes: 352b6c7116cd ("dpif-lookup: add avx512 gather implementation.") Fixes: abb807e27dd4 ("dpif-netdev: Add command to switch dpif implementation.") Fixes: 250ceddcc2d0 ("dpif-netdev/mfex: Add AVX512 based optimized miniflow extract") Fixes: b366fa2f4947 ("dpif-netdev: Call cpuid for x86 isa availability.") Reported-at: https://bugzilla.redhat.com/2100393 Reported-by: Ales Musil <amusil@redhat.com> Co-authored-by: Ales Musil <amusil@redhat.com> Signed-off-by: Ales Musil <amusil@redhat.com> Signed-off-by: David Marchand <david.marchand@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
-rw-r--r--lib/dpif-netdev-lookup-avx512-gather.c8
-rw-r--r--lib/dpif-netdev-lookup.c13
-rw-r--r--lib/dpif-netdev-lookup.h2
3 files changed, 15 insertions, 8 deletions
diff --git a/lib/dpif-netdev-lookup-avx512-gather.c b/lib/dpif-netdev-lookup-avx512-gather.c
index 5e3634249..55fcc327b 100644
--- a/lib/dpif-netdev-lookup-avx512-gather.c
+++ b/lib/dpif-netdev-lookup-avx512-gather.c
@@ -237,16 +237,10 @@ dpcls_avx512_gather_mf_any(struct dpcls_subtable *subtable, uint32_t keys_map,
}
dpcls_subtable_lookup_func
-dpcls_subtable_avx512_gather_probe(uint32_t u0_bits, uint32_t u1_bits)
+dpcls_subtable_avx512_gather_probe__(uint32_t u0_bits, uint32_t u1_bits)
{
dpcls_subtable_lookup_func f = NULL;
- int avx512f_available = dpdk_get_cpu_has_isa("x86_64", "avx512f");
- int bmi2_available = dpdk_get_cpu_has_isa("x86_64", "bmi2");
- if (!avx512f_available || !bmi2_available) {
- return NULL;
- }
-
CHECK_LOOKUP_FUNCTION(5, 1);
CHECK_LOOKUP_FUNCTION(4, 1);
CHECK_LOOKUP_FUNCTION(4, 0);
diff --git a/lib/dpif-netdev-lookup.c b/lib/dpif-netdev-lookup.c
index bd0a99abe..c19ac8dd3 100644
--- a/lib/dpif-netdev-lookup.c
+++ b/lib/dpif-netdev-lookup.c
@@ -22,6 +22,19 @@
VLOG_DEFINE_THIS_MODULE(dpif_netdev_lookup);
+#if (__x86_64__ && HAVE_AVX512F && HAVE_LD_AVX512_GOOD && __SSE4_2__)
+static dpcls_subtable_lookup_func
+dpcls_subtable_avx512_gather_probe(uint32_t u0_bits, uint32_t u1_bits)
+{
+ if (!dpdk_get_cpu_has_isa("x86_64", "avx512f")
+ || !dpdk_get_cpu_has_isa("x86_64", "bmi2")) {
+ return NULL;
+ }
+
+ return dpcls_subtable_avx512_gather_probe__(u0_bits, u1_bits);
+}
+#endif
+
/* Actual list of implementations goes here */
static struct dpcls_subtable_lookup_info_t subtable_lookups[] = {
/* The autovalidator implementation will not be used by default, it must
diff --git a/lib/dpif-netdev-lookup.h b/lib/dpif-netdev-lookup.h
index bd72aa29b..2c6c6532d 100644
--- a/lib/dpif-netdev-lookup.h
+++ b/lib/dpif-netdev-lookup.h
@@ -44,7 +44,7 @@ dpcls_subtable_generic_probe(uint32_t u0_bit_count, uint32_t u1_bit_count);
/* Probe function for AVX-512 gather implementation */
dpcls_subtable_lookup_func
-dpcls_subtable_avx512_gather_probe(uint32_t u0_bit_cnt, uint32_t u1_bit_cnt);
+dpcls_subtable_avx512_gather_probe__(uint32_t u0_bit_cnt, uint32_t u1_bit_cnt);
/* Subtable registration and iteration helpers */