The current thash performance tests only test the gfni thash functions when the max SIMD bitwidth is set to 512. To increase test coverage - and visibility of the perf benefits the functions provide - increase the max SIMD bitwidth automatically when the test is run on a supporting platform, and the build has gfni enabled.
Signed-off-by: Bruce Richardson <[email protected]> --- app/test/test_thash_perf.c | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/app/test/test_thash_perf.c b/app/test/test_thash_perf.c index 9dfd5d3c21..9d391fd296 100644 --- a/app/test/test_thash_perf.c +++ b/app/test/test_thash_perf.c @@ -7,10 +7,12 @@ #include <stdlib.h> #include <math.h> +#include <rte_cpuflags.h> #include <rte_cycles.h> #include <rte_malloc.h> #include <rte_random.h> #include <rte_thash.h> +#include <rte_vect.h> #include "test.h" @@ -92,6 +94,10 @@ run_thash_test(unsigned int tuple_len) uint32_t len = RTE_ALIGN_CEIL(tuple_len, sizeof(uint32_t)); uint64_t tsc_diff; + /* with GFNI each length reports four results, so separate the groups */ + if (rte_thash_gfni_supported()) + printf("\n--- key len %u ---\n", len); + for (i = 0; i < BATCH_SZ; i++) { tuples[i] = rte_zmalloc(NULL, len, 0); for (j = 0; j < len / sizeof(uint32_t); j++) @@ -124,9 +130,42 @@ run_thash_test(unsigned int tuple_len) (double)(tsc_diff) / (double)(ITERATIONS * BATCH_SZ), len); } +/* + * The GFNI implementation is only used when 512-bit SIMD is permitted, which + * is not the default on x86, so opt in to it where the CPU can support it. + */ +static void +enable_gfni_simd_bitwidth(void) +{ +#ifdef RTE_THASH_GFNI_DEFINED + const uint16_t cur = rte_vect_get_max_simd_bitwidth(); + + if (cur >= RTE_VECT_SIMD_512) + return; + + if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_GFNI) || + !rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512VBMI) || + !rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512DQ) || + !rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512VL)) + return; + + const int ret = rte_vect_set_max_simd_bitwidth(RTE_VECT_SIMD_512); + if (ret != 0) { + printf("WARNING: CPU supports GFNI, but max SIMD bitwidth is pinned at %u, so GFNI is not benchmarked\n", + cur); + return; + } + + printf("WARNING: CPU supports GFNI, raising max SIMD bitwidth from %u to %u to benchmark it\n", + cur, RTE_VECT_SIMD_512); +#endif +} + static int test_thash_perf(void) { + enable_gfni_simd_bitwidth(); + run_thash_test(IPV4_2_TUPLE_LEN); run_thash_test(IPV4_4_TUPLE_LEN); run_thash_test(IPV6_2_TUPLE_LEN); -- 2.55.0

