DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	Luca Boccassi <bluca@debian.org>,
	stable@dpdk.org, Reshma Pattan <reshma.pattan@intel.com>,
	Bruce Richardson <bruce.richardson@intel.com>
Subject: [PATCH] test/latency: fix intermittent failure on slow platforms
Date: Sun, 31 May 2026 11:01:18 -0700	[thread overview]
Message-ID: <20260531180118.274308-1-stephen@networkplumber.org> (raw)

The forwarding loop was bounded by a fixed interval of 0.5ms
but on slow or emulated platforms with a low-frequency timebase
(e.g. RISC-V rdtime) this fails because the loop only ran once.
The test needs two iterations to get any samples.

Rearrange the forwarding loop so that a minimum number of iterations
are required. The loop still has an upper bound on packets and time
interval which is expanded to 10 ms.

If no samples are collected, mark the test as skipped.
Refactor the forwarding loop test so that cleanup happens on
failure.

Reported-by: Luca Boccassi <bluca@debian.org>
Fixes: b34508b9cbcd ("test/latency: update with more checks")
Cc: stable@dpdk.org

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/test/test_latencystats.c | 75 ++++++++++++++++++++++--------------
 1 file changed, 46 insertions(+), 29 deletions(-)

diff --git a/app/test/test_latencystats.c b/app/test/test_latencystats.c
index e0483e3e4f..76498b66b4 100644
--- a/app/test/test_latencystats.c
+++ b/app/test/test_latencystats.c
@@ -16,6 +16,10 @@
 
 #define NUM_STATS 5
 #define LATENCY_NUM_PACKETS 10
+#define LATENCY_FORWARD_ITERATIONS 10000u
+#define LATENCY_FORWARD_MS 10u
+#define MIN_ITERATIONS	10u
+
 #define QUEUE_ID 0
 
 static uint16_t portid;
@@ -140,28 +144,13 @@ static void test_latency_ring_free(void)
 	test_vdev_uninit("net_ring_net_ringa");
 }
 
-static int test_latency_packet_forward(void)
+static int test_forward_loop(uint16_t portid, struct rte_mbuf *pbuf[LATENCY_NUM_PACKETS])
 {
-	unsigned int i;
-	int ret;
-	struct rte_mbuf *pbuf[LATENCY_NUM_PACKETS] = { };
-	struct rte_mempool *mp;
-	char poolname[] = "mbuf_pool";
+	unsigned int i, iters = 0;
 	uint64_t end_cycles;
 	struct rte_metric_value values[NUM_STATS] = { };
 	struct rte_metric_name names[NUM_STATS] = { };
-
-	ret = test_get_mbuf_from_pool(&mp, pbuf, poolname);
-	if (ret < 0) {
-		printf("allocate mbuf pool Failed\n");
-		return TEST_FAILED;
-	}
-	ret = test_dev_start(portid, mp);
-	if (ret < 0) {
-		printf("test_dev_start(%hu, %p) failed, error code: %d\n",
-			portid, mp, ret);
-		return TEST_FAILED;
-	}
+	int ret;
 
 	ret = rte_latencystats_get_names(names, NUM_STATS);
 	TEST_ASSERT((ret == NUM_STATS), "Test Failed to get metrics names");
@@ -170,37 +159,65 @@ static int test_latency_packet_forward(void)
 	TEST_ASSERT(ret == NUM_STATS, "Test failed to get results before forwarding");
 	TEST_ASSERT(values[4].value == 0, "Samples not zero at start of test");
 
-	/*
-	 * Want test to run long enough to collect sufficient samples
-	 * but not so long that scheduler decides to reschedule it (1000 hz).
-	 */
-	end_cycles = rte_rdtsc() + rte_get_tsc_hz() / 2000;
-	do {
+	/* Want test to run long enough to collect sufficient samples */
+	end_cycles = rte_rdtsc() + rte_get_tsc_hz() / MS_PER_S * LATENCY_FORWARD_MS;
+	for (i = 0; i < LATENCY_FORWARD_ITERATIONS; i++) {
 		ret = test_packet_forward(pbuf, portid, QUEUE_ID);
 		if (ret < 0)
 			printf("send pkts Failed\n");
-	} while (rte_rdtsc() < end_cycles);
+
+		if (++iters >= MIN_ITERATIONS && rte_rdtsc() >= end_cycles)
+			break;
+	}
 
 	ret = rte_latencystats_get(values, NUM_STATS);
 	TEST_ASSERT(ret == NUM_STATS, "Test failed to get results after forwarding");
 
+	if (values[4].value == 0) {
+		printf("No latency samples collected after %u iterations, skipping\n", iters);
+		return TEST_SKIPPED;
+	}
+
 	for (i = 0; i < NUM_STATS; i++) {
 		uint16_t k = values[i].key;
 
-		printf("%s = %"PRIu64"\n",
-		       names[k].name, values[i].value);
+		printf("%s = %"PRIu64"\n", names[k].name, values[i].value);
 	}
-
+	fflush(stdout);
 	TEST_ASSERT(values[4].value > 0, "No samples taken");
 
 	TEST_ASSERT(values[0].value < values[1].value, "Min latency > Avg latency");
 	TEST_ASSERT(values[0].value < values[2].value, "Min latency > Max latency");
 	TEST_ASSERT(values[1].value < values[2].value, "Avg latency > Max latency");
+	return TEST_SUCCESS;
+}
+
+static int test_latency_packet_forward(void)
+{
+	struct rte_mempool *mp = NULL;
+	char poolname[] = "mbuf_pool";
+	struct rte_mbuf *pbuf[LATENCY_NUM_PACKETS] = { };
+	int ret;
+
+	ret = test_get_mbuf_from_pool(&mp, pbuf, poolname);
+	if (ret < 0) {
+		printf("allocate mbuf pool Failed\n");
+		return TEST_FAILED;
+	}
+
+	ret = test_dev_start(portid, mp);
+	if (ret < 0) {
+		printf("test_dev_start(%hu, %p) failed, error code: %d\n",
+			portid, mp, ret);
+		ret = TEST_FAILED;
+	} else {
+		ret = test_forward_loop(portid, pbuf);
+	}
 
 	rte_eth_dev_stop(portid);
 	test_put_mbuf_to_pool(mp, pbuf);
 
-	return (ret >= 0) ? TEST_SUCCESS : TEST_FAILED;
+	return ret;
 }
 
 static struct
-- 
2.53.0


             reply	other threads:[~2026-05-31 18:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-31 18:01 Stephen Hemminger [this message]
2026-06-01 10:23 ` [PATCH] test/latency: fix intermittent failure on slow platforms Luca Boccassi
2026-06-03 15:37   ` Thomas Monjalon

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=20260531180118.274308-1-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=bluca@debian.org \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=reshma.pattan@intel.com \
    --cc=stable@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