DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] test: add additional tests for thash library
@ 2023-06-28 19:12 Vladimir Medvedkin
  2023-06-29 12:59 ` David Marchand
  2023-06-30 17:09 ` [PATCH v2 1/2] hash: fix reading unaligned bits implementation Vladimir Medvedkin
  0 siblings, 2 replies; 7+ messages in thread
From: Vladimir Medvedkin @ 2023-06-28 19:12 UTC (permalink / raw)
  To: dev; +Cc: konstantin.v.ananyev

Adds tests comparing the results of applying the output
of rte_thash_get_complement() to the tuple with the result
of calling rte_thash_adjust_tuple().

Suggested-by: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>
Signed-off-by: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>
Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
---
 app/test/test_thash.c | 132 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 132 insertions(+)

diff --git a/app/test/test_thash.c b/app/test/test_thash.c
index 62ba4a9528..53d9611e18 100644
--- a/app/test/test_thash.c
+++ b/app/test/test_thash.c
@@ -804,6 +804,137 @@ test_adjust_tuple(void)
 	return TEST_SUCCESS;
 }
 
+static uint32_t
+calc_tuple_hash(const uint8_t tuple[TUPLE_SZ], const uint8_t *key)
+{
+	uint32_t i, hash;
+	uint32_t tmp[TUPLE_SZ / sizeof(uint32_t)];
+
+	for (i = 0; i < RTE_DIM(tmp); i++)
+		tmp[i] = rte_be_to_cpu_32(
+			*(const uint32_t *)&tuple[i * sizeof(uint32_t)]);
+
+	hash = rte_softrss(tmp, RTE_DIM(tmp), key);
+	return hash;
+}
+
+static int
+check_adj_tuple(const uint8_t tuple[TUPLE_SZ], const uint8_t *key,
+		uint32_t dhv, uint32_t ohv, uint32_t adjust, uint32_t reta_sz,
+		const char *prefix)
+{
+	uint32_t hash, hashlsb;
+
+	hash = calc_tuple_hash(tuple, key);
+	hashlsb = hash & HASH_MSK(reta_sz);
+
+	printf("%s(%s) for tuple:\n", __func__, prefix);
+	rte_memdump(stdout, NULL, tuple, TUPLE_SZ);
+	printf("\treta_sz: %u,\n"
+		"\torig hash: %#x,\n"
+		"\tdesired: %#x,\n"
+		"\tadjust: %#x,\n"
+		"\tactual: %#x,\n",
+	       reta_sz, ohv, dhv, adjust, hashlsb);
+
+	if (dhv == hashlsb) {
+		printf("\t***Succeeded\n");
+		return 0;
+	}
+
+	printf("\t***Failed\n");
+	return -1;
+}
+
+static int
+test_adjust_tuple_mb(uint32_t reta_sz, uint32_t bofs)
+{
+	struct rte_thash_ctx *ctx;
+	struct rte_thash_subtuple_helper *h;
+	const int key_len = 40;
+	const uint8_t *new_key;
+	uint8_t orig_tuple[TUPLE_SZ];
+	uint8_t tuple_1[TUPLE_SZ];
+	uint8_t tuple_2[TUPLE_SZ];
+	uint32_t orig_hash;
+	int rc, ret;
+	uint32_t adj_bits;
+	unsigned int random = rte_rand();
+	unsigned int desired_value = random & HASH_MSK(reta_sz);
+
+	const uint32_t h_offset = offsetof(union rte_thash_tuple, v4.dport) * CHAR_BIT;
+	const uint32_t h_size = sizeof(uint16_t) * CHAR_BIT - bofs;
+
+	printf("===%s(reta_sz=%u,bofs=%u)===\n", __func__, reta_sz, bofs);
+
+	memset(orig_tuple, 0xab, sizeof(orig_tuple));
+
+	ctx = rte_thash_init_ctx("test", key_len, reta_sz, NULL, 0);
+	RTE_TEST_ASSERT(ctx != NULL, "can not create thash ctx\n");
+
+	ret = rte_thash_add_helper(ctx, "test", h_size, h_offset);
+	RTE_TEST_ASSERT(ret == 0, "can not add helper, ret %d\n", ret);
+
+	new_key = rte_thash_get_key(ctx);
+
+	h = rte_thash_get_helper(ctx, "test");
+
+	orig_hash = calc_tuple_hash(orig_tuple, new_key);
+
+	adj_bits = rte_thash_get_complement(h, orig_hash, desired_value);
+
+	/* use method #1, update tuple manually */
+	memcpy(tuple_1, orig_tuple, sizeof(tuple_1));
+	{
+		uint16_t nv, ov, *p;
+
+		p = (uint16_t *)(tuple_1 + h_offset / CHAR_BIT);
+		ov = p[0];
+		nv = ov ^ rte_cpu_to_be_16(adj_bits << bofs);
+		printf("%s#%d: ov=%#hx, nv=%#hx, adj=%#x;\n",
+			__func__, __LINE__, ov, nv, adj_bits);
+		p[0] = nv;
+	}
+
+	rc = check_adj_tuple(tuple_1, new_key, desired_value, orig_hash,
+		adj_bits, reta_sz, "method #1");
+	if (h_offset % CHAR_BIT == 0)
+		ret |= rc;
+
+	/* use method #2, use library function to adjust tuple */
+	memcpy(tuple_2, orig_tuple, sizeof(tuple_2));
+
+	rte_thash_adjust_tuple(ctx, h, tuple_2, sizeof(tuple_2),
+		desired_value, 1, NULL, NULL);
+	ret |= check_adj_tuple(tuple_2, new_key, desired_value, orig_hash,
+		adj_bits, reta_sz, "method #2");
+
+	rte_thash_free_ctx(ctx);
+
+	ret |= memcmp(tuple_1, tuple_2, sizeof(tuple_1));
+
+	printf("%s EXIT=======\n", __func__);
+	return ret;
+}
+
+static int
+test_adjust_tuple_mult_reta(void)
+{
+	uint32_t i, j, np, nt;
+
+	nt = 0, np = 0;
+	for (i = 0; i < CHAR_BIT; i++) {
+		for (j = 6; j <= RTE_THASH_RETA_SZ_MAX - i; j++) {
+			np += (test_adjust_tuple_mb(j, i) == 0);
+			nt++;
+		}
+	}
+
+	printf("%s: tests executed: %u, test passed: %u\n", __func__, nt, np);
+	RTE_TEST_ASSERT(nt == np, "%u subtests failed", nt - np);
+	return TEST_SUCCESS;
+}
+
 static struct unit_test_suite thash_tests = {
 	.suite_name = "thash autotest",
 	.setup = NULL,
@@ -824,6 +955,7 @@ static struct unit_test_suite thash_tests = {
 	TEST_CASE(test_predictable_rss_min_seq),
 	TEST_CASE(test_predictable_rss_multirange),
 	TEST_CASE(test_adjust_tuple),
+	TEST_CASE(test_adjust_tuple_mult_reta),
 	TEST_CASES_END()
 	}
 };
