Add performance tests for the RSS calculation functions for L3/L4 keys. For each look at l3, l3+contiguous l4, and l3+split l4.
Signed-off-by: Bruce Richardson <[email protected]> --- app/test/test_thash_perf.c | 97 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 3 deletions(-) diff --git a/app/test/test_thash_perf.c b/app/test/test_thash_perf.c index 9d391fd296..44bda932c7 100644 --- a/app/test/test_thash_perf.c +++ b/app/test/test_thash_perf.c @@ -3,8 +3,10 @@ */ #include <stdio.h> +#include <stdbool.h> #include <stdint.h> #include <stdlib.h> +#include <string.h> #include <math.h> #include <rte_cpuflags.h> @@ -12,12 +14,14 @@ #include <rte_malloc.h> #include <rte_random.h> #include <rte_thash.h> +#include <rte_thash_rss.h> #include <rte_vect.h> #include "test.h" #define ITERATIONS (1 << 15) #define BATCH_SZ (1 << 10) +#define RSS_ITERATIONS (1 << 12) #define IPV4_2_TUPLE_LEN (8) #define IPV4_4_TUPLE_LEN (12) @@ -86,6 +90,66 @@ run_rss_calc_bulk(uint32_t *tuples[BATCH_SZ], int len, const void *key) return end_tsc - start_tsc; } +#define RUN_PACKET_BENCH(label, call) do { \ + volatile uint32_t accumulated = 0; \ + const uint64_t start = rte_rdtsc_precise(); \ + for (unsigned int i = 0; i < RSS_ITERATIONS; i++) { \ + for (unsigned int j = 0; j < BATCH_SZ; j++) { \ + uint32_t hash; \ + if ((call) != 0) \ + return -1; \ + accumulated ^= hash; \ + } \ + } \ + const uint64_t elapsed = rte_rdtsc_precise() - start; \ + printf("Average %-32s %.1f cycles (%s)\n", label, \ + (double)elapsed / (RSS_ITERATIONS * BATCH_SZ), mode); \ + RTE_SET_USED(accumulated); \ +} while (0) + +static int +run_rss_packet_perf(const struct rte_thash_rss_ctx *ctx, const char *mode) +{ + static struct { + struct rte_ipv4_hdr ip; + uint8_t ports[4]; + } v4[BATCH_SZ]; + static struct { + struct rte_ipv6_hdr ip; + uint8_t ports[4]; + } v6[BATCH_SZ]; + static uint8_t split_ports[BATCH_SZ][4]; + + for (unsigned int i = 0; i < BATCH_SZ; i++) { + const uint32_t ports = rte_rand(); + + v4[i].ip.src_addr = rte_rand(); + v4[i].ip.dst_addr = rte_rand(); + for (unsigned int byte = 0; byte < sizeof(v6[i].ip.src_addr); byte++) { + v6[i].ip.src_addr.a[byte] = rte_rand(); + v6[i].ip.dst_addr.a[byte] = rte_rand(); + } + memcpy(v4[i].ports, &ports, sizeof(ports)); + memcpy(v6[i].ports, &ports, sizeof(ports)); + memcpy(split_ports[i], &ports, sizeof(ports)); + } + + printf("\nRSS packet hash (%s):\n", mode); + RUN_PACKET_BENCH("rte_thash_rss_ipv4_l3", rte_thash_rss_ipv4_l3(ctx, &v4[j].ip, &hash)); + RUN_PACKET_BENCH("rte_thash_rss_ipv4_l4 direct", + rte_thash_rss_ipv4_l4(ctx, &v4[j].ip, v4[j].ports, &hash)); + RUN_PACKET_BENCH("rte_thash_rss_ipv4_l4 split", + rte_thash_rss_ipv4_l4(ctx, &v4[j].ip, split_ports[j], &hash)); + RUN_PACKET_BENCH("rte_thash_rss_ipv6_l3", rte_thash_rss_ipv6_l3(ctx, &v6[j].ip, &hash)); + RUN_PACKET_BENCH("rte_thash_rss_ipv6_l4 direct", + rte_thash_rss_ipv6_l4(ctx, &v6[j].ip, v6[j].ports, &hash)); + RUN_PACKET_BENCH("rte_thash_rss_ipv6_l4 split", + rte_thash_rss_ipv6_l4(ctx, &v6[j].ip, split_ports[j], &hash)); + + return 0; +} +#undef RUN_PACKET_BENCH + static void run_thash_test(unsigned int tuple_len) { @@ -137,7 +201,7 @@ run_thash_test(unsigned int tuple_len) static void enable_gfni_simd_bitwidth(void) { -#ifdef RTE_THASH_GFNI_DEFINED +#ifdef RTE_ARCH_X86 const uint16_t cur = rte_vect_get_max_simd_bitwidth(); if (cur >= RTE_VECT_SIMD_512) @@ -151,7 +215,8 @@ enable_gfni_simd_bitwidth(void) 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", + printf("WARNING: CPU supports GFNI, but max SIMD bitwidth is pinned at %u, " + "so GFNI is not benchmarked\n", cur); return; } @@ -164,14 +229,40 @@ enable_gfni_simd_bitwidth(void) static int test_thash_perf(void) { + const uint16_t original_bitwidth = rte_vect_get_max_simd_bitwidth(); + const bool scalar_selected = + rte_vect_set_max_simd_bitwidth(RTE_VECT_SIMD_DISABLED) == 0; + struct rte_thash_rss_ctx *scalar = rte_thash_rss_ctx_create(default_rss_key, + sizeof(default_rss_key), 0); + struct rte_thash_rss_ctx *simd = NULL; + int ret; + + if (scalar_selected) + rte_vect_set_max_simd_bitwidth(original_bitwidth); + if (scalar == NULL) + return -1; + enable_gfni_simd_bitwidth(); + if (scalar_selected && rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_512) { + simd = rte_thash_rss_ctx_create(default_rss_key, sizeof(default_rss_key), 0); + if (simd == NULL) { + rte_thash_rss_ctx_free(scalar); + return -1; + } + } run_thash_test(IPV4_2_TUPLE_LEN); run_thash_test(IPV4_4_TUPLE_LEN); run_thash_test(IPV6_2_TUPLE_LEN); run_thash_test(IPV6_4_TUPLE_LEN); - return 0; + ret = run_rss_packet_perf(scalar, scalar_selected ? "scalar" : "configured SIMD"); + if (ret == 0 && simd != NULL) + ret = run_rss_packet_perf(simd, "512-bit limit"); + rte_thash_rss_ctx_free(scalar); + rte_thash_rss_ctx_free(simd); + + return ret; } REGISTER_PERF_TEST(thash_perf_autotest, test_thash_perf); -- 2.55.0

