From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E48E8606A320 for ; Tue, 1 Dec 2026 15:17:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=cnzL/k80 Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 67EC44069F; Tue, 1 Dec 2026 16:16:55 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) by mails.dpdk.org (Postfix) with ESMTPS id 4FEED40616 for ; Tue, 1 Dec 2026 16:16:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796138211; x=1827674211; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cP7zhjJy0I5Sphd8k6l9IomNKAQMfyJy53pWbQ6WlTw=; b=cnzL/k80WbXk3/NZTUbfCDdR7R7EympLStori9TrYYcOrDAP7ZG+egQx IR9E+I5h0JCN0JtigbtrZ6uTl23Zyjq/dsPCDTZyxtn7Ps0Q9N8nneXpr i8PRtA4UVG7Acwgg+UGaMvMH3LoIpiGepXEYMziYg0NN84aM/ECqIT5Vv NFr953HcYzYjjDy6X9jrmzfgjng4+qku0ba2mK99gVBmeefQ4sEiY8LRF typsPeJKnP+BV6ughu54kocndO+n4pj4mggANtKeE31Rg8xy3hBdQO+CO QsWTgXL2tXxpBloKWgWulPa99wTYRpgkTvJFBdptpQ3FQxta201YaLZYi g==; X-CSE-ConnectionGUID: 1XGcXCnjSeqZfhWw1i+3Ow== X-CSE-MsgGUID: qUB4iWXwQBSwfjZ7mI5ouw== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="5023497" X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="5023497" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 07:16:50 -0800 X-CSE-ConnectionGUID: wbFVL/EwTSiClX2JMLqK+g== X-CSE-MsgGUID: qv83FesMQcisxfJjAIP3Eg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="13749413" Received: from silpixa00401385.ir.intel.com ([10.20.224.226]) by fmviesa001.fm.intel.com with ESMTP; 01 Dec 2026 07:16:48 -0800 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson Subject: [PATCH 08/11] hash: add explicit handling for RSS with split L3/L4 data Date: Tue, 1 Dec 2026 15:16:20 +0000 Message-ID: <20261201151623.2240031-9-bruce.richardson@intel.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261201151623.2240031-1-bruce.richardson@intel.com> References: <20261201151623.2240031-1-bruce.richardson@intel.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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 --- app/test/test_thash.c | 129 +++++++++++++++++++++++++++++++++++ lib/hash/thash_gfni_avx512.c | 33 +++++++++ lib/hash/thash_private.h | 20 ++++++ lib/hash/thash_rss.c | 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 */ +#include +#include + #include #include #include @@ -9,7 +12,9 @@ #include #include #include +#include +#include "generic/rte_vect.h" #include "test.h" #include @@ -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 +#include + #include #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); diff --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