-- 
2.25.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] test: add additional tests for thash library
  2023-06-28 19:12 [PATCH] test: add additional tests for thash library Vladimir Medvedkin
@ 2023-06-29 12:59 ` David Marchand
  2023-06-29 13:17   ` Medvedkin, Vladimir
  2023-06-30 17:09 ` [PATCH v2 1/2] hash: fix reading unaligned bits implementation Vladimir Medvedkin
  1 sibling, 1 reply; 7+ messages in thread
From: David Marchand @ 2023-06-29 12:59 UTC (permalink / raw)
  To: Vladimir Medvedkin; +Cc: dev, konstantin.v.ananyev

On Wed, Jun 28, 2023 at 9:12 PM Vladimir Medvedkin
<vladimir.medvedkin@intel.com> wrote:
>
> Adds tests comparing the results of applying the output
> of rte_thash_get_complement() to the tuple with the result
> of calling rte_thash_adjust_tuple().
>
> Suggested-by: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>
> Signed-off-by: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>
> Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>

CI reports a failure on this new test, is it linked to the fix you
sent separately?
https://patchwork.dpdk.org/project/dpdk/patch/20230628191208.78701-1-vladimir.medvedkin@intel.com/


-- 
David Marchand


^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH] test: add additional tests for thash library
  2023-06-29 12:59 ` David Marchand
@ 2023-06-29 13:17   ` Medvedkin, Vladimir
  2023-06-29 13:47     ` David Marchand
  0 siblings, 1 reply; 7+ messages in thread
From: Medvedkin, Vladimir @ 2023-06-29 13:17 UTC (permalink / raw)
  To: David Marchand; +Cc: dev, konstantin.v.ananyev

Hi David,

Yes, I sent them separately because the bugfix in mentioned patch should be backported unlike adding a new test.

-----Original Message-----
From: David Marchand <david.marchand@redhat.com> 
Sent: Thursday, June 29, 2023 2:00 PM
To: Medvedkin, Vladimir <vladimir.medvedkin@intel.com>
Cc: dev@dpdk.org; konstantin.v.ananyev@yandex.ru
Subject: Re: [PATCH] test: add additional tests for thash library

On Wed, Jun 28, 2023 at 9:12 PM Vladimir Medvedkin <vladimir.medvedkin@intel.com> wrote:
>
> Adds tests comparing the results of applying the output of 
> rte_thash_get_complement() to the tuple with the result of calling 
> rte_thash_adjust_tuple().
>
> Suggested-by: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>
> Signed-off-by: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>
> Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>

CI reports a failure on this new test, is it linked to the fix you sent separately?
https://patchwork.dpdk.org/project/dpdk/patch/20230628191208.78701-1-vladimir.medvedkin@intel.com/


--
David Marchand


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] test: add additional tests for thash library
  2023-06-29 13:17   ` Medvedkin, Vladimir
@ 2023-06-29 13:47     ` David Marchand
  0 siblings, 0 replies; 7+ messages in thread
From: David Marchand @ 2023-06-29 13:47 UTC (permalink / raw)
  To: Medvedkin, Vladimir; +Cc: dev, konstantin.v.ananyev

On Thu, Jun 29, 2023 at 3:44 PM Medvedkin, Vladimir
<vladimir.medvedkin@intel.com> wrote:
>
> Hi David,
>
> Yes, I sent them separately because the bugfix in mentioned patch should be backported unlike adding a new test.

Well, having the two patches in a single series won't prevent us from
only backporting the fix, and the CI will still be happy.
Please resend.

Thanks.

-- 
David Marchand


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/2] hash: fix reading unaligned bits implementation
  2023-06-28 19:12 [PATCH] test: add additional tests for thash library Vladimir Medvedkin
  2023-06-29 12:59 ` David Marchand
@ 2023-06-30 17:09 ` Vladimir Medvedkin
  2023-06-30 17:09   ` [PATCH v2 2/2] test: add additional tests for thash library Vladimir Medvedkin
  2023-07-06 14:49   ` [PATCH v2 1/2] hash: fix reading unaligned bits implementation Thomas Monjalon
  1 sibling, 2 replies; 7+ messages in thread
From: Vladimir Medvedkin @ 2023-06-30 17:09 UTC (permalink / raw)
  To: dev; +Cc: konstantin.v.ananyev, stable

Fixes: 28ebff11c2dc ("hash: add predictable RSS")
Cc: stable@dpdk.org

Acked-by: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>
Tested-by: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>
Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
---
 lib/hash/rte_thash.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/lib/hash/rte_thash.c b/lib/hash/rte_thash.c
index 0249883b8d..2228af576b 100644
--- a/lib/hash/rte_thash.c
+++ b/lib/hash/rte_thash.c
@@ -670,7 +670,7 @@ rte_thash_get_gfni_matrices(struct rte_thash_ctx *ctx)
 }
 
 static inline uint8_t
-read_unaligned_byte(uint8_t *ptr, unsigned int len, unsigned int offset)
+read_unaligned_byte(uint8_t *ptr, unsigned int offset)
 {
 	uint8_t ret = 0;
 
@@ -681,13 +681,14 @@ read_unaligned_byte(uint8_t *ptr, unsigned int len, unsigned int offset)
 			(CHAR_BIT - (offset % CHAR_BIT));
 	}
 
-	return ret >> (CHAR_BIT - len);
+	return ret;
 }
 
 static inline uint32_t
 read_unaligned_bits(uint8_t *ptr, int len, int offset)
 {
 	uint32_t ret = 0;
+	int shift;
 
 	len = RTE_MAX(len, 0);
 	len = RTE_MIN(len, (int)(sizeof(uint32_t) * CHAR_BIT));
@@ -695,13 +696,14 @@ read_unaligned_bits(uint8_t *ptr, int len, int offset)
 	while (len > 0) {
 		ret <<= CHAR_BIT;
 
-		ret |= read_unaligned_byte(ptr, RTE_MIN(len, CHAR_BIT),
-			offset);
+		ret |= read_unaligned_byte(ptr, offset);
 		offset += CHAR_BIT;
 		len -= CHAR_BIT;
 	}
 
-	return ret;
+	shift = (len == 0) ? 0 :
+		(CHAR_BIT - ((len + CHAR_BIT) % CHAR_BIT));
+	return ret >> shift;
 }
 
 /* returns mask for len bits with given offset inside byte */
-- 
2.25.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 2/2] test: add additional tests for thash library
  2023-06-30 17:09 ` [PATCH v2 1/2] hash: fix reading unaligned bits implementation Vladimir Medvedkin
@ 2023-06-30 17:09   ` Vladimir Medvedkin
  2023-07-06 14:49   ` [PATCH v2 1/2] hash: fix reading unaligned bits implementation Thomas Monjalon
  1 sibling, 0 replies; 7+ messages in thread
From: Vladimir Medvedkin @ 2023-06-30 17:09 UTC (permalink / raw)
  To: dev; +Cc: konstantin.v.ananyev

Adds tests comparing the results of applying the output
of rte_thash_get_complement() to the tuple with the result
of calling rte_thash_adjust_tuple().

Suggested-by: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>
Signed-off-by: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>
Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
---
 app/test/test_thash.c | 132 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 132 insertions(+)

diff --git a/app/test/test_thash.c b/app/test/test_thash.c
index 62ba4a9528..53d9611e18 100644
--- a/app/test/test_thash.c
+++ b/app/test/test_thash.c
@@ -804,6 +804,137 @@ test_adjust_tuple(void)
 	return TEST_SUCCESS;
 }
 
+static uint32_t
+calc_tuple_hash(const uint8_t tuple[TUPLE_SZ], const uint8_t *key)
+{
+	uint32_t i, hash;
+	uint32_t tmp[TUPLE_SZ / sizeof(uint32_t)];
+
+	for (i = 0; i < RTE_DIM(tmp); i++)
+		tmp[i] = rte_be_to_cpu_32(
+			*(const uint32_t *)&tuple[i * sizeof(uint32_t)]);
+
+	hash = rte_softrss(tmp, RTE_DIM(tmp), key);
+	return hash;
+}
+
+static int
+check_adj_tuple(const uint8_t tuple[TUPLE_SZ], const uint8_t *key,
+		uint32_t dhv, uint32_t ohv, uint32_t adjust, uint32_t reta_sz,
+		const char *prefix)
+{
+	uint32_t hash, hashlsb;
+
+	hash = calc_tuple_hash(tuple, key);
+	hashlsb = hash & HASH_MSK(reta_sz);
+
+	printf("%s(%s) for tuple:\n", __func__, prefix);
+	rte_memdump(stdout, NULL, tuple, TUPLE_SZ);
+	printf("\treta_sz: %u,\n"
+		"\torig hash: %#x,\n"
+		"\tdesired: %#x,\n"
+		"\tadjust: %#x,\n"
+		"\tactual: %#x,\n",
+	       reta_sz, ohv, dhv, adjust, hashlsb);
+
+	if (dhv == hashlsb) {
+		printf("\t***Succeeded\n");
+		return 0;
+	}
+
+	printf("\t***Failed\n");
+	return -1;
+}
+
+static int
+test_adjust_tuple_mb(uint32_t reta_sz, uint32_t bofs)
+{
+	struct rte_thash_ctx *ctx;
+	struct rte_thash_subtuple_helper *h;
+	const int key_len = 40;
+	const uint8_t *new_key;
+	uint8_t orig_tuple[TUPLE_SZ];
+	uint8_t tuple_1[TUPLE_SZ];
+	uint8_t tuple_2[TUPLE_SZ];
+	uint32_t orig_hash;
+	int rc, ret;
+	uint32_t adj_bits;
+	unsigned int random = rte_rand();
+	unsigned int desired_value = random & HASH_MSK(reta_sz);
+
+	const uint32_t h_offset = offsetof(union rte_thash_tuple, v4.dport) * CHAR_BIT;
+	const uint32_t h_size = sizeof(uint16_t) * CHAR_BIT - bofs;
+
+	printf("===%s(reta_sz=%u,bofs=%u)===\n", __func__, reta_sz, bofs);
+
+	memset(orig_tuple, 0xab, sizeof(orig_tuple));
+
+	ctx = rte_thash_init_ctx("test", key_len, reta_sz, NULL, 0);
+	RTE_TEST_ASSERT(ctx != NULL, "can not create thash ctx\n");
+
+	ret = rte_thash_add_helper(ctx, "test", h_size, h_offset);
+	RTE_TEST_ASSERT(ret == 0, "can not add helper, ret %d\n", ret);
+
+	new_key = rte_thash_get_key(ctx);
+
+	h = rte_thash_get_helper(ctx, "test");
+
+	orig_hash = calc_tuple_hash(orig_tuple, new_key);
+
+	adj_bits = rte_thash_get_complement(h, orig_hash, desired_value);
+
+	/* use method #1, update tuple manually */
+	memcpy(tuple_1, orig_tuple, sizeof(tuple_1));
+	{
+		uint16_t nv, ov, *p;
+
+		p = (uint16_t *)(tuple_1 + h_offset / CHAR_BIT);
+		ov = p[0];
+		nv = ov ^ rte_cpu_to_be_16(adj_bits << bofs);
+		printf("%s#%d: ov=%#hx, nv=%#hx, adj=%#x;\n",
+			__func__, __LINE__, ov, nv, adj_bits);
+		p[0] = nv;
+	}
+
+	rc = check_adj_tuple(tuple_1, new_key, desired_value, orig_hash,
+		adj_bits, reta_sz, "method #1");
+	if (h_offset % CHAR_BIT == 0)
+		ret |= rc;
+
+	/* use method #2, use library function to adjust tuple */
+	memcpy(tuple_2, orig_tuple, sizeof(tuple_2));
+
+	rte_thash_adjust_tuple(ctx, h, tuple_2, sizeof(tuple_2),
+		desired_value, 1, NULL, NULL);
+	ret |= check_adj_tuple(tuple_2, new_key, desired_value, orig_hash,
+		adj_bits, reta_sz, "method #2");
+
+	rte_thash_free_ctx(ctx);
+
+	ret |= memcmp(tuple_1, tuple_2, sizeof(tuple_1));
+
+	printf("%s EXIT=======\n", __func__);
+	return ret;
+}
+
+static int
+test_adjust_tuple_mult_reta(void)
+{
+	uint32_t i, j, np, nt;
+
+	nt = 0, np = 0;
+	for (i = 0; i < CHAR_BIT; i++) {
+		for (j = 6; j <= RTE_THASH_RETA_SZ_MAX - i; j++) {
+			np += (test_adjust_tuple_mb(j, i) == 0);
+			nt++;
+		}
+	}
+
+	printf("%s: tests executed: %u, test passed: %u\n", __func__, nt, np);
+	RTE_TEST_ASSERT(nt == np, "%u subtests failed", nt - np);
+	return TEST_SUCCESS;
+}
+
 static struct unit_test_suite thash_tests = {
 	.suite_name = "thash autotest",
 	.setup = NULL,
@@ -824,6 +955,7 @@ static struct unit_test_suite thash_tests = {
 	TEST_CASE(test_predictable_rss_min_seq),
 	TEST_CASE(test_predictable_rss_multirange),
 	TEST_CASE(test_adjust_tuple),
+	TEST_CASE(test_adjust_tuple_mult_reta),
 	TEST_CASES_END()
 	}
 };
-- 
2.25.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] hash: fix reading unaligned bits implementation
  2023-06-30 17:09 ` [PATCH v2 1/2] hash: fix reading unaligned bits implementation Vladimir Medvedkin
  2023-06-30 17:09   ` [PATCH v2 2/2] test: add additional tests for thash library Vladimir Medvedkin
@ 2023-07-06 14:49   ` Thomas Monjalon
  1 sibling, 0 replies; 7+ messages in thread
