[PATCH v2 2/6] test: fix timeout for atomic test on high core count systems

Stephen Hemminger
2026-01-20T01:58:19Z

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.

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

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
app/test/test_atomic.c | 52 ++++++++++++++++++++++++++----------------
1 file changed, 32 insertions(+), 20 deletions(-)

diff --git a/app/test/test_atomic.c b/app/test/test_atomic.c
index b1a0d40ece..ccd8e5d29b 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,9 @@ test_atomic_exchange(__rte_unused void *arg)
static int
test_atomic(void)
{
+ /* Scale iterations by number of cores to keep test duration reasonable */
+ num_iterations = RTE_MAX(N_BASE / rte_lcore_count(), N_MIN);
+
rte_atomic16_init(&a16);
rte_atomic32_init(&a32);
rte_atomic64_init(&a64);
@@ -593,7 +605,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