public inbox for dev@dpdk.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>, stable@dpdk.org
Subject: [PATCH v3 02/14] test: scale atomic test based on core count
Date: Wed, 21 Jan 2026 16:50:18 -0800	[thread overview]
Message-ID: <20260122005356.1168221-3-stephen@networkplumber.org> (raw)
In-Reply-To: <20260122005356.1168221-1-stephen@networkplumber.org>

The atomic test uses tight spinloops to synchronize worker threads
and performs a fixed 1,000,000 iterations per worker. This causes
two problems on high core count systems:

With many cores (e.g., 32), the massive contention on shared
atomic variables causes the test to exceed the 10 second timeout.

Scale iterations inversely with core count to maintain roughly
constant test duration regardless of system size

With 32 cores, iterations drop from 1,000,000 to 31,250 per worker,
which keeps the test well within the timeout while still providing
meaningful coverage.

Add helper function to test.h so that other similar problems
can be addressed in followon patches.

Bugzilla ID: 952
Fixes: af75078fece3 ("first public release")
Cc: stable@dpdk.org

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/test/test.h        | 19 ++++++++++++++++
 app/test/test_atomic.c | 51 +++++++++++++++++++++++++-----------------
 2 files changed, 50 insertions(+), 20 deletions(-)

diff --git a/app/test/test.h b/app/test/test.h
index 10dc45f19d..1f12fc5397 100644
--- a/app/test/test.h
+++ b/app/test/test.h
@@ -12,6 +12,7 @@
 
 #include <rte_hexdump.h>
 #include <rte_common.h>
+#include <rte_lcore.h>
 #include <rte_os_shim.h>
 
 #define TEST_SUCCESS EXIT_SUCCESS
@@ -223,4 +224,22 @@ void add_test_command(struct test_command *t);
  */
 #define REGISTER_ATTIC_TEST REGISTER_TEST_COMMAND
 
+/**
+ * Scale test iterations inversely with core count.
+ *
+ * On high core count systems, tests with per-core work can exceed
+ * timeout limits due to increased lock contention and scheduling
+ * overhead. This helper scales iterations to keep total test time
+ * roughly constant regardless of core count.
+ *
+ * @param base  Base iteration count (used on single-core systems)
+ * @param min   Minimum iterations (floor to ensure meaningful testing)
+ * @return      Scaled iteration count
+ */
+static inline unsigned int
+test_scale_iterations(unsigned int base, unsigned int min)
+{
+	return RTE_MAX(base / rte_lcore_count(), min);
+}
+
 #endif
diff --git a/app/test/test_atomic.c b/app/test/test_atomic.c
index b1a0d40ece..2a4531b833 100644
--- a/app/test/test_atomic.c
+++ b/app/test/test_atomic.c
@@ -10,6 +10,7 @@
 #include <sys/queue.h>
 
 #include <rte_memory.h>
+#include <rte_common.h>
 #include <rte_per_lcore.h>
 #include <rte_launch.h>
 #include <rte_atomic.h>
@@ -101,7 +102,15 @@
 
 #define NUM_ATOMIC_TYPES 3
 
-#define N 1000000
+#define N_BASE 1000000u
+#define N_MIN  10000u
+
+/*
+ * Number of iterations for each test, scaled inversely with core count.
+ * More cores means more contention which increases time per operation.
+ * Calculated once at test start to avoid repeated computation in workers.
+ */
+static unsigned int num_iterations;
 
 static rte_atomic16_t a16;
 static rte_atomic32_t a32;
