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>
Subject: [PATCH v2 19/33] test/barrier: test sequentially consistent fence only
Date: Sun, 20 Sep 2026 11:10:11 -0700	[thread overview]
Message-ID: <20260920181347.747210-20-stephen@networkplumber.org> (raw)
In-Reply-To: <20260920181347.747210-1-stephen@networkplumber.org>

rte_smp_mb() is removed by this series, leaving the barrier test with
one case instead of two.  Drop the use type enum and the barrier
selector wrapper.

Convert the Peterson lock to explicit atomic accesses with relaxed
ordering, leaving rte_atomic_thread_fence(rte_memory_order_seq_cst)
as the only thing preventing store-load reordering.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/test/test_barrier.c | 105 +++++++++++++---------------------------
 1 file changed, 34 insertions(+), 71 deletions(-)

diff --git a/app/test/test_barrier.c b/app/test/test_barrier.c
index 925a88b68a..cb876d8fda 100644
--- a/app/test/test_barrier.c
+++ b/app/test/test_barrier.c
@@ -2,51 +2,41 @@
  * Copyright(c) 2010-2018 Intel Corporation
  */
 
- /*
-  * This is a simple functional test for rte_smp_mb() implementation.
-  * I.E. make sure that LOAD and STORE operations that precede the
-  * rte_smp_mb() call are globally visible across the lcores
-  * before the LOAD and STORE operations that follows it.
-  * The test uses simple implementation of Peterson's lock algorithm
-  * (https://en.wikipedia.org/wiki/Peterson%27s_algorithm)
-  * for two execution units to make sure that rte_smp_mb() prevents
-  * store-load reordering to happen.
-  * Also when executed on a single lcore could be used as a approximate
-  * estimation of number of cycles particular implementation of rte_smp_mb()
-  * will take.
-  */
+/*
+ * Functional test for rte_atomic_thread_fence(rte_memory_order_seq_cst).
+ * I.E. make sure that LOAD and STORE operations that precede the fence
+ * are globally visible across the lcores before the LOAD and STORE
+ * operations that follow it.
+ * The test uses a simple implementation of Peterson's lock algorithm
+ * (https://en.wikipedia.org/wiki/Peterson%27s_algorithm)
+ * for two execution units, since that algorithm only works if
+ * store-load reordering is prevented.
+ * Also when executed on a single lcore it can be used as an approximate
+ * estimate of the number of cycles a sequentially consistent fence takes.
+ */
 
+#include <errno.h>
 #include <stdio.h>
-#include <string.h>
 #include <stdint.h>
+#include <stdlib.h>
 #include <inttypes.h>
 
-#include <rte_memory.h>
-#include <rte_per_lcore.h>
 #include <rte_launch.h>
 #include <rte_eal.h>
 #include <rte_lcore.h>
 #include <rte_pause.h>
 #include <rte_random.h>
 #include <rte_cycles.h>
-#include <rte_vect.h>
-#include <rte_debug.h>
+#include <rte_stdatomic.h>
 
 #include "test.h"
 
 #define ADD_MAX		8
 #define ITER_MAX	0x1000000
 
-enum plock_use_type {
-	USE_MB,
-	USE_SMP_MB,
-	USE_NUM
-};
-
 struct plock {
-	volatile uint32_t flag[2];
-	volatile uint32_t victim;
-	enum plock_use_type utype;
+	RTE_ATOMIC(uint32_t) flag[2];
+	RTE_ATOMIC(uint32_t) victim;
 };
 
 /*
@@ -69,19 +59,11 @@ struct lcore_plock_test {
 	uint32_t lc;              /* given lcore id */
 };
 
-static inline void
-store_load_barrier(uint32_t utype)
-{
-	if (utype == USE_MB)
-		rte_mb();
-	else if (utype == USE_SMP_MB)
-		rte_smp_mb();
-	else
-		RTE_VERIFY(0);
-}
-
 /*
  * Peterson lock implementation.
+ * The stores below are relaxed on purpose: the sequentially consistent
+ * fence is the only thing keeping them ahead of the loads in the spin
+ * loop, so a broken fence shows up as two lcores in the critical section.
  */
 static void
 plock_lock(struct plock *l, uint32_t self)
@@ -90,29 +72,22 @@ plock_lock(struct plock *l, uint32_t self)
 
 	other = self ^ 1;
 
