DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>
Subject: [PATCH 09/11] test/thash: add perf tests for new RSS functions
Date: Tue,  1 Dec 2026 15:16:21 +0000	[thread overview]
Message-ID: <20261201151623.2240031-10-bruce.richardson@intel.com> (raw)
In-Reply-To: <20261201151623.2240031-1-bruce.richardson@intel.com>

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 <bruce.richardson@intel.com>
---
 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


  parent reply	other threads:[~2026-12-01 15:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 15:16 [PATCH 00/11] Add optimized path selection for thash Bruce Richardson
2026-12-01 15:16 ` [PATCH 01/11] hash: improve build-time instruction set checks " Bruce Richardson
2026-12-01 15:16 ` [PATCH 02/11] test/thash_perf: test gfni thash when platform supports Bruce Richardson
2026-12-01 15:16 ` [PATCH 03/11] hash: create library internal header file for thash Bruce Richardson
2026-12-01 15:16 ` [PATCH 04/11] hash: add functions for GFNI RSS hash calculations Bruce Richardson
2026-12-01 15:16 ` [PATCH 05/11] hash: add fixed-size scalar " Bruce Richardson
2026-12-01 15:16 ` [PATCH 06/11] hash: add thash context struct for runtime path selection Bruce Richardson
2026-12-01 15:16 ` [PATCH 07/11] hash: implement IPv4 and IPv6 RSS hashing in SW Bruce Richardson
2026-12-01 15:16 ` [PATCH 08/11] hash: add explicit handling for RSS with split L3/L4 data Bruce Richardson
2026-12-01 15:16 ` Bruce Richardson [this message]
2026-12-01 15:16 ` [PATCH 10/11] hash: remove extra store-load when performing RSS Bruce Richardson
2026-12-01 15:16 ` [PATCH 11/11] hash: add AVX2 RSS hash functions Bruce Richardson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201151623.2240031-10-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox