* [PATCH 00/11] Add optimized path selection for thash
@ 2026-12-01 15:16 Bruce Richardson
2026-12-01 15:16 ` [PATCH 01/11] hash: improve build-time instruction set checks " Bruce Richardson
` (10 more replies)
0 siblings, 11 replies; 12+ messages in thread
From: Bruce Richardson @ 2026-12-01 15:16 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
The Toeplitz hash function, used in NICs for RSS, may sometimes need to
be computed by software. DPDK already ships a scalar implementation of
this algorithm, and also includes an inline function for x86 optimized
using GFNI and AVX-512. Because the optimized function, which is very
much faster than the scalar one (on my system over an order of magnitude
faster), is an inlne one, it requires the application to itself know
when it is safe to use, i.e. that the application will be deployed on a
system with the necessary GFNI+AVX512 instruction sets. The vector
function and the scalar versions also differ in how the arguments need
to be prepared for use - specifically in terms of data endianness.
While leaving the existing code in place for backward compatibility, we
can provide a higher-level common interface for doing the calculations,
with runtime path selection to choose the best implementation - scalar
GFNI+AVX2 or GFNI+AVX512.
The path selection is managed via a thash context object, and the
decision on which set of functions to use is made once at context
creation time. The API functions to perform the actual calculation are
tied to the standard RSS protocol tuples for IPv4 and IPv6, not to
generic data lengths. While it is possible to have length-based APIs,
having the protocol based functions avoids potential performance
degradation issues in building the tuple array for hashing.
Specifially, copying data in chunks of 4 or 8 bytes to a local array and
then passing that into a vector function can lead to execution
slowdowns due to vector loads stalling on data written by scalar stores
(no store-forwarding). By having the API take the pointers to IP header
and L4 headers, the necessary vector registers can be loaded directly
from source, without any intermediate copying, avoiding any potential
store-forwarding issues in the function.
Bruce Richardson (11):
hash: improve build-time instruction set checks for thash
test/thash_perf: test gfni thash when platform supports
hash: create library internal header file for thash
hash: add functions for GFNI RSS hash calculations
hash: add fixed-size scalar RSS hash calculations
hash: add thash context struct for runtime path selection
hash: implement IPv4 and IPv6 RSS hashing in SW
hash: add explicit handling for RSS with split L3/L4 data
test/thash: add perf tests for new RSS functions
hash: remove extra store-load when performing RSS
hash: add AVX2 RSS hash functions
app/test/test_thash.c | 170 ++++++++++++++++++++
app/test/test_thash_perf.c | 150 +++++++++++++++++-
doc/guides/rel_notes/release_27_03.rst | 6 +
lib/hash/meson.build | 20 +++
lib/hash/rte_thash.c | 37 ++++-
lib/hash/rte_thash.h | 13 --
lib/hash/rte_thash_gf2_poly_math.c | 4 +-
lib/hash/rte_thash_rss.h | 156 +++++++++++++++++++
lib/hash/rte_thash_x86_gfni.h | 4 +-
lib/hash/thash_gfni_avx2.c | 170 ++++++++++++++++++++
lib/hash/thash_gfni_avx512.c | 132 ++++++++++++++++
lib/hash/thash_private.h | 108 +++++++++++++
lib/hash/thash_rss.c | 208 +++++++++++++++++++++++++
lib/meson.build | 3 +-
14 files changed, 1155 insertions(+), 26 deletions(-)
create mode 100644 lib/hash/rte_thash_rss.h
create mode 100644 lib/hash/thash_gfni_avx2.c
create mode 100644 lib/hash/thash_gfni_avx512.c
create mode 100644 lib/hash/thash_private.h
create mode 100644 lib/hash/thash_rss.c
--
2.55.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 01/11] hash: improve build-time instruction set checks for thash
2026-12-01 15:16 [PATCH 00/11] Add optimized path selection for thash Bruce Richardson
@ 2026-12-01 15:16 ` Bruce Richardson
2026-12-01 15:16 ` [PATCH 02/11] test/thash_perf: test gfni thash when platform supports Bruce Richardson
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Bruce Richardson @ 2026-12-01 15:16 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
The GFNI thash implementation depends upon AVX-512 as well as the GFNI
instruction set. The instruction set checks at build-time checked for
AVX-512F and GFNI, but the actual AVX instructions used come from
AVX-512 subsets VBMI, VL and DQ which are not implied by AVX-512F. While
this is not a problem in practice, since systems with AVX-512F and GFNI
do have all necessary other instruction sets, for correctness, let's
make the checks more explicit, checking for sets which are not implied
by any others.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
lib/hash/rte_thash_x86_gfni.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/hash/rte_thash_x86_gfni.h b/lib/hash/rte_thash_x86_gfni.h
index e5abdf2474..1a529d052a 100644
--- a/lib/hash/rte_thash_x86_gfni.h
+++ b/lib/hash/rte_thash_x86_gfni.h
@@ -19,7 +19,7 @@
extern "C" {
#endif
-#if defined(__GFNI__) && defined(__AVX512F__)
+#if defined(__GFNI__) && defined(__AVX512VBMI__) && defined(__AVX512DQ__) && defined(__AVX512VL__)
#define RTE_THASH_GFNI_DEFINED
#define RTE_THASH_FIRST_ITER_MSK 0x0f0f0f0f0f0e0c08
@@ -217,7 +217,7 @@ rte_thash_gfni_bulk(const uint64_t *mtrx, int len, uint8_t *tuple[],
}
}
-#endif /* __GFNI__ && __AVX512F__ */
+#endif /* GFNI and AVX512 support */
#ifdef __cplusplus
}
--
2.55.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 02/11] test/thash_perf: test gfni thash when platform supports
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 ` Bruce Richardson
2026-12-01 15:16 ` [PATCH 03/11] hash: create library internal header file for thash Bruce Richardson
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Bruce Richardson @ 2026-12-01 15:16 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
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 <bruce.richardson@intel.com>
---
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
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 03/11] hash: create library internal header file for thash
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 ` Bruce Richardson
2026-12-01 15:16 ` [PATCH 04/11] hash: add functions for GFNI RSS hash calculations Bruce Richardson
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Bruce Richardson @ 2026-12-01 15:16 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
Create a private header file, internal to the library, to hold function
prototypes and other content that is not to be exposed to applications.
This is better than having the content marked as internal in public
headers.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
lib/hash/rte_thash.c | 2 ++
lib/hash/rte_thash.h | 13 -------------
lib/hash/rte_thash_gf2_poly_math.c | 4 ++--
lib/hash/thash_private.h | 16 ++++++++++++++++
4 files changed, 20 insertions(+), 15 deletions(-)
create mode 100644 lib/hash/thash_private.h
diff --git a/lib/hash/rte_thash.c b/lib/hash/rte_thash.c
index fcd41248b9..dfbcb931d9 100644
--- a/lib/hash/rte_thash.c
+++ b/lib/hash/rte_thash.c
@@ -16,6 +16,8 @@
#include <rte_malloc.h>
#include <rte_cpuflags.h>
+#include "thash_private.h"
+
RTE_LOG_REGISTER_SUFFIX(thash_logtype, thash, INFO);
#define RTE_LOGTYPE_HASH thash_logtype
#define HASH_LOG(level, ...) \
diff --git a/lib/hash/rte_thash.h b/lib/hash/rte_thash.h
index 8bca430663..98115081b1 100644
--- a/lib/hash/rte_thash.h
+++ b/lib/hash/rte_thash.h
@@ -100,19 +100,6 @@ union rte_thash_tuple {
struct rte_ipv6_tuple v6;
};
-/** @internal
- * @brief Generates a random polynomial
- *
- * @param poly_degree
- * degree of the polynomial
- *
- * @return
- * random polynomial
- */
-__rte_internal
-uint32_t
-thash_get_rand_poly(uint32_t poly_degree);
-
/**
* Longest RSS hash key currently supported
*/
diff --git a/lib/hash/rte_thash_gf2_poly_math.c b/lib/hash/rte_thash_gf2_poly_math.c
index ddf4dd863b..286797a8d4 100644
--- a/lib/hash/rte_thash_gf2_poly_math.c
+++ b/lib/hash/rte_thash_gf2_poly_math.c
@@ -1,7 +1,6 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2024 Intel Corporation
*/
-#include <eal_export.h>
#include <rte_random.h>
#include <rte_common.h>
#include <rte_bitops.h>
@@ -9,6 +8,8 @@
#include <rte_thash.h>
#include <rte_log.h>
+#include "thash_private.h"
+
#define MAX_POLY_DEGREE 32
#define MAX_TOEPLITZ_KEY_LENGTH 64
RTE_LOG_REGISTER_SUFFIX(thash_poly_logtype, thash_poly, INFO);
@@ -242,7 +243,6 @@ thash_test_poly_order(uint32_t poly, int degree)
return 0;
}
-RTE_EXPORT_INTERNAL_SYMBOL(thash_get_rand_poly)
uint32_t
thash_get_rand_poly(uint32_t poly_degree)
{
diff --git a/lib/hash/thash_private.h b/lib/hash/thash_private.h
new file mode 100644
index 0000000000..ed13b605a3
--- /dev/null
+++ b/lib/hash/thash_private.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2026 Intel Corporation
+ */
+
+#ifndef THASH_PRIVATE_H
+#define THASH_PRIVATE_H
+
+#include <stdint.h>
+
+/**
+ * Get a random polynomial of the specified degree.
+ */
+uint32_t
+thash_get_rand_poly(uint32_t poly_degree);
+
+#endif /* THASH_PRIVATE_H */
--
2.55.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 04/11] hash: add functions for GFNI RSS hash calculations
2026-12-01 15:16 [PATCH 00/11] Add optimized path selection for thash Bruce Richardson
` (2 preceding siblings ...)
2026-12-01 15:16 ` [PATCH 03/11] hash: create library internal header file for thash Bruce Richardson
@ 2026-12-01 15:16 ` Bruce Richardson
2026-12-01 15:16 ` [PATCH 05/11] hash: add fixed-size scalar " Bruce Richardson
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Bruce Richardson @ 2026-12-01 15:16 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
The RSS is computed over IPv4 or IPv6 headers using 8 or 32-byte keys
respectively, or over IP + TCP/UDP headers using 12 or 36 byte keys.
Therefore create explicit non-inline functions for those key lengths. By
making these non-inline functions we can compile them using GFNI
instructions for later runtime selection, even when the current target
instruction set does not include all necessary instructions, e.g.
building for a "default" target.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
lib/hash/meson.build | 8 ++++++++
lib/hash/thash_gfni_avx512.c | 35 +++++++++++++++++++++++++++++++++++
lib/hash/thash_private.h | 12 ++++++++++++
3 files changed, 55 insertions(+)
create mode 100644 lib/hash/thash_gfni_avx512.c
diff --git a/lib/hash/meson.build b/lib/hash/meson.build
index 7ce504ee8b..de21cfac50 100644
--- a/lib/hash/meson.build
+++ b/lib/hash/meson.build
@@ -29,3 +29,11 @@ sources = files(
deps += ['net']
deps += ['ring']
deps += ['rcu']
+
+if dpdk_conf.has('RTE_ARCH_X86') and cc_has_avx512
+ thash_gfni_cflags = ['-mgfni', '-mavx512vbmi']
+ if cc.has_multi_arguments(thash_gfni_cflags)
+ sources_avx512 += files('thash_gfni_avx512.c')
+ cflags_avx512 += thash_gfni_cflags
+ endif
+endif
diff --git a/lib/hash/thash_gfni_avx512.c b/lib/hash/thash_gfni_avx512.c
new file mode 100644
index 0000000000..d62b5acc1f
--- /dev/null
+++ b/lib/hash/thash_gfni_avx512.c
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2026 Intel Corporation
+ */
+
+#include <rte_thash_x86_gfni.h>
+
+#include "thash_private.h"
+
+#ifndef RTE_THASH_GFNI_DEFINED
+#error "GFNI and required AVX512 extensions must be enabled to build this file"
+#endif
+
+uint32_t
+thash_gfni_avx512_8B(const uint64_t *mtrx, const uint8_t *tuple)
+{
+ return rte_thash_gfni(mtrx, tuple, 8);
+}
+
+uint32_t
+thash_gfni_avx512_12B(const uint64_t *mtrx, const uint8_t *tuple)
+{
+ return rte_thash_gfni(mtrx, tuple, 12);
+}
+
+uint32_t
+thash_gfni_avx512_32B(const uint64_t *mtrx, const uint8_t *tuple)
+{
+ return rte_thash_gfni(mtrx, tuple, 32);
+}
+
+uint32_t
+thash_gfni_avx512_36B(const uint64_t *mtrx, const uint8_t *tuple)
+{
+ return rte_thash_gfni(mtrx, tuple, 36);
+}
diff --git a/lib/hash/thash_private.h b/lib/hash/thash_private.h
index ed13b605a3..520d156d1d 100644
--- a/lib/hash/thash_private.h
+++ b/lib/hash/thash_private.h
@@ -13,4 +13,16 @@
uint32_t
thash_get_rand_poly(uint32_t poly_degree);
+uint32_t
+thash_gfni_avx512_8B(const uint64_t *mtrx, const uint8_t *tuple);
+
+uint32_t
+thash_gfni_avx512_12B(const uint64_t *mtrx, const uint8_t *tuple);
+
+uint32_t
+thash_gfni_avx512_32B(const uint64_t *mtrx, const uint8_t *tuple);
+
+uint32_t
+thash_gfni_avx512_36B(const uint64_t *mtrx, const uint8_t *tuple);
+
#endif /* THASH_PRIVATE_H */
--
2.55.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 05/11] hash: add fixed-size scalar RSS hash calculations
2026-12-01 15:16 [PATCH 00/11] Add optimized path selection for thash Bruce Richardson
` (3 preceding siblings ...)
2026-12-01 15:16 ` [PATCH 04/11] hash: add functions for GFNI RSS hash calculations Bruce Richardson
@ 2026-12-01 15:16 ` Bruce Richardson
2026-12-01 15:16 ` [PATCH 06/11] hash: add thash context struct for runtime path selection Bruce Richardson
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Bruce Richardson @ 2026-12-01 15:16 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
To match the GFNI RSS hash computation functions, add scalar
equivalents.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
lib/hash/meson.build | 1 +
lib/hash/thash_private.h | 12 ++++++++++
| 49 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 62 insertions(+)
create mode 100644 lib/hash/thash_rss.c
diff --git a/lib/hash/meson.build b/lib/hash/meson.build
index de21cfac50..abee43fa2a 100644
--- a/lib/hash/meson.build
+++ b/lib/hash/meson.build
@@ -24,6 +24,7 @@ sources = files(
'rte_thash.c',
'rte_thash_gfni.c',
'rte_thash_gf2_poly_math.c',
+ 'thash_rss.c',
)
deps += ['net']
diff --git a/lib/hash/thash_private.h b/lib/hash/thash_private.h
index 520d156d1d..f9187536aa 100644
--- a/lib/hash/thash_private.h
+++ b/lib/hash/thash_private.h
@@ -25,4 +25,16 @@ thash_gfni_avx512_32B(const uint64_t *mtrx, const uint8_t *tuple);
uint32_t
thash_gfni_avx512_36B(const uint64_t *mtrx, const uint8_t *tuple);
+uint32_t
+thash_scalar_8B(const uint8_t *key, const uint8_t *tuple);
+
+uint32_t
+thash_scalar_12B(const uint8_t *key, const uint8_t *tuple);
+
+uint32_t
+thash_scalar_32B(const uint8_t *key, const uint8_t *tuple);
+
+uint32_t
+thash_scalar_36B(const uint8_t *key, const uint8_t *tuple);
+
#endif /* THASH_PRIVATE_H */
--git a/lib/hash/thash_rss.c b/lib/hash/thash_rss.c
new file mode 100644
index 0000000000..65c109e1b0
--- /dev/null
+++ b/lib/hash/thash_rss.c
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2026 Intel Corporation
+ */
+
+#include <string.h>
+
+#include <rte_byteorder.h>
+#include <rte_thash.h>
+
+#include "thash_private.h"
+
+static inline uint32_t
+thash_scalar(const uint8_t *key, const uint8_t *tuple, uint32_t len)
+{
+ uint32_t input[RTE_THASH_V6_L4_LEN];
+
+ for (uint32_t i = 0; i < len / sizeof(input[0]); i++) {
+ uint32_t word;
+
+ memcpy(&word, &tuple[i * sizeof(word)], sizeof(word));
+ input[i] = rte_be_to_cpu_32(word);
+ }
+
+ return rte_softrss_be(input, len / sizeof(input[0]), key);
+}
+
+uint32_t
+thash_scalar_8B(const uint8_t *key, const uint8_t *tuple)
+{
+ return thash_scalar(key, tuple, 8);
+}
+
+uint32_t
+thash_scalar_12B(const uint8_t *key, const uint8_t *tuple)
+{
+ return thash_scalar(key, tuple, 12);
+}
+
+uint32_t
+thash_scalar_32B(const uint8_t *key, const uint8_t *tuple)
+{
+ return thash_scalar(key, tuple, 32);
+}
+
+uint32_t
+thash_scalar_36B(const uint8_t *key, const uint8_t *tuple)
+{
+ return thash_scalar(key, tuple, 36);
+}
--
2.55.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 06/11] hash: add thash context struct for runtime path selection
2026-12-01 15:16 [PATCH 00/11] Add optimized path selection for thash Bruce Richardson
` (4 preceding siblings ...)
2026-12-01 15:16 ` [PATCH 05/11] hash: add fixed-size scalar " Bruce Richardson
@ 2026-12-01 15:16 ` Bruce Richardson
2026-12-01 15:16 ` [PATCH 07/11] hash: implement IPv4 and IPv6 RSS hashing in SW Bruce Richardson
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Bruce Richardson @ 2026-12-01 15:16 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
Add a context structure to hold function pointers and appropriate key
structure data for use of either scalar or AVX-512 GFNI RSS
calculations. The context is kept opaque from applications with
lifecycle management through APIs and path selection done at context
creation time.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
app/test/test_thash.c | 37 ++++++++++++++++++
lib/hash/meson.build | 2 +
lib/hash/rte_thash.c | 23 +++++++----
| 69 +++++++++++++++++++++++++++++++++
lib/hash/thash_gfni_avx512.c | 16 ++++----
lib/hash/thash_private.h | 41 ++++++++++++++++----
| 74 ++++++++++++++++++++++++++++++++----
7 files changed, 231 insertions(+), 31 deletions(-)
create mode 100644 lib/hash/rte_thash_rss.h
diff --git a/app/test/test_thash.c b/app/test/test_thash.c
index eeb2e87f2c..413292943d 100644
--- a/app/test/test_thash.c
+++ b/app/test/test_thash.c
@@ -4,6 +4,7 @@
#include <rte_common.h>
#include <rte_eal.h>
+#include <rte_errno.h>
#include <rte_ip.h>
#include <rte_random.h>
#include <rte_malloc.h>
@@ -12,6 +13,7 @@
#include "test.h"
#include <rte_thash.h>
+#include <rte_thash_rss.h>
#define HASH_MSK(reta_sz) ((1 << reta_sz) - 1)
#define TUPLE_SZ (RTE_THASH_V4_L4_LEN * 4)
@@ -366,6 +368,40 @@ test_big_tuple_gfni(void)
return TEST_SUCCESS;
}
+static int
+test_rss_ctx_create_free(void)
+{
+ struct rte_thash_rss_ctx *ctx1;
+ struct rte_thash_rss_ctx *ctx2;
+
+ ctx1 = rte_thash_rss_ctx_create(NULL, sizeof(default_rss_key), 0);
+ TEST_ASSERT_NULL(ctx1, "Created context with NULL key");
+ TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong rte_errno for NULL key");
+
+ ctx1 = rte_thash_rss_ctx_create(default_rss_key, sizeof(default_rss_key) - 1, 0);
+ TEST_ASSERT_NULL(ctx1, "Created context with short key");
+ TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong rte_errno for short key");
+
+ ctx1 = rte_thash_rss_ctx_create(default_rss_key, sizeof(default_rss_key), 1);
+ TEST_ASSERT_NULL(ctx1, "Created context with non-zero flags");
+ TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong rte_errno for non-zero flags");
+
+ ctx1 = rte_thash_rss_ctx_create(default_rss_key, sizeof(default_rss_key), 0);
+ TEST_ASSERT_NOT_NULL(ctx1, "Failed to create context");
+
+ ctx2 = rte_thash_rss_ctx_create(big_rss_key, sizeof(big_rss_key), 0);
+ if (ctx2 == NULL)
+ rte_thash_rss_ctx_free(ctx1);
+ TEST_ASSERT_NOT_NULL(ctx2, "Failed to create context with long key");
+ TEST_ASSERT(ctx1 != ctx2, "Created contexts have the same address");
+
+ rte_thash_rss_ctx_free(ctx1);
+ rte_thash_rss_ctx_free(ctx2);
+ rte_thash_rss_ctx_free(NULL);
+
+ return TEST_SUCCESS;
+}
+
static int
test_create_invalid(void)
{
@@ -1038,6 +1074,7 @@ static struct unit_test_suite thash_tests = {
TEST_CASE(test_toeplitz_hash_rand_data),
TEST_CASE(test_toeplitz_hash_gfni_bulk),
TEST_CASE(test_big_tuple_gfni),
+ TEST_CASE(test_rss_ctx_create_free),
TEST_CASE(test_create_invalid),
TEST_CASE(test_multiple_create),
TEST_CASE(test_free_null),
diff --git a/lib/hash/meson.build b/lib/hash/meson.build
index abee43fa2a..72fb7efd8d 100644
--- a/lib/hash/meson.build
+++ b/lib/hash/meson.build
@@ -8,6 +8,7 @@ headers = files(
'rte_jhash.h',
'rte_thash.h',
'rte_thash_gfni.h',
+ 'rte_thash_rss.h',
)
indirect_headers += files(
'rte_crc_arm64.h',
@@ -36,5 +37,6 @@ if dpdk_conf.has('RTE_ARCH_X86') and cc_has_avx512
if cc.has_multi_arguments(thash_gfni_cflags)
sources_avx512 += files('thash_gfni_avx512.c')
cflags_avx512 += thash_gfni_cflags
+ cflags += '-DCC_THASH_GFNI_AVX512_SUPPORT'
endif
endif
diff --git a/lib/hash/rte_thash.c b/lib/hash/rte_thash.c
index dfbcb931d9..f544cc0d69 100644
--- a/lib/hash/rte_thash.c
+++ b/lib/hash/rte_thash.c
@@ -74,19 +74,28 @@ struct rte_thash_ctx {
uint8_t hash_key[];
};
+bool
+thash_gfni_avx512_usable(void)
+{
+#ifdef RTE_ARCH_X86
+ return rte_cpu_get_flag_enabled(RTE_CPUFLAG_GFNI) > 0 &&
+ rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512VBMI) > 0 &&
+ rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_512;
+#else
+ return false;
+#endif
+}
+
RTE_EXPORT_SYMBOL(rte_thash_gfni_supported)
int
rte_thash_gfni_supported(void)
{
#ifdef RTE_THASH_GFNI_DEFINED
- if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_GFNI) &&
- (rte_vect_get_max_simd_bitwidth() >=
- RTE_VECT_SIMD_512))
- return 1;
-#endif
-
+ return thash_gfni_avx512_usable();
+#else
return 0;
-};
+#endif
+}
RTE_EXPORT_SYMBOL(rte_thash_complete_matrix)
void
--git a/lib/hash/rte_thash_rss.h b/lib/hash/rte_thash_rss.h
new file mode 100644
index 0000000000..f76dd667fb
--- /dev/null
+++ b/lib/hash/rte_thash_rss.h
@@ -0,0 +1,69 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2026 Intel Corporation
+ */
+
+#ifndef RTE_THASH_RSS_H
+#define RTE_THASH_RSS_H
+
+/**
+ * @file
+ *
+ * RSS hash calculation using the fastest implementation available.
+ */
+
+#include <stdint.h>
+
+#include <rte_compat.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** Opaque context for RSS hash calculation. */
+struct rte_thash_rss_ctx;
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Create an RSS hash context.
+ *
+ * The context selects the fastest available implementation,
+ * subject to the maximum SIMD bitwidth configured in EAL.
+ * A context is local to the process that creates it and must not be shared
+ * with other processes.
+ *
+ * @param key
+ * Pointer to the RSS hash key, as programmed into the NIC.
+ * @param key_len
+ * Length of the key in bytes. Must be at least 40 bytes.
+ * Bytes beyond the first 40 are ignored.
+ * @param flags
+ * Reserved for future use; must be zero.
+ * @return
+ * Pointer to the new context on success.
+ * NULL on error, with rte_errno set to EINVAL for invalid parameters
+ * or ENOMEM if memory allocation failed.
+ */
+__rte_experimental
+struct rte_thash_rss_ctx *
+rte_thash_rss_ctx_create(const uint8_t *key, uint32_t key_len, uint64_t flags);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Free an RSS hash context.
+ *
+ * @param ctx
+ * Context to free. If NULL, no operation is performed.
+ */
+__rte_experimental
+void
+rte_thash_rss_ctx_free(struct rte_thash_rss_ctx *ctx);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* RTE_THASH_RSS_H */
diff --git a/lib/hash/thash_gfni_avx512.c b/lib/hash/thash_gfni_avx512.c
index d62b5acc1f..3804341f7b 100644
--- a/lib/hash/thash_gfni_avx512.c
+++ b/lib/hash/thash_gfni_avx512.c
@@ -11,25 +11,25 @@
#endif
uint32_t
-thash_gfni_avx512_8B(const uint64_t *mtrx, const uint8_t *tuple)
+thash_gfni_avx512_8B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
{
- return rte_thash_gfni(mtrx, tuple, 8);
+ return rte_thash_gfni(ctx->data.matrices, tuple, 8);
}
uint32_t
-thash_gfni_avx512_12B(const uint64_t *mtrx, const uint8_t *tuple)
+thash_gfni_avx512_12B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
{
- return rte_thash_gfni(mtrx, tuple, 12);
+ return rte_thash_gfni(ctx->data.matrices, tuple, 12);
}
uint32_t
-thash_gfni_avx512_32B(const uint64_t *mtrx, const uint8_t *tuple)
+thash_gfni_avx512_32B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
{
- return rte_thash_gfni(mtrx, tuple, 32);
+ return rte_thash_gfni(ctx->data.matrices, tuple, 32);
}
uint32_t
-thash_gfni_avx512_36B(const uint64_t *mtrx, const uint8_t *tuple)
+thash_gfni_avx512_36B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
{
- return rte_thash_gfni(mtrx, tuple, 36);
+ return rte_thash_gfni(ctx->data.matrices, tuple, 36);
}
diff --git a/lib/hash/thash_private.h b/lib/hash/thash_private.h
index f9187536aa..2860866c4a 100644
--- a/lib/hash/thash_private.h
+++ b/lib/hash/thash_private.h
@@ -5,8 +5,30 @@
#ifndef THASH_PRIVATE_H
#define THASH_PRIVATE_H
+#include <stdbool.h>
#include <stdint.h>
+#define THASH_RSS_KEY_LEN 40
+
+struct rte_thash_rss_ctx;
+
+typedef uint32_t (*thash_fn_t)(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple);
+
+struct thash_rss_ops {
+ thash_fn_t hash_8;
+ thash_fn_t hash_12;
+ thash_fn_t hash_32;
+ thash_fn_t hash_36;
+};
+
+struct rte_thash_rss_ctx {
+ union {
+ uint32_t key[THASH_RSS_KEY_LEN / sizeof(uint32_t)];
+ uint64_t matrices[THASH_RSS_KEY_LEN];
+ } data;
+ const struct thash_rss_ops *ops;
+};
+
/**
* Get a random polynomial of the specified degree.
*/
@@ -14,27 +36,30 @@ uint32_t
thash_get_rand_poly(uint32_t poly_degree);
uint32_t
-thash_gfni_avx512_8B(const uint64_t *mtrx, const uint8_t *tuple);
+thash_gfni_avx512_8B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple);
uint32_t
-thash_gfni_avx512_12B(const uint64_t *mtrx, const uint8_t *tuple);
+thash_gfni_avx512_12B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple);
uint32_t
-thash_gfni_avx512_32B(const uint64_t *mtrx, const uint8_t *tuple);
+thash_gfni_avx512_32B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple);
uint32_t
-thash_gfni_avx512_36B(const uint64_t *mtrx, const uint8_t *tuple);
+thash_gfni_avx512_36B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple);
uint32_t
-thash_scalar_8B(const uint8_t *key, const uint8_t *tuple);
+thash_scalar_8B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple);
uint32_t
-thash_scalar_12B(const uint8_t *key, const uint8_t *tuple);
+thash_scalar_12B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple);
uint32_t
-thash_scalar_32B(const uint8_t *key, const uint8_t *tuple);
+thash_scalar_32B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple);
uint32_t
-thash_scalar_36B(const uint8_t *key, const uint8_t *tuple);
+thash_scalar_36B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple);
+
+bool
+thash_gfni_avx512_usable(void);
#endif /* THASH_PRIVATE_H */
--git a/lib/hash/thash_rss.c b/lib/hash/thash_rss.c
index 65c109e1b0..c53e9dbefa 100644
--- a/lib/hash/thash_rss.c
+++ b/lib/hash/thash_rss.c
@@ -2,10 +2,15 @@
* Copyright(c) 2026 Intel Corporation
*/
+#include <errno.h>
+#include <stdlib.h>
#include <string.h>
+#include <eal_export.h>
#include <rte_byteorder.h>
+#include <rte_errno.h>
#include <rte_thash.h>
+#include <rte_thash_rss.h>
#include "thash_private.h"
@@ -25,25 +30,78 @@ thash_scalar(const uint8_t *key, const uint8_t *tuple, uint32_t len)
}
uint32_t
-thash_scalar_8B(const uint8_t *key, const uint8_t *tuple)
+thash_scalar_8B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
{
- return thash_scalar(key, tuple, 8);
+ return thash_scalar((const uint8_t *)ctx->data.key, tuple, 8);
}
uint32_t
-thash_scalar_12B(const uint8_t *key, const uint8_t *tuple)
+thash_scalar_12B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
{
- return thash_scalar(key, tuple, 12);
+ return thash_scalar((const uint8_t *)ctx->data.key, tuple, 12);
}
uint32_t
-thash_scalar_32B(const uint8_t *key, const uint8_t *tuple)
+thash_scalar_32B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
{
- return thash_scalar(key, tuple, 32);
+ return thash_scalar((const uint8_t *)ctx->data.key, tuple, 32);
}
uint32_t
-thash_scalar_36B(const uint8_t *key, const uint8_t *tuple)
+thash_scalar_36B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
{
- return thash_scalar(key, tuple, 36);
+ return thash_scalar((const uint8_t *)ctx->data.key, tuple, 36);
+}
+
+static const struct thash_rss_ops scalar_ops = {
+ .hash_8 = thash_scalar_8B,
+ .hash_12 = thash_scalar_12B,
+ .hash_32 = thash_scalar_32B,
+ .hash_36 = thash_scalar_36B,
+};
+
+#ifdef CC_THASH_GFNI_AVX512_SUPPORT
+static const struct thash_rss_ops gfni_avx512_ops = {
+ .hash_8 = thash_gfni_avx512_8B,
+ .hash_12 = thash_gfni_avx512_12B,
+ .hash_32 = thash_gfni_avx512_32B,
+ .hash_36 = thash_gfni_avx512_36B,
+};
+#endif
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_thash_rss_ctx_create, 27.03)
+struct rte_thash_rss_ctx *
+rte_thash_rss_ctx_create(const uint8_t *key, uint32_t key_len, uint64_t flags)
+{
+ if (key == NULL || key_len < THASH_RSS_KEY_LEN || flags != 0) {
+ rte_errno = EINVAL;
+ return NULL;
+ }
+
+ struct rte_thash_rss_ctx *ctx = malloc(sizeof(*ctx));
+ if (ctx == NULL) {
+ rte_errno = ENOMEM;
+ return NULL;
+ }
+
+#ifdef CC_THASH_GFNI_AVX512_SUPPORT
+ if (thash_gfni_avx512_usable()) {
+ ctx->ops = &gfni_avx512_ops;
+ rte_thash_complete_matrix(ctx->data.matrices, key, THASH_RSS_KEY_LEN);
+ return ctx;
+ }
+#endif
+
+ ctx->ops = &scalar_ops;
+ memcpy(ctx->data.key, key, THASH_RSS_KEY_LEN);
+ rte_convert_rss_key(ctx->data.key, ctx->data.key, THASH_RSS_KEY_LEN);
+
+ return ctx;
+}
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_thash_rss_ctx_free, 27.03)
+void
+rte_thash_rss_ctx_free(struct rte_thash_rss_ctx *ctx)
+{
+ free(ctx);
}
--
2.55.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 07/11] hash: implement IPv4 and IPv6 RSS hashing in SW
2026-12-01 15:16 [PATCH 00/11] Add optimized path selection for thash Bruce Richardson
` (5 preceding siblings ...)
2026-12-01 15:16 ` [PATCH 06/11] hash: add thash context struct for runtime path selection Bruce Richardson
@ 2026-12-01 15:16 ` Bruce Richardson
2026-12-01 15:16 ` [PATCH 08/11] hash: add explicit handling for RSS with split L3/L4 data Bruce Richardson
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Bruce Richardson @ 2026-12-01 15:16 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
Implement functions for generating an RSS hash in SW for IPv4 and IPv6,
with optional TCP/UDP src/dst included. Where the system supports
AVX-512 + GFNI instruction set, those optimized paths are taken,
otherwise a default scalar path is used.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
doc/guides/rel_notes/release_27_03.rst | 6 ++
| 87 ++++++++++++++++++++++++++
| 78 +++++++++++++++++++++++
3 files changed, 171 insertions(+)
diff --git a/doc/guides/rel_notes/release_27_03.rst b/doc/guides/rel_notes/release_27_03.rst
index a91813faca..0714b8bd46 100644
--- a/doc/guides/rel_notes/release_27_03.rst
+++ b/doc/guides/rel_notes/release_27_03.rst
@@ -55,6 +55,12 @@ New Features
Also, make sure to start the actual text at the margin.
=======================================================
+* **Added software RSS hashing for IP packets.**
+
+ Added ``rte_thash_rss_*`` APIs to calculate RSS hashes for IPv4 and IPv6 addresses,
+ with optional TCP/UDP ports.
+ Runtime dispatch selects GFNI implementations when supported and uses scalar hashing otherwise.
+
Removed Items
-------------
--git a/lib/hash/rte_thash_rss.h b/lib/hash/rte_thash_rss.h
index f76dd667fb..274eab2503 100644
--- a/lib/hash/rte_thash_rss.h
+++ b/lib/hash/rte_thash_rss.h
@@ -14,6 +14,7 @@
#include <stdint.h>
#include <rte_compat.h>
+#include <rte_ip.h>
#ifdef __cplusplus
extern "C" {
@@ -62,6 +63,92 @@ __rte_experimental
void
rte_thash_rss_ctx_free(struct rte_thash_rss_ctx *ctx);
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Calculate an RSS hash over the source and destination IPv4 addresses.
+ *
+ * @param ctx
+ * RSS hash context.
+ * @param ip
+ * Pointer to a complete fixed IPv4 header structure.
+ * @param hash
+ * Location to store the calculated hash.
+ * @return
+ * 0 on success, or -EINVAL for invalid parameters.
+ */
+__rte_experimental
+int
+rte_thash_rss_ipv4_l3(const struct rte_thash_rss_ctx *ctx,
+ const struct rte_ipv4_hdr *ip, uint32_t *hash);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Calculate an RSS hash over the IPv4 addresses and TCP or UDP ports.
+ *
+ * @param ctx
+ * RSS hash context.
+ * @param ip
+ * Pointer to a complete fixed IPv4 header structure.
+ * @param l4_hdr
+ * Pointer to at least the first 4 bytes of the TCP or UDP header.
+ * The caller must ensure that L4 hashing is appropriate for the packet.
+ * @param hash
+ * Location to store the calculated hash.
+ * @return
+ * 0 on success, or -EINVAL for invalid parameters.
+ */
+__rte_experimental
+int
+rte_thash_rss_ipv4_l4(const struct rte_thash_rss_ctx *ctx,
+ const struct rte_ipv4_hdr *ip, const void *l4_hdr, uint32_t *hash);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Calculate an RSS hash over the source and destination IPv6 addresses.
+ *
+ * @param ctx
+ * RSS hash context.
+ * @param ip
+ * Pointer to a complete IPv6 header structure.
+ * @param hash
+ * Location to store the calculated hash.
+ * @return
+ * 0 on success, or -EINVAL for invalid parameters.
+ */
+__rte_experimental
+int
+rte_thash_rss_ipv6_l3(const struct rte_thash_rss_ctx *ctx,
+ const struct rte_ipv6_hdr *ip, uint32_t *hash);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Calculate an RSS hash over the IPv6 addresses and TCP or UDP ports.
+ *
+ * @param ctx
+ * RSS hash context.
+ * @param ip
+ * Pointer to a complete IPv6 header structure.
+ * @param l4_hdr
+ * Pointer to at least the first 4 bytes of the TCP or UDP header.
+ * The caller must ensure that L4 hashing is appropriate for the packet.
+ * @param hash
+ * Location to store the calculated hash.
+ * @return
+ * 0 on success, or -EINVAL for invalid parameters.
+ */
+__rte_experimental
+int
+rte_thash_rss_ipv6_l4(const struct rte_thash_rss_ctx *ctx,
+ const struct rte_ipv6_hdr *ip, const void *l4_hdr, uint32_t *hash);
+
#ifdef __cplusplus
}
#endif
--git a/lib/hash/thash_rss.c b/lib/hash/thash_rss.c
index c53e9dbefa..ddc07720a3 100644
--- a/lib/hash/thash_rss.c
+++ b/lib/hash/thash_rss.c
@@ -105,3 +105,81 @@ rte_thash_rss_ctx_free(struct rte_thash_rss_ctx *ctx)
{
free(ctx);
}
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_thash_rss_ipv4_l3, 27.03)
+int
+rte_thash_rss_ipv4_l3(const struct rte_thash_rss_ctx *ctx,
+ const struct rte_ipv4_hdr *ip, uint32_t *hash)
+{
+ if (ctx == NULL || ip == NULL || hash == NULL)
+ return -EINVAL;
+
+ *hash = ctx->ops->hash_8(ctx, (const uint8_t *)&ip->src_addr);
+ return 0;
+}
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_thash_rss_ipv6_l3, 27.03)
+int
+rte_thash_rss_ipv6_l3(const struct rte_thash_rss_ctx *ctx,
+ const struct rte_ipv6_hdr *ip, uint32_t *hash)
+{
+ if (ctx == NULL || ip == NULL || hash == NULL)
+ return -EINVAL;
+
+ *hash = ctx->ops->hash_32(ctx, (const uint8_t *)&ip->src_addr);
+ return 0;
+}
+
+static __rte_noinline uint32_t
+thash_ipv4_l4_gather(const struct rte_thash_rss_ctx *ctx,
+ const struct rte_ipv4_hdr *ip, const void *l4_hdr)
+{
+ uint8_t tuple[12];
+
+ memcpy(tuple, &ip->src_addr, 2 * sizeof(ip->src_addr));
+ memcpy(&tuple[8], l4_hdr, 4);
+ return ctx->ops->hash_12(ctx, tuple);
+}
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_thash_rss_ipv4_l4, 27.03)
+int
+rte_thash_rss_ipv4_l4(const struct rte_thash_rss_ctx *ctx,
+ const struct rte_ipv4_hdr *ip, const void *l4_hdr, uint32_t *hash)
+{
+ if (ctx == NULL || ip == NULL || l4_hdr == NULL || hash == NULL)
+ return -EINVAL;
+
+ if (l4_hdr == ip + 1)
+ *hash = ctx->ops->hash_12(ctx, (const uint8_t *)&ip->src_addr);
+ else
+ *hash = thash_ipv4_l4_gather(ctx, ip, l4_hdr);
+
+ return 0;
+}
+
+static __rte_noinline uint32_t
+thash_ipv6_l4_gather(const struct rte_thash_rss_ctx *ctx,
+ const struct rte_ipv6_hdr *ip, const void *l4_hdr)
+{
+ uint8_t tuple[36];
+
+ memcpy(tuple, &ip->src_addr, 2 * sizeof(ip->src_addr));
+ memcpy(&tuple[32], l4_hdr, 4);
+ return ctx->ops->hash_36(ctx, tuple);
+}
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_thash_rss_ipv6_l4, 27.03)
+int
+rte_thash_rss_ipv6_l4(const struct rte_thash_rss_ctx *ctx,
+ const struct rte_ipv6_hdr *ip, const void *l4_hdr, uint32_t *hash)
+{
+ if (ctx == NULL || ip == NULL || l4_hdr == NULL || hash == NULL)
+ return -EINVAL;
+
+ if (l4_hdr == ip + 1)
+ *hash = ctx->ops->hash_36(ctx, (const uint8_t *)&ip->src_addr);
+ else
+ *hash = thash_ipv6_l4_gather(ctx, ip, l4_hdr);
+
+ return 0;
+}
--
2.55.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 08/11] hash: add explicit handling for RSS with split L3/L4 data
2026-12-01 15:16 [PATCH 00/11] Add optimized path selection for thash Bruce Richardson
` (6 preceding siblings ...)
2026-12-01 15:16 ` [PATCH 07/11] hash: implement IPv4 and IPv6 RSS hashing in SW Bruce Richardson
@ 2026-12-01 15:16 ` Bruce Richardson
2026-12-01 15:16 ` [PATCH 09/11] test/thash: add perf tests for new RSS functions Bruce Richardson
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Bruce Richardson @ 2026-12-01 15:16 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
If the L3 header has options or extension headers after the IP
addresses, then we cannot just compute the RSS hash of the L3+L4 data as
a contiguous block. Creating a generic function which merges the data
together using scalar functions leads to slowdown in the subsequent
vector functions, due to failed store forwarding (small stores followed
by larger loads). We can fix this by creating explicit vector split-key
handling functions, which will use vector stores rather than scalar when
merging the values to be hashed.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
app/test/test_thash.c | 129 +++++++++++++++++++++++++++++++++++
lib/hash/thash_gfni_avx512.c | 33 +++++++++
lib/hash/thash_private.h | 20 ++++++
| 52 +++++++-------
4 files changed, 210 insertions(+), 24 deletions(-)
diff --git a/app/test/test_thash.c b/app/test/test_thash.c
index 413292943d..148213be4b 100644
--- a/app/test/test_thash.c
+++ b/app/test/test_thash.c
@@ -2,6 +2,9 @@
* Copyright(c) 2015-2019 Vladimir Medvedkin <medvedkinv@gmail.com>
*/
+#include <stdbool.h>
+#include <string.h>
+
#include <rte_common.h>
#include <rte_eal.h>
#include <rte_errno.h>
@@ -9,7 +12,9 @@
#include <rte_random.h>
#include <rte_malloc.h>
#include <rte_byteorder.h>
+#include <rte_vect.h>
+#include "generic/rte_vect.h"
#include "test.h"
#include <rte_thash.h>
@@ -402,6 +407,129 @@ test_rss_ctx_create_free(void)
return TEST_SUCCESS;
}
+static int
+check_rss_packet_hashes(const struct rte_thash_rss_ctx *ctx)
+{
+ struct {
+ struct rte_ipv4_hdr ip;
+ uint8_t ports[4];
+ } v4_packet = {0};
+ struct {
+ struct rte_ipv6_hdr ip;
+ uint8_t ports[4];
+ } v6_packet = {0};
+ uint8_t split_ports[4];
+ uint32_t hash;
+
+ for (unsigned int i = 0; i < RTE_DIM(v4_tbl); i++) {
+ const rte_be16_t sport = rte_cpu_to_be_16(v4_tbl[i].src_port);
+ const rte_be16_t dport = rte_cpu_to_be_16(v4_tbl[i].dst_port);
+
+ v4_packet.ip.src_addr = rte_cpu_to_be_32(v4_tbl[i].src_ip);
+ v4_packet.ip.dst_addr = rte_cpu_to_be_32(v4_tbl[i].dst_ip);
+ memcpy(v4_packet.ports, &sport, sizeof(sport));
+ memcpy(v4_packet.ports + sizeof(sport), &dport, sizeof(dport));
+ memcpy(split_ports, v4_packet.ports, sizeof(split_ports));
+
+ TEST_ASSERT_SUCCESS(rte_thash_rss_ipv4_l3(ctx, &v4_packet.ip, &hash),
+ "IPv4 L3 hash failed at %u", i);
+ TEST_ASSERT_EQUAL(hash, v4_tbl[i].hash_l3, "IPv4 L3 hash mismatch at %u", i);
+ TEST_ASSERT_SUCCESS(rte_thash_rss_ipv4_l4(ctx, &v4_packet.ip,
+ v4_packet.ports, &hash), "IPv4 adjacent L4 hash failed at %u", i);
+ TEST_ASSERT_EQUAL(hash, v4_tbl[i].hash_l3l4,
+ "IPv4 adjacent L4 hash mismatch at %u", i);
+ TEST_ASSERT_SUCCESS(rte_thash_rss_ipv4_l4(ctx, &v4_packet.ip, split_ports, &hash),
+ "IPv4 split L4 hash failed at %u", i);
+ TEST_ASSERT_EQUAL(hash, v4_tbl[i].hash_l3l4,
+ "IPv4 split L4 hash mismatch at %u", i);
+ }
+
+ for (unsigned int i = 0; i < RTE_DIM(v6_tbl); i++) {
+ const rte_be16_t sport = rte_cpu_to_be_16(v6_tbl[i].src_port);
+ const rte_be16_t dport = rte_cpu_to_be_16(v6_tbl[i].dst_port);
+
+ v6_packet.ip.src_addr = v6_tbl[i].src_ip;
+ v6_packet.ip.dst_addr = v6_tbl[i].dst_ip;
+ memcpy(v6_packet.ports, &sport, sizeof(sport));
+ memcpy(v6_packet.ports + sizeof(sport), &dport, sizeof(dport));
+ memcpy(split_ports, v6_packet.ports, sizeof(split_ports));
+
+ TEST_ASSERT_SUCCESS(rte_thash_rss_ipv6_l3(ctx, &v6_packet.ip, &hash),
+ "IPv6 L3 hash failed at %u", i);
+ TEST_ASSERT_EQUAL(hash, v6_tbl[i].hash_l3, "IPv6 L3 hash mismatch at %u", i);
+ TEST_ASSERT_SUCCESS(rte_thash_rss_ipv6_l4(ctx, &v6_packet.ip,
+ v6_packet.ports, &hash), "IPv6 adjacent L4 hash failed at %u", i);
+ TEST_ASSERT_EQUAL(hash, v6_tbl[i].hash_l3l4,
+ "IPv6 adjacent L4 hash mismatch at %u", i);
+ TEST_ASSERT_SUCCESS(rte_thash_rss_ipv6_l4(ctx, &v6_packet.ip, split_ports, &hash),
+ "IPv6 split L4 hash failed at %u", i);
+ TEST_ASSERT_EQUAL(hash, v6_tbl[i].hash_l3l4,
+ "IPv6 split L4 hash mismatch at %u", i);
+ }
+
+ TEST_ASSERT_EQUAL(rte_thash_rss_ipv4_l3(NULL, &v4_packet.ip, &hash), -EINVAL,
+ "IPv4 L3 accepted NULL context");
+ TEST_ASSERT_EQUAL(rte_thash_rss_ipv4_l3(ctx, NULL, &hash), -EINVAL,
+ "IPv4 L3 accepted NULL header");
+ TEST_ASSERT_EQUAL(rte_thash_rss_ipv4_l3(ctx, &v4_packet.ip, NULL), -EINVAL,
+ "IPv4 L3 accepted NULL result");
+ TEST_ASSERT_EQUAL(rte_thash_rss_ipv6_l3(NULL, &v6_packet.ip, &hash), -EINVAL,
+ "IPv6 L3 accepted NULL context");
+ TEST_ASSERT_EQUAL(rte_thash_rss_ipv6_l3(ctx, NULL, &hash), -EINVAL,
+ "IPv6 L3 accepted NULL header");
+ TEST_ASSERT_EQUAL(rte_thash_rss_ipv6_l3(ctx, &v6_packet.ip, NULL), -EINVAL,
+ "IPv6 L3 accepted NULL result");
+ TEST_ASSERT_EQUAL(rte_thash_rss_ipv4_l4(NULL, &v4_packet.ip, split_ports, &hash),
+ -EINVAL, "IPv4 L4 accepted NULL context");
+ TEST_ASSERT_EQUAL(rte_thash_rss_ipv4_l4(ctx, NULL, split_ports, &hash),
+ -EINVAL, "IPv4 L4 accepted NULL header");
+ TEST_ASSERT_EQUAL(rte_thash_rss_ipv4_l4(ctx, &v4_packet.ip, NULL, &hash),
+ -EINVAL, "IPv4 L4 accepted NULL ports");
+ TEST_ASSERT_EQUAL(rte_thash_rss_ipv4_l4(ctx, &v4_packet.ip, split_ports, NULL),
+ -EINVAL, "IPv4 L4 accepted NULL result");
+ TEST_ASSERT_EQUAL(rte_thash_rss_ipv6_l4(NULL, &v6_packet.ip, split_ports, &hash),
+ -EINVAL, "IPv6 L4 accepted NULL context");
+ TEST_ASSERT_EQUAL(rte_thash_rss_ipv6_l4(ctx, NULL, split_ports, &hash),
+ -EINVAL, "IPv6 L4 accepted NULL header");
+ TEST_ASSERT_EQUAL(rte_thash_rss_ipv6_l4(ctx, &v6_packet.ip, NULL, &hash),
+ -EINVAL, "IPv6 L4 accepted NULL ports");
+ TEST_ASSERT_EQUAL(rte_thash_rss_ipv6_l4(ctx, &v6_packet.ip, split_ports, NULL),
+ -EINVAL, "IPv6 L4 accepted NULL result");
+
+ return TEST_SUCCESS;
+}
+
+static int
+test_rss_packet_hashes(void)
+{
+ const uint16_t original_bitwidth = rte_vect_get_max_simd_bitwidth();
+ const uint16_t bitwidths[] = { RTE_VECT_SIMD_DISABLED, RTE_VECT_SIMD_512 };
+ bool bitwidth_changed = false;
+ int ret = TEST_SUCCESS;
+
+ for (unsigned int i = 0; i < RTE_DIM(bitwidths); i++) {
+ const bool forced = rte_vect_set_max_simd_bitwidth(bitwidths[i]) != 0;
+ struct rte_thash_rss_ctx *ctx = rte_thash_rss_ctx_create(default_rss_key,
+ sizeof(default_rss_key), 0);
+
+ if (!forced)
+ bitwidth_changed = true;
+ if (ctx == NULL)
+ ret = -TEST_FAILED;
+ else {
+ ret = check_rss_packet_hashes(ctx);
+ rte_thash_rss_ctx_free(ctx);
+ }
+ if (ret != TEST_SUCCESS || forced)
+ break;
+ printf("Checked RSS packet hashes with SIMD bitwidth: %u\n", bitwidths[i]);
+ }
+
+ if (bitwidth_changed)
+ rte_vect_set_max_simd_bitwidth(original_bitwidth);
+ return ret;
+}
+
static int
test_create_invalid(void)
{
@@ -1075,6 +1203,7 @@ static struct unit_test_suite thash_tests = {
TEST_CASE(test_toeplitz_hash_gfni_bulk),
TEST_CASE(test_big_tuple_gfni),
TEST_CASE(test_rss_ctx_create_free),
+ TEST_CASE(test_rss_packet_hashes),
TEST_CASE(test_create_invalid),
TEST_CASE(test_multiple_create),
TEST_CASE(test_free_null),
diff --git a/lib/hash/thash_gfni_avx512.c b/lib/hash/thash_gfni_avx512.c
index 3804341f7b..e738812807 100644
--- a/lib/hash/thash_gfni_avx512.c
+++ b/lib/hash/thash_gfni_avx512.c
@@ -2,6 +2,9 @@
* Copyright(c) 2026 Intel Corporation
*/
+#include <stdalign.h>
+#include <string.h>
+
#include <rte_thash_x86_gfni.h>
#include "thash_private.h"
@@ -33,3 +36,33 @@ thash_gfni_avx512_36B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
{
return rte_thash_gfni(ctx->data.matrices, tuple, 36);
}
+
+uint32_t
+thash_gfni_avx512_12B_split(const struct rte_thash_rss_ctx *ctx,
+ const uint8_t *addresses, const uint8_t *ports)
+{
+ alignas(64) uint8_t tuple[64];
+ uint32_t ports_value;
+
+ memcpy(&ports_value, ports, sizeof(ports_value));
+ __m512i value = _mm512_maskz_loadu_epi8(UINT64_C(0xff), addresses);
+ value = _mm512_mask_set1_epi32(value, UINT16_C(1) << 2, ports_value);
+ _mm512_store_si512(tuple, value);
+
+ return rte_thash_gfni(ctx->data.matrices, tuple, 12);
+}
+
+uint32_t
+thash_gfni_avx512_36B_split(const struct rte_thash_rss_ctx *ctx,
+ const uint8_t *addresses, const uint8_t *ports)
+{
+ alignas(64) uint8_t tuple[64];
+ uint32_t ports_value;
+
+ memcpy(&ports_value, ports, sizeof(ports_value));
+ __m512i value = _mm512_maskz_loadu_epi8(UINT64_C(0xffffffff), addresses);
+ value = _mm512_mask_set1_epi32(value, UINT16_C(1) << 8, ports_value);
+ _mm512_store_si512(tuple, value);
+
+ return rte_thash_gfni(ctx->data.matrices, tuple, 36);
+}
diff --git a/lib/hash/thash_private.h b/lib/hash/thash_private.h
index 2860866c4a..a7a1b0148f 100644
--- a/lib/hash/thash_private.h
+++ b/lib/hash/thash_private.h
@@ -13,12 +13,16 @@
struct rte_thash_rss_ctx;
typedef uint32_t (*thash_fn_t)(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple);
+typedef uint32_t (*thash_split_fn_t)(const struct rte_thash_rss_ctx *ctx,
+ const uint8_t *addresses, const uint8_t *ports);
struct thash_rss_ops {
thash_fn_t hash_8;
thash_fn_t hash_12;
thash_fn_t hash_32;
thash_fn_t hash_36;
+ thash_split_fn_t hash_12_split;
+ thash_split_fn_t hash_36_split;
};
struct rte_thash_rss_ctx {
@@ -47,6 +51,14 @@ thash_gfni_avx512_32B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
uint32_t
thash_gfni_avx512_36B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple);
+uint32_t
+thash_gfni_avx512_12B_split(const struct rte_thash_rss_ctx *ctx, const uint8_t *addresses,
+ const uint8_t *ports);
+
+uint32_t
+thash_gfni_avx512_36B_split(const struct rte_thash_rss_ctx *ctx, const uint8_t *addresses,
+ const uint8_t *ports);
+
uint32_t
thash_scalar_8B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple);
@@ -59,6 +71,14 @@ thash_scalar_32B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple);
uint32_t
thash_scalar_36B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple);
+uint32_t
+thash_scalar_12B_split(const struct rte_thash_rss_ctx *ctx, const uint8_t *addresses,
+ const uint8_t *ports);
+
+uint32_t
+thash_scalar_36B_split(const struct rte_thash_rss_ctx *ctx, const uint8_t *addresses,
+ const uint8_t *ports);
+
bool
thash_gfni_avx512_usable(void);
--git a/lib/hash/thash_rss.c b/lib/hash/thash_rss.c
index ddc07720a3..95fecd6d92 100644
--- a/lib/hash/thash_rss.c
+++ b/lib/hash/thash_rss.c
@@ -53,11 +53,35 @@ thash_scalar_36B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
return thash_scalar((const uint8_t *)ctx->data.key, tuple, 36);
}
+uint32_t
+thash_scalar_12B_split(const struct rte_thash_rss_ctx *ctx,
+ const uint8_t *addresses, const uint8_t *ports)
+{
+ uint8_t tuple[12];
+
+ memcpy(tuple, addresses, 8);
+ memcpy(&tuple[8], ports, 4);
+ return thash_scalar((const uint8_t *)ctx->data.key, tuple, 12);
+}
+
+uint32_t
+thash_scalar_36B_split(const struct rte_thash_rss_ctx *ctx,
+ const uint8_t *addresses, const uint8_t *ports)
+{
+ uint8_t tuple[36];
+
+ memcpy(tuple, addresses, 32);
+ memcpy(&tuple[32], ports, 4);
+ return thash_scalar((const uint8_t *)ctx->data.key, tuple, 36);
+}
+
static const struct thash_rss_ops scalar_ops = {
.hash_8 = thash_scalar_8B,
.hash_12 = thash_scalar_12B,
.hash_32 = thash_scalar_32B,
.hash_36 = thash_scalar_36B,
+ .hash_12_split = thash_scalar_12B_split,
+ .hash_36_split = thash_scalar_36B_split,
};
#ifdef CC_THASH_GFNI_AVX512_SUPPORT
@@ -66,6 +90,8 @@ static const struct thash_rss_ops gfni_avx512_ops = {
.hash_12 = thash_gfni_avx512_12B,
.hash_32 = thash_gfni_avx512_32B,
.hash_36 = thash_gfni_avx512_36B,
+ .hash_12_split = thash_gfni_avx512_12B_split,
+ .hash_36_split = thash_gfni_avx512_36B_split,
};
#endif
@@ -130,17 +156,6 @@ rte_thash_rss_ipv6_l3(const struct rte_thash_rss_ctx *ctx,
return 0;
}
-static __rte_noinline uint32_t
-thash_ipv4_l4_gather(const struct rte_thash_rss_ctx *ctx,
- const struct rte_ipv4_hdr *ip, const void *l4_hdr)
-{
- uint8_t tuple[12];
-
- memcpy(tuple, &ip->src_addr, 2 * sizeof(ip->src_addr));
- memcpy(&tuple[8], l4_hdr, 4);
- return ctx->ops->hash_12(ctx, tuple);
-}
-
RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_thash_rss_ipv4_l4, 27.03)
int
rte_thash_rss_ipv4_l4(const struct rte_thash_rss_ctx *ctx,
@@ -152,22 +167,11 @@ rte_thash_rss_ipv4_l4(const struct rte_thash_rss_ctx *ctx,
if (l4_hdr == ip + 1)
*hash = ctx->ops->hash_12(ctx, (const uint8_t *)&ip->src_addr);
else
- *hash = thash_ipv4_l4_gather(ctx, ip, l4_hdr);
+ *hash = ctx->ops->hash_12_split(ctx, (const uint8_t *)&ip->src_addr, l4_hdr);
return 0;
}
-static __rte_noinline uint32_t
-thash_ipv6_l4_gather(const struct rte_thash_rss_ctx *ctx,
- const struct rte_ipv6_hdr *ip, const void *l4_hdr)
-{
- uint8_t tuple[36];
-
- memcpy(tuple, &ip->src_addr, 2 * sizeof(ip->src_addr));
- memcpy(&tuple[32], l4_hdr, 4);
- return ctx->ops->hash_36(ctx, tuple);
-}
-
RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_thash_rss_ipv6_l4, 27.03)
int
rte_thash_rss_ipv6_l4(const struct rte_thash_rss_ctx *ctx,
@@ -179,7 +183,7 @@ rte_thash_rss_ipv6_l4(const struct rte_thash_rss_ctx *ctx,
if (l4_hdr == ip + 1)
*hash = ctx->ops->hash_36(ctx, (const uint8_t *)&ip->src_addr);
else
- *hash = thash_ipv6_l4_gather(ctx, ip, l4_hdr);
+ *hash = ctx->ops->hash_36_split(ctx, (const uint8_t *)&ip->src_addr, l4_hdr);
return 0;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 09/11] test/thash: add perf tests for new RSS functions
2026-12-01 15:16 [PATCH 00/11] Add optimized path selection for thash Bruce Richardson
` (7 preceding siblings ...)
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
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
10 siblings, 0 replies; 12+ messages in thread
From: Bruce Richardson @ 2026-12-01 15:16 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
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
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 10/11] hash: remove extra store-load when performing RSS
2026-12-01 15:16 [PATCH 00/11] Add optimized path selection for thash Bruce Richardson
` (8 preceding siblings ...)
2026-12-01 15:16 ` [PATCH 09/11] test/thash: add perf tests for new RSS functions Bruce Richardson
@ 2026-12-01 15:16 ` Bruce Richardson
2026-12-01 15:16 ` [PATCH 11/11] hash: add AVX2 RSS hash functions Bruce Richardson
10 siblings, 0 replies; 12+ messages in thread
From: Bruce Richardson @ 2026-12-01 15:16 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
Because of the need to handle cases where the L4 is not contiguous with
the L3 addresses, we have to build up a tuple locally before calling the
hash calculation. This building the tuple, even using AVX-512, still
leads to an extra store of that tuple before loading it back inside the
calculation loop. We can eliminate this unnecessary store and load back
by making a simplified copy of the core calculation function that only
handles tuples of up to 64-bytes in size and that takes those as input
via an already populated AVX-512 register.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
lib/hash/thash_gfni_avx512.c | 94 ++++++++++++++++++++++++++++++------
1 file changed, 79 insertions(+), 15 deletions(-)
diff --git a/lib/hash/thash_gfni_avx512.c b/lib/hash/thash_gfni_avx512.c
index e738812807..8c8384919a 100644
--- a/lib/hash/thash_gfni_avx512.c
+++ b/lib/hash/thash_gfni_avx512.c
@@ -2,7 +2,6 @@
* Copyright(c) 2026 Intel Corporation
*/
-#include <stdalign.h>
#include <string.h>
#include <rte_thash_x86_gfni.h>
@@ -13,56 +12,121 @@
#error "GFNI and required AVX512 extensions must be enabled to build this file"
#endif
+static inline uint32_t
+thash_gfni_avx512_hash(const uint64_t *mtrx, __m512i tuple_bytes, int len)
+{
+ __m512i permute_idx = _mm512_set_epi32(0x07060504, 0x07060504,
+ 0x06050403, 0x06050403,
+ 0x05040302, 0x05040302,
+ 0x04030201, 0x04030201,
+ 0x03020100, 0x03020100,
+ 0x020100FF, 0x020100FF,
+ 0x0100FFFE, 0x0100FFFE,
+ 0x00FFFEFD, 0x00FFFEFD);
+ const __m512i rewind_idx = _mm512_set_epi32(0, 0, 0, 0,
+ 0, 0, 0, 0,
+ 0, 0, 0x0000003B, 0x0000003B,
+ 0x00003B3A, 0x00003B3A,
+ 0x003B3A39, 0x003B3A39);
+ const __m512i shift_8 = _mm512_set1_epi8(8);
+ __m512i xor_acc = _mm512_setzero_si512();
+ __m512i perm_bytes = _mm512_setzero_si512();
+ __mmask64 permute_mask = RTE_THASH_FIRST_ITER_MSK;
+ const int full_len = (len + 3) / 8;
+ uint32_t val, val_zero;
+
+ for (int i = 0; i < full_len; i++, mtrx += 8) {
+ perm_bytes = _mm512_mask_permutexvar_epi8(perm_bytes,
+ permute_mask, permute_idx, tuple_bytes);
+ const __m512i matrixes = _mm512_maskz_loadu_epi64(UINT8_MAX, mtrx);
+ const __m512i vals = _mm512_gf2p8affine_epi64_epi8(perm_bytes, matrixes, 0);
+
+ xor_acc = _mm512_xor_si512(xor_acc, vals);
+ permute_idx = _mm512_add_epi8(permute_idx, shift_8);
+ permute_mask = RTE_THASH_PERM_MSK;
+ }
+
+ const int rest_len = (len + 3) % 8;
+ if (rest_len != 0) {
+ const __mmask8 mtrx_mask = (1U << rest_len) - 1;
+ const __m512i matrixes = _mm512_maskz_loadu_epi64(mtrx_mask, mtrx);
+
+ if (full_len == 8)
+ perm_bytes = _mm512_maskz_permutexvar_epi8(RTE_THASH_REWIND_MSK,
+ rewind_idx, perm_bytes);
+ else
+ perm_bytes = _mm512_mask_permutexvar_epi8(perm_bytes,
+ permute_mask, permute_idx, tuple_bytes);
+
+ const __m512i vals = _mm512_gf2p8affine_epi64_epi8(perm_bytes, matrixes, 0);
+ xor_acc = _mm512_xor_si512(xor_acc, vals);
+ }
+
+ __rte_thash_xor_reduce(xor_acc, &val, &val_zero);
+ return val;
+}
+
uint32_t
thash_gfni_avx512_8B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
{
- return rte_thash_gfni(ctx->data.matrices, tuple, 8);
+ uint64_t value;
+
+ memcpy(&value, tuple, sizeof(value));
+ const __m512i tuple_bytes = _mm512_maskz_set1_epi64(1, value);
+
+ return thash_gfni_avx512_hash(ctx->data.matrices, tuple_bytes, 8);
}
uint32_t
thash_gfni_avx512_12B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
{
- return rte_thash_gfni(ctx->data.matrices, tuple, 12);
+ const __m512i tuple_bytes = _mm512_maskz_loadu_epi8(UINT64_C(0xfff), tuple);
+
+ return thash_gfni_avx512_hash(ctx->data.matrices, tuple_bytes, 12);
}
uint32_t
thash_gfni_avx512_32B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
{
- return rte_thash_gfni(ctx->data.matrices, tuple, 32);
+ const __m512i tuple_bytes = _mm512_zextsi256_si512(
+ _mm256_loadu_si256((const __m256i *)tuple));
+
+ return thash_gfni_avx512_hash(ctx->data.matrices, tuple_bytes, 32);
}
uint32_t
thash_gfni_avx512_36B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
{
- return rte_thash_gfni(ctx->data.matrices, tuple, 36);
+ const __m512i tuple_bytes = _mm512_maskz_loadu_epi8(UINT64_C(0xfffffffff), tuple);
+
+ return thash_gfni_avx512_hash(ctx->data.matrices, tuple_bytes, 36);
}
uint32_t
thash_gfni_avx512_12B_split(const struct rte_thash_rss_ctx *ctx,
const uint8_t *addresses, const uint8_t *ports)
{
- alignas(64) uint8_t tuple[64];
uint32_t ports_value;
+ uint64_t address_value;
memcpy(&ports_value, ports, sizeof(ports_value));
- __m512i value = _mm512_maskz_loadu_epi8(UINT64_C(0xff), addresses);
- value = _mm512_mask_set1_epi32(value, UINT16_C(1) << 2, ports_value);
- _mm512_store_si512(tuple, value);
+ memcpy(&address_value, addresses, sizeof(address_value));
+ __m512i tuple_bytes = _mm512_maskz_set1_epi64(1, address_value);
+ tuple_bytes = _mm512_mask_set1_epi32(tuple_bytes, UINT16_C(1) << 2, ports_value);
- return rte_thash_gfni(ctx->data.matrices, tuple, 12);
+ return thash_gfni_avx512_hash(ctx->data.matrices, tuple_bytes, 12);
}
uint32_t
thash_gfni_avx512_36B_split(const struct rte_thash_rss_ctx *ctx,
const uint8_t *addresses, const uint8_t *ports)
{
- alignas(64) uint8_t tuple[64];
uint32_t ports_value;
memcpy(&ports_value, ports, sizeof(ports_value));
- __m512i value = _mm512_maskz_loadu_epi8(UINT64_C(0xffffffff), addresses);
- value = _mm512_mask_set1_epi32(value, UINT16_C(1) << 8, ports_value);
- _mm512_store_si512(tuple, value);
+ __m512i tuple_bytes = _mm512_zextsi256_si512(
+ _mm256_loadu_si256((const __m256i *)addresses));
+ tuple_bytes = _mm512_mask_set1_epi32(tuple_bytes, UINT16_C(1) << 8, ports_value);
- return rte_thash_gfni(ctx->data.matrices, tuple, 36);
+ return thash_gfni_avx512_hash(ctx->data.matrices, tuple_bytes, 36);
}
--
2.55.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 11/11] hash: add AVX2 RSS hash functions
2026-12-01 15:16 [PATCH 00/11] Add optimized path selection for thash Bruce Richardson
` (9 preceding siblings ...)
2026-12-01 15:16 ` [PATCH 10/11] hash: remove extra store-load when performing RSS Bruce Richardson
@ 2026-12-01 15:16 ` Bruce Richardson
10 siblings, 0 replies; 12+ messages in thread
From: Bruce Richardson @ 2026-12-01 15:16 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
Add copies of the RSS L3/L4 hash functions using AVX2+GFNI, rather than
requiring AVX-512. The AVX2 implementation body is LLM created, and then
tuned with manual intervention. It is port of the AVX-512 code, rather
than a newly hand-crafted implementation.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
app/test/test_thash.c | 6 +-
app/test/test_thash_perf.c | 120 +++++++++++++++-----------
lib/hash/meson.build | 9 ++
lib/hash/rte_thash.c | 12 +++
lib/hash/thash_gfni_avx2.c | 170 +++++++++++++++++++++++++++++++++++++
lib/hash/thash_private.h | 23 +++++
| 19 +++++
lib/meson.build | 3 +-
8 files changed, 309 insertions(+), 53 deletions(-)
create mode 100644 lib/hash/thash_gfni_avx2.c
diff --git a/app/test/test_thash.c b/app/test/test_thash.c
index 148213be4b..0d8fe136e5 100644
--- a/app/test/test_thash.c
+++ b/app/test/test_thash.c
@@ -503,7 +503,11 @@ static int
test_rss_packet_hashes(void)
{
const uint16_t original_bitwidth = rte_vect_get_max_simd_bitwidth();
- const uint16_t bitwidths[] = { RTE_VECT_SIMD_DISABLED, RTE_VECT_SIMD_512 };
+ const uint16_t bitwidths[] = {
+ RTE_VECT_SIMD_DISABLED,
+ RTE_VECT_SIMD_256,
+ RTE_VECT_SIMD_512,
+ };
bool bitwidth_changed = false;
int ret = TEST_SUCCESS;
diff --git a/app/test/test_thash_perf.c b/app/test/test_thash_perf.c
index 44bda932c7..e3568ab8bb 100644
--- a/app/test/test_thash_perf.c
+++ b/app/test/test_thash_perf.c
@@ -194,35 +194,27 @@ 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)
+static bool
+cpu_has_avx2_gfni(void)
{
#ifdef RTE_ARCH_X86
- 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;
- }
+ return rte_cpu_get_flag_enabled(RTE_CPUFLAG_GFNI) > 0 &&
+ rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2) > 0;
+#else
+ return false;
+#endif
+}
- printf("WARNING: CPU supports GFNI, raising max SIMD bitwidth from %u to %u to benchmark it\n",
- cur, RTE_VECT_SIMD_512);
+static bool
+cpu_has_avx512_gfni(void)
+{
+#ifdef RTE_ARCH_X86
+ return rte_cpu_get_flag_enabled(RTE_CPUFLAG_GFNI) > 0 &&
+ rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512VBMI) > 0 &&
+ rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512DQ) > 0 &&
+ rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512VL) > 0;
+#else
+ return false;
#endif
}
@@ -230,38 +222,64 @@ 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;
- }
- }
+ struct rte_thash_rss_ctx *contexts[3] = { NULL };
+ const char *labels[3] = {
+ "SIMD disabled", "256-bit SIMD limit", "512-bit SIMD limit"
+ };
+ const bool has_avx2_gfni = cpu_has_avx2_gfni();
+ const bool has_avx512_gfni = cpu_has_avx512_gfni();
+ const uint16_t max_bitwidth = has_avx512_gfni ? RTE_VECT_SIMD_512 :
+ has_avx2_gfni ? RTE_VECT_SIMD_256 : RTE_VECT_SIMD_DISABLED;
+ const int bitwidth_set_ret = rte_vect_set_max_simd_bitwidth(max_bitwidth);
+ int ret = -1;
+
+ if (bitwidth_set_ret == 0 && max_bitwidth > original_bitwidth)
+ printf("WARNING: CPU supports GFNI, raising max SIMD bitwidth from %u to %u\n",
+ original_bitwidth, max_bitwidth);
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);
- 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);
+ /* we need to set the max SIMD bitwidth in order to create different contexts for testing */
+ if (bitwidth_set_ret != 0) {
+ printf("Skipping RSS packet hash perf test: max SIMD bitwidth is forced/locked\n");
+ return TEST_SKIPPED;
+ }
+
+ if (has_avx512_gfni) {
+ contexts[2] = rte_thash_rss_ctx_create(default_rss_key,
+ sizeof(default_rss_key), 0);
+ if (contexts[2] == NULL)
+ goto out;
+ }
+ if (has_avx2_gfni) {
+ if (rte_vect_set_max_simd_bitwidth(RTE_VECT_SIMD_256) != 0)
+ goto out;
+ contexts[1] = rte_thash_rss_ctx_create(default_rss_key,
+ sizeof(default_rss_key), 0);
+ if (contexts[1] == NULL)
+ goto out;
+ }
+ if (rte_vect_set_max_simd_bitwidth(RTE_VECT_SIMD_DISABLED) != 0)
+ goto out;
+ contexts[0] = rte_thash_rss_ctx_create(default_rss_key,
+ sizeof(default_rss_key), 0);
+ if (contexts[0] == NULL)
+ goto out;
+ rte_vect_set_max_simd_bitwidth(original_bitwidth);
+
+ ret = 0;
+ for (unsigned int i = 0; i < RTE_DIM(contexts) && ret == 0; i++) {
+ if (contexts[i] != NULL)
+ ret = run_rss_packet_perf(contexts[i], labels[i]);
+ }
+out:
+ rte_vect_set_max_simd_bitwidth(original_bitwidth);
+ for (unsigned int i = 0; i < RTE_DIM(contexts); i++)
+ rte_thash_rss_ctx_free(contexts[i]);
return ret;
}
diff --git a/lib/hash/meson.build b/lib/hash/meson.build
index 72fb7efd8d..71aca563a6 100644
--- a/lib/hash/meson.build
+++ b/lib/hash/meson.build
@@ -32,6 +32,15 @@ deps += ['net']
deps += ['ring']
deps += ['rcu']
+if dpdk_conf.has('RTE_ARCH_X86')
+ thash_gfni_avx2_cflags = ['-mgfni']
+ if cc.has_multi_arguments(thash_gfni_avx2_cflags)
+ sources_avx2 += files('thash_gfni_avx2.c')
+ cflags_avx2 += thash_gfni_avx2_cflags
+ cflags += '-DCC_THASH_GFNI_AVX2_SUPPORT'
+ endif
+endif
+
if dpdk_conf.has('RTE_ARCH_X86') and cc_has_avx512
thash_gfni_cflags = ['-mgfni', '-mavx512vbmi']
if cc.has_multi_arguments(thash_gfni_cflags)
diff --git a/lib/hash/rte_thash.c b/lib/hash/rte_thash.c
index f544cc0d69..5322ceb368 100644
--- a/lib/hash/rte_thash.c
+++ b/lib/hash/rte_thash.c
@@ -86,6 +86,18 @@ thash_gfni_avx512_usable(void)
#endif
}
+bool
+thash_gfni_avx2_usable(void)
+{
+#ifdef RTE_ARCH_X86
+ return rte_cpu_get_flag_enabled(RTE_CPUFLAG_GFNI) > 0 &&
+ rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2) > 0 &&
+ rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_256;
+#else
+ return false;
+#endif
+}
+
RTE_EXPORT_SYMBOL(rte_thash_gfni_supported)
int
rte_thash_gfni_supported(void)
diff --git a/lib/hash/thash_gfni_avx2.c b/lib/hash/thash_gfni_avx2.c
new file mode 100644
index 0000000000..23a788c24b
--- /dev/null
+++ b/lib/hash/thash_gfni_avx2.c
@@ -0,0 +1,170 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2026 Intel Corporation
+ */
+
+#include <string.h>
+
+#include <rte_vect.h>
+
+#include "thash_private.h"
+
+#if !defined(__AVX2__) || !defined(__GFNI__)
+#error "AVX2 and GFNI must be enabled to build this file"
+#endif
+
+/*
+ * Matrix k is applied to tuple bytes k - 3 .. k in the low dword of qword k % 4;
+ * the high dword never reaches the 32-bit result, so it is left zero.
+ */
+#define WIN_IDX(start, valid, i) \
+ ((start) + (i) >= 0 && (start) + (i) < (valid) ? (start) + (i) : -1)
+#define WIN_MASK(start, valid) _mm256_setr_epi8( \
+ WIN_IDX(start, valid, 0), WIN_IDX(start, valid, 1), \
+ WIN_IDX(start, valid, 2), WIN_IDX(start, valid, 3), -1, -1, -1, -1, \
+ WIN_IDX(start, valid, 1), WIN_IDX(start, valid, 2), \
+ WIN_IDX(start, valid, 3), WIN_IDX(start, valid, 4), -1, -1, -1, -1, \
+ WIN_IDX(start, valid, 2), WIN_IDX(start, valid, 3), \
+ WIN_IDX(start, valid, 4), WIN_IDX(start, valid, 5), -1, -1, -1, -1, \
+ WIN_IDX(start, valid, 3), WIN_IDX(start, valid, 4), \
+ WIN_IDX(start, valid, 5), WIN_IDX(start, valid, 6), -1, -1, -1, -1)
+
+static inline __m256i
+thash_gfni_avx2_group(__m256i xor_acc, __m256i src, __m256i mask, const uint64_t *mtrx)
+{
+ const __m256i matrixes = _mm256_loadu_si256((const __m256i *)mtrx);
+ const __m256i tuple_bytes = _mm256_shuffle_epi8(src, mask);
+
+ return _mm256_xor_si256(xor_acc,
+ _mm256_gf2p8affine_epi64_epi8(tuple_bytes, matrixes, 0));
+}
+
+static inline uint32_t
+thash_gfni_avx2_reduce(__m256i xor_acc)
+{
+ __m128i reduced = _mm_xor_si128(_mm256_castsi256_si128(xor_acc),
+ _mm256_extracti128_si256(xor_acc, 1));
+
+ reduced = _mm_xor_si128(reduced, _mm_srli_si128(reduced, 8));
+ return (uint32_t)_mm_cvtsi128_si32(reduced);
+}
+
+/* Each 128-bit lane holds 8 bytes from first followed by 4 bytes from second. */
+static inline __m256i
+thash_gfni_avx2_load_8_4(const uint8_t *first, const uint8_t *second)
+{
+ uint32_t second_value;
+
+ memcpy(&second_value, second, sizeof(second_value));
+ return _mm256_blend_epi32(
+ _mm256_broadcastq_epi64(_mm_loadl_epi64((const __m128i *)first)),
+ _mm256_set1_epi32((int)second_value), 0x44);
+}
+
+static inline __m256i
+thash_gfni_avx2_load_16(const uint8_t *src)
+{
+ return _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i *)src));
+}
+
+static inline uint32_t
+thash_gfni_avx2_hash_12(const uint64_t *mtrx, const uint8_t *addresses, const uint8_t *ports)
+{
+ const __m256i src = thash_gfni_avx2_load_8_4(addresses, ports);
+ __m256i xor_acc = _mm256_setzero_si256();
+
+ xor_acc = thash_gfni_avx2_group(xor_acc, src, WIN_MASK(-3, 12), &mtrx[0]);
+ xor_acc = thash_gfni_avx2_group(xor_acc, src, WIN_MASK(1, 12), &mtrx[4]);
+ xor_acc = thash_gfni_avx2_group(xor_acc, src, WIN_MASK(5, 12), &mtrx[8]);
+ xor_acc = thash_gfni_avx2_group(xor_acc, src, WIN_MASK(9, 12), &mtrx[12]);
+
+ return thash_gfni_avx2_reduce(xor_acc);
+}
+
+/* Matrices 0-27, covering tuple bytes 0-27 from the 32 address bytes. */
+static inline __m256i
+thash_gfni_avx2_hash_32_head(const uint64_t *mtrx, const uint8_t *addresses, __m256i *src_16)
+{
+ const __m256i src_0 = thash_gfni_avx2_load_16(addresses);
+ const __m256i src_8 = thash_gfni_avx2_load_16(&addresses[8]);
+ __m256i xor_acc = _mm256_setzero_si256();
+
+ *src_16 = thash_gfni_avx2_load_16(&addresses[16]);
+ xor_acc = thash_gfni_avx2_group(xor_acc, src_0, WIN_MASK(-3, 16), &mtrx[0]);
+ xor_acc = thash_gfni_avx2_group(xor_acc, src_0, WIN_MASK(1, 16), &mtrx[4]);
+ xor_acc = thash_gfni_avx2_group(xor_acc, src_0, WIN_MASK(5, 16), &mtrx[8]);
+ xor_acc = thash_gfni_avx2_group(xor_acc, src_0, WIN_MASK(9, 16), &mtrx[12]);
+ xor_acc = thash_gfni_avx2_group(xor_acc, src_8, WIN_MASK(5, 16), &mtrx[16]);
+ xor_acc = thash_gfni_avx2_group(xor_acc, *src_16, WIN_MASK(1, 16), &mtrx[20]);
+ return thash_gfni_avx2_group(xor_acc, *src_16, WIN_MASK(5, 16), &mtrx[24]);
+}
+
+uint32_t
+thash_gfni_avx2_8B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
+{
+ const uint64_t *mtrx = ctx->data.matrices;
+ const __m256i src = _mm256_broadcastq_epi64(_mm_loadl_epi64((const __m128i *)tuple));
+ __m256i xor_acc = _mm256_setzero_si256();
+
+ xor_acc = thash_gfni_avx2_group(xor_acc, src, WIN_MASK(-3, 8), &mtrx[0]);
+ xor_acc = thash_gfni_avx2_group(xor_acc, src, WIN_MASK(1, 8), &mtrx[4]);
+ xor_acc = thash_gfni_avx2_group(xor_acc, src, WIN_MASK(5, 8), &mtrx[8]);
+
+ return thash_gfni_avx2_reduce(xor_acc);
+}
+
+uint32_t
+thash_gfni_avx2_12B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
+{
+ return thash_gfni_avx2_hash_12(ctx->data.matrices, tuple, &tuple[8]);
+}
+
+uint32_t
+thash_gfni_avx2_32B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
+{
+ const uint64_t *mtrx = ctx->data.matrices;
+ __m256i src_16;
+ __m256i xor_acc = thash_gfni_avx2_hash_32_head(mtrx, tuple, &src_16);
+
+ xor_acc = thash_gfni_avx2_group(xor_acc, src_16, WIN_MASK(9, 16), &mtrx[28]);
+ xor_acc = thash_gfni_avx2_group(xor_acc, src_16, WIN_MASK(13, 16), &mtrx[32]);
+
+ return thash_gfni_avx2_reduce(xor_acc);
+}
+
+uint32_t
+thash_gfni_avx2_36B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
+{
+ const uint64_t *mtrx = ctx->data.matrices;
+ const __m256i src_20 = thash_gfni_avx2_load_16(&tuple[20]);
+ __m256i src_16;
+ __m256i xor_acc = thash_gfni_avx2_hash_32_head(mtrx, tuple, &src_16);
+
+ xor_acc = thash_gfni_avx2_group(xor_acc, src_20, WIN_MASK(5, 16), &mtrx[28]);
+ xor_acc = thash_gfni_avx2_group(xor_acc, src_20, WIN_MASK(9, 16), &mtrx[32]);
+ xor_acc = thash_gfni_avx2_group(xor_acc, src_20, WIN_MASK(13, 16), &mtrx[36]);
+
+ return thash_gfni_avx2_reduce(xor_acc);
+}
+
+uint32_t
+thash_gfni_avx2_12B_split(const struct rte_thash_rss_ctx *ctx,
+ const uint8_t *addresses, const uint8_t *ports)
+{
+ return thash_gfni_avx2_hash_12(ctx->data.matrices, addresses, ports);
+}
+
+uint32_t
+thash_gfni_avx2_36B_split(const struct rte_thash_rss_ctx *ctx,
+ const uint8_t *addresses, const uint8_t *ports)
+{
+ const uint64_t *mtrx = ctx->data.matrices;
+ const __m256i src_24 = thash_gfni_avx2_load_8_4(&addresses[24], ports);
+ __m256i src_16;
+ __m256i xor_acc = thash_gfni_avx2_hash_32_head(mtrx, addresses, &src_16);
+
+ xor_acc = thash_gfni_avx2_group(xor_acc, src_24, WIN_MASK(1, 12), &mtrx[28]);
+ xor_acc = thash_gfni_avx2_group(xor_acc, src_24, WIN_MASK(5, 12), &mtrx[32]);
+ xor_acc = thash_gfni_avx2_group(xor_acc, src_24, WIN_MASK(9, 12), &mtrx[36]);
+
+ return thash_gfni_avx2_reduce(xor_acc);
+}
diff --git a/lib/hash/thash_private.h b/lib/hash/thash_private.h
index a7a1b0148f..322a65a2e1 100644
--- a/lib/hash/thash_private.h
+++ b/lib/hash/thash_private.h
@@ -59,6 +59,26 @@ uint32_t
thash_gfni_avx512_36B_split(const struct rte_thash_rss_ctx *ctx, const uint8_t *addresses,
const uint8_t *ports);
+uint32_t
+thash_gfni_avx2_8B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple);
+
+uint32_t
+thash_gfni_avx2_12B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple);
+
+uint32_t
+thash_gfni_avx2_32B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple);
+
+uint32_t
+thash_gfni_avx2_36B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple);
+
+uint32_t
+thash_gfni_avx2_12B_split(const struct rte_thash_rss_ctx *ctx, const uint8_t *addresses,
+ const uint8_t *ports);
+
+uint32_t
+thash_gfni_avx2_36B_split(const struct rte_thash_rss_ctx *ctx, const uint8_t *addresses,
+ const uint8_t *ports);
+
uint32_t
thash_scalar_8B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple);
@@ -82,4 +102,7 @@ thash_scalar_36B_split(const struct rte_thash_rss_ctx *ctx, const uint8_t *addre
bool
thash_gfni_avx512_usable(void);
+bool
+thash_gfni_avx2_usable(void);
+
#endif /* THASH_PRIVATE_H */
--git a/lib/hash/thash_rss.c b/lib/hash/thash_rss.c
index 95fecd6d92..c0c76b2467 100644
--- a/lib/hash/thash_rss.c
+++ b/lib/hash/thash_rss.c
@@ -84,6 +84,17 @@ static const struct thash_rss_ops scalar_ops = {
.hash_36_split = thash_scalar_36B_split,
};
+#ifdef CC_THASH_GFNI_AVX2_SUPPORT
+static const struct thash_rss_ops gfni_avx2_ops = {
+ .hash_8 = thash_gfni_avx2_8B,
+ .hash_12 = thash_gfni_avx2_12B,
+ .hash_32 = thash_gfni_avx2_32B,
+ .hash_36 = thash_gfni_avx2_36B,
+ .hash_12_split = thash_gfni_avx2_12B_split,
+ .hash_36_split = thash_gfni_avx2_36B_split,
+};
+#endif
+
#ifdef CC_THASH_GFNI_AVX512_SUPPORT
static const struct thash_rss_ops gfni_avx512_ops = {
.hash_8 = thash_gfni_avx512_8B,
@@ -118,6 +129,14 @@ rte_thash_rss_ctx_create(const uint8_t *key, uint32_t key_len, uint64_t flags)
}
#endif
+#ifdef CC_THASH_GFNI_AVX2_SUPPORT
+ if (thash_gfni_avx2_usable()) {
+ ctx->ops = &gfni_avx2_ops;
+ rte_thash_complete_matrix(ctx->data.matrices, key, THASH_RSS_KEY_LEN);
+ return ctx;
+ }
+#endif
+
ctx->ops = &scalar_ops;
memcpy(ctx->data.key, key, THASH_RSS_KEY_LEN);
rte_convert_rss_key(ctx->data.key, ctx->data.key, THASH_RSS_KEY_LEN);
diff --git a/lib/meson.build b/lib/meson.build
index 458951054c..84594af8a3 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -120,6 +120,7 @@ foreach l:libraries
sources = []
sources_avx2 = []
sources_avx512 = []
+ cflags_avx2 = [] # extra cflags for the avx2 code, e.g. extra avx2 feature flags
cflags_avx512 = [] # extra cflags for the avx512 code, e.g. extra avx512 feature flags
headers = []
indirect_headers = [] # public headers not directly included by apps
@@ -249,7 +250,7 @@ foreach l:libraries
sources_avx2,
dependencies: static_deps,
include_directories: includes,
- c_args: [cflags, cc_avx2_flags])
+ c_args: [cflags, cflags_avx2, cc_avx2_flags])
objs += avx2_lib.extract_objects(sources_avx2)
endif
if sources_avx512.length() > 0 and cc_has_avx512
--
2.55.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-12-01 15:18 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 09/11] test/thash: add perf tests for new RSS functions Bruce Richardson
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox