From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>
Subject: [PATCH 07/11] hash: implement IPv4 and IPv6 RSS hashing in SW
Date: Tue, 1 Dec 2026 15:16:19 +0000 [thread overview]
Message-ID: <20261201151623.2240031-8-bruce.richardson@intel.com> (raw)
In-Reply-To: <20261201151623.2240031-1-bruce.richardson@intel.com>
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
next prev 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 ` Bruce Richardson [this message]
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
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-8-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