This commit implements a method to retrieve the CPU ISA capabilities, and allows each DPCLS implementation to use these ISA capabilities to decide if the specific implemenation is a valid candidate for the CPU.
Please note this is a POC patch only, the actual generic code here can always run. Future DPCLS implementations may require specific ISA, which is what this patch enables. Signed-off-by: Harry van Haaren <harry.van.haa...@intel.com> --- lib/dpdk-stub.c | 11 +++++++++++ lib/dpdk.c | 16 ++++++++++++++++ lib/dpdk.h | 7 +++++++ lib/dpif-netdev-lookup-generic.c | 7 +++++++ 4 files changed, 41 insertions(+) diff --git a/lib/dpdk-stub.c b/lib/dpdk-stub.c index c332c217c..0aaccd983 100644 --- a/lib/dpdk-stub.c +++ b/lib/dpdk-stub.c @@ -79,6 +79,17 @@ print_dpdk_version(void) { } +int +dpdk_get_cpu_has_isa(const char *arch, const char *feature) +{ + static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; + if (ovsthread_once_start(&once)) { + VLOG_ERR("DPDK not supported in this copy of Open vSwitch, cannot use CPU flag based optimizations"); + ovsthread_once_done(&once); + } + return 0; +} + void dpdk_status(const struct ovsrec_open_vswitch *cfg) { diff --git a/lib/dpdk.c b/lib/dpdk.c index 37ea2973c..927dc6867 100644 --- a/lib/dpdk.c +++ b/lib/dpdk.c @@ -22,6 +22,7 @@ #include <sys/stat.h> #include <getopt.h> +#include <rte_cpuflags.h> #include <rte_errno.h> #include <rte_log.h> #include <rte_memzone.h> @@ -525,6 +526,21 @@ print_dpdk_version(void) puts(rte_version()); } +int +dpdk_get_cpu_has_isa(const char *arch, const char *feature) +{ + /* Ensure Arch is x86_64 */ + if (strncmp(arch, "x86_64", 6)) + return 0; + + if (strncmp(feature, "avx512f", 7) == 0) + return rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) > 0; + + VLOG_WARN("%s does not know the %s, %s combo, returning not supported.\n", + __func__, arch, feature); + return 0; +} + void dpdk_status(const struct ovsrec_open_vswitch *cfg) { diff --git a/lib/dpdk.h b/lib/dpdk.h index 736a64279..6c2144624 100644 --- a/lib/dpdk.h +++ b/lib/dpdk.h @@ -44,4 +44,11 @@ bool dpdk_per_port_memory(void); bool dpdk_available(void); void print_dpdk_version(void); void dpdk_status(const struct ovsrec_open_vswitch *); + +/* Returns 1 if the CPU has support for the requested architecture specific + * ISA capability. Eg: "x86_64", "avx512f". The strings to use here are as + * shown in "lscpu" Architecture: and Flags: fields. + */ +int dpdk_get_cpu_has_isa(const char * arch, const char *feature); + #endif /* dpdk.h */ diff --git a/lib/dpif-netdev-lookup-generic.c b/lib/dpif-netdev-lookup-generic.c index 89c8be0fa..dbc830512 100644 --- a/lib/dpif-netdev-lookup-generic.c +++ b/lib/dpif-netdev-lookup-generic.c @@ -301,6 +301,13 @@ DECLARE_OPTIMIZED_LOOKUP_FUNCTION(4, 0) dpcls_subtable_lookup_func dpcls_subtable_generic_probe(uint32_t u0_bits, uint32_t u1_bits) { + /* POC only: check if we can use CPU based info */ + int avx512f_available = dpdk_get_cpu_has_isa("x86_64", "avx512f"); + printf("avx512f available? %d\n", avx512f_available); + + if (!avx512f_available) + return 0; + dpcls_subtable_lookup_func f = NULL; CHECK_LOOKUP_FUNCTION(5, 1); -- 2.17.1 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev