Message ID | 20200702174300.48470-5-harry.van.haaren@intel.com |
---|---|
State | Superseded |
Headers | show |
Series | DPCLS Subtable ISA Optimization | expand |
On 7/2/2020 6:42 PM, Harry van Haaren wrote: > This commit implements a method to retrieve the CPU ISA capabilities. > These ISA capabilities can be used in OVS to at runtime select a function > implementation to make the best use of the available ISA on the CPU. > > Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com> > LGTM, seems simple enough, I assume this gets called later in the series so in terms of testing will check it out there. BR Ian > --- > > v6: > - Add #if around RTE_CPUFLAG_AVX512F as it is not defined on CPU > architectures that don't support the ISA. This check fixes compilation > on those CPUs, as previously it had an undefined RTE_CPUFLAG_* error. > (Reported by Travis, thanks Ian & William for running checks) > > v5: > - Change API to return bool, and return to true/false (William Tu) > - Change error log to VLOG_ERR_ONCE instead of manual impl. (William Tu) > > v4: > - Improve commit title and message > --- > lib/dpdk-stub.c | 9 +++++++++ > lib/dpdk.c | 30 ++++++++++++++++++++++++++++++ > lib/dpdk.h | 2 ++ > 3 files changed, 41 insertions(+) > > diff --git a/lib/dpdk-stub.c b/lib/dpdk-stub.c > index c332c217c..b7d577870 100644 > --- a/lib/dpdk-stub.c > +++ b/lib/dpdk-stub.c > @@ -79,6 +79,15 @@ print_dpdk_version(void) > { > } > > +bool > +dpdk_get_cpu_has_isa(const char *arch OVS_UNUSED, > + const char *feature OVS_UNUSED) > +{ > + VLOG_ERR_ONCE("DPDK not supported in this version of Open vSwitch, " > + "cannot use CPU flag based optimizations"); > + return false; > +} > + > void > dpdk_status(const struct ovsrec_open_vswitch *cfg) > { > diff --git a/lib/dpdk.c b/lib/dpdk.c > index 31450d470..64a0d43e8 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> > @@ -513,6 +514,35 @@ print_dpdk_version(void) > puts(rte_version()); > } > > +#define CHECK_CPU_FEATURE(feature, name_str, RTE_CPUFLAG) \ > + do { \ > + if (strncmp(feature, name_str, strlen(name_str)) == 0) { \ > + int has_isa = rte_cpu_get_flag_enabled(RTE_CPUFLAG); \ > + VLOG_DBG("CPU flag %s, available %s\n", name_str, \ > + has_isa ? "yes" : "no"); \ > + return true; \ > + } \ > + } while (0) > + > +bool > +dpdk_get_cpu_has_isa(const char *arch, const char *feature) > +{ > + /* Ensure Arch is x86_64 */ > + if (strncmp(arch, "x86_64", 6) != 0) { > + return false; > + } > + > +#if __x86_64__ > + /* CPU flags only defined for the architecture that support it */ > + CHECK_CPU_FEATURE(feature, "avx512f", RTE_CPUFLAG_AVX512F); > + CHECK_CPU_FEATURE(feature, "bmi2", RTE_CPUFLAG_BMI2); > +#endif > + > + VLOG_WARN("Unknown CPU arch,feature: %s,%s. Returning not supported.\n", > + arch, feature); > + return false; > +} > + > void > dpdk_status(const struct ovsrec_open_vswitch *cfg) > { > diff --git a/lib/dpdk.h b/lib/dpdk.h > index 736a64279..445a51d06 100644 > --- a/lib/dpdk.h > +++ b/lib/dpdk.h > @@ -44,4 +44,6 @@ bool dpdk_per_port_memory(void); > bool dpdk_available(void); > void print_dpdk_version(void); > void dpdk_status(const struct ovsrec_open_vswitch *); > +bool dpdk_get_cpu_has_isa(const char *arch, const char *feature); > + > #endif /* dpdk.h */ >
diff --git a/lib/dpdk-stub.c b/lib/dpdk-stub.c index c332c217c..b7d577870 100644 --- a/lib/dpdk-stub.c +++ b/lib/dpdk-stub.c @@ -79,6 +79,15 @@ print_dpdk_version(void) { } +bool +dpdk_get_cpu_has_isa(const char *arch OVS_UNUSED, + const char *feature OVS_UNUSED) +{ + VLOG_ERR_ONCE("DPDK not supported in this version of Open vSwitch, " + "cannot use CPU flag based optimizations"); + return false; +} + void dpdk_status(const struct ovsrec_open_vswitch *cfg) { diff --git a/lib/dpdk.c b/lib/dpdk.c index 31450d470..64a0d43e8 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> @@ -513,6 +514,35 @@ print_dpdk_version(void) puts(rte_version()); } +#define CHECK_CPU_FEATURE(feature, name_str, RTE_CPUFLAG) \ + do { \ + if (strncmp(feature, name_str, strlen(name_str)) == 0) { \ + int has_isa = rte_cpu_get_flag_enabled(RTE_CPUFLAG); \ + VLOG_DBG("CPU flag %s, available %s\n", name_str, \ + has_isa ? "yes" : "no"); \ + return true; \ + } \ + } while (0) + +bool +dpdk_get_cpu_has_isa(const char *arch, const char *feature) +{ + /* Ensure Arch is x86_64 */ + if (strncmp(arch, "x86_64", 6) != 0) { + return false; + } + +#if __x86_64__ + /* CPU flags only defined for the architecture that support it */ + CHECK_CPU_FEATURE(feature, "avx512f", RTE_CPUFLAG_AVX512F); + CHECK_CPU_FEATURE(feature, "bmi2", RTE_CPUFLAG_BMI2); +#endif + + VLOG_WARN("Unknown CPU arch,feature: %s,%s. Returning not supported.\n", + arch, feature); + return false; +} + void dpdk_status(const struct ovsrec_open_vswitch *cfg) { diff --git a/lib/dpdk.h b/lib/dpdk.h index 736a64279..445a51d06 100644 --- a/lib/dpdk.h +++ b/lib/dpdk.h @@ -44,4 +44,6 @@ bool dpdk_per_port_memory(void); bool dpdk_available(void); void print_dpdk_version(void); void dpdk_status(const struct ovsrec_open_vswitch *); +bool dpdk_get_cpu_has_isa(const char *arch, const char *feature); + #endif /* dpdk.h */
This commit implements a method to retrieve the CPU ISA capabilities. These ISA capabilities can be used in OVS to at runtime select a function implementation to make the best use of the available ISA on the CPU. Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com> --- v6: - Add #if around RTE_CPUFLAG_AVX512F as it is not defined on CPU architectures that don't support the ISA. This check fixes compilation on those CPUs, as previously it had an undefined RTE_CPUFLAG_* error. (Reported by Travis, thanks Ian & William for running checks) v5: - Change API to return bool, and return to true/false (William Tu) - Change error log to VLOG_ERR_ONCE instead of manual impl. (William Tu) v4: - Improve commit title and message --- lib/dpdk-stub.c | 9 +++++++++ lib/dpdk.c | 30 ++++++++++++++++++++++++++++++ lib/dpdk.h | 2 ++ 3 files changed, 41 insertions(+)