@@ -112,36 +121,36 @@ static rte_atomic32_t synchro;
 static int
 test_atomic_usual(__rte_unused void *arg)
 {
-	unsigned i;
+	unsigned int i;
 
 	while (rte_atomic32_read(&synchro) == 0)
 		rte_pause();
 
-	for (i = 0; i < N; i++)
+	for (i = 0; i < num_iterations; i++)
 		rte_atomic16_inc(&a16);
-	for (i = 0; i < N; i++)
+	for (i = 0; i < num_iterations; i++)
 		rte_atomic16_dec(&a16);
-	for (i = 0; i < (N / 5); i++)
+	for (i = 0; i < (num_iterations / 5); i++)
 		rte_atomic16_add(&a16, 5);
-	for (i = 0; i < (N / 5); i++)
+	for (i = 0; i < (num_iterations / 5); i++)
 		rte_atomic16_sub(&a16, 5);
 
-	for (i = 0; i < N; i++)
+	for (i = 0; i < num_iterations; i++)
 		rte_atomic32_inc(&a32);
-	for (i = 0; i < N; i++)
+	for (i = 0; i < num_iterations; i++)
 		rte_atomic32_dec(&a32);
-	for (i = 0; i < (N / 5); i++)
+	for (i = 0; i < (num_iterations / 5); i++)
 		rte_atomic32_add(&a32, 5);
-	for (i = 0; i < (N / 5); i++)
+	for (i = 0; i < (num_iterations / 5); i++)
 		rte_atomic32_sub(&a32, 5);
 
-	for (i = 0; i < N; i++)
+	for (i = 0; i < num_iterations; i++)
 		rte_atomic64_inc(&a64);
-	for (i = 0; i < N; i++)
+	for (i = 0; i < num_iterations; i++)
 		rte_atomic64_dec(&a64);
-	for (i = 0; i < (N / 5); i++)
+	for (i = 0; i < (num_iterations / 5); i++)
 		rte_atomic64_add(&a64, 5);
-	for (i = 0; i < (N / 5); i++)
+	for (i = 0; i < (num_iterations / 5); i++)
 		rte_atomic64_sub(&a64, 5);
 
 	return 0;
@@ -169,12 +178,12 @@ test_atomic_addsub_and_return(__rte_unused void *arg)
 	uint32_t tmp16;
 	uint32_t tmp32;
 	uint64_t tmp64;
-	unsigned i;
+	unsigned int i;
 
 	while (rte_atomic32_read(&synchro) == 0)
 		rte_pause();
 
-	for (i = 0; i < N; i++) {
+	for (i = 0; i < num_iterations; i++) {
 		tmp16 = rte_atomic16_add_return(&a16, 1);
 		rte_atomic64_add(&count, tmp16);
 
@@ -274,7 +283,7 @@ test_atomic128_cmp_exchange(__rte_unused void *arg)
 
 	expected = count128;
 
-	for (i = 0; i < N; i++) {
+	for (i = 0; i < num_iterations; i++) {
 		do {
 			rte_int128_t desired;
 
@@ -401,7 +410,7 @@ get_crc8(uint8_t *message, int length)
 static int
 test_atomic_exchange(__rte_unused void *arg)
 {
-	int i;
+	unsigned int i;
 	test16_t nt16, ot16; /* new token, old token */
 	test32_t nt32, ot32;
 	test64_t nt64, ot64;
@@ -417,7 +426,7 @@ test_atomic_exchange(__rte_unused void *arg)
 	 * appropriate crc32 hash for the data) then the test iteration has
 	 * passed.  If the token is invalid, increment the counter.
 	 */
-	for (i = 0; i < N; i++) {
+	for (i = 0; i < num_iterations; i++) {
 
 		/* Test 64bit Atomic Exchange */
 		nt64.u64 = rte_rand();
@@ -446,6 +455,8 @@ test_atomic_exchange(__rte_unused void *arg)
 static int
 test_atomic(void)
 {
+	num_iterations = test_scale_iterations(N_BASE, N_MIN);
+
 	rte_atomic16_init(&a16);
 	rte_atomic32_init(&a32);
 	rte_atomic64_init(&a64);
@@ -593,7 +604,7 @@ test_atomic(void)
 	rte_atomic32_clear(&synchro);
 
 	iterations = count128.val[0] - count128.val[1];
-	if (iterations != (uint64_t)4*N*(rte_lcore_count()-1)) {
+	if (iterations != (uint64_t)4*num_iterations*(rte_lcore_count()-1)) {
 		printf("128-bit compare and swap failed\n");
 		return -1;
 	}
-- 
2.51.0


  parent reply	other threads:[~2026-01-22  0:54 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-18 20:09 [PATCH 0/6] test: fix sporadic failures on high core count systems Stephen Hemminger
2026-01-18 20:09 ` [PATCH 1/6] test: add pause to synchronization spinloops Stephen Hemminger
2026-01-18 20:09 ` [PATCH 2/6] test: fix timeout for atomic test on high core count systems Stephen Hemminger
2026-01-18 20:09 ` [PATCH 3/6] test: fix race condition in ELF load tests Stephen Hemminger
2026-01-19 11:42   ` Marat Khalili
2026-01-20  0:03     ` Stephen Hemminger
2026-01-20 10:30       ` Marat Khalili
2026-01-19 18:24   ` Stephen Hemminger
2026-01-18 20:09 ` [PATCH 4/6] test: fix unsupported BPF instructions in elf load test Stephen Hemminger
2026-01-19 11:43   ` Marat Khalili
2026-01-18 20:09 ` [PATCH 5/6] test: add file-prefix for all fast-tests on Linux Stephen Hemminger
2026-01-19 13:06   ` Marat Khalili
2026-01-19 14:01     ` Bruce Richardson
2026-01-18 20:09 ` [PATCH 6/6] test: fix trace_autotest_with_traces parallel execution Stephen Hemminger
2026-01-19 13:13   ` Marat Khalili
2026-01-20  0:07     ` Stephen Hemminger
2026-01-20 11:36       ` Marat Khalili
2026-01-22  0:50 ` [PATCH v3 00/14] test: fix test failures on high cores Stephen Hemminger
2026-01-22  0:50   ` [PATCH v3 01/14] test: add pause to synchronization spinloops Stephen Hemminger
2026-01-22  0:50   ` Stephen Hemminger [this message]
2026-01-22  0:50   ` [PATCH v3 03/14] test/mcslock: scale test based on number of cores Stephen Hemminger
2026-01-22 10:41     ` Konstantin Ananyev
2026-01-27 20:31       ` Stephen Hemminger
2026-01-22  0:50   ` [PATCH v3 04/14] test/stack: " Stephen Hemminger
2026-01-22  0:50   ` [PATCH v3 05/14] test/timer: " Stephen Hemminger
2026-01-22  0:50   ` [PATCH v3 06/14] test/bpf: fix error handling in ELF load tests Stephen Hemminger
2026-01-22  0:50   ` [PATCH v3 07/14] test/bpf: fix unsupported BPF instructions in ELF load test Stephen Hemminger
2026-01-22 10:33     ` Konstantin Ananyev
2026-01-22  0:50   ` [PATCH v3 08/14] test/bpf: skip ELF test if null PMD disabled Stephen Hemminger
2026-01-23 11:56     ` Marat Khalili
2026-01-22  0:50   ` [PATCH v3 09/14] test: add file-prefix for all fast-tests on Linux Stephen Hemminger
2026-01-22  0:50   ` [PATCH v3 10/14] test: fix trace_autotest_with_traces parallel execution Stephen Hemminger
2026-01-22  0:50   ` [PATCH v3 11/14] test/eventdev: skip test if eventdev driver disabled Stephen Hemminger
2026-01-22 20:40     ` Stephen Hemminger
2026-01-23  9:06       ` Bruce Richardson
2026-01-22  0:50   ` [PATCH v3 12/14] test/pcapng: skip test if null driver missing Stephen Hemminger
2026-01-22  0:50   ` [PATCH v3 13/14] test/vdev: skip test if no null PMD Stephen Hemminger
2026-01-22  0:50   ` [PATCH v3 14/14] test/bpf: pass correct size for Rx/Tx load tests Stephen Hemminger
2026-01-23 11:50     ` Marat Khalili
2026-03-05 16:39   ` [PATCH v3 00/14] test: fix test failures on high cores David Marchand
2026-03-05 17:50 ` [PATCH v4 00/11] test: fix test failures on high core count systems Stephen Hemminger
2026-03-05 17:50   ` [PATCH v4 01/11] test: add pause to synchronization spinloops Stephen Hemminger
2026-03-05 17:50   ` [PATCH v4 02/11] test/atomic: scale test based on core count Stephen Hemminger
2026-03-05 17:50   ` [PATCH v4 03/11] test/mcslock: scale test based on number of cores Stephen Hemminger
2026-03-05 17:50   ` [PATCH v4 04/11] test/stack: " Stephen Hemminger
2026-03-05 17:50   ` [PATCH v4 05/11] test/timer: " Stephen Hemminger
2026-03-05 17:51   ` [PATCH v4 06/11] test/timer: replace volatile with C11 atomics Stephen Hemminger
2026-03-05 17:51   ` [PATCH v4 07/11] test: add file-prefix for all fast-tests on Linux Stephen Hemminger
2026-03-05 17:51   ` [PATCH v4 08/11] test: fix trace_autotest_with_traces parallel execution Stephen Hemminger
2026-03-05 17:51   ` [PATCH v4 09/11] test/bpf: fix error handling in ELF load tests Stephen Hemminger
2026-03-05 17:51   ` [PATCH v4 10/11] test/bpf: fix unsupported BPF instructions in ELF load test Stephen Hemminger
2026-03-05 17:51   ` [PATCH v4 11/11] test/bpf: pass correct size for Rx/Tx load tests Stephen Hemminger
2026-03-17 13:28   ` [PATCH v4 00/11] test: fix test failures on high core count systems 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=20260122005356.1168221-3-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --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