From: Thomas Monjalon @ 2023-07-06 14:49 UTC (permalink / raw)
  To: Vladimir Medvedkin
  Cc: dev, konstantin.v.ananyev, stable, david.marchand, john.mcnamara

30/06/2023 19:09, Vladimir Medvedkin:
> Fixes: 28ebff11c2dc ("hash: add predictable RSS")
> Cc: stable@dpdk.org
> 
> Acked-by: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>
> Tested-by: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>
> Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>

I've just merged another patch from you where the explanation is useless.
Here there is no explanation at all.
The tags are in the wrong order, and there is a checkpatch warning.

I apply this series, considering they are not big issues in this case,
but please consider this is the very last time.




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-07-06 14:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-28 19:12 [PATCH] test: add additional tests for thash library Vladimir Medvedkin
2023-06-29 12:59 ` David Marchand
2023-06-29 13:17   ` Medvedkin, Vladimir
2023-06-29 13:47     ` David Marchand
2023-06-30 17:09 ` [PATCH v2 1/2] hash: fix reading unaligned bits implementation Vladimir Medvedkin
2023-06-30 17:09   ` [PATCH v2 2/2] test: add additional tests for thash library Vladimir Medvedkin
2023-07-06 14:49   ` [PATCH v2 1/2] hash: fix reading unaligned bits implementation Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).