-	l->flag[self] = 1;
-	rte_smp_wmb();
-	l->victim = self;
+	rte_atomic_store_explicit(&l->flag[self], 1, rte_memory_order_relaxed);
+	rte_atomic_store_explicit(&l->victim, self, rte_memory_order_relaxed);
 
-	store_load_barrier(l->utype);
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
-	while (l->flag[other] == 1 && l->victim == self)
+	while (rte_atomic_load_explicit(&l->flag[other], rte_memory_order_relaxed) == 1 &&
+			rte_atomic_load_explicit(&l->victim, rte_memory_order_relaxed) == self)
 		rte_pause();
-	rte_smp_rmb();
-}
 
-static void
-plock_unlock(struct plock *l, uint32_t self)
-{
-	rte_smp_wmb();
-	l->flag[self] = 0;
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 }
 
 static void
-plock_reset(struct plock *l, enum plock_use_type utype)
+plock_unlock(struct plock *l, uint32_t self)
 {
-	memset(l, 0, sizeof(*l));
-	l->utype = utype;
+	rte_atomic_store_explicit(&l->flag[self], 0, rte_memory_order_release);
 }
 
 /*
@@ -186,7 +161,7 @@ plock_test1_lcore(void *data)
  * and local data are the same.
  */
 static int
-plock_test(uint64_t iter, enum plock_use_type utype)
+plock_test(uint64_t iter)
 {
 	int32_t rc;
 	uint32_t i, lc, n;
@@ -201,8 +176,7 @@ plock_test(uint64_t iter, enum plock_use_type utype)
 	lpt = calloc(n, sizeof(*lpt));
 	sum = calloc(n + 1, sizeof(*sum));
 
-	printf("%s(iter=%" PRIu64 ", utype=%u) started on %u lcores\n",
-		__func__, iter, utype, n);
+	printf("%s(iter=%" PRIu64 ") started on %u lcores\n", __func__, iter, n);
 
 	if (pt == NULL || lpt == NULL || sum == NULL) {
 		printf("%s: failed to allocate memory for %u lcores\n",
@@ -213,9 +187,6 @@ plock_test(uint64_t iter, enum plock_use_type utype)
 		return -ENOMEM;
 	}
 
-	for (i = 0; i != n + 1; i++)
-		plock_reset(&pt[i].lock, utype);
-
 	i = 0;
 	RTE_LCORE_FOREACH(lc) {
 
@@ -263,26 +234,18 @@ plock_test(uint64_t iter, enum plock_use_type utype)
 	free(lpt);
 	free(sum);
 
-	printf("%s(utype=%u) returns %d\n", __func__, utype, rc);
+	printf("%s returns %d\n", __func__, rc);
 	return rc;
 }
 
 static int
 test_barrier(void)
 {
-	int32_t i, ret, rc[USE_NUM];
-
-	for (i = 0; i != RTE_DIM(rc); i++)
-		rc[i] = plock_test(ITER_MAX, i);
+	int rc = plock_test(ITER_MAX);
 
-	ret = 0;
-	for (i = 0; i != RTE_DIM(rc); i++) {
-		printf("%s for utype=%d %s\n",
-			__func__, i, rc[i] == 0 ? "passed" : "failed");
-		ret |= rc[i];
-	}
+	printf("%s %s\n", __func__, rc == 0 ? "passed" : "failed");
 
-	return ret;
+	return rc;
 }
 
 REGISTER_PERF_TEST(barrier_autotest, test_barrier);
-- 
2.53.0


  parent reply	other threads:[~2026-09-20 18:15 UTC|newest]

Thread overview: 98+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29 17:53 [RFC 00/32] remove rte_smp barrier functions Stephen Hemminger
2026-07-29 17:53 ` [RFC 01/32] bpf: replace deprecated SMP barriers with C11 fences Stephen Hemminger
2026-07-30  8:48   ` Marat Khalili
2026-07-30 11:19     ` Marat Khalili
2026-07-30 12:51       ` Konstantin Ananyev
2026-07-30  9:23   ` Konstantin Ananyev
2026-07-29 17:53 ` [RFC 02/32] test: remove test for rte_smp_mb Stephen Hemminger
2026-07-30  7:25   ` Konstantin Ananyev
2026-07-29 17:53 ` [RFC 03/32] bus/vmbus: fix ring buffer ordering on weakly ordered CPUs Stephen Hemminger
2026-08-05  1:22   ` [EXTERNAL] " Long Li
2026-07-29 17:53 ` [RFC 04/32] bus/vmbus: fix missing acquire on receive ring index Stephen Hemminger
2026-08-05  1:23   ` [EXTERNAL] " Long Li
2026-07-29 17:53 ` [RFC 05/32] bus/vmbus: replace SMP barriers with C11 memory fences Stephen Hemminger
2026-08-13 21:41   ` [EXTERNAL] " Long Li
2026-07-29 17:53 ` [RFC 06/32] baseband: convert rte_smp_rmb to fence Stephen Hemminger
2026-07-29 17:54 ` [RFC 07/32] net/hinic: replace rte_smp_rmb Stephen Hemminger
2026-07-29 17:54 ` [RFC 08/32] net/intel: " Stephen Hemminger
2026-08-13 10:17   ` Bruce Richardson
2026-07-29 17:54 ` [RFC 09/32] crypto_caam_jr: " Stephen Hemminger
2026-08-06  6:10   ` Hemant Agrawal
2026-07-29 17:54 ` [RFC 10/32] net/virtio: replcae rte_smp_rmb Stephen Hemminger
2026-07-29 17:54 ` [RFC 11/32] net/thunderx: replace rte_smp_rmb Stephen Hemminger
2026-07-29 17:54 ` [RFC 12/32] stack: always use C11 memory model implementation Stephen Hemminger
2026-07-31 14:53   ` Morten Brørup
2026-08-01 15:25     ` Stephen Hemminger
2026-08-01 17:01     ` Stephen Hemminger
2026-08-02  6:33       ` Morten Brørup
2026-07-29 17:54 ` [RFC 13/32] ring: replace SMP read barrier with C11 acquire fence Stephen Hemminger
2026-07-30  8:16   ` Konstantin Ananyev
2026-07-31 14:47   ` Morten Brørup
2026-07-29 17:54 ` [RFC 14/32] crypto/virtio: update comment reference to rte_smp_rmb Stephen Hemminger
2026-07-29 17:54 ` [RFC 15/32] event/sw: fix unlinks in progress counter races Stephen Hemminger
2026-08-13 10:38   ` Bruce Richardson
2026-07-29 17:54 ` [RFC 16/32] event/sw: replace SMP barriers with C11 atomics Stephen Hemminger
2026-07-29 17:54 ` [RFC 17/32] eal/x86: move optimized fence out of SMP barrier Stephen Hemminger
2026-07-30  7:27   ` Konstantin Ananyev
2026-07-29 17:54 ` [RFC 18/32] common/octeontx: remove redundant barrier in mbox Stephen Hemminger
2026-07-29 17:54 ` [RFC 19/32] crypto/caam_jr: use IO barrier before job ring doorbell Stephen Hemminger
2026-08-06  6:11   ` Hemant Agrawal
2026-07-29 17:54 ` [RFC 20/32] crypto/octeontx: use IO barrier before doorbell Stephen Hemminger
2026-07-29 17:54 ` [RFC 21/32] mempool/octeontx: use IO barrier in pool destroy Stephen Hemminger
2026-07-29 17:54 ` [RFC 22/32] event/octeontx: replace deprecated SMP barriers Stephen Hemminger
2026-07-29 17:54 ` [RFC 23/32] event/dpaa2: replace deprecated barrier in selftest Stephen Hemminger
2026-08-06  6:11   ` Hemant Agrawal
2026-07-29 17:54 ` [RFC 24/32] event/dsw: replace SMP barriers with release fences Stephen Hemminger
2026-07-31  4:37   ` Mattias Rönnblom
2026-07-29 17:54 ` [RFC 25/32] event/opdl: replace SMP barriers with C11 atomics Stephen Hemminger
2026-07-29 17:54 ` [RFC 26/32] net/netvsc: replace SMP barrier in RNDIS response Stephen Hemminger
2026-07-29 17:54 ` [RFC 27/32] net/thunderx: replace deprecated SMP barriers Stephen Hemminger
2026-07-29 17:54 ` [RFC 28/32] net/virtio: replace deprecated barrier in avail index update Stephen Hemminger
2026-07-29 17:54 ` [RFC 29/32] eal: remove stale SMP barrier in rte_service Stephen Hemminger
2026-07-29 17:54 ` [RFC 30/32] eal: remove rte_smp_XX Stephen Hemminger
2026-07-29 17:54 ` [RFC 31/32] checkpatches: no longer warn about rte_smp_XX Stephen Hemminger
2026-07-29 17:54 ` [RFC 32/32] doc: update release notes about rte_smp_XX removal Stephen Hemminger
2026-09-20 18:09 ` [PATCH v2 00/33] remove rte_smp_XX barrier Stephen Hemminger
2026-09-20 18:09   ` [PATCH v2 01/33] bpf: replace deprecated SMP barriers with C11 fences Stephen Hemminger
2026-09-21  8:36     ` Marat Khalili
2026-09-23  9:49     ` Konstantin Ananyev
2026-09-20 18:09   ` [PATCH v2 02/33] bus/vmbus: remove packed attribute from ring buffer Stephen Hemminger
2026-09-21  8:37     ` [EXTERNAL] " Wei Hu
2026-09-20 18:09   ` [PATCH v2 03/33] bus/vmbus: fix ring buffer ordering on weakly ordered CPUs Stephen Hemminger
2026-09-21  8:39     ` [EXTERNAL] " Wei Hu
2026-09-20 18:09   ` [PATCH v2 04/33] bus/vmbus: fix missing acquire on receive ring index Stephen Hemminger
2026-09-21  8:40     ` [EXTERNAL] " Wei Hu
2026-09-20 18:09   ` [PATCH v2 05/33] bus/vmbus: replace SMP barriers with C11 memory fences Stephen Hemminger
2026-09-21  8:40     ` [EXTERNAL] " Wei Hu
2026-09-20 18:09   ` [PATCH v2 06/33] drivers/baseband: convert rte_smp_rmb to fence Stephen Hemminger
2026-09-20 18:09   ` [PATCH v2 07/33] net/hinic: replace rte_smp_rmb Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 08/33] net/intel: " Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 09/33] net/virtio: " Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 10/33] net/thunderx: " Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 11/33] stack: always use C11 memory model implementation Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 12/33] ring: replace SMP read barrier with C11 acquire fence Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 13/33] crypto/virtio: update comment reference to rte_smp_rmb Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 14/33] crypto/caam_jr: replace rte_smp_rmb Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 15/33] crypto/caam_jr: use IO barrier before job ring doorbell Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 16/33] crypto/octeontx: use IO barrier before doorbell Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 17/33] event/sw: fix unlinks in progress counter races Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 18/33] event/sw: replace SMP barriers with C11 atomics Stephen Hemminger
2026-09-20 18:10   ` Stephen Hemminger [this message]
2026-10-04 12:57     ` [PATCH v2 19/33] test/barrier: test sequentially consistent fence only Konstantin Ananyev
2026-10-05 13:45       ` Sun Yuechi
2026-09-20 18:10   ` [PATCH v2 20/33] eal/x86: move optimized fence out of SMP barrier Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 21/33] common/octeontx: remove redundant barrier in mbox Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 22/33] mempool/octeontx: use IO barrier in pool destroy Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 23/33] event/octeontx: replace deprecated SMP barriers Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 24/33] event/dpaa2: replace deprecated barrier in selftest Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 25/33] event/dsw: replace SMP barriers with release fences Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 26/33] event/opdl: replace SMP barriers with C11 atomics Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 27/33] net/netvsc: replace SMP barrier in RNDIS response Stephen Hemminger
2026-09-21  9:00     ` [EXTERNAL] " Wei Hu
2026-09-20 18:10   ` [PATCH v2 28/33] net/thunderx: replace deprecated SMP barriers Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 29/33] net/virtio: replace deprecated barrier in avail index update Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 30/33] eal: remove stale SMP barrier in rte_service Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 31/33] eal: remove rte_smp_XX Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 32/33] checkpatches: no longer warn about rte_smp_XX Stephen Hemminger
2026-09-20 18:10   ` [PATCH v2 33/33] doc: update release notes about rte_smp_XX removal Stephen Hemminger
2026-10-07 15:29   ` [PATCH v2 00/33] remove rte_smp_XX barrier David Marchand

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=20260920181347.747210-20-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@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