From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1B9DF45BC3; Thu, 24 Oct 2024 20:47:29 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 42C4043555; Thu, 24 Oct 2024 20:47:21 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) by mails.dpdk.org (Postfix) with ESMTP id 82C3B40156 for ; Thu, 24 Oct 2024 20:47:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729795628; x=1761331628; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EdCKFoLrcVLi1wuRsPb/+bPjAu2mhtU1btPCsT621KQ=; b=hlFw+h+A5z6YEw7nx6EDrXsCVO1sMzrPxLi46oGcXyk8vY5B1PubCZ8o It+UGArIBE9V9aPxB9FT2OBxsg9POjG6YnHTsqpo/7sOyRDa3RGfN79DF 8qTVEppOQVeRmBN3ATlEVM4TQdOJxD2pgH+KNgwsDHoyUmC0CacwOk1Je pQ8QqvKJV9DmIEfPId7OVvXt8I226zgmo9pj+2gCX+ry6eHeWZpHTrN1z IUR6e/V4i1FrbQxXZozygh0NF7MSKYyEM5JyLUWSBbLYJQDp1Elx63Dm7 MLJCBoEp6x5/098kqkTMFxx9UZfRToSEfDOWAlkXgImPwqWLkbzP2Idhz w==; X-CSE-ConnectionGUID: 8i/Y1wHSRxSXkJyxY+AIHQ== X-CSE-MsgGUID: +omu11BATAOazQuvg98IqA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="29607983" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="29607983" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2024 11:47:07 -0700 X-CSE-ConnectionGUID: PDhwP/qjT6aWgYGIcS2Bow== X-CSE-MsgGUID: pQrNqmYzQX2820akDD4QYg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,230,1725346800"; d="scan'208";a="85280474" Received: from silpixa00401176.ir.intel.com ([10.243.23.21]) by fmviesa004.fm.intel.com with ESMTP; 24 Oct 2024 11:47:05 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: stephen@networkplumber.org, Yipeng Wang , Sameh Gobriel , Bruce Richardson Subject: [PATCH v4 4/4] test/thash: add tests for RSS key generation API Date: Thu, 24 Oct 2024 18:46:56 +0000 Message-ID: <20241024184657.901099-5-vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241024184657.901099-1-vladimir.medvedkin@intel.com> References: <20241011181703.236985-1-vladimir.medvedkin@intel.com> <20241024184657.901099-1-vladimir.medvedkin@intel.com> 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-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This patch adds tests for RSS key generation. In this test we measure distribution of hash LSBs for a given random tuple where only some part of bits is variable. At first we generate random hash key and measure the worst distribution for a given ReTa size value (RETA_SZ_LOG). Then we adjust the key with the new API and run the test again, noting the new distribution. Finally, we also measure said distribution for some well known RSS hash key which is used in some PMDs. Signed-off-by: Vladimir Medvedkin --- app/test/test_thash.c | 108 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/app/test/test_thash.c b/app/test/test_thash.c index 0ad6943cf8..b9c6e9118e 100644 --- a/app/test/test_thash.c +++ b/app/test/test_thash.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "test.h" @@ -923,6 +924,112 @@ test_adjust_tuple_mult_reta(void) return TEST_SUCCESS; } +#define RETA_SZ_LOG 11 +#define RSS_KEY_SZ 40 +#define RETA_SZ (1 << RETA_SZ_LOG) +#define NB_HASH_ITER RETA_SZ +#define NB_TEST_ITER 10 + +static inline void +run_hash_calc_loop(uint8_t *key, union rte_thash_tuple *tuple, + unsigned int *rss_reta_hits) +{ + uint32_t rss_hash; + int i; + + for (i = 0; i < NB_HASH_ITER; i++) { + /* variable part starts from the most significant bit */ + tuple->v4.dport = (i << (sizeof(tuple->v4.dport) * CHAR_BIT - + RETA_SZ_LOG)); + /* + * swap sport and dport on LE arch since rte_softrss() + * works with host byte order uint32_t values + */ + tuple->v4.dport = rte_cpu_to_be_16(tuple->v4.dport); + tuple->v4.sctp_tag = rte_be_to_cpu_32(tuple->v4.sctp_tag); + rss_hash = rte_softrss((uint32_t *)tuple, + RTE_THASH_V4_L4_LEN, key); + /* unroll swap, required only for sport */ + tuple->v4.sctp_tag = rte_cpu_to_be_32(tuple->v4.sctp_tag); + rss_reta_hits[rss_hash & (RETA_SZ - 1)]++; + } +} + +static int +hash_calc_iteration(unsigned int *min_before, unsigned int *max_before, + unsigned int *min_after, unsigned int *max_after, + unsigned int *min_default, unsigned int *max_default) +{ + uint8_t key[RSS_KEY_SZ] = {0}; + union rte_thash_tuple tuple; + unsigned int rss_reta_hits_before_adjust[RETA_SZ] = {0}; + unsigned int rss_reta_hits_after_adjust[RETA_SZ] = {0}; + unsigned int rss_reta_hits_default_key[RETA_SZ] = {0}; + int i; + + for (i = 0; i < RSS_KEY_SZ; i++) + key[i] = rte_rand(); + + tuple.v4.src_addr = rte_rand(); + tuple.v4.dst_addr = rte_rand(); + tuple.v4.sport = rte_rand(); + + run_hash_calc_loop(key, &tuple, rss_reta_hits_before_adjust); + + int ret = rte_thash_gen_key(key, RSS_KEY_SZ, RETA_SZ_LOG, + offsetof(union rte_thash_tuple, v4.dport)*CHAR_BIT, + RETA_SZ_LOG); + + if (ret) { + printf("Can't generate key\n"); + return -1; + } + + run_hash_calc_loop(key, &tuple, rss_reta_hits_after_adjust); + + run_hash_calc_loop(default_rss_key, &tuple, rss_reta_hits_default_key); + + for (i = 0; i < RETA_SZ; i++) { + *min_before = RTE_MIN(*min_before, rss_reta_hits_before_adjust[i]); + *max_before = RTE_MAX(*max_before, rss_reta_hits_before_adjust[i]); + *min_after = RTE_MIN(*min_after, rss_reta_hits_after_adjust[i]); + *max_after = RTE_MAX(*max_after, rss_reta_hits_after_adjust[i]); + *min_default = RTE_MIN(*min_default, rss_reta_hits_default_key[i]); + *max_default = RTE_MAX(*max_default, rss_reta_hits_default_key[i]); + } + + return 0; +} + +static int +test_keygen(void) +{ + int i, ret; + unsigned int min_before = UINT32_MAX; + unsigned int min_after = UINT32_MAX; + unsigned int min_default = UINT32_MAX; + unsigned int max_before = 0; + unsigned int max_after = 0; + unsigned int max_default = 0; + + for (i = 0; i < NB_TEST_ITER; i++) { + /* calculates the worst distribution for each key */ + ret = hash_calc_iteration(&min_before, &max_before, &min_after, + &max_after, &min_default, &max_default); + if (ret) + return ret; + } + + printf("RSS before key adjustment: min=%d, max=%d\n", + min_before, max_before); + printf("RSS after key adjustment: min=%d, max=%d\n", + min_after, max_after); + printf("RSS default key: min=%d, max=%d\n", + min_default, max_default); + + return TEST_SUCCESS; +} + static struct unit_test_suite thash_tests = { .suite_name = "thash autotest", .setup = NULL, @@ -944,6 +1051,7 @@ static struct unit_test_suite thash_tests = { TEST_CASE(test_predictable_rss_multirange), TEST_CASE(test_adjust_tuple), TEST_CASE(test_adjust_tuple_mult_reta), + TEST_CASE(test_keygen), TEST_CASES_END() } }; -- 2.43.0