Skip to contentSkip to conversation

remove rte_smp barrier functions

RFC Superseded Stephen Hemminger 15 participants 172 messages Jul 29 – Oct 24

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover remove rte_smp barrier functions

This patch series completes the removal of rte_smp_XX barrier functions that was announced over five years ago (20.05).

Most of this is mechanical with AI assistance, so strongly encourage maintainers to take a good look.

Stephen Hemminger (32):
bpf: replace deprecated SMP barriers with C11 fences
test: remove test for rte_smp_mb
bus/vmbus: fix ring buffer ordering on weakly ordered CPUs bus/vmbus: fix missing acquire on receive ring index bus/vmbus: replace SMP barriers with C11 memory fences
baseband: convert rte_smp_rmb to fence
net/hinic: replace rte_smp_rmb
net/intel: replace rte_smp_rmb
crypto_caam_jr: replace rte_smp_rmb
net/virtio: replcae rte_smp_rmb
net/thunderx: replace rte_smp_rmb
stack: always use C11 memory model implementation
ring: replace SMP read barrier with C11 acquire fence crypto/virtio: update comment reference to rte_smp_rmb event/sw: fix unlinks in progress counter races event/sw: replace SMP barriers with C11 atomics eal/x86: move optimized fence out of SMP barrier common/octeontx: remove redundant barrier in mbox crypto/caam_jr: use IO barrier before job ring doorbell crypto/octeontx: use IO barrier before doorbell mempool/octeontx: use IO barrier in pool destroy event/octeontx: replace deprecated SMP barriers event/dpaa2: replace deprecated barrier in selftest event/dsw: replace SMP barriers with release fences event/opdl: replace SMP barriers with C11 atomics net/netvsc: replace SMP barrier in RNDIS response net/thunderx: replace deprecated SMP barriers net/virtio: replace deprecated barrier in avail index update
eal: remove stale SMP barrier in rte_service
eal: remove rte_smp_XX
checkpatches: no longer warn about rte_smp_XX
doc: update release notes about rte_smp_XX removal

 app/test/meson.build                          |   1 -
 app/test/test_barrier.c                       | 288 ------------------
 devtools/checkpatches.sh                      |   8 -
 doc/guides/rel_notes/deprecation.rst          |   7 -
 doc/guides/rel_notes/release_26_11.rst        |   6 +
 .../fpga_5gnr_fec/rte_fpga_5gnr_fec.c         |   8 +-
 drivers/baseband/fpga_lte_fec/fpga_lte_fec.c  |  12 +-
 drivers/bus/vmbus/private.h                   |  12 +-
 drivers/bus/vmbus/vmbus_bufring.c             |  17 +-
 drivers/bus/vmbus/vmbus_channel.c             |  10 +-
 drivers/common/octeontx/octeontx_mbox.c       |   6 +-
 drivers/crypto/caam_jr/caam_jr.c              |   5 +-
 .../crypto/octeontx/otx_cryptodev_hw_access.h |   4 +-
 drivers/crypto/virtio/virtqueue.h             |   2 +-
 drivers/event/dpaa2/dpaa2_eventdev_selftest.c |   4 +-
 drivers/event/dsw/dsw_event.c                 |   8 +-
 drivers/event/octeontx/ssovf_evdev_selftest.c |   6 +-
 drivers/event/octeontx/ssovf_worker.c         |   8 +-
 drivers/event/opdl/opdl_evdev.c               |   7 +-
 drivers/event/sw/sw_evdev.c                   |  37 ++-
 drivers/event/sw/sw_evdev.h                   |   2 +-
 drivers/event/sw/sw_evdev_scheduler.c         |  13 +-
 drivers/mempool/octeontx/octeontx_fpavf.c     |   4 +-
 drivers/net/hinic/base/hinic_pmd_cmdq.c       |   2 +-
 drivers/net/hinic/base/hinic_pmd_mgmt.c       |   2 +-
 drivers/net/intel/ice/ice_rxtx.c              |   2 +-
 drivers/net/intel/ixgbe/ixgbe_rxtx.c          |   2 +-
 drivers/net/netvsc/hn_rndis.c                 |   2 +-
 drivers/net/thunderx/base/nicvf_hw.c          |   3 +-
 drivers/net/thunderx/base/nicvf_plat.h        |   5 +-
 drivers/net/virtio/virtqueue.h                |  18 +-
 lib/bpf/bpf_pkt.c                             |  18 +-
 lib/eal/arm/include/rte_atomic_32.h           |   6 -
 lib/eal/arm/include/rte_atomic_64.h           |   6 -
 lib/eal/common/rte_service.c                  |   1 -
 lib/eal/include/generic/rte_atomic.h          |  61 ----
 lib/eal/loongarch/include/rte_atomic.h        |   6 -
 lib/eal/ppc/include/rte_atomic.h              |   6 -
 lib/eal/riscv/include/rte_atomic.h            |   6 -
 lib/eal/x86/include/rte_atomic.h              |  41 +--
 lib/ring/rte_ring_gcc_pvt.h                   |   6 +-
 lib/stack/meson.build                         |   1 -
 lib/stack/rte_stack_lf.h                      |   4 -
 lib/stack/rte_stack_lf_generic.h              | 153 ----------
 44 files changed, 156 insertions(+), 670 deletions(-)
 delete mode 100644 app/test/test_barrier.c
 delete mode 100644 lib/stack/rte_stack_lf_generic.h
Signature · 1 line
2.53.0
#1 lore raw

RFC 1/32 bpf: replace deprecated SMP barriers with C11 fences

The use counter handshake is a store-load pattern, so rte_smp_mb() becomes a seq_cst thread fence; the read barrier in bpf_eth_cbi_unuse() becomes an acquire fence. Same code generated on x86 and arm64.

Use relaxed loads and stores for the counter itself. With enable_stdatomic, the plain increment of an RTE_ATOMIC() field compiled to a seq_cst add, i.e. two locked operations per burst.

---
 lib/bpf/bpf_pkt.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
lib/bpf/bpf_pkt.c +11 -7
index f072fdaaed..a831b5ad86 100644
@@ -80,9 +80,11 @@ static struct bpf_eth_cbh tx_cbh = {
 static __rte_always_inline void
 bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
 {
-	cbi->use++;
+	rte_atomic_store_explicit(&cbi->use,
+		rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed) + 1,
+		rte_memory_order_relaxed);
 	/* make sure no store/load reordering could happen */
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 }
 
 /*
@@ -92,8 +94,10 @@ static __rte_always_inline void
 bpf_eth_cbi_unuse(struct bpf_eth_cbi *cbi)
 {
 	/* make sure all previous loads are completed */
-	rte_smp_rmb();
-	cbi->use++;
+	rte_atomic_thread_fence(rte_memory_order_acquire);
+	rte_atomic_store_explicit(&cbi->use,
+		rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed) + 1,
+		rte_memory_order_relaxed);
 }
 
 /*
@@ -105,9 +109,9 @@ bpf_eth_cbi_wait(const struct bpf_eth_cbi *cbi)
 	uint32_t puse;
 
 	/* make sure all previous loads and stores are completed */
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
-	puse = cbi->use;
+	puse = rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed);
 
 	/* in use, busy wait till current RX/TX iteration is finished */
 	if ((puse & BPF_ETH_CBI_INUSE) != 0) {
@@ -439,7 +443,7 @@ bpf_eth_cbi_unload(struct bpf_eth_cbi *bc)
 {
 	/* mark this cbi as empty */
 	bc->cb = NULL;
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
 	/* make sure datapath doesn't use bpf anymore, then destroy bpf */
 	bpf_eth_cbi_wait(bc);
Signature · 1 line
2.53.0
#2 lore raw

RE: [RFC 01/32] bpf: replace deprecated SMP barriers with C11 fences

Quoted 6 lines
lib/bpf/bpf_pkt.c +0 -0
index f072fdaaed..a831b5ad86 100644
@@ -80,9 +80,11 @@ static struct bpf_eth_cbh tx_cbh = {
 static __rte_always_inline void

lib/bpf/bpf_pkt.c static struct bpf_eth_cbh tx_cbh = { · line 88

Quoted 10 lines
lib/bpf/bpf_pkt.c +4 -2
 bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
 {
-	cbi->use++;
+	rte_atomic_store_explicit(&cbi->use,
+		rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed) + 1,
+		rte_memory_order_relaxed);
 	/* make sure no store/load reordering could happen */
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 }

I think this needs to be analyzed further by AI to see if a more canonical way of doing things exists now. To me the whole construct above looks very strange.

Quoted 38 lines
lib/bpf/bpf_pkt.c +7 -6
 /*
@@ -92,8 +94,10 @@ static __rte_always_inline void
 bpf_eth_cbi_unuse(struct bpf_eth_cbi *cbi)
 {
 	/* make sure all previous loads are completed */
-	rte_smp_rmb();
-	cbi->use++;
+	rte_atomic_thread_fence(rte_memory_order_acquire);
+	rte_atomic_store_explicit(&cbi->use,
+		rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed) + 1,
+		rte_memory_order_relaxed);
 }
 
 /*
@@ -105,9 +109,9 @@ bpf_eth_cbi_wait(const struct bpf_eth_cbi *cbi)
 	uint32_t puse;
 
 	/* make sure all previous loads and stores are completed */
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
-	puse = cbi->use;
+	puse = rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed);
 
 	/* in use, busy wait till current RX/TX iteration is finished */
 	if ((puse & BPF_ETH_CBI_INUSE) != 0) {
@@ -439,7 +443,7 @@ bpf_eth_cbi_unload(struct bpf_eth_cbi *bc)
 {
 	/* mark this cbi as empty */
 	bc->cb = NULL;
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
 	/* make sure datapath doesn't use bpf anymore, then destroy bpf */
 	bpf_eth_cbi_wait(bc);
--

2.53.0

#3 lore raw

RE: [RFC 01/32] bpf: replace deprecated SMP barriers with C11 fences

Gemini's suggestion FWIW (looks sensible but not tested):

---

This commit replaces the deprecated DPDK SMP memory barriers in the BPF packet processing module with standard C11 atomic operations.

Rather than relying on standalone explicit fences (which can introduce unnecessary overhead and are less idiomatic in C11), this patch embeds the memory ordering directly into the atomic operations:

1. The usage counter (cbi->use) now utilizes rte_atomic_fetch_add_explicit. Entering the callback uses acquire semantics, and exiting uses release semantics, forming a proper lightweight lock without standalone fences.
2. The callback pointer (cbi->cb) is marked as RTE_ATOMIC to prevent data races between the datapath and control path. It is updated
and read using explicit atomic loads/stores with acquire/release semantics.

---
 lib/bpf/bpf_pkt.c | 61 +++++++++++++++++++++++++++--------------------
 1 file changed, 35 insertions(+), 26 deletions(-)
lib/bpf/bpf_pkt.c +37 -25
index f072fdaaed..a831b5ad86 100644
@@ -30,7 +30,7 @@
 struct __rte_cache_aligned bpf_eth_cbi {
 	/* used by both data & control path */
 	RTE_ATOMIC(uint32_t) use;    /*usage counter */
-	const struct rte_eth_rxtx_callback *cb;  /* callback handle */
+	RTE_ATOMIC(const struct rte_eth_rxtx_callback *) cb;  /* callback handle */
 	struct rte_bpf *bpf;
 	struct rte_bpf_jit jit;
 	/* used by control path only */
@@ -80,9 +80,7 @@ static struct bpf_eth_cbh tx_cbh = {
 static __rte_always_inline void
 bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
 {
-	cbi->use++;
-	/* make sure no store/load reordering could happen */
-	rte_smp_mb();
+	rte_atomic_fetch_add_explicit(&cbi->use, 1, rte_memory_order_acquire);
 }
 
 /*
@@ -91,9 +89,7 @@ bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
 static __rte_always_inline void
 bpf_eth_cbi_unuse(struct bpf_eth_cbi *cbi)
 {
-	/* make sure all previous loads are completed */
-	rte_smp_rmb();
-	cbi->use++;
+	rte_atomic_fetch_add_explicit(&cbi->use, 1, rte_memory_order_release);
 }
 
 /*
@@ -104,15 +100,12 @@ bpf_eth_cbi_wait(const struct bpf_eth_cbi *cbi)
 {
 	uint32_t puse;
 
-	/* make sure all previous loads and stores are completed */
-	rte_smp_mb();
-
-	puse = cbi->use;
+	puse = rte_atomic_load_explicit(&cbi->use, rte_memory_order_acquire);
 
 	/* in use, busy wait till current RX/TX iteration is finished */
 	if ((puse & BPF_ETH_CBI_INUSE) != 0) {
 		RTE_WAIT_UNTIL_MASKED((__rte_atomic uint32_t *)(uintptr_t)&cbi->use,
-			UINT32_MAX, !=, puse, rte_memory_order_relaxed);
+			UINT32_MAX, !=, puse, rte_memory_order_acquire);
 	}
 }
 
@@ -201,11 +194,13 @@ bpf_rx_callback_vm(__rte_unused uint16_t port, __rte_unused uint16_t queue,
 {
 	struct bpf_eth_cbi *cbi;
 	uint16_t rc;
+	const struct rte_eth_rxtx_callback *cb;
 
 	cbi = user_param;
 
 	bpf_eth_cbi_inuse(cbi);
-	rc = (cbi->cb != NULL) ?
+	cb = rte_atomic_load_explicit(&cbi->cb, rte_memory_order_acquire);
+	rc = (cb != NULL) ?
 		pkt_filter_vm(cbi->bpf, pkt, nb_pkts, 1) :
 		nb_pkts;
 	bpf_eth_cbi_unuse(cbi);
@@ -219,10 +214,12 @@ bpf_rx_callback_jit(__rte_unused uint16_t port, __rte_unused uint16_t queue,
 {
 	struct bpf_eth_cbi *cbi;
 	uint16_t rc;
+	const struct rte_eth_rxtx_callback *cb;
 
 	cbi = user_param;
 	bpf_eth_cbi_inuse(cbi);
-	rc = (cbi->cb != NULL) ?
+	cb = rte_atomic_load_explicit(&cbi->cb, rte_memory_order_acquire);
+	rc = (cb != NULL) ?
 		pkt_filter_jit(&cbi->jit, pkt, nb_pkts, 1) :
 		nb_pkts;
 	bpf_eth_cbi_unuse(cbi);
@@ -236,10 +233,12 @@ bpf_tx_callback_vm(__rte_unused uint16_t port, __rte_unused uint16_t queue,
 {
 	struct bpf_eth_cbi *cbi;
 	uint16_t rc;
+	const struct rte_eth_rxtx_callback *cb;
 
 	cbi = user_param;
 	bpf_eth_cbi_inuse(cbi);
-	rc = (cbi->cb != NULL) ?
+	cb = rte_atomic_load_explicit(&cbi->cb, rte_memory_order_acquire);
+	rc = (cb != NULL) ?
 		pkt_filter_vm(cbi->bpf, pkt, nb_pkts, 0) :
 		nb_pkts;
 	bpf_eth_cbi_unuse(cbi);
@@ -253,10 +252,12 @@ bpf_tx_callback_jit(__rte_unused uint16_t port, __rte_unused uint16_t queue,
 {
 	struct bpf_eth_cbi *cbi;
 	uint16_t rc;
+	const struct rte_eth_rxtx_callback *cb;
 
 	cbi = user_param;
 	bpf_eth_cbi_inuse(cbi);
-	rc = (cbi->cb != NULL) ?
+	cb = rte_atomic_load_explicit(&cbi->cb, rte_memory_order_acquire);
+	rc = (cb != NULL) ?
 		pkt_filter_jit(&cbi->jit, pkt, nb_pkts, 0) :
 		nb_pkts;
 	bpf_eth_cbi_unuse(cbi);
@@ -274,10 +275,12 @@ bpf_rx_callback_mb_vm(__rte_unused uint16_t port, __rte_unused uint16_t queue,
 {
 	struct bpf_eth_cbi *cbi;
 	uint16_t rc;
+	const struct rte_eth_rxtx_callback *cb;
 
 	cbi = user_param;
 	bpf_eth_cbi_inuse(cbi);
-	rc = (cbi->cb != NULL) ?
+	cb = rte_atomic_load_explicit(&cbi->cb, rte_memory_order_acquire);
+	rc = (cb != NULL) ?
 		pkt_filter_mb_vm(cbi->bpf, pkt, nb_pkts, 1) :
 		nb_pkts;
 	bpf_eth_cbi_unuse(cbi);
@@ -292,10 +295,12 @@ bpf_rx_callback_mb_jit(__rte_unused uint16_t port, __rte_unused uint16_t queue,
 {
 	struct bpf_eth_cbi *cbi;
 	uint16_t rc;
+	const struct rte_eth_rxtx_callback *cb;
 
 	cbi = user_param;
 	bpf_eth_cbi_inuse(cbi);
-	rc = (cbi->cb != NULL) ?
+	cb = rte_atomic_load_explicit(&cbi->cb, rte_memory_order_acquire);
+	rc = (cb != NULL) ?
 		pkt_filter_mb_jit(&cbi->jit, pkt, nb_pkts, 1) :
 		nb_pkts;
 	bpf_eth_cbi_unuse(cbi);
@@ -309,10 +314,12 @@ bpf_tx_callback_mb_vm(__rte_unused uint16_t port, __rte_unused uint16_t queue,
 {
 	struct bpf_eth_cbi *cbi;
 	uint16_t rc;
+	const struct rte_eth_rxtx_callback *cb;
 
 	cbi = user_param;
 	bpf_eth_cbi_inuse(cbi);
-	rc = (cbi->cb != NULL) ?
+	cb = rte_atomic_load_explicit(&cbi->cb, rte_memory_order_acquire);
+	rc = (cb != NULL) ?
 		pkt_filter_mb_vm(cbi->bpf, pkt, nb_pkts, 0) :
 		nb_pkts;
 	bpf_eth_cbi_unuse(cbi);
@@ -326,10 +333,12 @@ bpf_tx_callback_mb_jit(__rte_unused uint16_t port, __rte_unused uint16_t queue,
 {
 	struct bpf_eth_cbi *cbi;
 	uint16_t rc;
+	const struct rte_eth_rxtx_callback *cb;
 
 	cbi = user_param;
 	bpf_eth_cbi_inuse(cbi);
-	rc = (cbi->cb != NULL) ?
+	cb = rte_atomic_load_explicit(&cbi->cb, rte_memory_order_acquire);
+	rc = (cb != NULL) ?
 		pkt_filter_mb_jit(&cbi->jit, pkt, nb_pkts, 0) :
 		nb_pkts;
 	bpf_eth_cbi_unuse(cbi);
@@ -382,8 +391,7 @@ static void
 bpf_eth_cbi_unload(struct bpf_eth_cbi *bc)
 {
 	/* mark this cbi as empty */
-	bc->cb = NULL;
-	rte_smp_mb();
+	rte_atomic_store_explicit(&bc->cb, NULL, rte_memory_order_release);
 
 	/* make sure datapath doesn't use bpf anymore, then destroy bpf */
 	bpf_eth_cbi_wait(bc);
@@ -395,14 +403,17 @@ static void
 bpf_eth_unload(struct bpf_eth_cbh *cbh, uint16_t port, uint16_t queue)
 {
 	struct bpf_eth_cbi *bc;
+	const struct rte_eth_rxtx_callback *cb;
 
 	bc = bpf_eth_cbh_find(cbh, port, queue);
-	if (bc == NULL || bc->cb == NULL)
+	if (bc == NULL)
+		return;
+	cb = rte_atomic_load_explicit(&bc->cb, rte_memory_order_acquire);
+	if (cb == NULL)
 		return;
 
 	if (cbh->type == BPF_ETH_RX)
-		rte_eth_remove_rx_callback(port, queue, bc->cb);
+		rte_eth_remove_rx_callback(port, queue, cb);
 	else
-		rte_eth_remove_tx_callback(port, queue, bc->cb);
+		rte_eth_remove_tx_callback(port, queue, cb);
 

bpf_eth_cbi_unload(bc);
}
@@ -439,6 +450,7 @@ bpf_eth_elf_install(struct bpf_eth_cbh *cbh, uint16_t port, uint16_t queue,
rte_rx_callback_fn frx;
rte_tx_callback_fn ftx;
struct rte_bpf_jit jit;
+ const struct rte_eth_rxtx_callback *cb;

frx = NULL;
ftx = NULL;
@@ -470,17 +482,18 @@ bpf_eth_elf_install(struct bpf_eth_cbh *cbh, uint16_t port, uint16_t queue,
return -ENOMEM;

/* remove old one, if any */
- if (bc->cb != NULL)
+ if (rte_atomic_load_explicit(&bc->cb, rte_memory_order_acquire) != NULL)
bpf_eth_unload(cbh, port, queue);

bc->bpf = bpf;
bc->jit = jit;

if (cbh->type == BPF_ETH_RX)
- bc->cb = rte_eth_add_rx_callback(port, queue, frx, bc);
+ cb = rte_eth_add_rx_callback(port, queue, frx, bc);
else
- bc->cb = rte_eth_add_tx_callback(port, queue, ftx, bc);
+ cb = rte_eth_add_tx_callback(port, queue, ftx, bc);

- if (bc->cb == NULL) {
+ rte_atomic_store_explicit(&bc->cb, cb, rte_memory_order_release);
+ if (cb == NULL) {
rc = -rte_errno;
bpf_eth_cbi_cleanup(bc);

#4 lore raw

RE: [RFC 01/32] bpf: replace deprecated SMP barriers with C11 fences

Quoted 6 lines

This commit replaces the deprecated DPDK SMP memory barriers in the BPF packet processing module with standard C11 atomic operations.

Quoted 8 lines

Rather than relying on standalone explicit fences (which can introduce unnecessary overhead and are less idiomatic in C11), this patch embeds the memory ordering directly into the atomic operations:

1. The usage counter (cbi->use) now utilizes rte_atomic_fetch_add_explicit. Entering the callback uses acquire semantics, and exiting uses release semantics, forming a proper lightweight lock without standalone
fences.

While atomic_add() is possible here, it is really unnecessary, as whole DPDK ethdev RX/TX path assumes that only one thread at a time can do RX/TX on given HW queue.
So only one data-path can update cbi->use.
Memory fence (or it's analog) is necessary here to make sure that it would happen before any reads to other fields would happen.
I.E. we don't need a proper lock semantics here, we just need to make sure that STORE/LOAD re-ordering will not happen.

Quoted 3 lines

2. The callback pointer (cbi->cb) is marked as RTE_ATOMIC to prevent data races between the datapath and control path. It is updated and read using explicit atomic loads/stores with acquire/release semantics.

That is totally unnecessary and even contradicts with #1 above:
- we don't need a full lock protection here for cbi
- in case we really do, then atomic load wouldn't help us here as for such case we would need a proper mutex-like lock to protect all fields in struct bpf_eth_cbi. But as I said, we don't.

So in summary I am against those changes.

Just a bit of history here: what is implemented here is sort-of hand-written analog of RCU QSBR mechanism. It was done before RCU lib was introduced into the project.
Probably the right ways here would be to make ethdev RX/TX callback API thread-safe via using our own lib/rcu. Then all this code around cbi->use can be simply removed. But that's probably a subject for separate patch series.

Quoted 248 lines
---
 lib/bpf/bpf_pkt.c | 61 +++++++++++++++++++++++++++--------------------
 1 file changed, 35 insertions(+), 26 deletions(-)
lib/bpf/bpf_pkt.c +1 -1
index f072fdaaed..a831b5ad86 100644
@@ -30,7 +30,7 @@
 struct __rte_cache_aligned bpf_eth_cbi {
 	/* used by both data & control path */
 	RTE_ATOMIC(uint32_t) use;    /*usage counter */
-	const struct rte_eth_rxtx_callback *cb;  /* callback handle */
+	RTE_ATOMIC(const struct rte_eth_rxtx_callback *) cb;  /* callback handle
 */
 	struct rte_bpf *bpf;
 	struct rte_bpf_jit jit;
lib/bpf/bpf_pkt.c +1 -3
 	/* used by control path only */
@@ -80,9 +80,7 @@ static struct bpf_eth_cbh tx_cbh = {
 static __rte_always_inline void
 bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
 {
-	cbi->use++;
-	/* make sure no store/load reordering could happen */
-	rte_smp_mb();
+	rte_atomic_fetch_add_explicit(&cbi->use, 1,
 rte_memory_order_acquire);
 }
 

/*

lib/bpf/bpf_pkt.c +6 -9
@@ -91,9 +89,7 @@ bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
 static __rte_always_inline void
 bpf_eth_cbi_unuse(struct bpf_eth_cbi *cbi)
 {
-	/* make sure all previous loads are completed */
-	rte_smp_rmb();
-	cbi->use++;
+	rte_atomic_fetch_add_explicit(&cbi->use, 1, rte_memory_order_release);
 }
 
 /*
@@ -104,15 +100,12 @@ bpf_eth_cbi_wait(const struct bpf_eth_cbi *cbi)
 {
 	uint32_t puse;
 
-	/* make sure all previous loads and stores are completed */
-	rte_smp_mb();
-
-	puse = cbi->use;
+	puse = rte_atomic_load_explicit(&cbi->use, rte_memory_order_acquire);
 
 	/* in use, busy wait till current RX/TX iteration is finished */
 	if ((puse & BPF_ETH_CBI_INUSE) != 0) {
 		RTE_WAIT_UNTIL_MASKED((__rte_atomic uint32_t
 *)(uintptr_t)&cbi->use,
-			UINT32_MAX, !=, puse, rte_memory_order_relaxed);
+			UINT32_MAX, !=, puse, rte_memory_order_acquire);
 	}
 }
@@ -201,11 +194,13 @@ bpf_rx_callback_vm(__rte_unused uint16_t port,
 __rte_unused uint16_t queue,
 {
 	struct bpf_eth_cbi *cbi;
 	uint16_t rc;
+	const struct rte_eth_rxtx_callback *cb;
 
 	cbi = user_param;
 
 	bpf_eth_cbi_inuse(cbi);
-	rc = (cbi->cb != NULL) ?
+	cb = rte_atomic_load_explicit(&cbi->cb, rte_memory_order_acquire);
+	rc = (cb != NULL) ?
 		pkt_filter_vm(cbi->bpf, pkt, nb_pkts, 1) :
 		nb_pkts;
lib/bpf/bpf_pkt.c +3 -1
 	bpf_eth_cbi_unuse(cbi);
@@ -219,10 +214,12 @@ bpf_rx_callback_jit(__rte_unused uint16_t port,
 __rte_unused uint16_t queue,
 {
 	struct bpf_eth_cbi *cbi;
 	uint16_t rc;
+	const struct rte_eth_rxtx_callback *cb;
 
 	cbi = user_param;
 	bpf_eth_cbi_inuse(cbi);
-	rc = (cbi->cb != NULL) ?
+	cb = rte_atomic_load_explicit(&cbi->cb, rte_memory_order_acquire);
+	rc = (cb != NULL) ?
 		pkt_filter_jit(&cbi->jit, pkt, nb_pkts, 1) :
 		nb_pkts;
lib/bpf/bpf_pkt.c +3 -1
 	bpf_eth_cbi_unuse(cbi);
@@ -236,10 +233,12 @@ bpf_tx_callback_vm(__rte_unused uint16_t port,
 __rte_unused uint16_t queue,
 {
 	struct bpf_eth_cbi *cbi;
 	uint16_t rc;
+	const struct rte_eth_rxtx_callback *cb;
 
 	cbi = user_param;
 	bpf_eth_cbi_inuse(cbi);
-	rc = (cbi->cb != NULL) ?
+	cb = rte_atomic_load_explicit(&cbi->cb, rte_memory_order_acquire);
+	rc = (cb != NULL) ?
 		pkt_filter_vm(cbi->bpf, pkt, nb_pkts, 0) :
 		nb_pkts;
lib/bpf/bpf_pkt.c +3 -1
 	bpf_eth_cbi_unuse(cbi);
@@ -253,10 +252,12 @@ bpf_tx_callback_jit(__rte_unused uint16_t port,
 __rte_unused uint16_t queue,
 {
 	struct bpf_eth_cbi *cbi;
 	uint16_t rc;
+	const struct rte_eth_rxtx_callback *cb;
 
 	cbi = user_param;
 	bpf_eth_cbi_inuse(cbi);
-	rc = (cbi->cb != NULL) ?
+	cb = rte_atomic_load_explicit(&cbi->cb, rte_memory_order_acquire);
+	rc = (cb != NULL) ?
 		pkt_filter_jit(&cbi->jit, pkt, nb_pkts, 0) :
 		nb_pkts;
lib/bpf/bpf_pkt.c +3 -1
 	bpf_eth_cbi_unuse(cbi);
@@ -274,10 +275,12 @@ bpf_rx_callback_mb_vm(__rte_unused uint16_t port,
 __rte_unused uint16_t queue,
 {
 	struct bpf_eth_cbi *cbi;
 	uint16_t rc;
+	const struct rte_eth_rxtx_callback *cb;
 
 	cbi = user_param;
 	bpf_eth_cbi_inuse(cbi);
-	rc = (cbi->cb != NULL) ?
+	cb = rte_atomic_load_explicit(&cbi->cb, rte_memory_order_acquire);
+	rc = (cb != NULL) ?
 		pkt_filter_mb_vm(cbi->bpf, pkt, nb_pkts, 1) :
 		nb_pkts;
lib/bpf/bpf_pkt.c +3 -1
 	bpf_eth_cbi_unuse(cbi);
@@ -292,10 +295,12 @@ bpf_rx_callback_mb_jit(__rte_unused uint16_t port,
 __rte_unused uint16_t queue,
 {
 	struct bpf_eth_cbi *cbi;
 	uint16_t rc;
+	const struct rte_eth_rxtx_callback *cb;
 
 	cbi = user_param;
 	bpf_eth_cbi_inuse(cbi);
-	rc = (cbi->cb != NULL) ?
+	cb = rte_atomic_load_explicit(&cbi->cb, rte_memory_order_acquire);
+	rc = (cb != NULL) ?
 		pkt_filter_mb_jit(&cbi->jit, pkt, nb_pkts, 1) :
 		nb_pkts;
lib/bpf/bpf_pkt.c +3 -1
 	bpf_eth_cbi_unuse(cbi);
@@ -309,10 +314,12 @@ bpf_tx_callback_mb_vm(__rte_unused uint16_t port,
 __rte_unused uint16_t queue,
 {
 	struct bpf_eth_cbi *cbi;
 	uint16_t rc;
+	const struct rte_eth_rxtx_callback *cb;
 
 	cbi = user_param;
 	bpf_eth_cbi_inuse(cbi);
-	rc = (cbi->cb != NULL) ?
+	cb = rte_atomic_load_explicit(&cbi->cb, rte_memory_order_acquire);
+	rc = (cb != NULL) ?
 		pkt_filter_mb_vm(cbi->bpf, pkt, nb_pkts, 0) :
 		nb_pkts;
lib/bpf/bpf_pkt.c +3 -1
 	bpf_eth_cbi_unuse(cbi);
@@ -326,10 +333,12 @@ bpf_tx_callback_mb_jit(__rte_unused uint16_t port,
 __rte_unused uint16_t queue,
 {
 	struct bpf_eth_cbi *cbi;
 	uint16_t rc;
+	const struct rte_eth_rxtx_callback *cb;
 
 	cbi = user_param;
 	bpf_eth_cbi_inuse(cbi);
-	rc = (cbi->cb != NULL) ?
+	cb = rte_atomic_load_explicit(&cbi->cb, rte_memory_order_acquire);
+	rc = (cb != NULL) ?
 		pkt_filter_mb_jit(&cbi->jit, pkt, nb_pkts, 0) :
 		nb_pkts;
lib/bpf/bpf_pkt.c +9 -5
 	bpf_eth_cbi_unuse(cbi);
@@ -382,8 +391,7 @@ static void
 bpf_eth_cbi_unload(struct bpf_eth_cbi *bc)
 {
 	/* mark this cbi as empty */
-	bc->cb = NULL;
-	rte_smp_mb();
+	rte_atomic_store_explicit(&bc->cb, NULL, rte_memory_order_release);
 
 	/* make sure datapath doesn't use bpf anymore, then destroy bpf */
 	bpf_eth_cbi_wait(bc);
@@ -395,14 +403,17 @@ static void
 bpf_eth_unload(struct bpf_eth_cbh *cbh, uint16_t port, uint16_t queue)
 {
 	struct bpf_eth_cbi *bc;
+	const struct rte_eth_rxtx_callback *cb;
 
 	bc = bpf_eth_cbh_find(cbh, port, queue);
-	if (bc == NULL || bc->cb == NULL)
+	if (bc == NULL)
+		return;
+	cb = rte_atomic_load_explicit(&bc->cb, rte_memory_order_acquire);
+	if (cb == NULL)
 		return;
 
 	if (cbh->type == BPF_ETH_RX)
-		rte_eth_remove_rx_callback(port, queue, bc->cb);
+		rte_eth_remove_rx_callback(port, queue, cb);
 	else
-		rte_eth_remove_tx_callback(port, queue, bc->cb);
+		rte_eth_remove_tx_callback(port, queue, cb);
 
 	bpf_eth_cbi_unload(bc);
 }
@@ -439,6 +450,7 @@ bpf_eth_elf_install(struct bpf_eth_cbh *cbh, uint16_t
 port, uint16_t queue,
 	rte_rx_callback_fn frx;
 	rte_tx_callback_fn ftx;
 	struct rte_bpf_jit jit;
+	const struct rte_eth_rxtx_callback *cb;
 
 	frx = NULL;
lib/bpf/bpf_pkt.c +5 -4
 	ftx = NULL;
@@ -470,17 +482,18 @@ bpf_eth_elf_install(struct bpf_eth_cbh *cbh, uint16_t
 port, uint16_t queue,
 		return -ENOMEM;
 
 	/* remove old one, if any */
-	if (bc->cb != NULL)
+	if (rte_atomic_load_explicit(&bc->cb, rte_memory_order_acquire) !=
 NULL)
 		bpf_eth_unload(cbh, port, queue);
 
 	bc->bpf = bpf;
 	bc->jit = jit;
 
 	if (cbh->type == BPF_ETH_RX)
-		bc->cb = rte_eth_add_rx_callback(port, queue, frx, bc);
+		cb = rte_eth_add_rx_callback(port, queue, frx, bc);
 	else
-		bc->cb = rte_eth_add_tx_callback(port, queue, ftx, bc);
+		cb = rte_eth_add_tx_callback(port, queue, ftx, bc);
 
-	if (bc->cb == NULL) {
+	rte_atomic_store_explicit(&bc->cb, cb, rte_memory_order_release);
+	if (cb == NULL) {
lib/bpf/bpf_pkt.c +0 -0
 		rc = -rte_errno;
 		bpf_eth_cbi_cleanup(bc);
#5 lore raw

RE: [RFC 01/32] bpf: replace deprecated SMP barriers with C11 fences

In reply to Stephen Hemminger
Quoted 35 lines

The use counter handshake is a store-load pattern, so rte_smp_mb() becomes a seq_cst thread fence; the read barrier in bpf_eth_cbi_unuse() becomes an acquire fence. Same code generated on x86 and arm64.

Use relaxed loads and stores for the counter itself. With enable_stdatomic, the plain increment of an RTE_ATOMIC() field compiled to a seq_cst add, i.e. two locked operations per burst.

---
 lib/bpf/bpf_pkt.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
lib/bpf/bpf_pkt.c +5 -2
index f072fdaaed..a831b5ad86 100644
@@ -80,9 +80,11 @@ static struct bpf_eth_cbh tx_cbh = {
 static __rte_always_inline void
 bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
 {
-	cbi->use++;
+	rte_atomic_store_explicit(&cbi->use,
+		rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed)
+ 1,
+		rte_memory_order_relaxed);
 	/* make sure no store/load reordering could happen */
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 }
 
 /*

lib/bpf/bpf_pkt.c static __rte_always_inline void · line 97

Quoted 6 lines
lib/bpf/bpf_pkt.c +1 -2
@@ -92,8 +94,10 @@ static __rte_always_inline void
 bpf_eth_cbi_unuse(struct bpf_eth_cbi *cbi)
 {
 	/* make sure all previous loads are completed */
-	rte_smp_rmb();
-	cbi->use++;
+	rte_atomic_thread_fence(rte_memory_order_acquire);

Probably safer to use 'acq_release' order here?
We do want that all previous loads to be completed at that point.

Quoted 30 lines
lib/bpf/bpf_pkt.c +7 -4
+	rte_atomic_store_explicit(&cbi->use,
+		rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed)
+ 1,
+		rte_memory_order_relaxed);
 }
 
 /*
@@ -105,9 +109,9 @@ bpf_eth_cbi_wait(const struct bpf_eth_cbi *cbi)
 	uint32_t puse;
 
 	/* make sure all previous loads and stores are completed */
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
-	puse = cbi->use;
+	puse = rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed);
 
 	/* in use, busy wait till current RX/TX iteration is finished */
 	if ((puse & BPF_ETH_CBI_INUSE) != 0) {
@@ -439,7 +443,7 @@ bpf_eth_cbi_unload(struct bpf_eth_cbi *bc)
 {
 	/* mark this cbi as empty */
 	bc->cb = NULL;
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
 	/* make sure datapath doesn't use bpf anymore, then destroy bpf */
 	bpf_eth_cbi_wait(bc);
--

2.53.0

#6 lore raw

RFC 2/32 test: remove test for rte_smp_mb

In reply to Stephen Hemminger

The DPDK version of SMP barriers is deprecated and being removed. Drop the test as no longer relevant.

---
 app/test/meson.build    |   1 -
 app/test/test_barrier.c | 288 ----------------------------------------
 2 files changed, 289 deletions(-)
 delete mode 100644 app/test/test_barrier.c
app/test/meson.build +0 -1
index 51abeeb732..6df9dfa222 100644
@@ -28,7 +28,6 @@ source_file_deps = {
     'test_alarm.c': [],
     'test_argparse.c': ['argparse'],
     'test_atomic.c': ['hash'],
-    'test_barrier.c': [],
     'test_bitcount.c': [],
     'test_bitmap.c': [],
     'test_bitops.c': [],
app/test/test_barrier.c deleted +0 -288

288 lines not on this page · raw message

Signature · 1 line
2.53.0
#7 lore raw

RE: [RFC 02/32] test: remove test for rte_smp_mb

Quoted 4 lines

The DPDK version of SMP barriers is deprecated and being removed. Drop the test as no longer relevant.

Why to remove the whole test?
I believe it is still useful for testing our custom x86 implementation of rte_atomic_thread_fence(rte_memory_order_seq_cst).
See patch 17 in this series:
[RFC 17/32] eal/x86: move optimized fence out of SMP barrier Instead of removing it we can replace rte_smp_mb() with rte_atomic_thread_fence(rte_memory_order_seq_cst)
In one function below, i.e.:

static inline void
store_load_barrier(uint32_t utype)

{
	if (utype == USE_MB)
		rte_mb();
	else if (utype == USE_SMP_MB)
 -		rte_smp_mb();
+		rte_atomic_thread_fence(rte_memory_order_seq_cst);
	else
		RTE_VERIFY(0);
}
Quoted 316 lines
---
 app/test/meson.build    |   1 -
 app/test/test_barrier.c | 288 ----------------------------------------
 2 files changed, 289 deletions(-)
 delete mode 100644 app/test/test_barrier.c
app/test/meson.build +0 -1
index 51abeeb732..6df9dfa222 100644
@@ -28,7 +28,6 @@ source_file_deps = {
     'test_alarm.c': [],
     'test_argparse.c': ['argparse'],
     'test_atomic.c': ['hash'],
-    'test_barrier.c': [],
     'test_bitcount.c': [],
     'test_bitmap.c': [],
     'test_bitops.c': [],
app/test/test_barrier.c deleted +0 -252
deleted file mode 100644
index 925a88b68a..0000000000
@@ -1,288 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * 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.
-  */
-
-#include <stdio.h>
-#include <string.h>
-#include <stdint.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 "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;
-};
-
-/*
- * Lock plus protected by it two counters.
- */
-struct plock_test {
-	struct plock lock;
-	uint64_t val;
-	uint64_t iter;
-};
-
-/*
- * Each active lcore shares plock_test struct with it's left and right
- * neighbours.
- */
-struct lcore_plock_test {
-	struct plock_test *pt[2]; /* shared, lock-protected data */
-	uint64_t sum[2];          /* local copy of the shared data */
-	uint64_t iter;            /* number of iterations to perform */
-	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.
- */
-static void
-plock_lock(struct plock *l, uint32_t self)
-{
-	uint32_t other;
-
-	other = self ^ 1;
-
-	l->flag[self] = 1;
-	rte_smp_wmb();
-	l->victim = self;
-
-	store_load_barrier(l->utype);
-
-	while (l->flag[other] == 1 && l->victim == self)
-		rte_pause();
-	rte_smp_rmb();
-}
-
-static void
-plock_unlock(struct plock *l, uint32_t self)
-{
-	rte_smp_wmb();
-	l->flag[self] = 0;
-}
-
-static void
-plock_reset(struct plock *l, enum plock_use_type utype)
-{
-	memset(l, 0, sizeof(*l));
-	l->utype = utype;
-}
-
-/*
- * grab the lock, update both counters, release the lock.
- */
-static void
-plock_add(struct plock_test *pt, uint32_t self, uint32_t n)
-{
-	plock_lock(&pt->lock, self);
-	pt->iter++;
-	pt->val += n;
-	plock_unlock(&pt->lock, self);
-}
-
-static int
-plock_test1_lcore(void *data)
-{
-	uint64_t tm;
-	uint32_t lc, ln;
-	uint64_t i, n;
-	struct lcore_plock_test *lpt;
-
-	lpt = data;
-	lc = rte_lcore_id();
-
-	/* find lcore_plock_test struct for given lcore */
-	for (ln = rte_lcore_count(); ln != 0 && lpt->lc != lc; lpt++, ln--)
-		;
-
-	if (ln == 0) {
-		printf("%s(%u) error at init\n", __func__, lc);
-		return -1;
-	}
-
-	n = rte_rand() % ADD_MAX;
-	tm = rte_get_timer_cycles();
-
-	/*
-	 * for each iteration:
-	 * - update shared, locked protected data in a safe manner
-	 * - update local copy of the shared data
-	 */
-	for (i = 0; i != lpt->iter; i++) {
-
-		plock_add(lpt->pt[0], 0, n);
-		plock_add(lpt->pt[1], 1, n);
-
-		lpt->sum[0] += n;
-		lpt->sum[1] += n;
-
-		n = (n + 1) % ADD_MAX;
-	}
-
-	tm = rte_get_timer_cycles() - tm;
-
-	printf("%s(%u): %" PRIu64 " iterations finished, in %" PRIu64
-		" cycles, %#Lf cycles/iteration, "
-		"local sum={%" PRIu64 ", %" PRIu64 "}\n",
-		__func__, lc, i, tm, (long double)tm / i,
-		lpt->sum[0], lpt->sum[1]);
-	return 0;
-}
-
-/*
- * For N active lcores we allocate N+1 lcore_plock_test structures.
- * Each active lcore shares one lcore_plock_test structure with its
- * left lcore neighbor and one lcore_plock_test structure with its
- * right lcore neighbor.
- * During the test each lcore updates data in both shared structures and
- * its local copies. Then at validation phase we check that our shared
- * and local data are the same.
- */
-static int
-plock_test(uint64_t iter, enum plock_use_type utype)
-{
-	int32_t rc;
-	uint32_t i, lc, n;
-	uint64_t *sum;
-	struct plock_test *pt;
-	struct lcore_plock_test *lpt;
-
-	/* init phase, allocate and initialize shared data */
-
-	n = rte_lcore_count();
-	pt = calloc(n + 1, sizeof(*pt));
-	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);
-
-	if (pt == NULL || lpt == NULL || sum == NULL) {
-		printf("%s: failed to allocate memory for %u lcores\n",
-			__func__, n);
-		free(pt);
-		free(lpt);
-		free(sum);
-		return -ENOMEM;
-	}
-
-	for (i = 0; i != n + 1; i++)
-		plock_reset(&pt[i].lock, utype);
-
-	i = 0;
-	RTE_LCORE_FOREACH(lc) {
-
-		lpt[i].lc = lc;
-		lpt[i].iter = iter;
-		lpt[i].pt[0] = pt + i;
-		lpt[i].pt[1] = pt + i + 1;
-		i++;
-	}
-
-	lpt[i - 1].pt[1] = pt;
-
-	for (i = 0; i != n; i++)
-		printf("lpt[%u]={lc=%u, pt={%p, %p},};\n",
-			i, lpt[i].lc, lpt[i].pt[0], lpt[i].pt[1]);
-
-
-	/* test phase - start and wait for completion on each active lcore */
-
-	rte_eal_mp_remote_launch(plock_test1_lcore, lpt, CALL_MAIN);
-	rte_eal_mp_wait_lcore();
-
-	/* validation phase - make sure that shared and local data match */
-
-	for (i = 0; i != n; i++) {
-		sum[i] += lpt[i].sum[0];
-		sum[i + 1] += lpt[i].sum[1];
-	}
-
-	sum[0] += sum[i];
-
-	rc = 0;
-	for (i = 0; i != n; i++) {
-		printf("%s: sum[%u]=%" PRIu64 ", pt[%u].val=%" PRIu64 ",

pt[%u].iter=%" PRIu64 ";\n",

app/test/test_barrier.c deleted +0 -37
-			__func__, i, sum[i], i, pt[i].val, i, pt[i].iter);
-
-		/* race condition occurred, lock doesn't work properly */
-		if (sum[i] != pt[i].val || 2 * iter != pt[i].iter) {
-			printf("error: local and shared sums don't match\n");
-			rc = -1;
-		}
-	}
-
-	free(pt);
-	free(lpt);
-	free(sum);
-
-	printf("%s(utype=%u) returns %d\n", __func__, utype, 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);
-
-	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];
-	}
-
-	return ret;
-}
-
-REGISTER_PERF_TEST(barrier_autotest, test_barrier);
--

2.53.0

#8 lore raw

RFC 3/32 bus/vmbus: fix ring buffer ordering on weakly ordered CPUs

In reply to Stephen Hemminger

The read index update in vmbus_rxbr_read() was only protected by a compiler barrier. On a weakly ordered architecture the store of rindex can become visible to the host before the data copy completes, allowing the host to reuse and overwrite ring data still being read. Use a release store for the read index.

The barrier in rte_vmbus_chan_signal_tx() must order the earlier ring index update against the load of the host interrupt mask, and a write barrier does not order stores against loads. Use a full fence, which matches virt_mb() in the equivalent Linux and FreeBSD code.

Neither change affects generated code on x86.

Fixes 831dba47bd36 ("bus/vmbus: add Hyper-V virtual bus support")
---
 drivers/bus/vmbus/vmbus_bufring.c | 11 +++++++----
 drivers/bus/vmbus/vmbus_channel.c |  4 ++--
 2 files changed, 9 insertions(+), 6 deletions(-)
drivers/bus/vmbus/vmbus_bufring.c +7 -4
index fcb97287dc..f622869974 100644
@@ -237,10 +237,13 @@ vmbus_rxbr_read(struct vmbus_br *rbr, void *data, size_t dlen, size_t skip)
 	 */
 	rindex = vmbus_br_idxinc(rindex, sizeof(uint64_t), br_dsize);
 
-	/* Update the read index _after_ the channel packet is fetched.	 */
-	rte_compiler_barrier();
-
-	vbr->rindex = rindex;
+	/*
+	 * Update the read index after the channel packet is fetched.
+	 * Release store ensures the host can not observe the new read
+	 * index before the data copy is complete.
+	 */
+	rte_atomic_store_explicit((volatile uint32_t __rte_atomic *)&vbr->rindex,
+				  rindex, rte_memory_order_release);
 
 	return 0;
 }
drivers/bus/vmbus/vmbus_channel.c +2 -2
index 6887fbad46..2648d8e3fd 100644
@@ -104,8 +104,8 @@ rte_vmbus_chan_signal_tx(struct rte_vmbus_device *dev, const struct vmbus_channe
 {
 	const struct vmbus_br *tbr = &chan->txbr;
 
-	/* Make sure all updates are done before signaling host */
-	rte_smp_wmb();
+	/* Order ring index update before reading host interrupt mask */
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
 	/* If host is ignoring interrupts? */
 	if (tbr->vbr->imask)
Signature · 1 line
2.53.0
Reviewed-by on v1 3/32
#9 lore raw

RE: [EXTERNAL] [RFC 03/32] bus/vmbus: fix ring buffer ordering on weakly ordered CPUs

Quoted 13 lines

Subject: [EXTERNAL] [RFC 03/32] bus/vmbus: fix ring buffer ordering on weakly ordered CPUs

The read index update in vmbus_rxbr_read() was only protected by a compiler barrier. On a weakly ordered architecture the store of rindex can become visible to the host before the data copy completes, allowing the host to reuse and overwrite ring data still being read. Use a release store for the read index.

The barrier in rte_vmbus_chan_signal_tx() must order the earlier ring index update against the load of the host interrupt mask, and a write barrier does not order stores against loads. Use a full fence, which matches virt_mb() in the equivalent Linux and FreeBSD code.

Quoted 6 lines

Neither change affects generated code on x86.

Fixes 831dba47bd36 ("bus/vmbus: add Hyper-V virtual bus support")
Quoted 48 lines
---
 drivers/bus/vmbus/vmbus_bufring.c | 11 +++++++----
drivers/bus/vmbus/vmbus_channel.c |  4 ++--
 2 files changed, 9 insertions(+), 6 deletions(-)
drivers/bus/vmbus/vmbus_bufring.c +7 -4
index fcb97287dc..f622869974 100644
@@ -237,10 +237,13 @@ vmbus_rxbr_read(struct vmbus_br *rbr, void *data,
 size_t dlen, size_t skip)
 	 */
 	rindex = vmbus_br_idxinc(rindex, sizeof(uint64_t), br_dsize);
 
-	/* Update the read index _after_ the channel packet is fetched.	 */
-	rte_compiler_barrier();
-
-	vbr->rindex = rindex;
+	/*
+	 * Update the read index after the channel packet is fetched.
+	 * Release store ensures the host can not observe the new read
+	 * index before the data copy is complete.
+	 */
+	rte_atomic_store_explicit((volatile uint32_t __rte_atomic *)&vbr-
 >rindex,
+				  rindex, rte_memory_order_release);
 
drivers/bus/vmbus/vmbus_bufring.c +0 -0
 	return 0;
 }
drivers/bus/vmbus/vmbus_channel.c +2 -3
index 6887fbad46..2648d8e3fd 100644
@@ -104,8 +104,8 @@ rte_vmbus_chan_signal_tx(struct rte_vmbus_device
 *dev, const struct vmbus_channe  {
 	const struct vmbus_br *tbr = &chan->txbr;
 
-	/* Make sure all updates are done before signaling host */
-	rte_smp_wmb();
+	/* Order ring index update before reading host interrupt mask */
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
 	/* If host is ignoring interrupts? */
 	if (tbr->vbr->imask)
--

2.53.0

#10 lore raw

RFC 4/32 bus/vmbus: fix missing acquire on receive ring index

In reply to Stephen Hemminger

The receive path checks available data by reading the write index and then copies ring data. The link between the two is only the comparison, a control dependency, which does not order load against load on a weakly ordered architecture: packet data can be read before the host has finished writing it. Load the write index with acquire, pairing with the host's release store. This is the equivalent of virt_rmb() in the Linux hv_pkt_iter code. No change in generated code on x86.

Fixes 831dba47bd36 ("bus/vmbus: add Hyper-V virtual bus support")
---
 drivers/bus/vmbus/private.h | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/bus/vmbus/private.h +11 -1
index 6efac86b77..aca5b534f9 100644
@@ -12,6 +12,7 @@
 #include <bus_driver.h>
 #include <bus_vmbus_driver.h>
 #include <rte_log.h>
+#include <rte_stdatomic.h>
 #include <rte_eal_paging.h>
 #include <rte_vmbus_reg.h>
 
@@ -130,7 +131,16 @@ vmbus_br_availwrite(const struct vmbus_br *br, uint32_t windex)
 static inline uint32_t
 vmbus_br_availread(const struct vmbus_br *br)
 {
-	return br->dsize - vmbus_br_availwrite(br, br->vbr->windex);
+	uint32_t windex;
+
+	/* Pairs with the host's release store of the write index;
+	 * ring data must not be read before the index.
+	 */
+	windex = rte_atomic_load_explicit(
+		(volatile uint32_t __rte_atomic *)&br->vbr->windex,
+		rte_memory_order_acquire);
+
+	return br->dsize - vmbus_br_availwrite(br, windex);
 }
 
 int vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen,
Signature · 1 line
2.53.0
Reviewed-by on v1 4/32
#11 lore raw

RE: [EXTERNAL] [RFC 04/32] bus/vmbus: fix missing acquire on receive ring index

Quoted 8 lines

The receive path checks available data by reading the write index and then copies ring data. The link between the two is only the comparison, a control dependency, which does not order load against load on a weakly ordered
architecture: packet data can be read before the host has finished writing it. Load the write index with acquire, pairing with the host's release store. This is the equivalent of virt_rmb() in the Linux hv_pkt_iter code. No change in generated code on x86.

Quoted 4 lines
Fixes 831dba47bd36 ("bus/vmbus: add Hyper-V virtual bus support")
Quoted 35 lines
---
 drivers/bus/vmbus/private.h | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/bus/vmbus/private.h index renamed from drivers/bus/vmbus/private.h +0 -0

6efac86b77..aca5b534f9 100644

drivers/bus/vmbus/private.h +1 -0
@@ -12,6 +12,7 @@
 #include <bus_driver.h>
 #include <bus_vmbus_driver.h>
 #include <rte_log.h>
+#include <rte_stdatomic.h>
 #include <rte_eal_paging.h>
 #include <rte_vmbus_reg.h>
 
@@ -130,7 +131,16 @@ vmbus_br_availwrite(const struct vmbus_br *br,

uint32_t windex) static inline uint32_t vmbus_br_availread(const struct vmbus_br *br) {

drivers/bus/vmbus/private.h +10 -2
-	return br->dsize - vmbus_br_availwrite(br, br->vbr->windex);
+	uint32_t windex;
+
+	/* Pairs with the host's release store of the write index;
+	 * ring data must not be read before the index.
+	 */
+	windex = rte_atomic_load_explicit(
+		(volatile uint32_t __rte_atomic *)&br->vbr->windex,
+		rte_memory_order_acquire);
+
+	return br->dsize - vmbus_br_availwrite(br, windex);
 }
 
 int vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen,
--

2.53.0

#12 lore raw

RFC 5/32 bus/vmbus: replace SMP barriers with C11 memory fences

In reply to Stephen Hemminger

Full barriers order the preceding index store against the following load of the interrupt mask or pending size and stay seq_cst; read barriers become acquire fences. Same code generated on x86 and arm64.

The write barrier before publishing the transmit index becomes a release fence. Nominally stronger on arm64, but it is immediately followed by a full barrier cmpset; converting that to a release compare-exchange is left for the rte_atomic32 removal series.

---
 drivers/bus/vmbus/vmbus_bufring.c | 6 +++---
 drivers/bus/vmbus/vmbus_channel.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/bus/vmbus/vmbus_bufring.c +3 -3
index f622869974..31478d3bfa 100644
@@ -58,11 +58,11 @@ void vmbus_br_setup(struct vmbus_br *br, void *buf, unsigned int blen)
 static inline bool
 vmbus_txbr_need_signal(const struct vmbus_bufring *vbr, uint32_t old_windex)
 {
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 	if (vbr->imask)
 		return false;
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	/*
 	 * This is the only case we need to signal when the
@@ -158,7 +158,7 @@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen,
 	RTE_ASSERT(windex == next_windex);
 
 	/* Ensure that data is available before updating host index */
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	/* Checkin for our reservation. wait for our turn to update host */
 	while (!rte_atomic32_cmpset(&vbr->windex, old_windex, next_windex))
drivers/bus/vmbus/vmbus_channel.c +3 -3
index 2648d8e3fd..10293f59be 100644
@@ -211,7 +211,7 @@ bool rte_vmbus_chan_rx_empty(const struct vmbus_channel *channel)
 {
 	const struct vmbus_br *br = &channel->rxbr;
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 	return br->vbr->rindex == br->vbr->windex;
 }
 
@@ -229,13 +229,13 @@ void rte_vmbus_chan_signal_read(struct rte_vmbus_device *dev,
 		return;
 
 	/* Make sure reading of pending happens after new read index */
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
 	pending_sz = rbr->vbr->pending_send;
 	if (!pending_sz)
 		return;
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 	write_sz = vmbus_br_availwrite(rbr, rbr->vbr->windex);
 
 	/* If there was space before then host was not blocked */
Signature · 1 line
2.53.0
Reviewed-by on v1 5/32
#13 lore raw

RE: [EXTERNAL] [RFC 05/32] bus/vmbus: replace SMP barriers with C11 memory fences

Quoted 11 lines

Full barriers order the preceding index store against the following load of the interrupt mask or pending size and stay seq_cst; read barriers become acquire fences. Same code generated on x86 and arm64.

The write barrier before publishing the transmit index becomes a release fence. Nominally stronger on arm64, but it is immediately followed by a full barrier cmpset; converting that to a release compare-exchange is left for the rte_atomic32 removal series.

Quoted 65 lines
---
 drivers/bus/vmbus/vmbus_bufring.c | 6 +++---
drivers/bus/vmbus/vmbus_channel.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/bus/vmbus/vmbus_bufring.c +0 -0
index f622869974..31478d3bfa 100644
@@ -58,11 +58,11 @@ void vmbus_br_setup(struct vmbus_br *br, void *buf,

unsigned int blen) static inline bool vmbus_txbr_need_signal(const struct vmbus_bufring *vbr, uint32_t old_windex) {

drivers/bus/vmbus/vmbus_bufring.c +2 -2
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 	if (vbr->imask)
 		return false;
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	/*
 	 * This is the only case we need to signal when the @@ -158,7 +158,7

@@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen,

drivers/bus/vmbus/vmbus_bufring.c +1 -1
 	RTE_ASSERT(windex == next_windex);
 
 	/* Ensure that data is available before updating host index */
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	/* Checkin for our reservation. wait for our turn to update host */
 	while (!rte_atomic32_cmpset(&vbr->windex, old_windex,

next_windex)) diff --git a/drivers/bus/vmbus/vmbus_channel.c b/drivers/bus/vmbus/vmbus_channel.c
index 2648d8e3fd..10293f59be 100644

drivers/bus/vmbus/vmbus_channel.c +3 -3
@@ -211,7 +211,7 @@ bool rte_vmbus_chan_rx_empty(const struct
 vmbus_channel *channel)  {
 	const struct vmbus_br *br = &channel->rxbr;
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 	return br->vbr->rindex == br->vbr->windex;  }
 
@@ -229,13 +229,13 @@ void rte_vmbus_chan_signal_read(struct
 rte_vmbus_device *dev,
 		return;
 
 	/* Make sure reading of pending happens after new read index */
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
 	pending_sz = rbr->vbr->pending_send;
 	if (!pending_sz)
 		return;
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 	write_sz = vmbus_br_availwrite(rbr, rbr->vbr->windex);
 

/* If there was space before then host was not blocked */
--
2.53.0

#14 lore raw

RFC 6/32 baseband: convert rte_smp_rmb to fence

In reply to Stephen Hemminger

Replace deprecated rte_smp_rmb with equivalent
te_atomic_thread_fence(rte_memory_order_acquire).

---
 drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c |  8 ++++----
 drivers/baseband/fpga_lte_fec/fpga_lte_fec.c       | 12 ++++++------
 2 files changed, 10 insertions(+), 10 deletions(-)
drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c +4 -4
index 45bd171ca7..e804be4cea 100644
@@ -2662,7 +2662,7 @@ vc_5gnr_dequeue_ldpc_enc_one_op_cb(struct fpga_5gnr_queue *q, struct rte_bbdev_e
 		return -1;
 
 	/* make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	rte_bbdev_log_debug("DMA response desc %p", desc);
 
@@ -2691,7 +2691,7 @@ agx100_dequeue_ldpc_enc_one_op_cb(struct fpga_5gnr_queue *q, struct rte_bbdev_en
 		return -1;
 
 	/* make sure the response is read atomically. */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	rte_bbdev_log_debug("DMA response desc %p", desc);
 
@@ -2723,7 +2723,7 @@ vc_5gnr_dequeue_ldpc_dec_one_op_cb(struct fpga_5gnr_queue *q, struct rte_bbdev_d
 		return -1;
 
 	/* make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 #ifdef RTE_LIBRTE_BBDEV_DEBUG
 	vc_5gnr_print_dma_dec_desc_debug_info(desc);
@@ -2769,7 +2769,7 @@ agx100_dequeue_ldpc_dec_one_op_cb(struct fpga_5gnr_queue *q, struct rte_bbdev_de
 		return -1;
 
 	/* make sure the response is read atomically. */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 #ifdef RTE_LIBRTE_BBDEV_DEBUG
 	agx100_print_dma_dec_desc_debug_info(desc);
drivers/baseband/fpga_lte_fec/fpga_lte_fec.c +6 -6
index 04ac445820..cb3f29c10b 100644
@@ -2093,7 +2093,7 @@ dequeue_enc_one_op_cb(struct fpga_queue *q, struct rte_bbdev_enc_op **op,
 		return -1;
 
 	/* make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	rte_bbdev_log_debug("DMA response desc %p", desc);
 
@@ -2123,7 +2123,7 @@ dequeue_enc_one_op_tb(struct fpga_queue *q, struct rte_bbdev_enc_op **op,
 		return -1;
 
 	/* Make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	/* Verify if done bit in all CBs is set */
 	cbs_in_op = desc->enc_req.cbs_in_op;
@@ -2135,7 +2135,7 @@ dequeue_enc_one_op_tb(struct fpga_queue *q, struct rte_bbdev_enc_op **op,
 	}
 
 	/* Make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	for (cb_idx = 0; cb_idx < cbs_in_op; ++cb_idx) {
 		desc = q->ring_addr + ((q->head_free_desc + desc_offset +
@@ -2166,7 +2166,7 @@ dequeue_dec_one_op_cb(struct fpga_queue *q, struct rte_bbdev_dec_op **op,
 		return -1;
 
 	/* make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 #ifdef RTE_LIBRTE_BBDEV_DEBUG
 	print_dma_dec_desc_debug_info(desc);
@@ -2201,7 +2201,7 @@ dequeue_dec_one_op_tb(struct fpga_queue *q, struct rte_bbdev_dec_op **op,
 		return -1;
 
 	/* Make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	/* Verify if done bit in all CBs is set */
 	cbs_in_op = desc->dec_req.cbs_in_op;
@@ -2213,7 +2213,7 @@ dequeue_dec_one_op_tb(struct fpga_queue *q, struct rte_bbdev_dec_op **op,
 	}
 
 	/* Make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	for (cb_idx = 0; cb_idx < cbs_in_op; ++cb_idx) {
 		desc = q->ring_addr + ((q->head_free_desc + desc_offset +
Signature · 1 line
2.53.0
#15 lore raw

RFC 7/32 net/hinic: replace rte_smp_rmb

In reply to Stephen Hemminger

Replace deprecated rte_smp_rmb with equivalent rte_atomic_thread_fence(rte_memory_order_acquire).

---
 drivers/net/hinic/base/hinic_pmd_cmdq.c | 2 +-
 drivers/net/hinic/base/hinic_pmd_mgmt.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/hinic/base/hinic_pmd_cmdq.c +1 -1
index 1816636c34..0c805e1528 100644
@@ -825,7 +825,7 @@ static int cmdq_sync_cmd_direct_resp(struct hinic_cmdq *cmdq,
 		goto cmdq_unlock;
 	}
 
-	rte_smp_rmb();	/* read error code after completion */
+	rte_atomic_thread_fence(rte_memory_order_acquire);	/* read error code after completion */
 
 	if (out_param) {
 		wqe_lcmd = &curr_wqe->wqe_lcmd;
drivers/net/hinic/base/hinic_pmd_mgmt.c +1 -1
index 6ecca407a1..f1a0b15c21 100644
@@ -459,7 +459,7 @@ hinic_pf_to_mgmt_sync(struct hinic_hwdev *hwdev,
 		goto unlock_sync_msg;
 	}
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 	if (recv_msg->msg_len && buf_out && out_size) {
 		if (recv_msg->msg_len <= *out_size) {
 			memcpy(buf_out, recv_msg->msg,
Signature · 1 line
2.53.0
#16 lore raw

RFC 8/32 net/intel: replace rte_smp_rmb

In reply to Stephen Hemminger

Replace deprecated rte_smp_rmb with equivalent rte_atomic_thread_fence(rte_memory_order_acquire).

---
 drivers/net/intel/ice/ice_rxtx.c     | 2 +-
 drivers/net/intel/ixgbe/ixgbe_rxtx.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/intel/ice/ice_rxtx.c +1 -1
index c4b5454c53..6f168e358f 100644
@@ -1955,7 +1955,7 @@ ice_rx_scan_hw_ring(struct ci_rx_queue *rxq)
 		for (j = ICE_LOOK_AHEAD - 1; j >= 0; j--)
 			s[j] = rte_le_to_cpu_16(rxdp[j].wb.status_error0);
 
-		rte_smp_rmb();
+		rte_atomic_thread_fence(rte_memory_order_acquire);
 
 		/* Compute how many status bits were set */
 		for (j = 0, nb_dd = 0; j < ICE_LOOK_AHEAD; j++)
drivers/net/intel/ixgbe/ixgbe_rxtx.c +1 -1
index 60222693fe..ce0a3dde34 100644
@@ -1549,7 +1549,7 @@ ixgbe_rx_scan_hw_ring(struct ci_rx_queue *rxq)
 		for (j = 0; j < LOOK_AHEAD; j++)
 			s[j] = rte_le_to_cpu_32(rxdp[j].wb.upper.status_error);
 
-		rte_smp_rmb();
+		rte_atomic_thread_fence(rte_memory_order_acquire);
 
 		/* Compute how many status bits were set */
 		for (nb_dd = 0; nb_dd < LOOK_AHEAD &&
Signature · 1 line
2.53.0
#18 lore raw

RFC 9/32 crypto_caam_jr: replace rte_smp_rmb

In reply to Stephen Hemminger

Replace rte_smp_rmb with equivalent rte_atomic_thread_fence(rte_memory_order_acquire).

---
 drivers/crypto/caam_jr/caam_jr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/caam_jr/caam_jr.c +1 -1
index a57dc56b80..1f97e72337 100644
@@ -572,7 +572,7 @@ hw_poll_job_ring(struct sec_job_ring_t *job_ring,
 		job_ring, job_ring->pidx, job_ring->cidx,
 		limit, number_of_jobs_available, jobs_no_to_notify);
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	while (jobs_no_to_notify > notified_descs_no) {
 		static uint64_t false_alarm;
Signature · 1 line
2.53.0
Acked-by on v1 9/32
#19 lore raw

Re: [RFC 09/32] crypto_caam_jr: replace rte_smp_rmb

Quoted 4 lines · Stephen Hemminger

Replace rte_smp_rmb with equivalent rte_atomic_thread_fence(rte_memory_order_acquire).

Quoted 17 lines
---
  drivers/crypto/caam_jr/caam_jr.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/caam_jr/caam_jr.c +1 -1
index a57dc56b80..1f97e72337 100644
@@ -572,7 +572,7 @@ hw_poll_job_ring(struct sec_job_ring_t *job_ring,
  		job_ring, job_ring->pidx, job_ring->cidx,
  		limit, number_of_jobs_available, jobs_no_to_notify);
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
  	while (jobs_no_to_notify > notified_descs_no) {
  		static uint64_t false_alarm;
#20 lore raw

RFC 10/32 net/virtio: replcae rte_smp_rmb

In reply to Stephen Hemminger

Replace rte_smp_rmb with equivalent rte_atomic_thread_fence(rte_memory_order_acquire).

---
 drivers/net/virtio/virtqueue.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/virtio/virtqueue.h +3 -3
index 1f0e6ae77e..37fbd47d42 100644
@@ -445,15 +445,15 @@ virtqueue_nused(const struct virtqueue *vq)
 
 	if (vq->hw->weak_barriers) {
 	/**
-	 * x86 prefers to using rte_smp_rmb over rte_atomic_load_explicit as it
-	 * reports a slightly better perf, which comes from the saved
+	 * x86 prefers to using rte_atomic_thread_fence over rte_atomic_load_explicit
+	 * as it reports a slightly better perf, which comes from the saved
 	 * branch by the compiler.
 	 * The if and else branches are identical with the smp and io
 	 * barriers both defined as compiler barriers on x86.
 	 */
 #ifdef RTE_ARCH_X86_64
 		idx = vq->vq_split.ring.used->idx;
-		rte_smp_rmb();
+		rte_atomic_thread_fence(rte_memory_order_acquire);
 #else
 		idx = rte_atomic_load_explicit(&(vq)->vq_split.ring.used->idx,
 				rte_memory_order_acquire);
Signature · 1 line
2.53.0
#21 lore raw

RFC 11/32 net/thunderx: replace rte_smp_rmb

In reply to Stephen Hemminger

Replace rte_smp_rmb with equivalent rte_atomic_thread_fence(rte_memory_order_acquire).

---
 drivers/net/thunderx/base/nicvf_plat.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/thunderx/base/nicvf_plat.h +1 -1
index 8421f57040..7d22563035 100644
@@ -26,7 +26,7 @@
 /* barrier */
 #include <rte_atomic.h>
 #define nicvf_smp_wmb() rte_smp_wmb()
-#define nicvf_smp_rmb() rte_smp_rmb()
+#define nicvf_smp_rmb() rte_atomic_thread_fence(rte_memory_order_acquire)
 
 /* utils */
 #include <rte_common.h>
Signature · 1 line
2.53.0
#22 lore raw

RFC 12/32 stack: always use C11 memory model implementation

In reply to Stephen Hemminger

The generic and C11 lock-free stack implementations differ only in memory ordering. The generic version uses a full barrier where its own comments state an acquire fence is sufficient, and seq_cst for all length counter operations.

Only x86 and ThunderX still used the generic version. On x86 the switch removes a locked add per CAS attempt in push and pop; TSO provides the acquire semantics. On ThunderX the pop fence weakens from dmb ish to dmb ishld and the push fence goes away. Unlike the ring, no platform selected the generic stack for measured performance reasons.

Remove it and use the C11 implementation everywhere.

---
 lib/stack/meson.build            |   1 -
 lib/stack/rte_stack_lf.h         |   4 -
 lib/stack/rte_stack_lf_generic.h | 153 -------------------------------
 3 files changed, 158 deletions(-)
 delete mode 100644 lib/stack/rte_stack_lf_generic.h
lib/stack/meson.build +0 -1
index 18177a742f..1fab46208f 100644
@@ -7,7 +7,6 @@ headers = files('rte_stack.h')
 indirect_headers += files(
         'rte_stack_std.h',
         'rte_stack_lf.h',
-        'rte_stack_lf_generic.h',
         'rte_stack_lf_c11.h',
         'rte_stack_lf_stubs.h',
 )
lib/stack/rte_stack_lf.h +0 -4
index f2b012cd0e..1bc6ee8f40 100644
@@ -8,11 +8,7 @@
 #if !(defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_ARM64))
 #include "rte_stack_lf_stubs.h"
 #else
-#ifdef RTE_USE_C11_MEM_MODEL
 #include "rte_stack_lf_c11.h"
-#else
-#include "rte_stack_lf_generic.h"
-#endif
 
 /**
  * Indicates that RTE_STACK_F_LF is supported.
lib/stack/rte_stack_lf_generic.h deleted +0 -153

153 lines not on this page · raw message

Signature · 1 line
2.53.0
#23 lore raw

RE: [RFC 12/32] stack: always use C11 memory model implementation

+TO: x86 maintainers, ThunderX maintainers

Quoted 8 lines

From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, 29 July 2026 19.54

The generic and C11 lock-free stack implementations differ only in memory ordering. The generic version uses a full barrier where its own comments state an acquire fence is sufficient, and seq_cst for all length counter operations.

Quoted 8 lines

Only x86 and ThunderX still used the generic version. On x86 the switch removes a locked add per CAS attempt in push and pop; TSO provides the acquire semantics. On ThunderX the pop fence weakens from dmb ish to dmb ishld and the push fence goes away. Unlike the ring, no platform selected the generic stack for measured performance reasons.

Remove it and use the C11 implementation everywhere.

The lack of measured performance difference documentation is not a valid reason to remove the generic version!

It would be reasonable to assume that x86 (and ThunderX) use the generic version for non-insignificant performance reasons.

If there is no performance difference, I agree with this patch. Otherwise not. This could be verified by providing the missing measurements.

#24 lore raw

Re: [RFC 12/32] stack: always use C11 memory model implementation

Quoted 17 lines · On Fri, 31 Jul 2026 16:53:45 +0200 Morten Brørup <[email protected]>…

+TO: x86 maintainers, ThunderX maintainers

Quoted 15 lines

From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, 29 July 2026 19.54

The generic and C11 lock-free stack implementations differ only in memory ordering. The generic version uses a full barrier where its own comments state an acquire fence is sufficient, and seq_cst for all length counter operations.

Only x86 and ThunderX still used the generic version. On x86 the switch removes a locked add per CAS attempt in push and pop; TSO provides the acquire semantics. On ThunderX the pop fence weakens from dmb ish to dmb ishld and the push fence goes away. Unlike the ring, no platform selected the generic stack for measured performance reasons.

Quoted 9 lines
Quoted 1 line

Remove it and use the C11 implementation everywhere.

The lack of measured performance difference documentation is not a valid reason to remove the generic version!

It would be reasonable to assume that x86 (and ThunderX) use the generic version for non-insignificant performance reasons.

If there is no performance difference, I agree with this patch. Otherwise not. This could be verified by providing the missing measurements.

The reason is that smp_mb's need to go away.
The other option is revise to replace with thread fence, at which point it becomes the same as generic code.

#25 lore raw

Re: [RFC 12/32] stack: always use C11 memory model implementation

In reply to Morten Brørup
Quoted 17 lines · On Fri, 31 Jul 2026 16:53:45 +0200 Morten Brørup <[email protected]>…

+TO: x86 maintainers, ThunderX maintainers

Quoted 15 lines

From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, 29 July 2026 19.54

The generic and C11 lock-free stack implementations differ only in memory ordering. The generic version uses a full barrier where its own comments state an acquire fence is sufficient, and seq_cst for all length counter operations.

Only x86 and ThunderX still used the generic version. On x86 the switch removes a locked add per CAS attempt in push and pop; TSO provides the acquire semantics. On ThunderX the pop fence weakens from dmb ish to dmb ishld and the push fence goes away. Unlike the ring, no platform selected the generic stack for measured performance reasons.

Quoted 9 lines
Quoted 1 line

Remove it and use the C11 implementation everywhere.

The lack of measured performance difference documentation is not a valid reason to remove the generic version!

It would be reasonable to assume that x86 (and ThunderX) use the generic version for non-insignificant performance reasons.

If there is no performance difference, I agree with this patch. Otherwise not. This could be verified by providing the missing measurements.

Surprisingly, the performance of the C11 version is better than the old generic version that had smp_mb. That is because C11 code generates no locked prefixes. Gets speedup of upto 60%.

Between main (with rte_smp_mb) and the unified C11 version on the 32-core x86 machine:

Test main (n=9) unified C11 (n=9) delta
single push/pop 46.62 ±0.30 33.41 ±0.10 -28%
empty pop 1.47 ±0.01 0.98 ±0.01 -33%
1 lcore, bulk 8 9.06 ±0.05 8.20 ±0.08 -10%
1 lcore, bulk 32 6.09 ±0.02 6.15 ±0.03 +1%
2 HT, bulk 8 42.05 ±0.31 39.24 ±0.52 -7%
2 HT, bulk 32 11.92 ±0.13 11.89 ±0.10 0
2 cores, bulk 8 78.90 ±0.60 72.96 ±1.11 -7%
2 cores, bulk 32 20.74 ±1.56 7.70 ±0.13 -63%
32 cores, bulk 8 6126 ±72 6121 ±89 0
32 cores, bulk 32 1953.9 ±2.9 1984.6 ±13.3 +1.6%

#26 lore raw

RE: [RFC 12/32] stack: always use C11 memory model implementation

Quoted 46 lines

From: Stephen Hemminger [mailto:[email protected]]
Sent: Saturday, 1 August 2026 19.02

Quoted 17 lines · On Fri, 31 Jul 2026 16:53:45 +0200 Morten Brørup <[email protected]>…

+TO: x86 maintainers, ThunderX maintainers

Quoted 15 lines

From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, 29 July 2026 19.54

The generic and C11 lock-free stack implementations differ only in memory ordering. The generic version uses a full barrier where its own comments state an acquire fence is sufficient, and seq_cst for all length counter operations.

Only x86 and ThunderX still used the generic version. On x86 the switch removes a locked add per CAS attempt in push and pop; TSO provides the acquire semantics. On ThunderX the pop fence weakens from dmb ish to dmb ishld and the push fence goes away. Unlike the ring, no platform selected the generic stack for measured performance reasons.

Quoted 3 lines
Quoted 1 line

Remove it and use the C11 implementation everywhere.

The lack of measured performance difference documentation is not a

valid reason to remove the generic version!

Quoted 2 lines

It would be reasonable to assume that x86 (and ThunderX) use the

generic version for non-insignificant performance reasons.

Quoted 2 lines

If there is no performance difference, I agree with this patch.

Otherwise not.

Quoted 2 lines

This could be verified by providing the missing measurements.

Surprisingly, the performance of the C11 version is better than the old generic
version that had smp_mb. That is because C11 code generates no locked prefixes.
Gets speedup of upto 60%.

Between main (with rte_smp_mb) and the unified C11 version on the 32- core x86 machine:

Quoted 11 lines

Test main (n=9) unified C11 (n=9) delta
single push/pop 46.62 ±0.30 33.41 ±0.10 -28%
empty pop 1.47 ±0.01 0.98 ±0.01 -33%
1 lcore, bulk 8 9.06 ±0.05 8.20 ±0.08 -10%
1 lcore, bulk 32 6.09 ±0.02 6.15 ±0.03 +1%
2 HT, bulk 8 42.05 ±0.31 39.24 ±0.52 -7%
2 HT, bulk 32 11.92 ±0.13 11.89 ±0.10 0
2 cores, bulk 8 78.90 ±0.60 72.96 ±1.11 -7%
2 cores, bulk 32 20.74 ±1.56 7.70 ±0.13 -63%
32 cores, bulk 8 6126 ±72 6121 ±89 0
32 cores, bulk 32 1953.9 ±2.9 1984.6 ±13.3 +1.6%

Thank you for testing, Stephen.

It clearly shows this patch deserves a big fat

#27 lore raw

RFC 13/32 ring: replace SMP read barrier with C11 acquire fence

In reply to Stephen Hemminger

rte_smp_rmb() is deprecated. The acquire fence generates the same code everywhere the gcc implementation is used: a compiler barrier on x86 and dmb ishld on ThunderX.

The gcc implementation itself is kept: unlike the lock-free stack, the in-tree comment records a 10% x86 performance drop with the C11 version, which needs re-measuring with current compilers before RTE_USE_C11_MEM_MODEL can be removed.

---
 lib/ring/rte_ring_gcc_pvt.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/ring/rte_ring_gcc_pvt.h +3 -3
index 340ece28c7..9c2c58824d 100644
@@ -55,10 +55,10 @@ __rte_ring_headtail_move_head_st(struct rte_ring_headtail *d,
 
 	*old_head = d->head;
 
-	/* add rmb barrier to avoid load/load reorder in weak
-	 * memory model. It is noop on x86
+	/* Acquire fence to avoid load/load reorder in weak
+	 * memory model. It is noop on x86.
 	 */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	/*
 	 *  The subtraction is done between two unsigned 32bits value
Signature · 1 line
2.53.0
Acked-by on v1 13/32
#28 lore raw

RE: [RFC 13/32] ring: replace SMP read barrier with C11 acquire fence

Quoted 34 lines

rte_smp_rmb() is deprecated. The acquire fence generates the same code everywhere the gcc implementation is used: a compiler barrier on x86 and dmb ishld on ThunderX.

The gcc implementation itself is kept: unlike the lock-free stack, the in-tree comment records a 10% x86 performance drop with the C11 version, which needs re-measuring with current compilers before RTE_USE_C11_MEM_MODEL can be removed.

---
 lib/ring/rte_ring_gcc_pvt.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/ring/rte_ring_gcc_pvt.h +3 -3
index 340ece28c7..9c2c58824d 100644
@@ -55,10 +55,10 @@ __rte_ring_headtail_move_head_st(struct
 rte_ring_headtail *d,
 
 	*old_head = d->head;
 
-	/* add rmb barrier to avoid load/load reorder in weak
-	 * memory model. It is noop on x86
+	/* Acquire fence to avoid load/load reorder in weak
+	 * memory model. It is noop on x86.
 	 */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	/*
Quoted 2 lines

* The subtraction is done between two unsigned 32bits value
--

As a side note - do we really need two versions of __rte_ring_headtail_move_head_st()? Might be just keep 2 versions of _mt, while _st can be merged into one?

Quoted 1 line

2.53.0

Acked-by on v1 13/32
#29 lore raw

RE: [RFC 13/32] ring: replace SMP read barrier with C11 acquire fence

In reply to Stephen Hemminger
Quoted 35 lines

From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, 29 July 2026 19.54

rte_smp_rmb() is deprecated. The acquire fence generates the same code everywhere the gcc implementation is used: a compiler barrier on x86 and dmb ishld on ThunderX.

The gcc implementation itself is kept: unlike the lock-free stack, the in-tree comment records a 10% x86 performance drop with the C11 version, which needs re-measuring with current compilers before RTE_USE_C11_MEM_MODEL can be removed.

---
 lib/ring/rte_ring_gcc_pvt.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/ring/rte_ring_gcc_pvt.h +3 -3
index 340ece28c7..9c2c58824d 100644
@@ -55,10 +55,10 @@ __rte_ring_headtail_move_head_st(struct
 rte_ring_headtail *d,
 
 	*old_head = d->head;
 
-	/* add rmb barrier to avoid load/load reorder in weak
-	 * memory model. It is noop on x86
+	/* Acquire fence to avoid load/load reorder in weak
+	 * memory model. It is noop on x86.
 	 */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	/*
Quoted 3 lines

* The subtraction is done between two unsigned 32bits value
--
2.53.0

#30 lore raw

RFC 14/32 crypto/virtio: update comment reference to rte_smp_rmb

In reply to Stephen Hemminger

The rte_smp_rmb helper is no longer used.

---
 drivers/crypto/virtio/virtqueue.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/virtio/virtqueue.h +1 -1
index 97a3ace48c..23c001a8e6 100644
@@ -302,7 +302,7 @@ virtqueue_nused(const struct virtqueue *vq)
 
 	if (vq->hw->weak_barriers) {
 	/**
-	 * x86 prefers to using rte_smp_rmb over rte_atomic_load_explicit as it
+	 * x86 prefers to using virtio_rmb over rte_atomic_load_explicit as it
 	 * reports a slightly better perf, which comes from the saved
 	 * branch by the compiler.
 	 * The if and else branches are identical with the smp and io
Signature · 1 line
2.53.0
#31 lore raw

RFC 15/32 event/sw: fix unlinks in progress counter races

In reply to Stephen Hemminger

The counter is written by both the application thread (increment on unlink) and the scheduler (clear on ack) as a plain uint8_t. An increment is lost if it lands between the scheduler's test and clear, making rte_event_port_unlinks_in_progress() report completion before the scheduler has seen the unlink. Nothing orders the scheduler's later cq map reads against the counter test on a weakly ordered CPU either.

Make the counter atomic: release fetch-add on unlink, acquire exchange to clear. The exchange cannot lose a concurrent increment, and the acquire guarantees the scheduler only acks unlinks whose cq map update it can observe, replacing the full barrier in unlink.

Fixes bd5ac24fea88 ("event/sw: implement unlinks in progress function")
---
 drivers/event/sw/sw_evdev.c           |  8 +++++---
 drivers/event/sw/sw_evdev.h           |  2 +-
 drivers/event/sw/sw_evdev_scheduler.c | 13 ++++++++++---
 3 files changed, 16 insertions(+), 7 deletions(-)
drivers/event/sw/sw_evdev.c +5 -3
index 3ad82e94ac..bb6f50e03b 100644
@@ -119,8 +119,9 @@ sw_port_unlink(struct rte_eventdev *dev, void *port, uint8_t queues[],
 		}
 	}
 
-	p->unlinks_in_progress += unlinked;
-	rte_smp_mb();
+	/* Pairs with the acquire exchange in the scheduler */
+	rte_atomic_fetch_add_explicit(&p->unlinks_in_progress, unlinked,
+				      rte_memory_order_release);
 
 	return unlinked;
 }
@@ -130,7 +131,8 @@ sw_port_unlinks_in_progress(struct rte_eventdev *dev, void *port)
 {
 	RTE_SET_USED(dev);
 	struct sw_port *p = port;
-	return p->unlinks_in_progress;
+	return rte_atomic_load_explicit(&p->unlinks_in_progress,
+					rte_memory_order_relaxed);
 }
 
 static int
drivers/event/sw/sw_evdev.h +1 -1
index c159be21be..8b9118bf91 100644
@@ -160,7 +160,7 @@ struct sw_port {
 	 * progress is read by the scheduler, no more events will be pushed to
 	 * the port - hence the scheduler core can just assign zero.
 	 */
-	uint8_t unlinks_in_progress;
+	RTE_ATOMIC(uint8_t) unlinks_in_progress;
 
 	int16_t is_directed; /** Takes from a single directed QID */
 	/**
drivers/event/sw/sw_evdev_scheduler.c +10 -3
index a5fdcf301b..f4bce2cbb8 100644
@@ -523,9 +523,16 @@ sw_event_schedule(struct rte_eventdev *dev)
 		do {
 			in_pkts = 0;
 			for (i = 0; i < sw->port_count; i++) {
-				/* ack the unlinks in progress as done */
-				if (sw->ports[i].unlinks_in_progress)
-					sw->ports[i].unlinks_in_progress = 0;
+				/* Ack the unlinks in progress as done. The
+				 * acquire exchange orders the cq map reads
+				 * below after the unlinker's map update.
+				 */
+				if (rte_atomic_load_explicit(
+						&sw->ports[i].unlinks_in_progress,
+						rte_memory_order_relaxed))
+					rte_atomic_exchange_explicit(
+						&sw->ports[i].unlinks_in_progress,
+						0, rte_memory_order_acquire);
 
 				if (sw->ports[i].is_directed)
 					in_pkts += sw_schedule_pull_port_dir(sw, i);
Signature · 1 line
2.53.0
Acked-by on v1 15/32
#32 lore raw

Re: [RFC 15/32] event/sw: fix unlinks in progress counter races

Quoted 13 lines · Stephen Hemminger

The counter is written by both the application thread (increment on unlink) and the scheduler (clear on ack) as a plain uint8_t. An increment is lost if it lands between the scheduler's test and clear, making rte_event_port_unlinks_in_progress() report completion before the scheduler has seen the unlink. Nothing orders the scheduler's later cq map reads against the counter test on a weakly ordered CPU either.

Make the counter atomic: release fetch-add on unlink, acquire exchange to clear. The exchange cannot lose a concurrent increment, and the acquire guarantees the scheduler only acks unlinks whose cq map update it can observe, replacing the full barrier in unlink.

Quoted 4 lines
Fixes bd5ac24fea88 ("event/sw: implement unlinks in progress function")
#33 lore raw

RFC 16/32 event/sw: replace SMP barriers with C11 atomics

In reply to Stephen Hemminger

The write barrier plus plain store publish patterns (cq map count, port initialized, device started) become release stores; the barrier after clearing started in sw_stop() becomes a release fence. All are control path.

Scheduler reads of cq_num_mapped_cqs stay plain loads: acquire loads would land in the inner scheduling loops on weakly ordered CPUs. The transient window where a new count is visible before the map entry on such CPUs predates this change and is unchanged by it; unlink is covered by the counter handshake.

---
 drivers/event/sw/sw_evdev.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)
drivers/event/sw/sw_evdev.c +20 -9
index bb6f50e03b..bdb3dff997 100644
@@ -84,8 +84,10 @@ sw_port_link(struct rte_eventdev *dev, void *port, const uint8_t queues[],
 		}
 
 		q->cq_map[q->cq_num_mapped_cqs] = p->id;
-		rte_smp_wmb();
-		q->cq_num_mapped_cqs++;
+		/* Release publishes the map entry before the new count */
+		rte_atomic_store_explicit(
+			(uint32_t __rte_atomic *)&q->cq_num_mapped_cqs,
+			q->cq_num_mapped_cqs + 1, rte_memory_order_release);
 	}
 	return i;
 }
@@ -105,8 +107,14 @@ sw_port_unlink(struct rte_eventdev *dev, void *port, uint8_t queues[],
 			if (q->cq_map[j] == p->id) {
 				q->cq_map[j] =
 					q->cq_map[q->cq_num_mapped_cqs - 1];
-				rte_smp_wmb();
-				q->cq_num_mapped_cqs--;
+				/* Release publishes the map update
+				 * before the new count
+				 */
+				rte_atomic_store_explicit(
+					(uint32_t __rte_atomic *)
+						&q->cq_num_mapped_cqs,
+					q->cq_num_mapped_cqs - 1,
+					rte_memory_order_release);
 				unlinked++;
 
 				p->num_qids_mapped--;
@@ -208,8 +216,9 @@ sw_port_setup(struct rte_eventdev *dev, uint8_t port_id,
 	}
 	dev->data->ports[port_id] = p;
 
-	rte_smp_wmb();
-	p->initialized = 1;
+	/* Release publishes the port setup before initialized flag */
+	rte_atomic_store_explicit((uint8_t __rte_atomic *)&p->initialized, 1,
+				  rte_memory_order_release);
 	return 0;
 }
 
@@ -815,8 +824,9 @@ sw_start(struct rte_eventdev *dev)
 	if (sw_xstats_init(sw) < 0)
 		return -EINVAL;
 
-	rte_smp_wmb();
-	sw->started = 1;
+	/* Release publishes device state before the started flag */
+	rte_atomic_store_explicit((uint8_t __rte_atomic *)&sw->started, 1,
+				  rte_memory_order_release);
 
 	return 0;
 }
@@ -845,7 +855,8 @@ sw_stop(struct rte_eventdev *dev)
 	sw_clean_qid_iqs(dev);
 	sw_xstats_uninit(sw);
 	sw->started = 0;
-	rte_smp_wmb();
+	/* Order the started store before re-enabling the service */
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	if (runstate == 1)
 		rte_service_runstate_set(sw->service_id, 1);
Signature · 1 line
2.53.0
#34 lore raw

RFC 17/32 eal/x86: move optimized fence out of SMP barrier

In reply to Stephen Hemminger

rte_atomic_thread_fence() implemented the seq_cst case by calling the deprecated rte_smp_mb(). Invert the dependency: the lock add based fence moves into rte_atomic_thread_fence() and rte_smp_mb() becomes a wrapper around it, so removing the deprecated barriers later is a pure deletion. The optimization itself must stay; a plain seq_cst fence is an mfence, about twice the cost. No change in generated code.

Drop no longer used rte_smp_mb().

---
 lib/eal/x86/include/rte_atomic.h | 37 ++++++++++++++------------------
 1 file changed, 16 insertions(+), 21 deletions(-)
lib/eal/x86/include/rte_atomic.h +16 -21
index e071e4234e..780fdce871 100644
@@ -60,23 +60,8 @@ extern "C" {
  * Basic idea is to use lock prefixed add with some dummy memory location
  * as the destination. From their experiments 128B(2 cache lines) below
  * current stack pointer looks like a good candidate.
- * So below we use that technique for rte_smp_mb() implementation.
  */
 
-static __rte_always_inline void
-rte_smp_mb(void)
-{
-#ifdef RTE_TOOLCHAIN_MSVC
-	_mm_mfence();
-#else
-#ifdef RTE_ARCH_I686
-	asm volatile("lock addl $0, -128(%%esp); " ::: "memory");
-#else
-	asm volatile("lock addl $0, -128(%%rsp); " ::: "memory");
-#endif
-#endif
-}
-
 #define rte_io_mb() rte_mb()
 
 #define rte_io_wmb() rte_compiler_barrier()
@@ -86,17 +71,27 @@ rte_smp_mb(void)
 /**
  * Synchronization fence between threads based on the specified memory order.
  *
- * On x86 the __rte_atomic_thread_fence(rte_memory_order_seq_cst) generates full 'mfence'
- * which is quite expensive. The optimized implementation of rte_smp_mb is
- * used instead.
+ * On x86 the __rte_atomic_thread_fence(rte_memory_order_seq_cst) generates
+ * a full 'mfence' which is quite expensive. The optimized lock add on a
+ * dummy stack location (see above) is used instead.
  */
 static __rte_always_inline void
 rte_atomic_thread_fence(rte_memory_order memorder)
 {
-	if (memorder == rte_memory_order_seq_cst)
-		rte_smp_mb();
-	else
+	if (memorder != rte_memory_order_seq_cst) {
 		__rte_atomic_thread_fence(memorder);
+		return;
+	}
+
+#ifdef RTE_TOOLCHAIN_MSVC
+	_mm_mfence();
+#else
+#ifdef RTE_ARCH_I686
+	asm volatile("lock addl $0, -128(%%esp); " ::: "memory");
+#else
+	asm volatile("lock addl $0, -128(%%rsp); " ::: "memory");
+#endif
+#endif
 }
 
 #ifdef __cplusplus
Signature · 1 line
2.53.0
Acked-by on v1 17/32
#35 lore raw

RE: [RFC 17/32] eal/x86: move optimized fence out of SMP barrier

Quoted 71 lines

rte_atomic_thread_fence() implemented the seq_cst case by calling the deprecated rte_smp_mb(). Invert the dependency: the lock add based fence moves into rte_atomic_thread_fence() and rte_smp_mb() becomes a wrapper around it, so removing the deprecated barriers later is a pure deletion. The optimization itself must stay; a plain seq_cst fence is an mfence, about twice the cost. No change in generated code.

Drop no longer used rte_smp_mb().

---
 lib/eal/x86/include/rte_atomic.h | 37 ++++++++++++++------------------
 1 file changed, 16 insertions(+), 21 deletions(-)
lib/eal/x86/include/rte_atomic.h +0 -16
index e071e4234e..780fdce871 100644
@@ -60,23 +60,8 @@ extern "C" {
  * Basic idea is to use lock prefixed add with some dummy memory location
  * as the destination. From their experiments 128B(2 cache lines) below
  * current stack pointer looks like a good candidate.
- * So below we use that technique for rte_smp_mb() implementation.
  */
 
-static __rte_always_inline void
-rte_smp_mb(void)
-{
-#ifdef RTE_TOOLCHAIN_MSVC
-	_mm_mfence();
-#else
-#ifdef RTE_ARCH_I686
-	asm volatile("lock addl $0, -128(%%esp); " ::: "memory");
-#else
-	asm volatile("lock addl $0, -128(%%rsp); " ::: "memory");
-#endif
-#endif
-}
-
 #define rte_io_mb() rte_mb()
 
 #define rte_io_wmb() rte_compiler_barrier()
@@ -86,17 +71,27 @@ rte_smp_mb(void)
 /**
  * Synchronization fence between threads based on the specified memory order.
  *
- * On x86 the __rte_atomic_thread_fence(rte_memory_order_seq_cst)

generates full 'mfence'
- * which is quite expensive. The optimized implementation of rte_smp_mb is
- * used instead.
+ * On x86 the __rte_atomic_thread_fence(rte_memory_order_seq_cst) generates
+ * a full 'mfence' which is quite expensive. The optimized lock add on a
+ * dummy stack location (see above) is used instead.
*/
static __rte_always_inline void rte_atomic_thread_fence(rte_memory_order memorder)
{

lib/eal/x86/include/rte_atomic.h +7 -3
-	if (memorder == rte_memory_order_seq_cst)
-		rte_smp_mb();
-	else
+	if (memorder != rte_memory_order_seq_cst) {
 		__rte_atomic_thread_fence(memorder);
+		return;
+	}
+
+#ifdef RTE_TOOLCHAIN_MSVC
+	_mm_mfence();
+#else

lib/eal/x86/include/rte_atomic.h rte_smp_mb(void)

Quoted 10 lines
lib/eal/x86/include/rte_atomic.h +6 -1
+#ifdef RTE_ARCH_I686
+	asm volatile("lock addl $0, -128(%%esp); " ::: "memory");
+#else
+	asm volatile("lock addl $0, -128(%%rsp); " ::: "memory");
+#endif
+#endif
 }
 
 #ifdef __cplusplus
--
Quoted 1 line

2.53.0

#36 lore raw

RFC 18/32 common/octeontx: remove redundant barrier in mbox

In reply to Stephen Hemminger

The SMP write barrier between writing the mailbox header and ringing the mailbox register is redundant: rte_write64() begins with rte_io_wmb(), which already orders the header write before the trigger, and does so against the device rather than only within the inner shareable domain.

---
 drivers/common/octeontx/octeontx_mbox.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/common/octeontx/octeontx_mbox.c +4 -2
index 9e0bbf453f..8b0da3a98e 100644
@@ -113,8 +113,10 @@ mbox_send_request(struct mbox *m, struct octeontx_mbox_hdr *hdr,
 
 	/* Write the msg header */
 	rte_write64(new_hdr.u64, ram_mbox_hdr);
-	rte_smp_wmb();
-	/* Notify PF about the new msg - write to MBOX reg generates PF IRQ */
+	/* Notify PF about the new msg - write to MBOX reg generates PF IRQ.
+	 * rte_write64() issues rte_io_wmb() which orders the header write
+	 * before the trigger; no separate barrier is needed.
+	 */
 	rte_write64(0, m->reg);
 }
 
Signature · 1 line
2.53.0
#37 lore raw

RFC 19/32 crypto/caam_jr: use IO barrier before job ring doorbell

In reply to Stephen Hemminger

The barrier orders the input ring descriptor write in DMA memory against the MMIO doorbell write. That is device ordering, not SMP
ordering: rte_io_wmb() is the correct barrier, and on arm64 the inner shareable dmb the SMP barrier generated was not sufficient to order against the device in the first place.

---
 drivers/crypto/caam_jr/caam_jr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/crypto/caam_jr/caam_jr.c +2 -1
index 1f97e72337..7a345c436e 100644
@@ -1451,7 +1451,8 @@ caam_jr_enqueue_op(struct rte_crypto_op *op, struct caam_jr_qp *qp)
 	/* Set ptr in input ring to current descriptor	*/
 	sec_write_addr(&ring->input_ring[ring->pidx],
 			(phys_addr_t)caam_jr_vtop_ctx(ctx, ctx->jobdes.desc));
-	rte_smp_wmb();
+	/* Descriptor must be visible to the device before the doorbell */
+	rte_io_wmb();
 
 	/* Notify HW that a new job is enqueued */
 	hw_enqueue_desc_on_job_ring(ring);
Signature · 1 line
2.53.0
Acked-by on v1 19/32
#38 lore raw

Re: [RFC 19/32] crypto/caam_jr: use IO barrier before job ring doorbell

Quoted 7 lines · Stephen Hemminger

The barrier orders the input ring descriptor write in DMA memory against the MMIO doorbell write. That is device ordering, not SMP
ordering: rte_io_wmb() is the correct barrier, and on arm64 the inner shareable dmb the SMP barrier generated was not sufficient to order against the device in the first place.

Quoted 18 lines
---
  drivers/crypto/caam_jr/caam_jr.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/crypto/caam_jr/caam_jr.c +2 -1
index 1f97e72337..7a345c436e 100644
@@ -1451,7 +1451,8 @@ caam_jr_enqueue_op(struct rte_crypto_op *op, struct caam_jr_qp *qp)
  	/* Set ptr in input ring to current descriptor	*/
  	sec_write_addr(&ring->input_ring[ring->pidx],
  			(phys_addr_t)caam_jr_vtop_ctx(ctx, ctx->jobdes.desc));
-	rte_smp_wmb();
+	/* Descriptor must be visible to the device before the doorbell */
+	rte_io_wmb();
 
  	/* Notify HW that a new job is enqueued */
  	hw_enqueue_desc_on_job_ring(ring);
#39 lore raw

RFC 20/32 crypto/octeontx: use IO barrier before doorbell

In reply to Stephen Hemminger

The doorbell is written with rte_write64_relaxed(), so the barrier before it is what orders the queued instructions against the device. That is device ordering, not SMP ordering: use rte_io_wmb().

---
 drivers/crypto/octeontx/otx_cryptodev_hw_access.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/crypto/octeontx/otx_cryptodev_hw_access.h +2 -2
index 3104e6d31e..096dcf8f87 100644
@@ -203,8 +203,8 @@ static __rte_always_inline void
 otx_cpt_ring_dbell(struct cpt_instance *instance, uint16_t count)
 {
 	struct cpt_vf *cptvf = (struct cpt_vf *)instance;
-	/* Memory barrier to flush pending writes */
-	rte_smp_wmb();
+	/* Instructions must be visible to the device before the doorbell */
+	rte_io_wmb();
 	otx_cpt_write_vq_doorbell(cptvf, count);
 }
 
Signature · 1 line
2.53.0
#40 lore raw

RFC 21/32 mempool/octeontx: use IO barrier in pool destroy

In reply to Stephen Hemminger

The barrier flushes outstanding writes to the FPA pool before the teardown mailbox sequence. That is ordering against the device, so use rte_io_wmb(). Control path.

---
 drivers/mempool/octeontx/octeontx_fpavf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mempool/octeontx/octeontx_fpavf.c +2 -2
index 6cd0fc057f..7051422cb7 100644
@@ -616,8 +616,8 @@ octeontx_fpa_bufpool_destroy(uintptr_t handle, int node_id)
 
 	RTE_SET_USED(node_id);
 
-	/* Wait for all outstanding writes to be committed */
-	rte_smp_wmb();
+	/* Make outstanding pool writes visible to the device */
+	rte_io_wmb();
 
 	if (unlikely(!octeontx_fpa_handle_valid(handle)))
 		return -EINVAL;
Signature · 1 line
2.53.0
#41 lore raw

RFC 22/32 event/octeontx: replace deprecated SMP barriers

In reply to Stephen Hemminger

The worker barriers order event payload writes in normal memory before the add work or tag switch store to the SSO device, so they are IO ordering: use rte_io_wmb(). The selftest barriers publish worker parameters before launching lcores; convert them to release fences.

---
 drivers/event/octeontx/ssovf_evdev_selftest.c | 6 +++---
 drivers/event/octeontx/ssovf_worker.c         | 8 ++++----
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/event/octeontx/ssovf_evdev_selftest.c +3 -3
index b54ae126d2..614f9bbaef 100644
@@ -65,7 +65,7 @@ seqn_list_update(int val)
 		return -1;
 
 	seqn_list[seqn_list_index++] = val;
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 	return 0;
 }
 
@@ -637,7 +637,7 @@ launch_workers_and_wait(int (*main_worker)(void *),
 	param[0].sched_type = sched_type;
 	param[0].port = 0;
 	param[0].dequeue_tmo_ticks = dequeue_tmo_ticks;
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	w_lcore = rte_get_next_lcore(
 			/* start core */ -1,
@@ -650,7 +650,7 @@ launch_workers_and_wait(int (*main_worker)(void *),
 		param[port].sched_type = sched_type;
 		param[port].port = port;
 		param[port].dequeue_tmo_ticks = dequeue_tmo_ticks;
-		rte_smp_wmb();
+		rte_atomic_thread_fence(rte_memory_order_release);
 		w_lcore = rte_get_next_lcore(w_lcore, 1, 0);
 		rte_eal_remote_launch(worker, &param[port], w_lcore);
 	}
drivers/event/octeontx/ssovf_worker.c +4 -4
index 89b5dc056c..f3c6a0da5c 100644
@@ -59,10 +59,10 @@ ssows_fwd_group(struct ssows *ws, const struct rte_event *ev, const uint8_t grp)
 		newtag |= grp << 20;
 		newtag |= tag;
 		ssows_swtag_norm(ws, newtag, SSO_SYNC_ATOMIC);
-		rte_smp_wmb();
+		rte_io_wmb();
 		ssows_swtag_wait(ws);
 	} else {
-		rte_smp_wmb();
+		rte_io_wmb();
 	}
 	ssows_add_work(ws, event_ptr, tag, new_tt, grp);
 }
@@ -158,7 +158,7 @@ ssows_enq_burst(void *port, const struct rte_event ev[], uint16_t nb_events)
 
 	switch (ev->op) {
 	case RTE_EVENT_OP_NEW:
-		rte_smp_wmb();
+		rte_io_wmb();
 		ssows_new_event(ws, ev);
 		break;
 	case RTE_EVENT_OP_FORWARD:
@@ -179,7 +179,7 @@ ssows_enq_new_burst(void *port, const struct rte_event ev[], uint16_t nb_events)
 	uint16_t i;
 	struct ssows *ws = port;
 
-	rte_smp_wmb();
+	rte_io_wmb();
 	for (i = 0; i < nb_events; i++)
 		ssows_new_event(ws,  &ev[i]);
 
Signature · 1 line
2.53.0
#42 lore raw

RFC 23/32 event/dpaa2: replace deprecated barrier in selftest

In reply to Stephen Hemminger

Publish worker parameters with a release fence before launching the lcores instead of the deprecated SMP write barrier.

---
 drivers/event/dpaa2/dpaa2_eventdev_selftest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/event/dpaa2/dpaa2_eventdev_selftest.c +2 -2
index 9d4938efe6..12c1bc9878 100644
@@ -524,7 +524,7 @@ launch_workers_and_wait(int (*main_worker)(void *),
 	param[0].sched_type = sched_type;
 	param[0].port = 0;
 	param[0].dequeue_tmo_ticks = dequeue_tmo_ticks;
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	w_lcore = rte_get_next_lcore(
 			/* start core */ -1,
@@ -537,7 +537,7 @@ launch_workers_and_wait(int (*main_worker)(void *),
 		param[port].sched_type = sched_type;
 		param[port].port = port;
 		param[port].dequeue_tmo_ticks = dequeue_tmo_ticks;
-		rte_smp_wmb();
+		rte_atomic_thread_fence(rte_memory_order_release);
 		w_lcore = rte_get_next_lcore(w_lcore, 1, 0);
 		rte_eal_remote_launch(workers, &param[port], w_lcore);
 	}
Signature · 1 line
2.53.0
#44 lore raw

RFC 24/32 event/dsw: replace SMP barriers with release fences

In reply to Stephen Hemminger

All four barriers publish flow table or ring updates before a control message enqueue, which is release ordering. All are on the migration control path, not per event.

The fences may in fact be removable: the control messages travel through rte_ring, whose producer tail update is itself a release store covering the preceding writes. Left in place here to keep this a like for like conversion.

---
 drivers/event/dsw/dsw_event.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/event/dsw/dsw_event.c +4 -4
index 399d9f050e..82d3636b29 100644
@@ -339,7 +339,7 @@ dsw_port_handle_pause_flows(struct dsw_evdev *dsw, struct dsw_port *port,
 	/* Make sure any stores to the original port's in_ring is seen
 	 * before the ctl message.
 	 */
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	dsw_port_ctl_enqueue(&dsw->ports[originating_port_id], &cfm);
 }
@@ -821,7 +821,7 @@ dsw_port_move_parallel_flows(struct dsw_evdev *dsw,
 		}
 	}
 
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	dsw_port_end_emigration(dsw, source_port, RTE_SCHED_TYPE_PARALLEL);
 }
@@ -1190,7 +1190,7 @@ dsw_port_move_emigrating_flows(struct dsw_evdev *dsw,
 		    dest_port_id;
 	}
 
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	dsw_port_drain_in_ring(source_port);
 	dsw_port_forward_emigrated_flows(dsw, source_port);
@@ -1213,7 +1213,7 @@ dsw_port_move_emigrating_flows(struct dsw_evdev *dsw,
 	/* Flow table update and migration destination port's enqueues
 	 * must be seen before the control message.
 	 */
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	dsw_port_ctl_broadcast(dsw, source_port, DSW_CTL_UNPAUSE_REQ,
 			       source_port->emigration_target_qfs,
Signature · 1 line
2.53.0
Reviewed-by on v1 24/32
#45 lore raw

Re: [RFC 24/32] event/dsw: replace SMP barriers with release fences

Quoted 9 lines · Stephen Hemminger

All four barriers publish flow table or ring updates before a control message enqueue, which is release ordering. All are on the migration control path, not per event.

The fences may in fact be removable: the control messages travel through rte_ring, whose producer tail update is itself a release store covering the preceding writes. Left in place here to keep this a like for like conversion.

I also suspect you can remove some or all of these. Not sure it's worth the trouble though.

Quoted 37 lines
---
  drivers/event/dsw/dsw_event.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
drivers/event/dsw/dsw_event.c +3 -3
index 399d9f050e..82d3636b29 100644
@@ -339,7 +339,7 @@ dsw_port_handle_pause_flows(struct dsw_evdev *dsw, struct dsw_port *port,
  	/* Make sure any stores to the original port's in_ring is seen
  	 * before the ctl message.
  	 */
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
  	dsw_port_ctl_enqueue(&dsw->ports[originating_port_id], &cfm);
  }
@@ -821,7 +821,7 @@ dsw_port_move_parallel_flows(struct dsw_evdev *dsw,
  		}
  	}
 
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
  	dsw_port_end_emigration(dsw, source_port, RTE_SCHED_TYPE_PARALLEL);
  }
@@ -1190,7 +1190,7 @@ dsw_port_move_emigrating_flows(struct dsw_evdev *dsw,
  		    dest_port_id;
  	}
 
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
  	dsw_port_drain_in_ring(source_port);
  	dsw_port_forward_emigrated_flows(dsw, source_port);

drivers/event/dsw/dsw_event.c dsw_port_move_emigrating_flows(struct dsw_evdev *dsw, · line 1219

Quoted 8 lines
drivers/event/dsw/dsw_event.c +1 -1
@@ -1213,7 +1213,7 @@ dsw_port_move_emigrating_flows(struct dsw_evdev *dsw,
  	/* Flow table update and migration destination port's enqueues
  	 * must be seen before the control message.
  	 */
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
  	dsw_port_ctl_broadcast(dsw, source_port, DSW_CTL_UNPAUSE_REQ,
  			       source_port->emigration_target_qfs,
#46 lore raw

RFC 25/32 event/opdl: replace SMP barriers with C11 atomics

In reply to Stephen Hemminger

Publishing the port becomes a release store of the configured flag; the barrier after clearing started becomes a release fence. Both are control path.

---
 drivers/event/opdl/opdl_evdev.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/event/opdl/opdl_evdev.c +4 -3
index ffa65ef930..1450fa5ae8 100644
@@ -200,8 +200,9 @@ opdl_port_setup(struct rte_eventdev *dev,
 	p->queue_id = OPDL_INVALID_QID;
 	p->external_qid = OPDL_INVALID_QID;
 	dev->data->ports[port_id] = p;
-	rte_smp_wmb();
-	p->configured = 1;
+	/* Release publishes port setup before the configured flag */
+	rte_atomic_store_explicit((uint8_t __rte_atomic *)&p->configured, 1,
+				  rte_memory_order_release);
 	device->nb_ports++;
 	return 0;
 }
@@ -477,7 +478,7 @@ opdl_stop(struct rte_eventdev *dev)
 
 	device->started = 0;
 
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 }
 
 static int
Signature · 1 line
2.53.0
#47 lore raw

RFC 26/32 net/netvsc: replace SMP barrier in RNDIS response

In reply to Stephen Hemminger

Publishing the copied response before clearing the pending id is release ordering. The following cmpset is a full barrier today, but keep the explicit fence so the ordering survives when cmpset is converted to a release compare exchange.

---
 drivers/net/netvsc/hn_rndis.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/netvsc/hn_rndis.c +1 -1
index 7c54eebcef..d1142fa1dd 100644
@@ -357,7 +357,7 @@ void hn_rndis_receive_response(struct hn_data *hv,
 	memcpy(hv->rndis_resp, data, len);
 
 	/* make sure response copied before update */
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	if (rte_atomic32_cmpset(&hv->rndis_pending, hdr->rid, 0) == 0) {
 		PMD_DRV_LOG(NOTICE,
Signature · 1 line
2.53.0
#48 lore raw

RFC 27/32 net/thunderx: replace deprecated SMP barriers

In reply to Stephen Hemminger

Redefine the nicvf barrier wrappers as C11 fences and add an IO variant. The RBDR refill barrier orders descriptor writes in DMA memory against the doorbell register write, which is device
ordering: use the IO barrier there. The mailbox flag barriers are genuine inter thread ordering and become release/acquire fences.

---
 drivers/net/thunderx/base/nicvf_hw.c   | 3 ++-
 drivers/net/thunderx/base/nicvf_plat.h | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/net/thunderx/base/nicvf_hw.c +2 -1
index 5b1abe2015..d1e31ffdaa 100644
@@ -499,7 +499,8 @@ nicvf_qset_rbdr_precharge(void *dev, struct nicvf *nic,
 			break;
 		}
 	}
-	nicvf_smp_wmb();
+	/* Descriptors must be visible to the device before the doorbell */
+	nicvf_io_wmb();
 	nicvf_queue_reg_write(nic, NIC_QSET_RBDR_0_1_DOOR, ridx, count);
 	rbdr->tail = nicvf_queue_reg_read(nic,
 				NIC_QSET_RBDR_0_1_TAIL, ridx) >> 3;
drivers/net/thunderx/base/nicvf_plat.h +2 -1
index 7d22563035..08ebb0cf62 100644
@@ -25,8 +25,9 @@
 
 /* barrier */
 #include <rte_atomic.h>
-#define nicvf_smp_wmb() rte_smp_wmb()
+#define nicvf_smp_wmb() rte_atomic_thread_fence(rte_memory_order_release)
 #define nicvf_smp_rmb() rte_atomic_thread_fence(rte_memory_order_acquire)
+#define nicvf_io_wmb() rte_io_wmb()
 
 /* utils */
 #include <rte_common.h>
Signature · 1 line
2.53.0
#49 lore raw

RFC 28/32 net/virtio: replace deprecated barrier in avail index update

In reply to Stephen Hemminger

The x86 special case keeps its shape: a release fence is the same compiler barrier the SMP write barrier was, so the measured perf reason for the branch is preserved.

---
 drivers/net/virtio/virtqueue.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/net/virtio/virtqueue.h +6 -6
index 37fbd47d42..cd954108a8 100644
@@ -474,14 +474,14 @@ static inline void
 vq_update_avail_idx(struct virtqueue *vq)
 {
 	if (vq->hw->weak_barriers) {
-	/* x86 prefers to using rte_smp_wmb over rte_atomic_store_explicit as
-	 * it reports a slightly better perf, which comes from the
-	 * saved branch by the compiler.
-	 * The if and else branches are identical with the smp and
-	 * io barriers both defined as compiler barriers on x86.
+	/* x86 prefers a fence plus plain store over
+	 * rte_atomic_store_explicit as it reports a slightly better
+	 * perf, which comes from the saved branch by the compiler.
+	 * The if and else branches are identical with the release
+	 * and io barriers both compiler barriers on x86.
 	 */
 #ifdef RTE_ARCH_X86_64
-		rte_smp_wmb();
+		rte_atomic_thread_fence(rte_memory_order_release);
 		vq->vq_split.ring.avail->idx = vq->vq_avail_idx;
 #else
 		rte_atomic_store_explicit(&vq->vq_split.ring.avail->idx,
Signature · 1 line
2.53.0
#50 lore raw

RFC 29/32 eal: remove stale SMP barrier in rte_service

In reply to Stephen Hemminger

Leftover missed by the C11 atomics conversion of this file. The barrier pairs with nothing: no store follows it, and the next use of the lcore is synchronized by remote launch.

---
 lib/eal/common/rte_service.c | 1 -
 1 file changed, 1 deletion(-)
lib/eal/common/rte_service.c +0 -1
index d2ac9d3f14..0c6467285b 100644
@@ -795,7 +795,6 @@ rte_service_lcore_del(uint32_t lcore)
 
 	set_lcore_state(lcore, ROLE_RTE);
 
-	rte_smp_wmb();
 	return 0;
 }
 
Signature · 1 line
2.53.0
#51 lore raw

RFC 30/32 eal: remove rte_smp_XX

In reply to Stephen Hemminger

These functions were marked for deprecation and no longer used. Drop from EAL.

---
 lib/eal/arm/include/rte_atomic_32.h    |  6 ---
 lib/eal/arm/include/rte_atomic_64.h    |  6 ---
 lib/eal/include/generic/rte_atomic.h   | 61 --------------------------
 lib/eal/loongarch/include/rte_atomic.h |  6 ---
 lib/eal/ppc/include/rte_atomic.h       |  6 ---
 lib/eal/riscv/include/rte_atomic.h     |  6 ---
 lib/eal/x86/include/rte_atomic.h       |  4 --
 7 files changed, 95 deletions(-)
lib/eal/arm/include/rte_atomic_32.h +0 -6
index 0b9a0dfa30..3809ddefb7 100644
@@ -21,12 +21,6 @@ extern "C" {
 
 #define	rte_rmb() __sync_synchronize()
 
-#define rte_smp_mb() rte_mb()
-
-#define rte_smp_wmb() rte_wmb()
-
-#define rte_smp_rmb() rte_rmb()
-
 #define rte_io_mb() rte_mb()
 
 #define rte_io_wmb() rte_wmb()
lib/eal/arm/include/rte_atomic_64.h +0 -6
index 181bb60929..c9b41f6212 100644
@@ -24,12 +24,6 @@ extern "C" {
 
 #define rte_rmb() asm volatile("dmb oshld" : : : "memory")
 
-#define rte_smp_mb() asm volatile("dmb ish" : : : "memory")
-
-#define rte_smp_wmb() asm volatile("dmb ishst" : : : "memory")
-
-#define rte_smp_rmb() asm volatile("dmb ishld" : : : "memory")
-
 #define rte_io_mb() rte_mb()
 
 #define rte_io_wmb() rte_wmb()
lib/eal/include/generic/rte_atomic.h +0 -61

67 lines not on this page · raw message

lib/eal/loongarch/include/rte_atomic.h +0 -6
index c8066a4612..49e0c67020 100644
@@ -22,12 +22,6 @@ extern "C" {
 
 #define rte_rmb()	rte_mb()
 
-#define rte_smp_mb()	rte_mb()
-
-#define rte_smp_wmb()	rte_mb()
-
-#define rte_smp_rmb()	rte_mb()
-
 #define rte_io_mb()	rte_mb()
 
 #define rte_io_wmb()	rte_mb()
lib/eal/ppc/include/rte_atomic.h +0 -6
index 10acc238f9..1da5afccbf 100644
@@ -24,12 +24,6 @@ extern "C" {
 
 #define	rte_rmb() asm volatile("sync" : : : "memory")
 
-#define rte_smp_mb() rte_mb()
-
-#define rte_smp_wmb() rte_wmb()
-
-#define rte_smp_rmb() rte_rmb()
-
 #define rte_io_mb() rte_mb()
 
 #define rte_io_wmb() rte_wmb()
lib/eal/riscv/include/rte_atomic.h +0 -6
index 66346ad474..dd10ad5127 100644
@@ -27,12 +27,6 @@ extern "C" {
 
 #define rte_rmb()	asm volatile("fence r, r" : : : "memory")
 
-#define rte_smp_mb()	rte_mb()
-
-#define rte_smp_wmb()	rte_wmb()
-
-#define rte_smp_rmb()	rte_rmb()
-
 #define rte_io_mb()	asm volatile("fence iorw, iorw" : : : "memory")
 
 #define rte_io_wmb()	asm volatile("fence orw, ow" : : : "memory")
lib/eal/x86/include/rte_atomic.h +0 -4
index 780fdce871..826b5033d1 100644
@@ -23,10 +23,6 @@
 
 #define	rte_rmb() _mm_lfence()
 
-#define rte_smp_wmb() rte_compiler_barrier()
-
-#define rte_smp_rmb() rte_compiler_barrier()
-
 #ifdef __cplusplus
 extern "C" {
 #endif
Signature · 1 line
2.53.0
#52 lore raw

RFC 31/32 checkpatches: no longer warn about rte_smp_XX

In reply to Stephen Hemminger

These macros/functions are now removed.
Any new use will be detected as compile errors.

---
 devtools/checkpatches.sh | 8 --------
 1 file changed, 8 deletions(-)
devtools/checkpatches.sh +0 -8
index 18bd825372..3649645488 100755
@@ -129,14 +129,6 @@ check_forbidden_additions() { # <patch>
 		-f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
 		"$1" || res=1
 
-	# refrain from new additions of rte_smp_[r/w]mb()
-	awk -v FOLDERS="lib drivers app examples" \
-		-v EXPRESSIONS="rte_smp_(r|w)?mb\\\(" \
-		-v RET_ON_FAIL=1 \
-		-v MESSAGE='Using rte_smp_[r/w]mb' \
-		-f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
-		"$1" || res=1
-
 	# refrain from using compiler __sync_xxx builtins
 	awk -v FOLDERS="lib drivers app examples" \
 		-v EXPRESSIONS="__sync_.*\\\(" \
Signature · 1 line
2.53.0
#53 lore raw

RFC 32/32 doc: update release notes about rte_smp_XX removal

In reply to Stephen Hemminger

The functions rte_smp_XX were previously marked for removal. The removal is now complete across the tree.

---
 doc/guides/rel_notes/deprecation.rst   | 7 -------
 doc/guides/rel_notes/release_26_11.rst | 6 ++++++
 2 files changed, 6 insertions(+), 7 deletions(-)
doc/guides/rel_notes/deprecation.rst +0 -7
index 6ad7698c6b..b310801b84 100644
@@ -46,13 +46,6 @@ Deprecation Notices
   operations must be used for patches that need to be merged in 20.08 onwards.
   This change will not introduce any performance degradation.
 
-* rte_smp_*mb: These APIs provide full barrier functionality. However, many
-  use cases do not require full barriers. To support such use cases, DPDK has
-  adopted atomic operations from
-  https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html. These
-  operations and a new wrapper ``rte_atomic_thread_fence`` instead of
-  ``__atomic_thread_fence`` must be used for patches that need to be merged in
-  20.08 onwards. This change will not introduce any performance degradation.
 
 * mempool: The ``flushthresh`` field in ``struct rte_mempool_cache`` is obsolete,
   and will be removed in DPDK 26.11.
doc/guides/rel_notes/release_26_11.rst +6 -0
index c8cc86295d..d9ebbac77b 100644
@@ -77,6 +77,12 @@ Removed Items
     ``rte_rib6_is_equal``
   * table: ``RTE_LPM_IPV6_ADDR_SIZE``
 
+* Removed SMP memory barriers:
+
+  * ``rte_smp_mb()`` replaced with ``rte_atomic_thread_fence(rte_memory_order_seq_cst)``
+  * ``rte_smp_rmb()`` replaced with ``rte_atomic_thread_fence(rte_memory_order_acquire)``
+  * ``rte_smp_wmb()`` revised code to use ``rte_atomic_load/store``
+
 
 API Changes
 -----------
Signature · 1 line
2.53.0
#54 lore raw

v2 cover remove rte_smp_XX barrier

In reply to Stephen Hemminger

This patch series completes the removal of rte_smp_XX barrier functions that was announced over five years ago (20.05).

In the process several cases of race conditions were found and fixed. See patches 3, 4, and 17. These are marked with Fixes:
tags and Cc: stable.

Most of this is mechanical with AI assistance, so strongly encourage maintainers to take a good look.

Functional and build run on x86 and ARM native.
Should have no functional change, but as previous cleanups of atomic have shown performance might be impacted by compiler bugs.

The lock-free stack patch measured faster than the generic version it replaces, up to 63% on a 32-core x86 box; the numbers are in that patch's commit message.

The RFC removed the barrier test outright.
Konstantin pointed out it still covers the custom x86 seq_cst fence, so patch 19 now keeps the Peterson lock test and rewrites it around rte_atomic_thread_fence(rte_memory_order_seq_cst) instead. Need some careful patch series ordering to keep this all bisect clean.

v2 - address review feedback

Stephen Hemminger (33):
bpf: replace deprecated SMP barriers with C11 fences bus/vmbus: remove packed attribute from ring buffer bus/vmbus: fix ring buffer ordering on weakly ordered CPUs bus/vmbus: fix missing acquire on receive ring index bus/vmbus: replace SMP barriers with C11 memory fences drivers/baseband: convert rte_smp_rmb to fence net/hinic: replace rte_smp_rmb
net/intel: replace rte_smp_rmb
net/virtio: replace rte_smp_rmb
net/thunderx: replace rte_smp_rmb
stack: always use C11 memory model implementation
ring: replace SMP read barrier with C11 acquire fence crypto/virtio: update comment reference to rte_smp_rmb crypto/caam_jr: replace rte_smp_rmb crypto/caam_jr: use IO barrier before job ring doorbell crypto/octeontx: use IO barrier before doorbell event/sw: fix unlinks in progress counter races event/sw: replace SMP barriers with C11 atomics test/barrier: test sequentially consistent fence only eal/x86: move optimized fence out of SMP barrier common/octeontx: remove redundant barrier in mbox mempool/octeontx: use IO barrier in pool destroy event/octeontx: replace deprecated SMP barriers event/dpaa2: replace deprecated barrier in selftest event/dsw: replace SMP barriers with release fences event/opdl: replace SMP barriers with C11 atomics net/netvsc: replace SMP barrier in RNDIS response net/thunderx: replace deprecated SMP barriers net/virtio: replace deprecated barrier in avail index update
eal: remove stale SMP barrier in rte_service
eal: remove rte_smp_XX
checkpatches: no longer warn about rte_smp_XX
doc: update release notes about rte_smp_XX removal

 app/test/test_barrier.c                       | 105 ++++--------
 devtools/checkpatches.sh                      |   8 -
 doc/guides/rel_notes/deprecation.rst          |   8 -
 doc/guides/rel_notes/release_26_11.rst        |  11 ++
 .../fpga_5gnr_fec/rte_fpga_5gnr_fec.c         |   8 +-
 drivers/baseband/fpga_lte_fec/fpga_lte_fec.c  |  12 +-
 drivers/bus/vmbus/private.h                   |  12 +-
 drivers/bus/vmbus/rte_vmbus_reg.h             |   4 +-
 drivers/bus/vmbus/vmbus_bufring.c             |  17 +-
 drivers/bus/vmbus/vmbus_channel.c             |  10 +-
 drivers/common/octeontx/octeontx_mbox.c       |   6 +-
 drivers/crypto/caam_jr/caam_jr.c              |   5 +-
 .../crypto/octeontx/otx_cryptodev_hw_access.h |   4 +-
 drivers/crypto/virtio/virtqueue.h             |   2 +-
 drivers/event/dpaa2/dpaa2_eventdev_selftest.c |   4 +-
 drivers/event/dsw/dsw_event.c                 |   8 +-
 drivers/event/octeontx/ssovf_evdev_selftest.c |   6 +-
 drivers/event/octeontx/ssovf_worker.c         |   8 +-
 drivers/event/opdl/opdl_evdev.c               |   7 +-
 drivers/event/sw/sw_evdev.c                   |  37 +++--
 drivers/event/sw/sw_evdev.h                   |   2 +-
 drivers/event/sw/sw_evdev_scheduler.c         |  17 +-
 drivers/mempool/octeontx/octeontx_fpavf.c     |   4 +-
 drivers/net/hinic/base/hinic_pmd_cmdq.c       |   3 +-
 drivers/net/hinic/base/hinic_pmd_mgmt.c       |   2 +-
 drivers/net/intel/ice/ice_rxtx.c              |   2 +-
 drivers/net/intel/ixgbe/ixgbe_rxtx.c          |   2 +-
 drivers/net/netvsc/hn_rndis.c                 |   2 +-
 drivers/net/thunderx/base/nicvf_hw.c          |   3 +-
 drivers/net/thunderx/base/nicvf_plat.h        |   5 +-
 drivers/net/virtio/virtqueue.h                |  18 +--
 lib/bpf/bpf_pkt.c                             |  25 ++-
 lib/eal/arm/include/rte_atomic_32.h           |   6 -
 lib/eal/arm/include/rte_atomic_64.h           |   6 -
 lib/eal/common/rte_service.c                  |   1 -
 lib/eal/include/generic/rte_atomic.h          |  61 -------
 lib/eal/loongarch/include/rte_atomic.h        |   6 -
 lib/eal/ppc/include/rte_atomic.h              |   6 -
 lib/eal/riscv/include/rte_atomic.h            |   6 -
 lib/eal/x86/include/rte_atomic.h              |  41 ++---
 lib/ring/rte_ring_gcc_pvt.h                   |   6 +-
 lib/stack/meson.build                         |   1 -
 lib/stack/rte_stack_lf.h                      |   4 -
 lib/stack/rte_stack_lf_generic.h              | 153 ------------------
 44 files changed, 208 insertions(+), 456 deletions(-)
 delete mode 100644 lib/stack/rte_stack_lf_generic.h
Signature · 1 line
2.53.0
#55 lore raw

PATCH v2 1/33 bpf: replace deprecated SMP barriers with C11 fences

The use counter is a seqcount, not a reference count: odd means the datapath is inside the callback, even means it is not. The two barriers around it play different roles.

In bpf_eth_cbi_inuse() the counter goes odd and the following loads of cb, bpf and jit must not be hoisted above that store. Ordering a store against later loads needs a full barrier, so rte_smp_mb() becomes a seq_cst thread fence.

In bpf_eth_cbi_unuse() the read barrier becomes an acquire fence. What must not happen there is the critical section loads sinking past the store that makes the counter even, which is load/store ordering, and that is what a standalone acquire fence provides. acq_rel would additionally order prior stores, but the read side only loads from the cbi and so has nothing to publish; it would only upgrade dmb ishld to dmb ish on the datapath for no benefit.

Same code generated on x86 and arm64.

Use relaxed loads and stores for the counter itself. With enable_stdatomic, the plain increment of an RTE_ATOMIC() field compiled to a seq_cst add, i.e. two locked operations per burst.

---
 lib/bpf/bpf_pkt.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
lib/bpf/bpf_pkt.c +17 -8
index f072fdaaed..c7b1019239 100644
@@ -80,9 +80,11 @@ static struct bpf_eth_cbh tx_cbh = {
 static __rte_always_inline void
 bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
 {
-	cbi->use++;
+	rte_atomic_store_explicit(&cbi->use,
+		rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed) + 1,
+		rte_memory_order_relaxed);
 	/* make sure no store/load reordering could happen */
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 }
 
 /*
@@ -91,9 +93,16 @@ bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
 static __rte_always_inline void
 bpf_eth_cbi_unuse(struct bpf_eth_cbi *cbi)
 {
-	/* make sure all previous loads are completed */
-	rte_smp_rmb();
-	cbi->use++;
+	/*
+	 * Make sure all previous loads are completed before the counter
+	 * goes even. Acquire is enough: the read side only loads from the
+	 * cbi, so there are no stores to publish and acq_rel would just
+	 * cost a stronger barrier on weakly ordered CPUs.
+	 */
+	rte_atomic_thread_fence(rte_memory_order_acquire);
+	rte_atomic_store_explicit(&cbi->use,
+		rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed) + 1,
+		rte_memory_order_relaxed);
 }
 
 /*
@@ -105,9 +114,9 @@ bpf_eth_cbi_wait(const struct bpf_eth_cbi *cbi)
 	uint32_t puse;
 
 	/* make sure all previous loads and stores are completed */
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
-	puse = cbi->use;
+	puse = rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed);
 
 	/* in use, busy wait till current RX/TX iteration is finished */
 	if ((puse & BPF_ETH_CBI_INUSE) != 0) {
@@ -439,7 +448,7 @@ bpf_eth_cbi_unload(struct bpf_eth_cbi *bc)
 {
 	/* mark this cbi as empty */
 	bc->cb = NULL;
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
 	/* make sure datapath doesn't use bpf anymore, then destroy bpf */
 	bpf_eth_cbi_wait(bc);
Signature · 1 line
2.53.0
#56 lore raw

Re: [PATCH v2 01/33] bpf: replace deprecated SMP barriers with C11 fences

Thanks for doing this. I see that comments were expanded since v1, but the code stayed the same. Using both atomic operations _and_ memory barriers looks redundant and misleading, and the original got away with just memory barriers. In the reviews to v1 there were different opinions on which way to choose, just barriers (for the minimal change) or just atomics, but I think we need to choose at most one.

Quoted 8 lines · Stephen Hemminger

The use counter is a seqcount, not a reference count: odd means the datapath is inside the callback, even means it is not. The two barriers around it play different roles.

In bpf_eth_cbi_inuse() the counter goes odd and the following loads of cb, bpf and jit must not be hoisted above that store. Ordering a store against later loads needs a full barrier, so rte_smp_mb() becomes a seq_cst thread fence.

This explanation probably belongs to the code, not commit message.

Quoted 7 lines

In bpf_eth_cbi_unuse() the read barrier becomes an acquire fence. What must not happen there is the critical section loads sinking past the store that makes the counter even, which is load/store ordering, and that is what a standalone acquire fence provides. acq_rel would additionally order prior stores, but the read side only loads from the cbi and so has nothing to publish; it would only upgrade dmb ishld to dmb ish on the datapath for no benefit.

The last part is not very readable for uninitiated. Perhaps it's better not to mix C abstract machine language with ARM instructions when justifying the solution.

#57 lore raw

RE: [PATCH v2 01/33] bpf: replace deprecated SMP barriers with C11 fences

In reply to Stephen Hemminger
Quoted 10 lines

The use counter is a seqcount, not a reference count: odd means the datapath is inside the callback, even means it is not. The two barriers around it play different roles.

In bpf_eth_cbi_inuse() the counter goes odd and the following loads of cb, bpf and jit must not be hoisted above that store. Ordering a store against later loads needs a full barrier, so rte_smp_mb() becomes a seq_cst thread fence.

Quoted 4 lines

In bpf_eth_cbi_unuse() the read barrier becomes an acquire fence. What must not happen there is the critical section loads sinking past the store that makes the counter even, which is load/store ordering, and that is what a standalone acquire fence provides.

Hmm.., as I remember 'acquire' serves as a hoist barrier. For sink barrier we do need 'release' semantics, no?

Quoted 20 lines

acq_rel would additionally order prior stores, but the read side only loads from the cbi and so has nothing to publish; it would only upgrade dmb ishld to dmb ish on the datapath for no benefit.

Same code generated on x86 and arm64.

Use relaxed loads and stores for the counter itself. With enable_stdatomic, the plain increment of an RTE_ATOMIC() field compiled to a seq_cst add, i.e. two locked operations per burst.

---
 lib/bpf/bpf_pkt.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
lib/bpf/bpf_pkt.c +0 -0
index f072fdaaed..c7b1019239 100644

lib/bpf/bpf_pkt.c static struct bpf_eth_cbh tx_cbh = { · line 86

Quoted 8 lines
lib/bpf/bpf_pkt.c +4 -1
@@ -80,9 +80,11 @@ static struct bpf_eth_cbh tx_cbh = {
 static __rte_always_inline void
 bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
 {
-	cbi->use++;
+	rte_atomic_store_explicit(&cbi->use,
+		rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed)
+ 1,
+		rte_memory_order_relaxed);

if we are using atomic_store anyway, might be we can unite it with explicit barrier below? i.e:
rte_atomic_store_explicit(&cbi->use,

	rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed) + 1,
	rte_memory_order_seq_cst);

?

I think Marat also mentioned such possibility here.

Quoted 10 lines
lib/bpf/bpf_pkt.c +1 -1
 	/* make sure no store/load reordering could happen */
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 }
 
 /*
@@ -91,9 +93,16 @@ bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
 static __rte_always_inline void
 bpf_eth_cbi_unuse(struct bpf_eth_cbi *cbi)
 {

lib/bpf/bpf_pkt.c bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi) · line 102

Quoted 10 lines
lib/bpf/bpf_pkt.c +7 -3
-	/* make sure all previous loads are completed */
-	rte_smp_rmb();
-	cbi->use++;
+	/*
+	 * Make sure all previous loads are completed before the counter
+	 * goes even. Acquire is enough: the read side only loads from the
+	 * cbi, so there are no stores to publish and acq_rel would just
+	 * cost a stronger barrier on weakly ordered CPUs.
+	 */
+	rte_atomic_thread_fence(rte_memory_order_acquire);

As it is a sink barrier, I think it should be 'release'. Again we probably unite it with atomic store below. rte_atomic_store_explicit(&cbi->use,

	 rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed) + 1,
	rte_memory_order_release);
Quoted 20 lines
lib/bpf/bpf_pkt.c +6 -2
+	rte_atomic_store_explicit(&cbi->use,
+		rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed)
+ 1,
+		rte_memory_order_relaxed);
 }
 
 /*
@@ -105,9 +114,9 @@ bpf_eth_cbi_wait(const struct bpf_eth_cbi *cbi)
 	uint32_t puse;
 
 	/* make sure all previous loads and stores are completed */
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
-	puse = cbi->use;
+	puse = rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed);
 
 	/* in use, busy wait till current RX/TX iteration is finished */
 	if ((puse & BPF_ETH_CBI_INUSE) != 0) {

lib/bpf/bpf_pkt.c bpf_eth_cbi_unload(struct bpf_eth_cbi *bc) · line 451

Quoted 5 lines
lib/bpf/bpf_pkt.c +1 -1
@@ -439,7 +448,7 @@ bpf_eth_cbi_unload(struct bpf_eth_cbi *bc)
 {
 	/* mark this cbi as empty */
 	bc->cb = NULL;
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);

In fact, that one seems unnecessary here (and smb_mb() too).
As we call bpf_eth_cbi_wait() straight after that, and first thing it does - calls smb_mb() itself. So we probably can just safely remove it here.

Quoted 5 lines
lib/bpf/bpf_pkt.c +0 -1
 	/* make sure datapath doesn't use bpf anymore, then destroy bpf */
 	bpf_eth_cbi_wait(bc);
--

2.53.0

#58 lore raw

PATCH v2 2/33 bus/vmbus: remove packed attribute from ring buffer

In reply to Stephen Hemminger

The attribute came from the FreeBSD structure this was copied from, which ends in a flexible array member for the ring data and is asserted to be page sized. DPDK computes the data offset from the page size instead and never declared that member, so nothing is left that packing affects: all remaining members are naturally aligned and the layout is identical without it.

Byte alignment does prevent atomic access to the ring indexes, which clang rejects with -Watomic-alignment.

---
 drivers/bus/vmbus/rte_vmbus_reg.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/bus/vmbus/rte_vmbus_reg.h +2 -2
index 6370a07f95..210328c877 100644
@@ -69,7 +69,7 @@ struct __rte_packed_begin vmbus_mon_page {
  * Buffer ring
  */
 
-struct __rte_packed_begin vmbus_bufring {
+struct vmbus_bufring {
 	volatile uint32_t windex;
 	volatile uint32_t rindex;
 
@@ -111,7 +111,7 @@ struct __rte_packed_begin vmbus_bufring {
 	 * page aligned and starts at rte_mem_page_size() from the beginning
 	 * of this structure
 	 */
-} __rte_packed_end;
+};
 
 /*
  * Channel packets
Signature · 1 line
2.53.0
Reviewed-by on v2 2/33
#59 lore raw

RE: [EXTERNAL] [PATCH v2 02/33] bus/vmbus: remove packed attribute from ring buffer

Quoted 17 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Monday, September 21, 2026 2:10 AM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; Wei Hu <[email protected]>
Subject: [EXTERNAL] [PATCH v2 02/33] bus/vmbus: remove packed attribute from ring buffer

The attribute came from the FreeBSD structure this was copied from, which ends in a flexible array member for the ring data and is asserted to be page sized. DPDK computes the data offset from the page size instead and never declared that member, so nothing is left that packing affects: all remaining members are naturally aligned and the layout is identical without it.

Quoted 4 lines

Byte alignment does prevent atomic access to the ring indexes, which clang rejects with -Watomic-alignment.

Reviewed-by [email protected]
Quoted 29 lines
---
 drivers/bus/vmbus/rte_vmbus_reg.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/bus/vmbus/rte_vmbus_reg.h +2 -3
index 6370a07f95..210328c877 100644
@@ -69,7 +69,7 @@ struct __rte_packed_begin vmbus_mon_page {
  * Buffer ring
  */
 
-struct __rte_packed_begin vmbus_bufring {
+struct vmbus_bufring {
 	volatile uint32_t windex;
 	volatile uint32_t rindex;
 
@@ -111,7 +111,7 @@ struct __rte_packed_begin vmbus_bufring {
 	 * page aligned and starts at rte_mem_page_size() from the beginning
 	 * of this structure
 	 */
-} __rte_packed_end;
+};
 
 /*
  * Channel packets
--

2.53.0

#60 lore raw

PATCH v2 3/33 bus/vmbus: fix ring buffer ordering on weakly ordered CPUs

In reply to Stephen Hemminger

The read index update in vmbus_rxbr_read() was only protected by a compiler barrier. On a weakly ordered architecture the store of rindex can become visible to the host before the data copy completes, allowing the host to reuse and overwrite ring data still being read. Use a release store for the read index.

The barrier in rte_vmbus_chan_signal_tx() must order the earlier ring index update against the load of the host interrupt mask, and a write barrier does not order stores against loads. Use a full fence, which matches virt_mb() in the equivalent Linux and FreeBSD code.

Neither change affects generated code on x86.

Fixes 831dba47bd36 ("bus/vmbus: add Hyper-V virtual bus support")
---
 drivers/bus/vmbus/vmbus_bufring.c | 11 +++++++----
 drivers/bus/vmbus/vmbus_channel.c |  4 ++--
 2 files changed, 9 insertions(+), 6 deletions(-)
drivers/bus/vmbus/vmbus_bufring.c +7 -4
index fcb97287dc..f622869974 100644
@@ -237,10 +237,13 @@ vmbus_rxbr_read(struct vmbus_br *rbr, void *data, size_t dlen, size_t skip)
 	 */
 	rindex = vmbus_br_idxinc(rindex, sizeof(uint64_t), br_dsize);
 
-	/* Update the read index _after_ the channel packet is fetched.	 */
-	rte_compiler_barrier();
-
-	vbr->rindex = rindex;
+	/*
+	 * Update the read index after the channel packet is fetched.
+	 * Release store ensures the host can not observe the new read
+	 * index before the data copy is complete.
+	 */
+	rte_atomic_store_explicit((volatile uint32_t __rte_atomic *)&vbr->rindex,
+				  rindex, rte_memory_order_release);
 
 	return 0;
 }
drivers/bus/vmbus/vmbus_channel.c +2 -2
index 6887fbad46..2648d8e3fd 100644
@@ -104,8 +104,8 @@ rte_vmbus_chan_signal_tx(struct rte_vmbus_device *dev, const struct vmbus_channe
 {
 	const struct vmbus_br *tbr = &chan->txbr;
 
-	/* Make sure all updates are done before signaling host */
-	rte_smp_wmb();
+	/* Order ring index update before reading host interrupt mask */
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
 	/* If host is ignoring interrupts? */
 	if (tbr->vbr->imask)
Signature · 1 line
2.53.0
Reviewed-by on v2 3/33
#61 lore raw

RE: [EXTERNAL] [PATCH v2 03/33] bus/vmbus: fix ring buffer ordering on weakly ordered CPUs

Quoted 21 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Monday, September 21, 2026 2:10 AM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; [email protected]; Long Li <[email protected]>; Wei Hu <[email protected]>
Subject: [EXTERNAL] [PATCH v2 03/33] bus/vmbus: fix ring buffer ordering on weakly ordered CPUs

The read index update in vmbus_rxbr_read() was only protected by a compiler barrier. On a weakly ordered architecture the store of rindex can become visible to the host before the data copy completes, allowing the host to reuse and overwrite ring data still being read. Use a release store for the read index.

The barrier in rte_vmbus_chan_signal_tx() must order the earlier ring index update against the load of the host interrupt mask, and a write barrier does not order stores against loads. Use a full fence, which matches virt_mb() in the equivalent Linux and FreeBSD code.

Quoted 7 lines

Neither change affects generated code on x86.

Fixes 831dba47bd36 ("bus/vmbus: add Hyper-V virtual bus support")
Quoted 48 lines
---
 drivers/bus/vmbus/vmbus_bufring.c | 11 +++++++----
drivers/bus/vmbus/vmbus_channel.c |  4 ++--
 2 files changed, 9 insertions(+), 6 deletions(-)
drivers/bus/vmbus/vmbus_bufring.c +7 -4
index fcb97287dc..f622869974 100644
@@ -237,10 +237,13 @@ vmbus_rxbr_read(struct vmbus_br *rbr, void
 *data, size_t dlen, size_t skip)
 	 */
 	rindex = vmbus_br_idxinc(rindex, sizeof(uint64_t), br_dsize);
 
-	/* Update the read index _after_ the channel packet is fetched.	 */
-	rte_compiler_barrier();
-
-	vbr->rindex = rindex;
+	/*
+	 * Update the read index after the channel packet is fetched.
+	 * Release store ensures the host can not observe the new read
+	 * index before the data copy is complete.
+	 */
+	rte_atomic_store_explicit((volatile uint32_t __rte_atomic *)&vbr-
 >rindex,
+				  rindex, rte_memory_order_release);
 
drivers/bus/vmbus/vmbus_bufring.c +0 -0
 	return 0;
 }
drivers/bus/vmbus/vmbus_channel.c +2 -3
index 6887fbad46..2648d8e3fd 100644
@@ -104,8 +104,8 @@ rte_vmbus_chan_signal_tx(struct rte_vmbus_device
 *dev, const struct vmbus_channe  {
 	const struct vmbus_br *tbr = &chan->txbr;
 
-	/* Make sure all updates are done before signaling host */
-	rte_smp_wmb();
+	/* Order ring index update before reading host interrupt mask */
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
 	/* If host is ignoring interrupts? */
 	if (tbr->vbr->imask)
--

2.53.0

#62 lore raw

PATCH v2 4/33 bus/vmbus: fix missing acquire on receive ring index

In reply to Stephen Hemminger

The receive path checks available data by reading the write index and then copies ring data. The link between the two is only the comparison, a control dependency, which does not order load against load on a weakly ordered architecture: packet data can be read before the host has finished writing it. Load the write index with acquire, pairing with the host's release store. This is the equivalent of virt_rmb() in the Linux hv_pkt_iter code. No change in generated code on x86.

Fixes 831dba47bd36 ("bus/vmbus: add Hyper-V virtual bus support")
---
 drivers/bus/vmbus/private.h | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/bus/vmbus/private.h +11 -1
index 6efac86b77..aca5b534f9 100644
@@ -12,6 +12,7 @@
 #include <bus_driver.h>
 #include <bus_vmbus_driver.h>
 #include <rte_log.h>
+#include <rte_stdatomic.h>
 #include <rte_eal_paging.h>
 #include <rte_vmbus_reg.h>
 
@@ -130,7 +131,16 @@ vmbus_br_availwrite(const struct vmbus_br *br, uint32_t windex)
 static inline uint32_t
 vmbus_br_availread(const struct vmbus_br *br)
 {
-	return br->dsize - vmbus_br_availwrite(br, br->vbr->windex);
+	uint32_t windex;
+
+	/* Pairs with the host's release store of the write index;
+	 * ring data must not be read before the index.
+	 */
+	windex = rte_atomic_load_explicit(
+		(volatile uint32_t __rte_atomic *)&br->vbr->windex,
+		rte_memory_order_acquire);
+
+	return br->dsize - vmbus_br_availwrite(br, windex);
 }
 
 int vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen,
Signature · 1 line
2.53.0
Reviewed-by on v2 4/33
#63 lore raw

RE: [EXTERNAL] [PATCH v2 04/33] bus/vmbus: fix missing acquire on receive ring index

Quoted 19 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Monday, September 21, 2026 2:10 AM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; [email protected]; Long Li <[email protected]>; Wei Hu <[email protected]>
Subject: [EXTERNAL] [PATCH v2 04/33] bus/vmbus: fix missing acquire on receive ring index

The receive path checks available data by reading the write index and then copies ring data. The link between the two is only the comparison, a control dependency, which does not order load against load on a weakly ordered
architecture: packet data can be read before the host has finished writing it. Load the write index with acquire, pairing with the host's release store. This is the equivalent of virt_rmb() in the Linux hv_pkt_iter code. No change in generated code on x86.

Quoted 5 lines
Fixes 831dba47bd36 ("bus/vmbus: add Hyper-V virtual bus support")
Quoted 36 lines
---
 drivers/bus/vmbus/private.h | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/bus/vmbus/private.h index renamed from drivers/bus/vmbus/private.h +0 -0

6efac86b77..aca5b534f9 100644

drivers/bus/vmbus/private.h +1 -0
@@ -12,6 +12,7 @@
 #include <bus_driver.h>
 #include <bus_vmbus_driver.h>
 #include <rte_log.h>
+#include <rte_stdatomic.h>
 #include <rte_eal_paging.h>
 #include <rte_vmbus_reg.h>
 
@@ -130,7 +131,16 @@ vmbus_br_availwrite(const struct vmbus_br *br,

uint32_t windex) static inline uint32_t vmbus_br_availread(const struct vmbus_br *br) {

drivers/bus/vmbus/private.h +10 -1
-	return br->dsize - vmbus_br_availwrite(br, br->vbr->windex);
+	uint32_t windex;
+
+	/* Pairs with the host's release store of the write index;
+	 * ring data must not be read before the index.
+	 */
+	windex = rte_atomic_load_explicit(
+		(volatile uint32_t __rte_atomic *)&br->vbr->windex,
+		rte_memory_order_acquire);
+
+	return br->dsize - vmbus_br_availwrite(br, windex);
 }
 
 int vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int

iovlen,
--
2.53.0

#64 lore raw

PATCH v2 5/33 bus/vmbus: replace SMP barriers with C11 memory fences

In reply to Stephen Hemminger

Full barriers order the preceding index store against the following load of the interrupt mask or pending size and stay seq_cst; read barriers become acquire fences. Same code generated on x86 and arm64.

The write barrier before publishing the transmit index becomes a release fence. Nominally stronger on arm64, but it is immediately followed by a full barrier cmpset; converting that to a release compare-exchange is left for the rte_atomic32 removal series.

---
 drivers/bus/vmbus/vmbus_bufring.c | 6 +++---
 drivers/bus/vmbus/vmbus_channel.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/bus/vmbus/vmbus_bufring.c +3 -3
index f622869974..31478d3bfa 100644
@@ -58,11 +58,11 @@ void vmbus_br_setup(struct vmbus_br *br, void *buf, unsigned int blen)
 static inline bool
 vmbus_txbr_need_signal(const struct vmbus_bufring *vbr, uint32_t old_windex)
 {
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 	if (vbr->imask)
 		return false;
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	/*
 	 * This is the only case we need to signal when the
@@ -158,7 +158,7 @@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen,
 	RTE_ASSERT(windex == next_windex);
 
 	/* Ensure that data is available before updating host index */
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	/* Checkin for our reservation. wait for our turn to update host */
 	while (!rte_atomic32_cmpset(&vbr->windex, old_windex, next_windex))
drivers/bus/vmbus/vmbus_channel.c +3 -3
index 2648d8e3fd..10293f59be 100644
@@ -211,7 +211,7 @@ bool rte_vmbus_chan_rx_empty(const struct vmbus_channel *channel)
 {
 	const struct vmbus_br *br = &channel->rxbr;
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 	return br->vbr->rindex == br->vbr->windex;
 }
 
@@ -229,13 +229,13 @@ void rte_vmbus_chan_signal_read(struct rte_vmbus_device *dev,
 		return;
 
 	/* Make sure reading of pending happens after new read index */
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
 	pending_sz = rbr->vbr->pending_send;
 	if (!pending_sz)
 		return;
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 	write_sz = vmbus_br_availwrite(rbr, rbr->vbr->windex);
 
 	/* If there was space before then host was not blocked */
Signature · 1 line
2.53.0
Reviewed-by on v2 5/33
#65 lore raw

RE: [EXTERNAL] [PATCH v2 05/33] bus/vmbus: replace SMP barriers with C11 memory fences

Quoted 15 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Monday, September 21, 2026 2:10 AM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; Long Li <[email protected]>; Wei Hu <[email protected]>
Subject: [EXTERNAL] [PATCH v2 05/33] bus/vmbus: replace SMP barriers with C11 memory fences

Full barriers order the preceding index store against the following load of the interrupt mask or pending size and stay seq_cst; read barriers become acquire fences. Same code generated on x86 and arm64.

Quoted 7 lines

The write barrier before publishing the transmit index becomes a release fence. Nominally stronger on arm64, but it is immediately followed by a full barrier cmpset; converting that to a release compare-exchange is left for the rte_atomic32 removal series.

Quoted 65 lines
---
 drivers/bus/vmbus/vmbus_bufring.c | 6 +++---
drivers/bus/vmbus/vmbus_channel.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/bus/vmbus/vmbus_bufring.c +2 -2
index f622869974..31478d3bfa 100644
@@ -58,11 +58,11 @@ void vmbus_br_setup(struct vmbus_br *br, void
 *buf, unsigned int blen)  static inline bool  vmbus_txbr_need_signal(const
 struct vmbus_bufring *vbr, uint32_t old_windex)  {
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 	if (vbr->imask)
 		return false;
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	/*
 	 * This is the only case we need to signal when the @@ -158,7 +158,7

@@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen,

drivers/bus/vmbus/vmbus_bufring.c +1 -1
 	RTE_ASSERT(windex == next_windex);
 
 	/* Ensure that data is available before updating host index */
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	/* Checkin for our reservation. wait for our turn to update host */
 	while (!rte_atomic32_cmpset(&vbr->windex, old_windex,

next_windex)) diff --git a/drivers/bus/vmbus/vmbus_channel.c b/drivers/bus/vmbus/vmbus_channel.c
index 2648d8e3fd..10293f59be 100644

drivers/bus/vmbus/vmbus_channel.c +3 -3
@@ -211,7 +211,7 @@ bool rte_vmbus_chan_rx_empty(const struct
 vmbus_channel *channel)  {
 	const struct vmbus_br *br = &channel->rxbr;
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 	return br->vbr->rindex == br->vbr->windex;  }
 
@@ -229,13 +229,13 @@ void rte_vmbus_chan_signal_read(struct
 rte_vmbus_device *dev,
 		return;
 
 	/* Make sure reading of pending happens after new read index */
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
 	pending_sz = rbr->vbr->pending_send;
 	if (!pending_sz)
 		return;
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 	write_sz = vmbus_br_availwrite(rbr, rbr->vbr->windex);
 

/* If there was space before then host was not blocked */
--
2.53.0

#66 lore raw

PATCH v2 6/33 drivers/baseband: convert rte_smp_rmb to fence

In reply to Stephen Hemminger

Replace deprecated rte_smp_rmb with equivalent rte_atomic_thread_fence(rte_memory_order_acquire).

---
 drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c |  8 ++++----
 drivers/baseband/fpga_lte_fec/fpga_lte_fec.c       | 12 ++++++------
 2 files changed, 10 insertions(+), 10 deletions(-)
drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c +4 -4
index 45bd171ca7..e804be4cea 100644
@@ -2662,7 +2662,7 @@ vc_5gnr_dequeue_ldpc_enc_one_op_cb(struct fpga_5gnr_queue *q, struct rte_bbdev_e
 		return -1;
 
 	/* make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	rte_bbdev_log_debug("DMA response desc %p", desc);
 
@@ -2691,7 +2691,7 @@ agx100_dequeue_ldpc_enc_one_op_cb(struct fpga_5gnr_queue *q, struct rte_bbdev_en
 		return -1;
 
 	/* make sure the response is read atomically. */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	rte_bbdev_log_debug("DMA response desc %p", desc);
 
@@ -2723,7 +2723,7 @@ vc_5gnr_dequeue_ldpc_dec_one_op_cb(struct fpga_5gnr_queue *q, struct rte_bbdev_d
 		return -1;
 
 	/* make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 #ifdef RTE_LIBRTE_BBDEV_DEBUG
 	vc_5gnr_print_dma_dec_desc_debug_info(desc);
@@ -2769,7 +2769,7 @@ agx100_dequeue_ldpc_dec_one_op_cb(struct fpga_5gnr_queue *q, struct rte_bbdev_de
 		return -1;
 
 	/* make sure the response is read atomically. */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 #ifdef RTE_LIBRTE_BBDEV_DEBUG
 	agx100_print_dma_dec_desc_debug_info(desc);
drivers/baseband/fpga_lte_fec/fpga_lte_fec.c +6 -6
index 04ac445820..cb3f29c10b 100644
@@ -2093,7 +2093,7 @@ dequeue_enc_one_op_cb(struct fpga_queue *q, struct rte_bbdev_enc_op **op,
 		return -1;
 
 	/* make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	rte_bbdev_log_debug("DMA response desc %p", desc);
 
@@ -2123,7 +2123,7 @@ dequeue_enc_one_op_tb(struct fpga_queue *q, struct rte_bbdev_enc_op **op,
 		return -1;
 
 	/* Make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	/* Verify if done bit in all CBs is set */
 	cbs_in_op = desc->enc_req.cbs_in_op;
@@ -2135,7 +2135,7 @@ dequeue_enc_one_op_tb(struct fpga_queue *q, struct rte_bbdev_enc_op **op,
 	}
 
 	/* Make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	for (cb_idx = 0; cb_idx < cbs_in_op; ++cb_idx) {
 		desc = q->ring_addr + ((q->head_free_desc + desc_offset +
@@ -2166,7 +2166,7 @@ dequeue_dec_one_op_cb(struct fpga_queue *q, struct rte_bbdev_dec_op **op,
 		return -1;
 
 	/* make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 #ifdef RTE_LIBRTE_BBDEV_DEBUG
 	print_dma_dec_desc_debug_info(desc);
@@ -2201,7 +2201,7 @@ dequeue_dec_one_op_tb(struct fpga_queue *q, struct rte_bbdev_dec_op **op,
 		return -1;
 
 	/* Make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	/* Verify if done bit in all CBs is set */
 	cbs_in_op = desc->dec_req.cbs_in_op;
@@ -2213,7 +2213,7 @@ dequeue_dec_one_op_tb(struct fpga_queue *q, struct rte_bbdev_dec_op **op,
 	}
 
 	/* Make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	for (cb_idx = 0; cb_idx < cbs_in_op; ++cb_idx) {
 		desc = q->ring_addr + ((q->head_free_desc + desc_offset +
Signature · 1 line
2.53.0
#67 lore raw

PATCH v2 7/33 net/hinic: replace rte_smp_rmb

In reply to Stephen Hemminger

Replace deprecated rte_smp_rmb with equivalent rte_atomic_thread_fence(rte_memory_order_acquire).

---
 drivers/net/hinic/base/hinic_pmd_cmdq.c | 3 ++-
 drivers/net/hinic/base/hinic_pmd_mgmt.c | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/net/hinic/base/hinic_pmd_cmdq.c +2 -1
index 1816636c34..57af522f6a 100644
@@ -825,7 +825,8 @@ static int cmdq_sync_cmd_direct_resp(struct hinic_cmdq *cmdq,
 		goto cmdq_unlock;
 	}
 
-	rte_smp_rmb();	/* read error code after completion */
+	/* read error code after completion */
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	if (out_param) {
 		wqe_lcmd = &curr_wqe->wqe_lcmd;
drivers/net/hinic/base/hinic_pmd_mgmt.c +1 -1
index 6ecca407a1..f1a0b15c21 100644
@@ -459,7 +459,7 @@ hinic_pf_to_mgmt_sync(struct hinic_hwdev *hwdev,
 		goto unlock_sync_msg;
 	}
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 	if (recv_msg->msg_len && buf_out && out_size) {
 		if (recv_msg->msg_len <= *out_size) {
 			memcpy(buf_out, recv_msg->msg,
Signature · 1 line
2.53.0
#68 lore raw

PATCH v2 8/33 net/intel: replace rte_smp_rmb

In reply to Stephen Hemminger

Replace deprecated rte_smp_rmb with equivalent rte_atomic_thread_fence(rte_memory_order_acquire).

---
 drivers/net/intel/ice/ice_rxtx.c     | 2 +-
 drivers/net/intel/ixgbe/ixgbe_rxtx.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/intel/ice/ice_rxtx.c +1 -1
index c4b5454c53..6f168e358f 100644
@@ -1955,7 +1955,7 @@ ice_rx_scan_hw_ring(struct ci_rx_queue *rxq)
 		for (j = ICE_LOOK_AHEAD - 1; j >= 0; j--)
 			s[j] = rte_le_to_cpu_16(rxdp[j].wb.status_error0);
 
-		rte_smp_rmb();
+		rte_atomic_thread_fence(rte_memory_order_acquire);
 
 		/* Compute how many status bits were set */
 		for (j = 0, nb_dd = 0; j < ICE_LOOK_AHEAD; j++)
drivers/net/intel/ixgbe/ixgbe_rxtx.c +1 -1
index 60222693fe..ce0a3dde34 100644
@@ -1549,7 +1549,7 @@ ixgbe_rx_scan_hw_ring(struct ci_rx_queue *rxq)
 		for (j = 0; j < LOOK_AHEAD; j++)
 			s[j] = rte_le_to_cpu_32(rxdp[j].wb.upper.status_error);
 
-		rte_smp_rmb();
+		rte_atomic_thread_fence(rte_memory_order_acquire);
 
 		/* Compute how many status bits were set */
 		for (nb_dd = 0; nb_dd < LOOK_AHEAD &&
Signature · 1 line
2.53.0
#69 lore raw

PATCH v2 9/33 net/virtio: replace rte_smp_rmb

In reply to Stephen Hemminger

Replace rte_smp_rmb with equivalent rte_atomic_thread_fence(rte_memory_order_acquire).

---
 drivers/net/virtio/virtqueue.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/virtio/virtqueue.h +3 -3
index 1f0e6ae77e..37fbd47d42 100644
@@ -445,15 +445,15 @@ virtqueue_nused(const struct virtqueue *vq)
 
 	if (vq->hw->weak_barriers) {
 	/**
-	 * x86 prefers to using rte_smp_rmb over rte_atomic_load_explicit as it
-	 * reports a slightly better perf, which comes from the saved
+	 * x86 prefers to using rte_atomic_thread_fence over rte_atomic_load_explicit
+	 * as it reports a slightly better perf, which comes from the saved
 	 * branch by the compiler.
 	 * The if and else branches are identical with the smp and io
 	 * barriers both defined as compiler barriers on x86.
 	 */
 #ifdef RTE_ARCH_X86_64
 		idx = vq->vq_split.ring.used->idx;
-		rte_smp_rmb();
+		rte_atomic_thread_fence(rte_memory_order_acquire);
 #else
 		idx = rte_atomic_load_explicit(&(vq)->vq_split.ring.used->idx,
 				rte_memory_order_acquire);
Signature · 1 line
2.53.0
#70 lore raw

PATCH v2 10/33 net/thunderx: replace rte_smp_rmb

In reply to Stephen Hemminger

Replace rte_smp_rmb with equivalent rte_atomic_thread_fence(rte_memory_order_acquire).

---
 drivers/net/thunderx/base/nicvf_plat.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/thunderx/base/nicvf_plat.h +1 -1
index 8421f57040..7d22563035 100644
@@ -26,7 +26,7 @@
 /* barrier */
 #include <rte_atomic.h>
 #define nicvf_smp_wmb() rte_smp_wmb()
-#define nicvf_smp_rmb() rte_smp_rmb()
+#define nicvf_smp_rmb() rte_atomic_thread_fence(rte_memory_order_acquire)
 
 /* utils */
 #include <rte_common.h>
Signature · 1 line
2.53.0
#71 lore raw

PATCH v2 11/33 stack: always use C11 memory model implementation

In reply to Stephen Hemminger

The generic and C11 lock-free stack implementations differ only in memory ordering. The generic version uses a full barrier where its own comments state an acquire fence is sufficient, and seq_cst for all length counter operations.

Only x86 and ThunderX still used the generic version. On x86 the switch removes a locked add per CAS attempt in push and pop; TSO provides the acquire semantics. On ThunderX the pop fence weakens from dmb ish to dmb ishld and the push fence goes away.

Measured on a 32-core x86 machine, stack_perf_autotest, cycles per operation, main versus the unified C11 version (n=9 each):

  Test              main          unified C11   delta
  single push/pop   46.62 +-0.30  33.41 +-0.10  -28%
  empty pop          1.47 +-0.01   0.98 +-0.01  -33%
  1 lcore, bulk 8    9.06 +-0.05   8.20 +-0.08  -10%
  1 lcore, bulk 32   6.09 +-0.02   6.15 +-0.03   +1%
  2 HT, bulk 8      42.05 +-0.31  39.24 +-0.52   -7%
  2 HT, bulk 32     11.92 +-0.13  11.89 +-0.10    0
  2 cores, bulk 8   78.90 +-0.60  72.96 +-1.11   -7%
  2 cores, bulk 32  20.74 +-1.56   7.70 +-0.13  -63%
  32 cores, bulk 8  6126 +-72     6121 +-89       0

32 cores, bulk 32 1953.9 +-2.9 1984.6 +-13.3 +1.6%

The C11 version is faster because it emits no lock prefixed instructions.

Remove the generic version and use the C11 implementation everywhere.

---
 lib/stack/meson.build            |   1 -
 lib/stack/rte_stack_lf.h         |   4 -
 lib/stack/rte_stack_lf_generic.h | 153 -------------------------------
 3 files changed, 158 deletions(-)
 delete mode 100644 lib/stack/rte_stack_lf_generic.h
lib/stack/meson.build +0 -1
index 18177a742f..1fab46208f 100644
@@ -7,7 +7,6 @@ headers = files('rte_stack.h')
 indirect_headers += files(
         'rte_stack_std.h',
         'rte_stack_lf.h',
-        'rte_stack_lf_generic.h',
         'rte_stack_lf_c11.h',
         'rte_stack_lf_stubs.h',
 )
lib/stack/rte_stack_lf.h +0 -4
index f2b012cd0e..1bc6ee8f40 100644
@@ -8,11 +8,7 @@
 #if !(defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_ARM64))
 #include "rte_stack_lf_stubs.h"
 #else
-#ifdef RTE_USE_C11_MEM_MODEL
 #include "rte_stack_lf_c11.h"
-#else
-#include "rte_stack_lf_generic.h"
-#endif
 
 /**
  * Indicates that RTE_STACK_F_LF is supported.
lib/stack/rte_stack_lf_generic.h deleted +0 -153

153 lines not on this page · raw message

Signature · 1 line
2.53.0
#72 lore raw

PATCH v2 12/33 ring: replace SMP read barrier with C11 acquire fence

In reply to Stephen Hemminger

rte_smp_rmb() is deprecated. The acquire fence generates the same code everywhere the gcc implementation is used: a compiler barrier on x86 and dmb ishld on ThunderX.

The gcc implementation itself is kept: unlike the lock-free stack, the in-tree comment records a 10% x86 performance drop with the C11 version, which needs re-measuring with current compilers before RTE_USE_C11_MEM_MODEL can be removed.

---
 lib/ring/rte_ring_gcc_pvt.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/ring/rte_ring_gcc_pvt.h +3 -3
index 340ece28c7..9c2c58824d 100644
@@ -55,10 +55,10 @@ __rte_ring_headtail_move_head_st(struct rte_ring_headtail *d,
 
 	*old_head = d->head;
 
-	/* add rmb barrier to avoid load/load reorder in weak
-	 * memory model. It is noop on x86
+	/* Acquire fence to avoid load/load reorder in weak
+	 * memory model. It is noop on x86.
 	 */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	/*
 	 *  The subtraction is done between two unsigned 32bits value
Signature · 1 line
2.53.0
#73 lore raw

PATCH v2 13/33 crypto/virtio: update comment reference to rte_smp_rmb

In reply to Stephen Hemminger

The rte_smp_rmb helper is no longer used.

---
 drivers/crypto/virtio/virtqueue.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/virtio/virtqueue.h +1 -1
index 97a3ace48c..23c001a8e6 100644
@@ -302,7 +302,7 @@ virtqueue_nused(const struct virtqueue *vq)
 
 	if (vq->hw->weak_barriers) {
 	/**
-	 * x86 prefers to using rte_smp_rmb over rte_atomic_load_explicit as it
+	 * x86 prefers to using virtio_rmb over rte_atomic_load_explicit as it
 	 * reports a slightly better perf, which comes from the saved
 	 * branch by the compiler.
 	 * The if and else branches are identical with the smp and io
Signature · 1 line
2.53.0
#74 lore raw

PATCH v2 14/33 crypto/caam_jr: replace rte_smp_rmb

In reply to Stephen Hemminger

Replace rte_smp_rmb with equivalent rte_atomic_thread_fence(rte_memory_order_acquire).

---
 drivers/crypto/caam_jr/caam_jr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/caam_jr/caam_jr.c +1 -1
index a57dc56b80..1f97e72337 100644
@@ -572,7 +572,7 @@ hw_poll_job_ring(struct sec_job_ring_t *job_ring,
 		job_ring, job_ring->pidx, job_ring->cidx,
 		limit, number_of_jobs_available, jobs_no_to_notify);
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	while (jobs_no_to_notify > notified_descs_no) {
 		static uint64_t false_alarm;
Signature · 1 line
2.53.0
#75 lore raw

PATCH v2 15/33 crypto/caam_jr: use IO barrier before job ring doorbell

In reply to Stephen Hemminger

The barrier orders the input ring descriptor write in DMA memory against the MMIO doorbell write. That is device ordering, not SMP
ordering: rte_io_wmb() is the correct barrier, and on arm64 the inner shareable dmb the SMP barrier generated was not sufficient to order against the device in the first place.

---
 drivers/crypto/caam_jr/caam_jr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/crypto/caam_jr/caam_jr.c +2 -1
index 1f97e72337..7a345c436e 100644
@@ -1451,7 +1451,8 @@ caam_jr_enqueue_op(struct rte_crypto_op *op, struct caam_jr_qp *qp)
 	/* Set ptr in input ring to current descriptor	*/
 	sec_write_addr(&ring->input_ring[ring->pidx],
 			(phys_addr_t)caam_jr_vtop_ctx(ctx, ctx->jobdes.desc));
-	rte_smp_wmb();
+	/* Descriptor must be visible to the device before the doorbell */
+	rte_io_wmb();
 
 	/* Notify HW that a new job is enqueued */
 	hw_enqueue_desc_on_job_ring(ring);
Signature · 1 line
2.53.0
#76 lore raw

PATCH v2 16/33 crypto/octeontx: use IO barrier before doorbell

In reply to Stephen Hemminger

The doorbell is written with rte_write64_relaxed(), so the barrier before it is what orders the queued instructions against the device. That is device ordering, not SMP ordering: use rte_io_wmb().

---
 drivers/crypto/octeontx/otx_cryptodev_hw_access.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/crypto/octeontx/otx_cryptodev_hw_access.h +2 -2
index 3104e6d31e..096dcf8f87 100644
@@ -203,8 +203,8 @@ static __rte_always_inline void
 otx_cpt_ring_dbell(struct cpt_instance *instance, uint16_t count)
 {
 	struct cpt_vf *cptvf = (struct cpt_vf *)instance;
-	/* Memory barrier to flush pending writes */
-	rte_smp_wmb();
+	/* Instructions must be visible to the device before the doorbell */
+	rte_io_wmb();
 	otx_cpt_write_vq_doorbell(cptvf, count);
 }
 
Signature · 1 line
2.53.0
#77 lore raw

PATCH v2 17/33 event/sw: fix unlinks in progress counter races

In reply to Stephen Hemminger

The counter is written by both the application thread (increment on unlink) and the scheduler (clear on ack) as a plain uint8_t. An increment is lost if it lands between the scheduler's test and clear, making rte_event_port_unlinks_in_progress() report completion before the scheduler has seen the unlink. On a weakly ordered CPU nothing orders the scheduler's cq map reads against the counter test, nor the application's reads against the counter reaching zero.

Make the counter atomic: release fetch-add on unlink, unconditional acquire-release exchange to clear, acquire load to read.

Fixes bd5ac24fea88 ("event/sw: implement unlinks in progress function")
---
 drivers/event/sw/sw_evdev.c           |  8 +++++---
 drivers/event/sw/sw_evdev.h           |  2 +-
 drivers/event/sw/sw_evdev_scheduler.c | 17 ++++++++++++++---
 3 files changed, 20 insertions(+), 7 deletions(-)
drivers/event/sw/sw_evdev.c +5 -3
index 3ad82e94ac..fedf638c60 100644
@@ -119,8 +119,9 @@ sw_port_unlink(struct rte_eventdev *dev, void *port, uint8_t queues[],
 		}
 	}
 
-	p->unlinks_in_progress += unlinked;
-	rte_smp_mb();
+	/* Pairs with the acquire exchange in the scheduler */
+	rte_atomic_fetch_add_explicit(&p->unlinks_in_progress, unlinked,
+				      rte_memory_order_release);
 
 	return unlinked;
 }
@@ -130,7 +131,8 @@ sw_port_unlinks_in_progress(struct rte_eventdev *dev, void *port)
 {
 	RTE_SET_USED(dev);
 	struct sw_port *p = port;
-	return p->unlinks_in_progress;
+	return rte_atomic_load_explicit(&p->unlinks_in_progress,
+					rte_memory_order_acquire);
 }
 
 static int
drivers/event/sw/sw_evdev.h +1 -1
index c159be21be..8b9118bf91 100644
@@ -160,7 +160,7 @@ struct sw_port {
 	 * progress is read by the scheduler, no more events will be pushed to
 	 * the port - hence the scheduler core can just assign zero.
 	 */
-	uint8_t unlinks_in_progress;
+	RTE_ATOMIC(uint8_t) unlinks_in_progress;
 
 	int16_t is_directed; /** Takes from a single directed QID */
 	/**
drivers/event/sw/sw_evdev_scheduler.c +14 -3
index a5fdcf301b..207dee5854 100644
@@ -523,9 +523,20 @@ sw_event_schedule(struct rte_eventdev *dev)
 		do {
 			in_pkts = 0;
 			for (i = 0; i < sw->port_count; i++) {
-				/* ack the unlinks in progress as done */
-				if (sw->ports[i].unlinks_in_progress)
-					sw->ports[i].unlinks_in_progress = 0;
+				struct sw_port *p = &sw->ports[i];
+
+				/* Ack the unlinks in progress as done.
+				 * The exchange cannot lose an increment that
+				 * lands after the test, and its acquire orders
+				 * the cq map reads below after the unlinker's
+				 * map update. Nothing to synchronize with when
+				 * the counter reads zero, so test first and
+				 * keep the locked op off the common path.
+				 */
+				if (rte_atomic_load_explicit(&p->unlinks_in_progress,
+						rte_memory_order_relaxed) != 0)
+					rte_atomic_exchange_explicit(&p->unlinks_in_progress,
+						0, rte_memory_order_acq_rel);
 
 				if (sw->ports[i].is_directed)
 					in_pkts += sw_schedule_pull_port_dir(sw, i);
Signature · 1 line
2.53.0
#78 lore raw

PATCH v2 18/33 event/sw: replace SMP barriers with C11 atomics

In reply to Stephen Hemminger

The write barrier plus plain store publish patterns (cq map count, port initialized, device started) become release stores; the barrier after clearing started in sw_stop() becomes a release fence. All are control path.

Scheduler reads of cq_num_mapped_cqs stay plain loads: acquire loads would land in the inner scheduling loops on weakly ordered CPUs. The transient window where a new count is visible before the map entry on such CPUs predates this change and is unchanged by it; unlink is covered by the counter handshake.

---
 drivers/event/sw/sw_evdev.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)
drivers/event/sw/sw_evdev.c +20 -9
index fedf638c60..6bd6b077fa 100644
@@ -84,8 +84,10 @@ sw_port_link(struct rte_eventdev *dev, void *port, const uint8_t queues[],
 		}
 
 		q->cq_map[q->cq_num_mapped_cqs] = p->id;
-		rte_smp_wmb();
-		q->cq_num_mapped_cqs++;
+		/* Release publishes the map entry before the new count */
+		rte_atomic_store_explicit(
+			(uint32_t __rte_atomic *)&q->cq_num_mapped_cqs,
+			q->cq_num_mapped_cqs + 1, rte_memory_order_release);
 	}
 	return i;
 }
@@ -105,8 +107,14 @@ sw_port_unlink(struct rte_eventdev *dev, void *port, uint8_t queues[],
 			if (q->cq_map[j] == p->id) {
 				q->cq_map[j] =
 					q->cq_map[q->cq_num_mapped_cqs - 1];
-				rte_smp_wmb();
-				q->cq_num_mapped_cqs--;
+				/* Release publishes the map update
+				 * before the new count
+				 */
+				rte_atomic_store_explicit(
+					(uint32_t __rte_atomic *)
+						&q->cq_num_mapped_cqs,
+					q->cq_num_mapped_cqs - 1,
+					rte_memory_order_release);
 				unlinked++;
 
 				p->num_qids_mapped--;
@@ -208,8 +216,9 @@ sw_port_setup(struct rte_eventdev *dev, uint8_t port_id,
 	}
 	dev->data->ports[port_id] = p;
 
-	rte_smp_wmb();
-	p->initialized = 1;
+	/* Release publishes the port setup before initialized flag */
+	rte_atomic_store_explicit((uint8_t __rte_atomic *)&p->initialized, 1,
+				  rte_memory_order_release);
 	return 0;
 }
 
@@ -815,8 +824,9 @@ sw_start(struct rte_eventdev *dev)
 	if (sw_xstats_init(sw) < 0)
 		return -EINVAL;
 
-	rte_smp_wmb();
-	sw->started = 1;
+	/* Release publishes device state before the started flag */
+	rte_atomic_store_explicit((uint8_t __rte_atomic *)&sw->started, 1,
+				  rte_memory_order_release);
 
 	return 0;
 }
@@ -845,7 +855,8 @@ sw_stop(struct rte_eventdev *dev)
 	sw_clean_qid_iqs(dev);
 	sw_xstats_uninit(sw);
 	sw->started = 0;
-	rte_smp_wmb();
+	/* Order the started store before re-enabling the service */
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	if (runstate == 1)
 		rte_service_runstate_set(sw->service_id, 1);
Signature · 1 line
2.53.0
#79 lore raw

PATCH v2 19/33 test/barrier: test sequentially consistent fence only

In reply to Stephen Hemminger

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.

---
 app/test/test_barrier.c | 105 +++++++++++++---------------------------
 1 file changed, 34 insertions(+), 71 deletions(-)
app/test/test_barrier.c +34 -71
index 925a88b68a..cb876d8fda 100644
@@ -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);
Signature · 1 line
2.53.0
Acked-by Tested-by on v2 19/33
#80 lore raw

Re: [PATCH v2 19/33] test/barrier: test sequentially consistent fence only

Quoted 7 lines

te_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.

Run it on both x86 and arm boxes, both passed.
Other arch maintainers, pls review, test.

Quoted 106 lines
---
  app/test/test_barrier.c <https://inbox.dpdk.org/dev/[email protected]/#Z31app:test:test_barrier.c> | 105 +++++++++++++---------------------------
  1 file changed, 34 insertions(+), 71 deletions(-)

diff <https://inbox.dpdk.org/dev/[email protected]/#iZ31app:test:test_barrier.c>
--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. + */

app/test/test_barrier.c +2 -3
+#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; };

/*

(quoted diff) +1 -2
@@ -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)

app/test/test_barrier.c +2 -15
@@ -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);
Signature · 1 line
2.53.0
#82 lore raw

PATCH v2 20/33 eal/x86: move optimized fence out of SMP barrier

In reply to Stephen Hemminger

rte_atomic_thread_fence() implemented the seq_cst case by calling the deprecated rte_smp_mb(). Invert the dependency: the lock add based fence moves into rte_atomic_thread_fence(), and rte_smp_mb() goes away with it since the test that was its last user is converted in the preceding patch. The optimization itself must stay; a plain seq_cst fence is an mfence, about twice the cost. No change in generated code.

---
 lib/eal/x86/include/rte_atomic.h | 37 ++++++++++++++------------------
 1 file changed, 16 insertions(+), 21 deletions(-)
lib/eal/x86/include/rte_atomic.h +16 -21
index e071e4234e..780fdce871 100644
@@ -60,23 +60,8 @@ extern "C" {
  * Basic idea is to use lock prefixed add with some dummy memory location
  * as the destination. From their experiments 128B(2 cache lines) below
  * current stack pointer looks like a good candidate.
- * So below we use that technique for rte_smp_mb() implementation.
  */
 
-static __rte_always_inline void
-rte_smp_mb(void)
-{
-#ifdef RTE_TOOLCHAIN_MSVC
-	_mm_mfence();
-#else
-#ifdef RTE_ARCH_I686
-	asm volatile("lock addl $0, -128(%%esp); " ::: "memory");
-#else
-	asm volatile("lock addl $0, -128(%%rsp); " ::: "memory");
-#endif
-#endif
-}
-
 #define rte_io_mb() rte_mb()
 
 #define rte_io_wmb() rte_compiler_barrier()
@@ -86,17 +71,27 @@ rte_smp_mb(void)
 /**
  * Synchronization fence between threads based on the specified memory order.
  *
- * On x86 the __rte_atomic_thread_fence(rte_memory_order_seq_cst) generates full 'mfence'
- * which is quite expensive. The optimized implementation of rte_smp_mb is
- * used instead.
+ * On x86 the __rte_atomic_thread_fence(rte_memory_order_seq_cst) generates
+ * a full 'mfence' which is quite expensive. The optimized lock add on a
+ * dummy stack location (see above) is used instead.
  */
 static __rte_always_inline void
 rte_atomic_thread_fence(rte_memory_order memorder)
 {
-	if (memorder == rte_memory_order_seq_cst)
-		rte_smp_mb();
-	else
+	if (memorder != rte_memory_order_seq_cst) {
 		__rte_atomic_thread_fence(memorder);
+		return;
+	}
+
+#ifdef RTE_TOOLCHAIN_MSVC
+	_mm_mfence();
+#else
+#ifdef RTE_ARCH_I686
+	asm volatile("lock addl $0, -128(%%esp); " ::: "memory");
+#else
+	asm volatile("lock addl $0, -128(%%rsp); " ::: "memory");
+#endif
+#endif
 }
 
 #ifdef __cplusplus
Signature · 1 line
2.53.0
#83 lore raw

PATCH v2 21/33 common/octeontx: remove redundant barrier in mbox

In reply to Stephen Hemminger

The SMP write barrier between writing the mailbox header and ringing the mailbox register is redundant: rte_write64() begins with rte_io_wmb(), which already orders the header write before the trigger, and does so against the device rather than only within the inner shareable domain.

---
 drivers/common/octeontx/octeontx_mbox.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/common/octeontx/octeontx_mbox.c +4 -2
index 9e0bbf453f..8b0da3a98e 100644
@@ -113,8 +113,10 @@ mbox_send_request(struct mbox *m, struct octeontx_mbox_hdr *hdr,
 
 	/* Write the msg header */
 	rte_write64(new_hdr.u64, ram_mbox_hdr);
-	rte_smp_wmb();
-	/* Notify PF about the new msg - write to MBOX reg generates PF IRQ */
+	/* Notify PF about the new msg - write to MBOX reg generates PF IRQ.
+	 * rte_write64() issues rte_io_wmb() which orders the header write
+	 * before the trigger; no separate barrier is needed.
+	 */
 	rte_write64(0, m->reg);
 }
 
Signature · 1 line
2.53.0
#84 lore raw

PATCH v2 22/33 mempool/octeontx: use IO barrier in pool destroy

In reply to Stephen Hemminger

The barrier flushes outstanding writes to the FPA pool before the teardown mailbox sequence. That is ordering against the device, so use rte_io_wmb(). Control path.

---
 drivers/mempool/octeontx/octeontx_fpavf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mempool/octeontx/octeontx_fpavf.c +2 -2
index 6cd0fc057f..7051422cb7 100644
@@ -616,8 +616,8 @@ octeontx_fpa_bufpool_destroy(uintptr_t handle, int node_id)
 
 	RTE_SET_USED(node_id);
 
-	/* Wait for all outstanding writes to be committed */
-	rte_smp_wmb();
+	/* Make outstanding pool writes visible to the device */
+	rte_io_wmb();
 
 	if (unlikely(!octeontx_fpa_handle_valid(handle)))
 		return -EINVAL;
Signature · 1 line
2.53.0
#85 lore raw

PATCH v2 23/33 event/octeontx: replace deprecated SMP barriers

In reply to Stephen Hemminger

The worker barriers order event payload writes in normal memory before the add work or tag switch store to the SSO device, so they are IO ordering: use rte_io_wmb(). The selftest barriers publish worker parameters before launching lcores; convert them to release fences.

---
 drivers/event/octeontx/ssovf_evdev_selftest.c | 6 +++---
 drivers/event/octeontx/ssovf_worker.c         | 8 ++++----
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/event/octeontx/ssovf_evdev_selftest.c +3 -3
index b54ae126d2..614f9bbaef 100644
@@ -65,7 +65,7 @@ seqn_list_update(int val)
 		return -1;
 
 	seqn_list[seqn_list_index++] = val;
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 	return 0;
 }
 
@@ -637,7 +637,7 @@ launch_workers_and_wait(int (*main_worker)(void *),
 	param[0].sched_type = sched_type;
 	param[0].port = 0;
 	param[0].dequeue_tmo_ticks = dequeue_tmo_ticks;
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	w_lcore = rte_get_next_lcore(
 			/* start core */ -1,
@@ -650,7 +650,7 @@ launch_workers_and_wait(int (*main_worker)(void *),
 		param[port].sched_type = sched_type;
 		param[port].port = port;
 		param[port].dequeue_tmo_ticks = dequeue_tmo_ticks;
-		rte_smp_wmb();
+		rte_atomic_thread_fence(rte_memory_order_release);
 		w_lcore = rte_get_next_lcore(w_lcore, 1, 0);
 		rte_eal_remote_launch(worker, &param[port], w_lcore);
 	}
drivers/event/octeontx/ssovf_worker.c +4 -4
index 89b5dc056c..f3c6a0da5c 100644
@@ -59,10 +59,10 @@ ssows_fwd_group(struct ssows *ws, const struct rte_event *ev, const uint8_t grp)
 		newtag |= grp << 20;
 		newtag |= tag;
 		ssows_swtag_norm(ws, newtag, SSO_SYNC_ATOMIC);
-		rte_smp_wmb();
+		rte_io_wmb();
 		ssows_swtag_wait(ws);
 	} else {
-		rte_smp_wmb();
+		rte_io_wmb();
 	}
 	ssows_add_work(ws, event_ptr, tag, new_tt, grp);
 }
@@ -158,7 +158,7 @@ ssows_enq_burst(void *port, const struct rte_event ev[], uint16_t nb_events)
 
 	switch (ev->op) {
 	case RTE_EVENT_OP_NEW:
-		rte_smp_wmb();
+		rte_io_wmb();
 		ssows_new_event(ws, ev);
 		break;
 	case RTE_EVENT_OP_FORWARD:
@@ -179,7 +179,7 @@ ssows_enq_new_burst(void *port, const struct rte_event ev[], uint16_t nb_events)
 	uint16_t i;
 	struct ssows *ws = port;
 
-	rte_smp_wmb();
+	rte_io_wmb();
 	for (i = 0; i < nb_events; i++)
 		ssows_new_event(ws,  &ev[i]);
 
Signature · 1 line
2.53.0
#86 lore raw

PATCH v2 24/33 event/dpaa2: replace deprecated barrier in selftest

In reply to Stephen Hemminger

Publish worker parameters with a release fence before launching the lcores instead of the deprecated SMP write barrier.

---
 drivers/event/dpaa2/dpaa2_eventdev_selftest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/event/dpaa2/dpaa2_eventdev_selftest.c +2 -2
index 9d4938efe6..12c1bc9878 100644
@@ -524,7 +524,7 @@ launch_workers_and_wait(int (*main_worker)(void *),
 	param[0].sched_type = sched_type;
 	param[0].port = 0;
 	param[0].dequeue_tmo_ticks = dequeue_tmo_ticks;
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	w_lcore = rte_get_next_lcore(
 			/* start core */ -1,
@@ -537,7 +537,7 @@ launch_workers_and_wait(int (*main_worker)(void *),
 		param[port].sched_type = sched_type;
 		param[port].port = port;
 		param[port].dequeue_tmo_ticks = dequeue_tmo_ticks;
-		rte_smp_wmb();
+		rte_atomic_thread_fence(rte_memory_order_release);
 		w_lcore = rte_get_next_lcore(w_lcore, 1, 0);
 		rte_eal_remote_launch(workers, &param[port], w_lcore);
 	}
Signature · 1 line
2.53.0
#87 lore raw

PATCH v2 25/33 event/dsw: replace SMP barriers with release fences

In reply to Stephen Hemminger

All four barriers publish flow table or ring updates before a control message enqueue, which is release ordering. All are on the migration control path, not per event.

The fences may in fact be removable: the control messages travel through rte_ring, whose producer tail update is itself a release store covering the preceding writes. Left in place here to keep this a like for like conversion.

---
 drivers/event/dsw/dsw_event.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/event/dsw/dsw_event.c +4 -4
index 399d9f050e..82d3636b29 100644
@@ -339,7 +339,7 @@ dsw_port_handle_pause_flows(struct dsw_evdev *dsw, struct dsw_port *port,
 	/* Make sure any stores to the original port's in_ring is seen
 	 * before the ctl message.
 	 */
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	dsw_port_ctl_enqueue(&dsw->ports[originating_port_id], &cfm);
 }
@@ -821,7 +821,7 @@ dsw_port_move_parallel_flows(struct dsw_evdev *dsw,
 		}
 	}
 
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	dsw_port_end_emigration(dsw, source_port, RTE_SCHED_TYPE_PARALLEL);
 }
@@ -1190,7 +1190,7 @@ dsw_port_move_emigrating_flows(struct dsw_evdev *dsw,
 		    dest_port_id;
 	}
 
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	dsw_port_drain_in_ring(source_port);
 	dsw_port_forward_emigrated_flows(dsw, source_port);
@@ -1213,7 +1213,7 @@ dsw_port_move_emigrating_flows(struct dsw_evdev *dsw,
 	/* Flow table update and migration destination port's enqueues
 	 * must be seen before the control message.
 	 */
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	dsw_port_ctl_broadcast(dsw, source_port, DSW_CTL_UNPAUSE_REQ,
 			       source_port->emigration_target_qfs,
Signature · 1 line
2.53.0
#88 lore raw

PATCH v2 26/33 event/opdl: replace SMP barriers with C11 atomics

In reply to Stephen Hemminger

Publishing the port becomes a release store of the configured flag; the barrier after clearing started becomes a release fence. Both are control path.

---
 drivers/event/opdl/opdl_evdev.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/event/opdl/opdl_evdev.c +4 -3
index ffa65ef930..1450fa5ae8 100644
@@ -200,8 +200,9 @@ opdl_port_setup(struct rte_eventdev *dev,
 	p->queue_id = OPDL_INVALID_QID;
 	p->external_qid = OPDL_INVALID_QID;
 	dev->data->ports[port_id] = p;
-	rte_smp_wmb();
-	p->configured = 1;
+	/* Release publishes port setup before the configured flag */
+	rte_atomic_store_explicit((uint8_t __rte_atomic *)&p->configured, 1,
+				  rte_memory_order_release);
 	device->nb_ports++;
 	return 0;
 }
@@ -477,7 +478,7 @@ opdl_stop(struct rte_eventdev *dev)
 
 	device->started = 0;
 
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 }
 
 static int
Signature · 1 line
2.53.0
#89 lore raw

PATCH v2 27/33 net/netvsc: replace SMP barrier in RNDIS response

In reply to Stephen Hemminger

Publishing the copied response before clearing the pending id is release ordering. The following cmpset is a full barrier today, but keep the explicit fence so the ordering survives when cmpset is converted to a release compare exchange.

---
 drivers/net/netvsc/hn_rndis.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/netvsc/hn_rndis.c +1 -1
index 7c54eebcef..d1142fa1dd 100644
@@ -357,7 +357,7 @@ void hn_rndis_receive_response(struct hn_data *hv,
 	memcpy(hv->rndis_resp, data, len);
 
 	/* make sure response copied before update */
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	if (rte_atomic32_cmpset(&hv->rndis_pending, hdr->rid, 0) == 0) {
 		PMD_DRV_LOG(NOTICE,
Signature · 1 line
2.53.0
Reviewed-by on v2 27/33
#90 lore raw

RE: [EXTERNAL] [PATCH v2 27/33] net/netvsc: replace SMP barrier in RNDIS response

Quoted 35 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Monday, September 21, 2026 2:10 AM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; Wei Hu <[email protected]>
Subject: [EXTERNAL] [PATCH v2 27/33] net/netvsc: replace SMP barrier in RNDIS response

Publishing the copied response before clearing the pending id is release ordering. The following cmpset is a full barrier today, but keep the explicit fence so the ordering survives when cmpset is converted to a release compare exchange.

---
 drivers/net/netvsc/hn_rndis.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/netvsc/hn_rndis.c +1 -2
index 7c54eebcef..d1142fa1dd 100644
@@ -357,7 +357,7 @@ void hn_rndis_receive_response(struct hn_data *hv,
 	memcpy(hv->rndis_resp, data, len);
 
 	/* make sure response copied before update */
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	if (rte_atomic32_cmpset(&hv->rndis_pending, hdr->rid, 0) == 0) {
 		PMD_DRV_LOG(NOTICE,
--
Quoted 1 line

2.53.0

The review reveals a pre-existing issue, not introduced by this patch. The old rte_smp_wmb() only ordered the producer. Hn_rndis_execl() loaked an acquire operation before reading rndis_resp.

The change perserves the existing producer-side semantics and is stronger on arm64, so it does not create a regression.

The missing consumer acquire should be reported as a separate follow-up fix.

Thanks,
Wei

#91 lore raw

PATCH v2 28/33 net/thunderx: replace deprecated SMP barriers

In reply to Stephen Hemminger

Redefine the nicvf barrier wrappers as C11 fences and add an IO variant. The RBDR refill barrier orders descriptor writes in DMA memory against the doorbell register write, which is device
ordering: use the IO barrier there. The mailbox flag barriers are genuine inter thread ordering and become release/acquire fences.

---
 drivers/net/thunderx/base/nicvf_hw.c   | 3 ++-
 drivers/net/thunderx/base/nicvf_plat.h | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/net/thunderx/base/nicvf_hw.c +2 -1
index 5b1abe2015..d1e31ffdaa 100644
@@ -499,7 +499,8 @@ nicvf_qset_rbdr_precharge(void *dev, struct nicvf *nic,
 			break;
 		}
 	}
-	nicvf_smp_wmb();
+	/* Descriptors must be visible to the device before the doorbell */
+	nicvf_io_wmb();
 	nicvf_queue_reg_write(nic, NIC_QSET_RBDR_0_1_DOOR, ridx, count);
 	rbdr->tail = nicvf_queue_reg_read(nic,
 				NIC_QSET_RBDR_0_1_TAIL, ridx) >> 3;
drivers/net/thunderx/base/nicvf_plat.h +2 -1
index 7d22563035..08ebb0cf62 100644
@@ -25,8 +25,9 @@
 
 /* barrier */
 #include <rte_atomic.h>
-#define nicvf_smp_wmb() rte_smp_wmb()
+#define nicvf_smp_wmb() rte_atomic_thread_fence(rte_memory_order_release)
 #define nicvf_smp_rmb() rte_atomic_thread_fence(rte_memory_order_acquire)
+#define nicvf_io_wmb() rte_io_wmb()
 
 /* utils */
 #include <rte_common.h>
Signature · 1 line
2.53.0
#92 lore raw

PATCH v2 29/33 net/virtio: replace deprecated barrier in avail index update

In reply to Stephen Hemminger

The x86 special case keeps its shape: a release fence is the same compiler barrier the SMP write barrier was, so the measured perf reason for the branch is preserved.

---
 drivers/net/virtio/virtqueue.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/net/virtio/virtqueue.h +6 -6
index 37fbd47d42..cd954108a8 100644
@@ -474,14 +474,14 @@ static inline void
 vq_update_avail_idx(struct virtqueue *vq)
 {
 	if (vq->hw->weak_barriers) {
-	/* x86 prefers to using rte_smp_wmb over rte_atomic_store_explicit as
-	 * it reports a slightly better perf, which comes from the
-	 * saved branch by the compiler.
-	 * The if and else branches are identical with the smp and
-	 * io barriers both defined as compiler barriers on x86.
+	/* x86 prefers a fence plus plain store over
+	 * rte_atomic_store_explicit as it reports a slightly better
+	 * perf, which comes from the saved branch by the compiler.
+	 * The if and else branches are identical with the release
+	 * and io barriers both compiler barriers on x86.
 	 */
 #ifdef RTE_ARCH_X86_64
-		rte_smp_wmb();
+		rte_atomic_thread_fence(rte_memory_order_release);
 		vq->vq_split.ring.avail->idx = vq->vq_avail_idx;
 #else
 		rte_atomic_store_explicit(&vq->vq_split.ring.avail->idx,
Signature · 1 line
2.53.0
#93 lore raw

PATCH v2 30/33 eal: remove stale SMP barrier in rte_service

In reply to Stephen Hemminger

Leftover missed by the C11 atomics conversion of this file. The barrier pairs with nothing: no store follows it, and the next use of the lcore is synchronized by remote launch.

---
 lib/eal/common/rte_service.c | 1 -
 1 file changed, 1 deletion(-)
lib/eal/common/rte_service.c +0 -1
index d2ac9d3f14..0c6467285b 100644
@@ -795,7 +795,6 @@ rte_service_lcore_del(uint32_t lcore)
 
 	set_lcore_state(lcore, ROLE_RTE);
 
-	rte_smp_wmb();
 	return 0;
 }
 
Signature · 1 line
2.53.0
#94 lore raw

PATCH v2 31/33 eal: remove rte_smp_XX

In reply to Stephen Hemminger

These functions were marked for deprecation and no longer used. Drop from EAL.

---
 lib/eal/arm/include/rte_atomic_32.h    |  6 ---
 lib/eal/arm/include/rte_atomic_64.h    |  6 ---
 lib/eal/include/generic/rte_atomic.h   | 61 --------------------------
 lib/eal/loongarch/include/rte_atomic.h |  6 ---
 lib/eal/ppc/include/rte_atomic.h       |  6 ---
 lib/eal/riscv/include/rte_atomic.h     |  6 ---
 lib/eal/x86/include/rte_atomic.h       |  4 --
 7 files changed, 95 deletions(-)
lib/eal/arm/include/rte_atomic_32.h +0 -6
index 0b9a0dfa30..3809ddefb7 100644
@@ -21,12 +21,6 @@ extern "C" {
 
 #define	rte_rmb() __sync_synchronize()
 
-#define rte_smp_mb() rte_mb()
-
-#define rte_smp_wmb() rte_wmb()
-
-#define rte_smp_rmb() rte_rmb()
-
 #define rte_io_mb() rte_mb()
 
 #define rte_io_wmb() rte_wmb()
lib/eal/arm/include/rte_atomic_64.h +0 -6
index 181bb60929..c9b41f6212 100644
@@ -24,12 +24,6 @@ extern "C" {
 
 #define rte_rmb() asm volatile("dmb oshld" : : : "memory")
 
-#define rte_smp_mb() asm volatile("dmb ish" : : : "memory")
-
-#define rte_smp_wmb() asm volatile("dmb ishst" : : : "memory")
-
-#define rte_smp_rmb() asm volatile("dmb ishld" : : : "memory")
-
 #define rte_io_mb() rte_mb()
 
 #define rte_io_wmb() rte_wmb()
lib/eal/include/generic/rte_atomic.h +0 -61

67 lines not on this page · raw message

lib/eal/loongarch/include/rte_atomic.h +0 -6
index c8066a4612..49e0c67020 100644
@@ -22,12 +22,6 @@ extern "C" {
 
 #define rte_rmb()	rte_mb()
 
-#define rte_smp_mb()	rte_mb()
-
-#define rte_smp_wmb()	rte_mb()
-
-#define rte_smp_rmb()	rte_mb()
-
 #define rte_io_mb()	rte_mb()
 
 #define rte_io_wmb()	rte_mb()
lib/eal/ppc/include/rte_atomic.h +0 -6
index 10acc238f9..1da5afccbf 100644
@@ -24,12 +24,6 @@ extern "C" {
 
 #define	rte_rmb() asm volatile("sync" : : : "memory")
 
-#define rte_smp_mb() rte_mb()
-
-#define rte_smp_wmb() rte_wmb()
-
-#define rte_smp_rmb() rte_rmb()
-
 #define rte_io_mb() rte_mb()
 
 #define rte_io_wmb() rte_wmb()
lib/eal/riscv/include/rte_atomic.h +0 -6
index 66346ad474..dd10ad5127 100644
@@ -27,12 +27,6 @@ extern "C" {
 
 #define rte_rmb()	asm volatile("fence r, r" : : : "memory")
 
-#define rte_smp_mb()	rte_mb()
-
-#define rte_smp_wmb()	rte_wmb()
-
-#define rte_smp_rmb()	rte_rmb()
-
 #define rte_io_mb()	asm volatile("fence iorw, iorw" : : : "memory")
 
 #define rte_io_wmb()	asm volatile("fence orw, ow" : : : "memory")
lib/eal/x86/include/rte_atomic.h +0 -4
index 780fdce871..826b5033d1 100644
@@ -23,10 +23,6 @@
 
 #define	rte_rmb() _mm_lfence()
 
-#define rte_smp_wmb() rte_compiler_barrier()
-
-#define rte_smp_rmb() rte_compiler_barrier()
-
 #ifdef __cplusplus
 extern "C" {
 #endif
Signature · 1 line
2.53.0
#95 lore raw

PATCH v2 32/33 checkpatches: no longer warn about rte_smp_XX

In reply to Stephen Hemminger

These macros/functions are now removed.
Any new use will be detected as compile errors.

---
 devtools/checkpatches.sh | 8 --------
 1 file changed, 8 deletions(-)
devtools/checkpatches.sh +0 -8
index 18bd825372..3649645488 100755
@@ -129,14 +129,6 @@ check_forbidden_additions() { # <patch>
 		-f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
 		"$1" || res=1
 
-	# refrain from new additions of rte_smp_[r/w]mb()
-	awk -v FOLDERS="lib drivers app examples" \
-		-v EXPRESSIONS="rte_smp_(r|w)?mb\\\(" \
-		-v RET_ON_FAIL=1 \
-		-v MESSAGE='Using rte_smp_[r/w]mb' \
-		-f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
-		"$1" || res=1
-
 	# refrain from using compiler __sync_xxx builtins
 	awk -v FOLDERS="lib drivers app examples" \
 		-v EXPRESSIONS="__sync_.*\\\(" \
Signature · 1 line
2.53.0
#96 lore raw

PATCH v2 33/33 doc: update release notes about rte_smp_XX removal

In reply to Stephen Hemminger

The functions rte_smp_XX were previously marked for removal. The removal is now complete across the tree.

---
 doc/guides/rel_notes/deprecation.rst   |  8 --------
 doc/guides/rel_notes/release_26_11.rst | 11 +++++++++++
 2 files changed, 11 insertions(+), 8 deletions(-)
doc/guides/rel_notes/deprecation.rst +0 -8
index 6ad7698c6b..ff0bab60ab 100644
@@ -46,14 +46,6 @@ Deprecation Notices
   operations must be used for patches that need to be merged in 20.08 onwards.
   This change will not introduce any performance degradation.
 
-* rte_smp_*mb: These APIs provide full barrier functionality. However, many
-  use cases do not require full barriers. To support such use cases, DPDK has
-  adopted atomic operations from
-  https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html. These
-  operations and a new wrapper ``rte_atomic_thread_fence`` instead of
-  ``__atomic_thread_fence`` must be used for patches that need to be merged in
-  20.08 onwards. This change will not introduce any performance degradation.
-
 * mempool: The ``flushthresh`` field in ``struct rte_mempool_cache`` is obsolete,
   and will be removed in DPDK 26.11.
 
doc/guides/rel_notes/release_26_11.rst +11 -0
index 4b3e5d995c..c545374b6d 100644
@@ -79,6 +79,17 @@ Removed Items
     ``rte_rib6_is_equal``
   * table: ``RTE_LPM_IPV6_ADDR_SIZE``
 
+* Removed SMP memory barriers:
+
+  * ``rte_smp_mb()`` replaced with ``rte_atomic_thread_fence(rte_memory_order_seq_cst)``
+  * ``rte_smp_rmb()`` replaced with ``rte_atomic_thread_fence(rte_memory_order_acquire)``
+  * ``rte_smp_wmb()`` replaced with ``rte_atomic_thread_fence(rte_memory_order_release)``
+
+  Some call sites became release stores or acquire loads instead of a
+  standalone fence. Barriers that order CPU accesses against a device,
+  rather than against another CPU, should use ``rte_io_wmb()`` and
+  ``rte_io_rmb()`` instead.
+
 
 API Changes
 -----------
Signature · 1 line
2.53.0
#97 lore raw

Re: [PATCH v2 00/33] remove rte_smp_XX barrier

In reply to Stephen Hemminger
Quoted 27 lines · Stephen Hemminger

This patch series completes the removal of rte_smp_XX barrier functions that was announced over five years ago (20.05).

In the process several cases of race conditions were found and fixed. See patches 3, 4, and 17. These are marked with Fixes:
tags and Cc: stable.

Most of this is mechanical with AI assistance, so strongly encourage maintainers to take a good look.

Functional and build run on x86 and ARM native.
Should have no functional change, but as previous cleanups of atomic have shown performance might be impacted by compiler bugs.

The lock-free stack patch measured faster than the generic version it replaces, up to 63% on a 32-core x86 box; the numbers are in that patch's commit message.

The RFC removed the barrier test outright.
Konstantin pointed out it still covers the custom x86 seq_cst fence, so patch 19 now keeps the Peterson lock test and rewrites it around rte_atomic_thread_fence(rte_memory_order_seq_cst) instead. Need some careful patch series ordering to keep this all bisect clean.

Quoted 1 line

v2 - address review feedback

I see comments on patch 1.
There are two conflicts after merging the rte_atomicXX cleanup (those look simple).

The last 3 patches are a single topic.

Signature · 1 line
David Marchand
#98 lore raw

v3 cover remove rte_smp_XX barriers

In reply to Stephen Hemminger

This patch series completes the removal of rte_smp_XX barrier functions that was announced over five years ago (20.05).

In the process several cases of race conditions were found and fixed. See patches 3, 4, and 17. These are marked with Fixes:
tags and Cc: stable. Patch 2 is also marked for stable because 3 and 4 do not build with clang without it.

Most of this is mechanical with AI assistance, so strongly encourage maintainers to take a good look.

Functional and build run on x86 and ARM native.
Barriers ordering memory writes against a device doorbell now use rte_io_wmb() rather than an SMP barrier; on arm64 that is dmb oshst instead of dmb ishst. In some cases the C11 form gives marginal performance gains.

The lock-free stack patch measured faster than the generic version it replaces, up to 63% on a 32-core x86 box; the numbers are in that patch's commit message.

The RFC removed the barrier test outright. Konstantin pointed out it still covers the custom x86 seq_cst fence, so patch 19 now keeps the Peterson lock test and converts it to C11 atomics instead, with the fence and rte_mb() as its two cases. It comes before the x86 patch that drops rte_smp_mb(), since it holds the last caller and x86 builds with tests enabled would otherwise break for the rest of the series.

As a side note, Konstantin asked whether the two versions of __rte_ring_headtail_move_head_st() could be merged into one, keeping only the _mt variants separate. That looks reasonable but is out of scope here; left for a follow-up.

v3 - rebase
- address review feedback
- detailed review of bpf change
- reword overly verbose AI verbiage
- combine patches where possible

Stephen Hemminger (29):
bpf: replace deprecated SMP barriers with C11 fences bus/vmbus: remove packed attribute from ring buffer bus/vmbus: fix ring buffer ordering on weakly ordered CPUs bus/vmbus: fix missing acquire on receive ring index bus/vmbus: replace SMP barriers with C11 memory fences drivers/baseband: convert rte_smp_rmb to fence net/hinic: replace rte_smp_rmb
net/intel: replace rte_smp_rmb
net/virtio: replace rte_smp_rmb
net/thunderx: replace deprecated SMP barriers
stack: always use C11 memory model implementation
ring: replace SMP read barrier with C11 acquire fence crypto/virtio: update comment reference to rte_smp_rmb crypto/caam_jr: replace rte_smp_rmb crypto/caam_jr: use IO barrier before job ring doorbell crypto/octeontx: use IO barrier before doorbell event/sw: fix unlinks in progress counter races event/sw: replace SMP barriers with C11 atomics test/barrier: convert to C11 atomics
eal/x86: move optimized fence out of SMP barrier common/octeontx: remove redundant barrier in mbox mempool/octeontx: use IO barrier in pool destroy event/octeontx: replace deprecated SMP barriers event/dpaa2: replace deprecated barrier in selftest event/dsw: replace SMP barriers with release fences event/opdl: replace SMP barriers with C11 atomics net/virtio: replace deprecated barrier in avail index update
eal: remove stale SMP barrier in rte_service
eal: remove rte_smp_XX

 app/test/test_barrier.c                       |  71 ++++----
 devtools/checkpatches.sh                      |   8 -
 doc/guides/rel_notes/deprecation.rst          |   8 -
 doc/guides/rel_notes/release_26_11.rst        |  11 ++
 .../fpga_5gnr_fec/rte_fpga_5gnr_fec.c         |   8 +-
 drivers/baseband/fpga_lte_fec/fpga_lte_fec.c  |  12 +-
 drivers/bus/vmbus/private.h                   |  12 +-
 drivers/bus/vmbus/rte_vmbus_reg.h             |   4 +-
 drivers/bus/vmbus/vmbus_bufring.c             |  22 +--
 drivers/bus/vmbus/vmbus_channel.c             |  13 +-
 drivers/common/octeontx/octeontx_mbox.c       |   6 +-
 drivers/crypto/caam_jr/caam_jr.c              |   5 +-
 .../crypto/octeontx/otx_cryptodev_hw_access.h |   4 +-
 drivers/crypto/virtio/virtqueue.h             |   8 +-
 drivers/event/dpaa2/dpaa2_eventdev_selftest.c |   4 +-
 drivers/event/dsw/dsw_event.c                 |   8 +-
 drivers/event/octeontx/ssovf_evdev_selftest.c |   6 +-
 drivers/event/octeontx/ssovf_worker.c         |   8 +-
 drivers/event/opdl/opdl_evdev.c               |   8 +-
 drivers/event/sw/sw_evdev.c                   |  37 +++--
 drivers/event/sw/sw_evdev.h                   |   2 +-
 drivers/event/sw/sw_evdev_scheduler.c         |  24 ++-
 drivers/mempool/octeontx/octeontx_fpavf.c     |   4 +-
 drivers/net/hinic/base/hinic_pmd_cmdq.c       |   3 +-
 drivers/net/hinic/base/hinic_pmd_mgmt.c       |   2 +-
 drivers/net/intel/ice/ice_rxtx.c              |   2 +-
 drivers/net/intel/ixgbe/ixgbe_rxtx.c          |   2 +-
 drivers/net/thunderx/base/nicvf_hw.c          |   3 +-
 drivers/net/thunderx/base/nicvf_plat.h        |   5 +-
 drivers/net/virtio/virtqueue.h                |  22 +--
 lib/bpf/bpf_pkt.c                             |  45 ++++--
 lib/eal/arm/include/rte_atomic_32.h           |   6 -
 lib/eal/arm/include/rte_atomic_64.h           |   6 -
 lib/eal/common/rte_service.c                  |   1 -
 lib/eal/include/generic/rte_atomic.h          |  61 -------
 lib/eal/loongarch/include/rte_atomic.h        |   6 -
 lib/eal/ppc/include/rte_atomic.h              |   6 -
 lib/eal/riscv/include/rte_atomic.h            |   6 -
 lib/eal/x86/include/rte_atomic.h              |  41 ++---
 lib/ring/rte_ring_gcc_pvt.h                   |   6 +-
 lib/stack/meson.build                         |   1 -
 lib/stack/rte_stack_lf.h                      |   4 -
 lib/stack/rte_stack_lf_generic.h              | 153 ------------------
 43 files changed, 237 insertions(+), 437 deletions(-)
 delete mode 100644 lib/stack/rte_stack_lf_generic.h
Signature · 1 line
2.53.0
#99 lore raw

PATCH v3 1/29 bpf: replace deprecated SMP barriers with C11 fences

The rx/tx callback use counter relied on rte_smp_mb() and rte_smp_rmb(), which are deprecated. Convert it to C11 atomics.

The counter is odd while the datapath is inside the callback and even otherwise. Only one thread at a time does rx/tx burst on a queue, so the counter has a single writer and is updated with a plain load and store.

- bpf_eth_cbi_inuse(): keep a full barrier after the store. The datapath stores the counter then loads cb; unload stores cb then loads the counter. A seq_cst fence on each side makes sure at least one of them sees the other's store.

- bpf_eth_cbi_unuse(): use a release store instead of a read barrier before the increment.

- bpf_eth_cbi_wait(): use acquire loads to pair with that store, so rte_bpf_destroy() is ordered after the datapath's last use of the program.

- bpf_eth_cbi_unload(): drop the barrier; bpf_eth_cbi_wait() starts with one.

With enable_stdatomic the old cbi->use++ was a locked add. On x86 that build now does one locked instruction per burst instead of three.

---
 lib/bpf/bpf_pkt.c | 45 ++++++++++++++++++++++++++++++---------------
 1 file changed, 30 insertions(+), 15 deletions(-)
lib/bpf/bpf_pkt.c +30 -15
index f072fdaaed..95f76e47c7 100644
@@ -36,10 +36,6 @@ struct __rte_cache_aligned bpf_eth_cbi {
 	uint16_t queue;
 };
 
-/*
- * Odd number means that callback is used by datapath.
- * Even number means that callback is not used by datapath.
- */
 #define BPF_ETH_CBI_INUSE  1
 
 /*
@@ -74,15 +70,34 @@ static struct bpf_eth_cbh tx_cbh = {
 	.type = BPF_ETH_TX,
 };
 
+/*
+ * Removing an rx/tx callback involves two steps (similar to RCU).
+ * The callback is first removed from the ethdev queue so that
+ * it will not be used by later burst.
+ * But the callback may still be in process or the core may have
+ * raced and seen the old callback.
+ * The use counter is used to indicate that it is not safe to
+ * free the BPF program yet.
+ * The datapath makes the counter odd on entry and even on exit.
+ * During unload, if the counter is odd then it indicates
+ * we must wait.
+ * This assumes that only one thread at a time may do rx/tx burst
+ * on a queue. Therefore the counter has a single writer and the
+ * increment need not be atomic.
+ */
+
 /*
  * Marks given callback as used by datapath.
  */
 static __rte_always_inline void
 bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
 {
-	cbi->use++;
-	/* make sure no store/load reordering could happen */
-	rte_smp_mb();
+	rte_atomic_store_explicit(&cbi->use,
+		rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed) + 1,
+		rte_memory_order_relaxed);
+
+	/* full barrier: count must be visible before cb is read */
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 }
 
 /*
@@ -91,9 +106,10 @@ bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
 static __rte_always_inline void
 bpf_eth_cbi_unuse(struct bpf_eth_cbi *cbi)
 {
-	/* make sure all previous loads are completed */
-	rte_smp_rmb();
-	cbi->use++;
+	/* release: pairs with the acquire bpf_eth_cbi_wait() */
+	rte_atomic_store_explicit(&cbi->use,
+		rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed) + 1,
+		rte_memory_order_release);
 }
 
 /*
@@ -104,15 +120,15 @@ bpf_eth_cbi_wait(const struct bpf_eth_cbi *cbi)
 {
 	uint32_t puse;
 
-	/* make sure all previous loads and stores are completed */
-	rte_smp_mb();
+	/* full barrier: cleared cb must be visible before counter is read */
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
-	puse = cbi->use;
+	puse = rte_atomic_load_explicit(&cbi->use, rte_memory_order_acquire);
 
 	/* in use, busy wait till current RX/TX iteration is finished */
 	if ((puse & BPF_ETH_CBI_INUSE) != 0) {
 		RTE_WAIT_UNTIL_MASKED((__rte_atomic uint32_t *)(uintptr_t)&cbi->use,
-			UINT32_MAX, !=, puse, rte_memory_order_relaxed);
+			UINT32_MAX, !=, puse, rte_memory_order_acquire);
 	}
 }
 
@@ -439,7 +455,6 @@ bpf_eth_cbi_unload(struct bpf_eth_cbi *bc)
 {
 	/* mark this cbi as empty */
 	bc->cb = NULL;
-	rte_smp_mb();
 
 	/* make sure datapath doesn't use bpf anymore, then destroy bpf */
 	bpf_eth_cbi_wait(bc);
Signature · 1 line
2.53.0
#100 lore raw

Re: [PATCH v3 01/29] bpf: replace deprecated SMP barriers with C11 fences

Quoted 6 lines

/*
* Marks given callback as used by datapath.
*/
static __rte_always_inline void
bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
{

lib/bpf/bpf_pkt.c static struct bpf_eth_cbh tx_cbh = { · line 100

Quoted 9 lines
lib/bpf/bpf_pkt.c +6 -3
-	cbi->use++;
-	/* make sure no store/load reordering could happen */
-	rte_smp_mb();
+	rte_atomic_store_explicit(&cbi->use,
+		rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed) + 1,
+		rte_memory_order_relaxed);
+
+	/* full barrier: count must be visible before cb is read */
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);

This is correct but why use a barrier when the above store itself could be SEQ_CST that synchronizes with load in bpf_eth_cbi_wait?

Quoted 38 lines
  }

/*

lib/bpf/bpf_pkt.c +8 -7
@@ -91,9 +106,10 @@ bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
  static __rte_always_inline void
  bpf_eth_cbi_unuse(struct bpf_eth_cbi *cbi)
  {
-	/* make sure all previous loads are completed */
-	rte_smp_rmb();
-	cbi->use++;
+	/* release: pairs with the acquire bpf_eth_cbi_wait() */
+	rte_atomic_store_explicit(&cbi->use,
+		rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed) + 1,
+		rte_memory_order_release);
  }
 
  /*
@@ -104,15 +120,15 @@ bpf_eth_cbi_wait(const struct bpf_eth_cbi *cbi)
  {
  	uint32_t puse;
 
-	/* make sure all previous loads and stores are completed */
-	rte_smp_mb();
+	/* full barrier: cleared cb must be visible before counter is read */
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
-	puse = cbi->use;
+	puse = rte_atomic_load_explicit(&cbi->use, rte_memory_order_acquire);
 
  	/* in use, busy wait till current RX/TX iteration is finished */
  	if ((puse & BPF_ETH_CBI_INUSE) != 0) {
  		RTE_WAIT_UNTIL_MASKED((__rte_atomic uint32_t *)(uintptr_t)&cbi->use,
-			UINT32_MAX, !=, puse, rte_memory_order_relaxed);
+			UINT32_MAX, !=, puse, rte_memory_order_acquire);
  	}
  }
 

lib/bpf/bpf_pkt.c bpf_eth_cbi_unload(struct bpf_eth_cbi *bc) · line 460

Quoted 7 lines
lib/bpf/bpf_pkt.c +0 -1
@@ -439,7 +455,6 @@ bpf_eth_cbi_unload(struct bpf_eth_cbi *bc)
  {
  	/* mark this cbi as empty */
  	bc->cb = NULL;
-	rte_smp_mb();
 
  	/* make sure datapath doesn't use bpf anymore, then destroy bpf */
  	bpf_eth_cbi_wait(bc);

--wathsala

#101 lore raw

Re: [PATCH v3 01/29] bpf: replace deprecated SMP barriers with C11 fences

Quoted 11 lines · On Fri, 9 Oct 2026 01:05:56 -0500 Wathsala Vithanage…
Quoted 11 lines

/*
* Marks given callback as used by datapath.
*/
static __rte_always_inline void
bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
{

lib/bpf/bpf_pkt.c +2 -3
-	cbi->use++;
-	/* make sure no store/load reordering could happen */
-	rte_smp_mb();
+	rte_atomic_store_explicit(&cbi->use,
+		rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed) + 1,
Quoted 8 lines

lib/bpf/bpf_pkt.c static struct bpf_eth_cbh tx_cbh = { · line 100

Quoted 4 lines
lib/bpf/bpf_pkt.c +4 -0
+		rte_memory_order_relaxed);
+
+	/* full barrier: count must be visible before cb is read */
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);  

This is correct but why use a barrier when the above store itself could be SEQ_CST that
synchronizes with load in bpf_eth_cbi_wait?

There are two different things be covered for safety here. The counter and the callback pointer. The counter uses atomic operations and the callback pointer is referenced without atomic.

AI explains it as:

A seq_cst store on the counter is not enough. This is a store/load pattern across two objects:

datapath: store use, load cb
unload: store cb, load use

At least one side has to see the other's store. Making the store of use seq_cst does not order the datapath's later load of cb, which is a plain load. On arm64 that compiles to stlr followed by ldr, and the ldr can be satisfied before the stlr is visible. Only stlr/ldar pairs are kept in order.

It can be done without fences by making cb atomic and using seq_cst for all four accesses (stlr + ldar on arm64). That touches every callback and is a bigger change than replacing the barriers, so I would rather do it as a follow-up if at all.

There is no cost difference on x86. A seq_cst store is xchg and the fence is lock addl, one locked instruction per burst either way.

Reviewed-by
#102 lore raw

Re: [PATCH v3 01/29] bpf: replace deprecated SMP barriers with C11 fences

Quoted 38 lines · Stephen Hemminger
Quoted 10 lines · On Fri, 9 Oct 2026 01:05:56 -0500 Wathsala Vithanage…
Quoted 10 lines

/*
* Marks given callback as used by datapath.
*/
static __rte_always_inline void
bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
{

lib/bpf/bpf_pkt.c +1 -3
-	cbi->use++;
-	/* make sure no store/load reordering could happen */
-	rte_smp_mb();
+	rte_atomic_store_explicit(&cbi->use,
Quoted 8 lines

lib/bpf/bpf_pkt.c static struct bpf_eth_cbh tx_cbh = { · line 100

Quoted 5 lines
lib/bpf/bpf_pkt.c +5 -0
+		rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed) + 1,
+		rte_memory_order_relaxed);
+
+	/* full barrier: count must be visible before cb is read */
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);

This is correct but why use a barrier when the above store itself could be SEQ_CST that
synchronizes with load in bpf_eth_cbi_wait?

There are two different things be covered for safety here. The counter and the callback pointer. The counter uses atomic operations and the callback pointer is referenced without atomic. AI explains it as:

A seq_cst store on the counter is not enough. This is a store/load pattern across two objects:

datapath: store use, load cb
unload: store cb, load use

At least one side has to see the other's store. Making the store of use seq_cst does not order the datapath's later load of cb, which is a plain load. On arm64 that compiles to stlr followed by ldr, and the ldr can be satisfied before the stlr is visible. Only stlr/ldar pairs are kept in order.

Quoted 8 lines

It can be done without fences by making cb atomic and using seq_cst for all four accesses (stlr + ldar on arm64). That touches every callback and is a bigger change than replacing the barriers, so I would rather do it as a follow-up if at all.

There is no cost difference on x86. A seq_cst store is xchg and the fence is lock addl, one locked instruction per burst either way.

Agreed, barrier is the better implementation than converting everything into seq_cst.

--wathsala

#103 lore raw

Re: [PATCH v3 01/29] bpf: replace deprecated SMP barriers with C11 fences

In reply to Wathsala Vithanage
Quoted 8 lines · Wathsala Vithanage
Quoted 8 lines

  /*
   * Marks given callback as used by datapath.
   */
  static __rte_always_inline void bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
  {
-    cbi->use++;
-    /* make sure no store/load reordering could happen */

Quoted 8 lines
Quoted 8 lines

-    rte_smp_mb();
+    rte_atomic_store_explicit(&cbi->use,
+        rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed) + 1,
+        rte_memory_order_relaxed);
+
+    /* full barrier: count must be visible before cb is read */ +    rte_atomic_thread_fence(rte_memory_order_seq_cst);

NAK: optimizing this increment makes little sense when more careful analysis shows that it can be simply removed.

I highly recommend keeping this patchset dedicated to removing rte_smp_XX barriers and moving other bpf_pkt.c improvements elsewhere.

#104 lore raw

Re: [PATCH v3 01/29] bpf: replace deprecated SMP barriers with C11 fences

Quoted 19 lines · Marat Khalili
Quoted 8 lines · Wathsala Vithanage
Quoted 8 lines

/*
* Marks given callback as used by datapath.
*/
static __rte_always_inline void
bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
{

lib/bpf/bpf_pkt.c +0 -2
-    cbi->use++;
-    /* make sure no store/load reordering could happen */
Quoted 8 lines

lib/bpf/bpf_pkt.c static struct bpf_eth_cbh tx_cbh = { · line 100

Quoted 8 lines
lib/bpf/bpf_pkt.c +2 -1
-    rte_smp_mb();
+    rte_atomic_store_explicit(&cbi->use,
+        rte_atomic_load_explicit(&cbi->use,

rte_memory_order_relaxed) + 1,

lib/bpf/bpf_pkt.c +4 -0
+        rte_memory_order_relaxed);
+
+    /* full barrier: count must be visible before cb is read */
+    rte_atomic_thread_fence(rte_memory_order_seq_cst);
Quoted 5 lines

NAK: optimizing this increment makes little sense when more careful analysis shows that it can be simply removed.

I highly recommend keeping this patchset dedicated to removing rte_smp_XX barriers and moving other bpf_pkt.c improvements elsewhere.

This blocks the SMP barrier removal for rc1.

What is your proposal?

I think it makes sense to take
https://patchwork.dpdk.org/project/dpdk/list/?series=39599 first, then resolve the conflict for the patch from this thread.
Is this BPF series ready for merge?

If it is not ready yet, what should be done on the current patch? Is a s/rte_smp_rmb()/rte_atomic_thread_fence(rte_memory_order_seq_cst)/ enough? The commitlog would also need some rewritting.

Signature · 1 line
David Marchand
#105 lore raw

Re: [PATCH v3 01/29] bpf: replace deprecated SMP barriers with C11 fences

Quoted 4 lines · David Marchand

This blocks the SMP barrier removal for rc1.

What is your proposal?

Quoted 8 lines

I think it makes sense to take
https://patchwork.dpdk.org/project/dpdk/list/?series=39599 first, then resolve the conflict for the patch from this thread.
Is this BPF series ready for merge?

If it is not ready yet, what should be done on the current patch? Is a s/rte_smp_rmb()/rte_atomic_thread_fence(rte_memory_order_seq_cst)/ enough? The commitlog would also need some rewritting.

I think we should be able to unblock this patchset with the diff below. Last version contains some additional out-of-scope changes that might not be helpful in the long run, but I tend to believe Stephen and Wathsala that they are not breaking anything (I have not checked it myself). If the version below is ok with Stephen I would prefer it (consider it acked), otherwise I can withdraw my NAK for the sake of the release, at the cost of some potentially confusing noise in the commit history in the future.

lib/bpf/bpf_pkt.c +0 -0
index f072fdaaed..0d0c37cdc5 100644
@@ -82,7 +82,7 @@ bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)

 {
        cbi->use++;
        /* make sure no store/load reordering could happen */ -       rte_smp_mb();
+       rte_atomic_thread_fence(rte_memory_order_seq_cst); }

 /*
@@ -92,7 +92,7 @@ static __rte_always_inline void bpf_eth_cbi_unuse(struct bpf_eth_cbi *cbi)
 {
        /* make sure all previous loads are completed */ -       rte_smp_rmb();
+       rte_atomic_thread_fence(rte_memory_order_release); cbi->use++;
 }

@@ -105,7 +105,7 @@ bpf_eth_cbi_wait(const struct bpf_eth_cbi *cbi) uint32_t puse;

        /* make sure all previous loads and stores are completed */ -       rte_smp_mb();
+       rte_atomic_thread_fence(rte_memory_order_seq_cst);

        puse = cbi->use;

@@ -439,7 +439,7 @@ bpf_eth_cbi_unload(struct bpf_eth_cbi *bc) {
        /* mark this cbi as empty */
        bc->cb = NULL;
-       rte_smp_mb();
+       rte_atomic_thread_fence(rte_memory_order_seq_cst);

        /* make sure datapath doesn't use bpf anymore, then destroy bpf */ bpf_eth_cbi_wait(bc);

#106 lore raw

Re: [PATCH v3 01/29] bpf: replace deprecated SMP barriers with C11 fences

Quoted 56 lines · On Tue, 13 Oct 2026 17:04:33 +0100 Marat Khalili <[email protected]> wrote:
Quoted 4 lines · David Marchand

This blocks the SMP barrier removal for rc1.

What is your proposal?

Quoted 8 lines

I think it makes sense to take
https://patchwork.dpdk.org/project/dpdk/list/?series=39599 first, then resolve the conflict for the patch from this thread.
Is this BPF series ready for merge?

If it is not ready yet, what should be done on the current patch? Is a s/rte_smp_rmb()/rte_atomic_thread_fence(rte_memory_order_seq_cst)/ enough? The commitlog would also need some rewritting.

I think we should be able to unblock this patchset with the diff below. Last version contains some additional out-of-scope changes that might not be helpful in the long run, but I tend to believe Stephen and Wathsala that they are not breaking anything (I have not checked it myself). If the version below is ok with Stephen I would prefer it (consider it acked), otherwise I can withdraw my NAK for the sake of the release, at the cost of some potentially confusing noise in the commit history in the future.

lib/bpf/bpf_pkt.c +3 -3
index f072fdaaed..0d0c37cdc5 100644
@@ -82,7 +82,7 @@ bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
  {
         cbi->use++;
         /* make sure no store/load reordering could happen */
-       rte_smp_mb();
+       rte_atomic_thread_fence(rte_memory_order_seq_cst);
  }
 
  /*
@@ -92,7 +92,7 @@ static __rte_always_inline void
  bpf_eth_cbi_unuse(struct bpf_eth_cbi *cbi)
  {
         /* make sure all previous loads are completed */
-       rte_smp_rmb();
+       rte_atomic_thread_fence(rte_memory_order_release);
         cbi->use++;
  }
 
@@ -105,7 +105,7 @@ bpf_eth_cbi_wait(const struct bpf_eth_cbi *cbi)
         uint32_t puse;
 
         /* make sure all previous loads and stores are completed */
-       rte_smp_mb();
+       rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
         puse = cbi->use;
 

lib/bpf/bpf_pkt.c bpf_eth_cbi_unload(struct bpf_eth_cbi *bc) · line 445

Quoted 8 lines
lib/bpf/bpf_pkt.c +1 -1
@@ -439,7 +439,7 @@ bpf_eth_cbi_unload(struct bpf_eth_cbi *bc)
  {
         /* mark this cbi as empty */
         bc->cb = NULL;
-       rte_smp_mb();
+       rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
         /* make sure datapath doesn't use bpf anymore, then destroy bpf */
         bpf_eth_cbi_wait(bc);

I am not a language lawyer, but what I read is that C11 atomic fence is defined to only guarantee ordering of atomic objects. Since the use counter is not atomic in the original code, the replacement with rte_atomic_thread_fence() is not the same as original asm.

My patch made these atomic and that is why.

Should have no impact in datapath.

I will respin with better human oriented comments, I have developed a distaste for AI prose. Reads like a lawyer wrote it.

#107 lore raw

Re: [PATCH v3 01/29] bpf: replace deprecated SMP barriers with C11 fences

Quoted 11 lines

I am not a language lawyer, but what I read is that C11 atomic fence is defined to only guarantee ordering of atomic objects. Since the use counter is not atomic in the original code, the replacement with rte_atomic_thread_fence() is not the same as original asm.

My patch made these atomic and that is why.

Should have no impact in datapath.

I will respin with better human oriented comments, I have developed a distaste for AI prose. Reads like a lawyer wrote it.

Just a small clarification: use is currently declared as atomic in main, so all simple reads and writes to it are seq_cst atomic (and simple increment is a pair of two seq_cst atomic operations).

#108 lore raw

Re: [PATCH v3 01/29] bpf: replace deprecated SMP barriers with C11 fences

Quoted 7 lines · On Tue, 13 Oct 2026 22:11:21 +0100 Marat Khalili <[email protected]> wrote:
Quoted 7 lines

I am not a language lawyer, but what I read is that C11 atomic fence is defined to only guarantee ordering of atomic objects. Since the use counter is not atomic in the original code, the replacement with rte_atomic_thread_fence() is not the same as original asm.

My patch made these atomic and that is why.

Quoted 7 lines
Quoted 4 lines

Should have no impact in datapath.

I will respin with better human oriented comments, I have developed a distaste for AI prose. Reads like a lawyer wrote it.

Just a small clarification: use is currently declared as atomic in main, so all simple reads and writes to it are seq_cst atomic (and simple increment is a pair of two seq_cst atomic operations).

Right and non-atomic access to a variable declared as type _Atomic is not allowed by standard and several compilers complain about it.

#109 lore raw

Re: [PATCH v3 01/29] bpf: replace deprecated SMP barriers with C11 fences

In reply to Marat Khalili
Quoted 18 lines · Marat Khalili
Quoted 8 lines · Wathsala Vithanage
Quoted 8 lines

  /*
   * Marks given callback as used by datapath.
   */
  static __rte_always_inline void bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
  {
-    cbi->use++;
-    /* make sure no store/load reordering could happen */

Quoted 8 lines
Quoted 8 lines

-    rte_smp_mb();
+    rte_atomic_store_explicit(&cbi->use,
+        rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed) + 1,
+        rte_memory_order_relaxed);
+
+    /* full barrier: count must be visible before cb is read */ +    rte_atomic_thread_fence(rte_memory_order_seq_cst);

Quoted 3 lines

NAK: optimizing this increment makes little sense when more careful analysis shows that it can be simply removed.

I highly recommend keeping this patchset dedicated to removing rte_smp_XX barriers and moving other bpf_pkt.c improvements elsewhere.

Withdrawing my NAK. It was mostly for stylistic and commit history considerations, we have run out of time and this is the only version that has a reviewed-by.

#110 lore raw

PATCH v3 2/29 bus/vmbus: remove packed attribute from ring buffer

In reply to Stephen Hemminger

The attribute came from the FreeBSD structure this was copied from, which ends in a flexible array member for the ring data and is asserted to be page sized. DPDK computes the data offset from the page size instead and never declared that member, so nothing is left that packing affects: all remaining members are naturally aligned and the layout is identical without it.

Byte alignment does prevent atomic access to the ring indexes, which clang rejects with -Watomic-alignment. The write index store in vmbus_txbr_write() no longer needs a cast through uintptr_t to launder the alignment, so drop it and the comment explaining it.

This is not a fix on its own, so it carries no Fixes: tag, but the two ordering fixes that follow do not build with clang without it.

---
 drivers/bus/vmbus/rte_vmbus_reg.h | 4 ++--
 drivers/bus/vmbus/vmbus_bufring.c | 7 ++-----
 2 files changed, 4 insertions(+), 7 deletions(-)
drivers/bus/vmbus/rte_vmbus_reg.h +2 -2
index 6370a07f95..210328c877 100644
@@ -69,7 +69,7 @@ struct __rte_packed_begin vmbus_mon_page {
  * Buffer ring
  */
 
-struct __rte_packed_begin vmbus_bufring {
+struct vmbus_bufring {
 	volatile uint32_t windex;
 	volatile uint32_t rindex;
 
@@ -111,7 +111,7 @@ struct __rte_packed_begin vmbus_bufring {
 	 * page aligned and starts at rte_mem_page_size() from the beginning
 	 * of this structure
 	 */
-} __rte_packed_end;
+};
 
 /*
  * Channel packets
drivers/bus/vmbus/vmbus_bufring.c +2 -5
index dcd66390a3..b49725da3e 100644
@@ -160,11 +160,8 @@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen,
 	/* Wait for previous producer to publish their windex update */
 	rte_wait_until_equal_32(&vbr->windex, old_windex, rte_memory_order_acquire);
 
-	/* Publish our windex update; prior data writes ordered via release.
-	 * windex is 4-byte aligned in practice (struct is page-aligned, windex
-	 * at offset 0); cast launders the packed-struct alignment-1 attribute.
-	 */
-	rte_atomic_store_explicit((volatile __rte_atomic uint32_t *)(uintptr_t)&vbr->windex,
+	/* Publish our windex update; prior data writes ordered via release. */
+	rte_atomic_store_explicit((volatile uint32_t __rte_atomic *)&vbr->windex,
 				  next_windex, rte_memory_order_release);
 
 	/* If host had read all data before this, then need to signal */
Signature · 1 line
2.53.0
#111 lore raw

PATCH v3 3/29 bus/vmbus: fix ring buffer ordering on weakly ordered CPUs

In reply to Stephen Hemminger

The read index update in vmbus_rxbr_read() was only protected by a compiler barrier. On a weakly ordered architecture the store of rindex can become visible to the host before the data copy completes, allowing the host to reuse and overwrite ring data still being read. Use a release store for the read index.

On x86 no barrier instruction is added, only a different instruction schedule; on arm64 the store becomes stlr.

Fixes 831dba47bd36 ("bus/vmbus: add Hyper-V virtual bus support")
---
 drivers/bus/vmbus/vmbus_bufring.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/bus/vmbus/vmbus_bufring.c +7 -4
index b49725da3e..86dc446786 100644
@@ -238,10 +238,13 @@ vmbus_rxbr_read(struct vmbus_br *rbr, void *data, size_t dlen, size_t skip)
 	 */
 	rindex = vmbus_br_idxinc(rindex, sizeof(uint64_t), br_dsize);
 
-	/* Update the read index _after_ the channel packet is fetched.	 */
-	rte_compiler_barrier();
-
-	vbr->rindex = rindex;
+	/*
+	 * Update the read index after the channel packet is fetched.
+	 * Release store ensures the host can not observe the new read
+	 * index before the data copy is complete.
+	 */
+	rte_atomic_store_explicit((volatile uint32_t __rte_atomic *)&vbr->rindex,
+				  rindex, rte_memory_order_release);
 
 	return 0;
 }
Signature · 1 line
2.53.0
#112 lore raw

PATCH v3 4/29 bus/vmbus: fix missing acquire on receive ring index

In reply to Stephen Hemminger

The receive path checks available data by reading the write index and then copies ring data. The link between the two is only the comparison, a control dependency, which does not order load against load on a weakly ordered architecture: packet data can be read before the host has finished writing it. Load the write index with acquire, pairing with the host's release store. This is the equivalent of virt_rmb() in the Linux hv_pkt_iter code.

On x86 no barrier instruction is added and every affected function keeps its size; on arm64 the load becomes ldar.

Fixes 831dba47bd36 ("bus/vmbus: add Hyper-V virtual bus support")
---
 drivers/bus/vmbus/private.h | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/bus/vmbus/private.h +11 -1
index 6b7782724f..33545b6614 100644
@@ -12,6 +12,7 @@
 #include <bus_driver.h>
 #include <bus_vmbus_driver.h>
 #include <rte_log.h>
+#include <rte_stdatomic.h>
 #include <rte_eal_paging.h>
 #include <rte_vmbus_reg.h>
 
@@ -130,7 +131,16 @@ vmbus_br_availwrite(const struct vmbus_br *br, uint32_t windex)
 static inline uint32_t
 vmbus_br_availread(const struct vmbus_br *br)
 {
-	return br->dsize - vmbus_br_availwrite(br, br->vbr->windex);
+	uint32_t windex;
+
+	/* Pairs with the host's release store of the write index;
+	 * ring data must not be read before the index.
+	 */
+	windex = rte_atomic_load_explicit(
+		(volatile uint32_t __rte_atomic *)&br->vbr->windex,
+		rte_memory_order_acquire);
+
+	return br->dsize - vmbus_br_availwrite(br, windex);
 }
 
 int vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen,
Signature · 1 line
2.53.0
#113 lore raw

PATCH v3 5/29 bus/vmbus: replace SMP barriers with C11 memory fences

In reply to Stephen Hemminger

Full barriers order the preceding index store against the following load of the interrupt mask or pending size and stay seq_cst; read barriers become acquire fences. Same code generated on x86 and arm64.

The write barrier in rte_vmbus_chan_signal_tx() goes away instead. Every caller reaches it through vmbus_txbr_write(), which ends in vmbus_txbr_need_signal() and its full barrier, so the load of the interrupt mask is already ordered after the write index store.

---
 drivers/bus/vmbus/vmbus_bufring.c |  4 ++--
 drivers/bus/vmbus/vmbus_channel.c | 13 ++++++-------
 2 files changed, 8 insertions(+), 9 deletions(-)
drivers/bus/vmbus/vmbus_bufring.c +2 -2
index 86dc446786..95f03929cb 100644
@@ -58,11 +58,11 @@ void vmbus_br_setup(struct vmbus_br *br, void *buf, unsigned int blen)
 static inline bool
 vmbus_txbr_need_signal(const struct vmbus_bufring *vbr, uint32_t old_windex)
 {
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 	if (vbr->imask)
 		return false;
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	/*
 	 * This is the only case we need to signal when the
drivers/bus/vmbus/vmbus_channel.c +6 -7
index 6887fbad46..90ba3d1ef6 100644
@@ -104,10 +104,9 @@ rte_vmbus_chan_signal_tx(struct rte_vmbus_device *dev, const struct vmbus_channe
 {
 	const struct vmbus_br *tbr = &chan->txbr;
 
-	/* Make sure all updates are done before signaling host */
-	rte_smp_wmb();
-
-	/* If host is ignoring interrupts? */
+	/* vmbus_txbr_write() did a full barrier after the write index
+	 * update, no further ordering needed here.
+	 */
 	if (tbr->vbr->imask)
 		return;
 
@@ -211,7 +210,7 @@ bool rte_vmbus_chan_rx_empty(const struct vmbus_channel *channel)
 {
 	const struct vmbus_br *br = &channel->rxbr;
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 	return br->vbr->rindex == br->vbr->windex;
 }
 
@@ -229,13 +228,13 @@ void rte_vmbus_chan_signal_read(struct rte_vmbus_device *dev,
 		return;
 
 	/* Make sure reading of pending happens after new read index */
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
 	pending_sz = rbr->vbr->pending_send;
 	if (!pending_sz)
 		return;
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 	write_sz = vmbus_br_availwrite(rbr, rbr->vbr->windex);
 
 	/* If there was space before then host was not blocked */
Signature · 1 line
2.53.0
#114 lore raw

PATCH v3 6/29 drivers/baseband: convert rte_smp_rmb to fence

In reply to Stephen Hemminger

Replace deprecated rte_smp_rmb with equivalent rte_atomic_thread_fence(rte_memory_order_acquire).

---
 drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c |  8 ++++----
 drivers/baseband/fpga_lte_fec/fpga_lte_fec.c       | 12 ++++++------
 2 files changed, 10 insertions(+), 10 deletions(-)
drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c +4 -4
index 45bd171ca7..e804be4cea 100644
@@ -2662,7 +2662,7 @@ vc_5gnr_dequeue_ldpc_enc_one_op_cb(struct fpga_5gnr_queue *q, struct rte_bbdev_e
 		return -1;
 
 	/* make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	rte_bbdev_log_debug("DMA response desc %p", desc);
 
@@ -2691,7 +2691,7 @@ agx100_dequeue_ldpc_enc_one_op_cb(struct fpga_5gnr_queue *q, struct rte_bbdev_en
 		return -1;
 
 	/* make sure the response is read atomically. */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	rte_bbdev_log_debug("DMA response desc %p", desc);
 
@@ -2723,7 +2723,7 @@ vc_5gnr_dequeue_ldpc_dec_one_op_cb(struct fpga_5gnr_queue *q, struct rte_bbdev_d
 		return -1;
 
 	/* make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 #ifdef RTE_LIBRTE_BBDEV_DEBUG
 	vc_5gnr_print_dma_dec_desc_debug_info(desc);
@@ -2769,7 +2769,7 @@ agx100_dequeue_ldpc_dec_one_op_cb(struct fpga_5gnr_queue *q, struct rte_bbdev_de
 		return -1;
 
 	/* make sure the response is read atomically. */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 #ifdef RTE_LIBRTE_BBDEV_DEBUG
 	agx100_print_dma_dec_desc_debug_info(desc);
drivers/baseband/fpga_lte_fec/fpga_lte_fec.c +6 -6
index 04ac445820..cb3f29c10b 100644
@@ -2093,7 +2093,7 @@ dequeue_enc_one_op_cb(struct fpga_queue *q, struct rte_bbdev_enc_op **op,
 		return -1;
 
 	/* make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	rte_bbdev_log_debug("DMA response desc %p", desc);
 
@@ -2123,7 +2123,7 @@ dequeue_enc_one_op_tb(struct fpga_queue *q, struct rte_bbdev_enc_op **op,
 		return -1;
 
 	/* Make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	/* Verify if done bit in all CBs is set */
 	cbs_in_op = desc->enc_req.cbs_in_op;
@@ -2135,7 +2135,7 @@ dequeue_enc_one_op_tb(struct fpga_queue *q, struct rte_bbdev_enc_op **op,
 	}
 
 	/* Make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	for (cb_idx = 0; cb_idx < cbs_in_op; ++cb_idx) {
 		desc = q->ring_addr + ((q->head_free_desc + desc_offset +
@@ -2166,7 +2166,7 @@ dequeue_dec_one_op_cb(struct fpga_queue *q, struct rte_bbdev_dec_op **op,
 		return -1;
 
 	/* make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 #ifdef RTE_LIBRTE_BBDEV_DEBUG
 	print_dma_dec_desc_debug_info(desc);
@@ -2201,7 +2201,7 @@ dequeue_dec_one_op_tb(struct fpga_queue *q, struct rte_bbdev_dec_op **op,
 		return -1;
 
 	/* Make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	/* Verify if done bit in all CBs is set */
 	cbs_in_op = desc->dec_req.cbs_in_op;
@@ -2213,7 +2213,7 @@ dequeue_dec_one_op_tb(struct fpga_queue *q, struct rte_bbdev_dec_op **op,
 	}
 
 	/* Make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	for (cb_idx = 0; cb_idx < cbs_in_op; ++cb_idx) {
 		desc = q->ring_addr + ((q->head_free_desc + desc_offset +
Signature · 1 line
2.53.0
Acked-by on v3 6/29
#115 lore raw

RE: [PATCH v3 06/29] drivers/baseband: convert rte_smp_rmb to fence

Quoted 129 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Thursday, October 8, 2026 4:35 PM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; Chautru, Nicolas <[email protected]>
Subject: [PATCH v3 06/29] drivers/baseband: convert rte_smp_rmb to fence

Replace deprecated rte_smp_rmb with equivalent rte_atomic_thread_fence(rte_memory_order_acquire).

---
 drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c |  8 ++++----
 drivers/baseband/fpga_lte_fec/fpga_lte_fec.c       | 12 ++++++------
 2 files changed, 10 insertions(+), 10 deletions(-)
drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c +0 -0
index 45bd171ca7..e804be4cea 100644
@@ -2662,7 +2662,7 @@ vc_5gnr_dequeue_ldpc_enc_one_op_cb(struct

fpga_5gnr_queue *q, struct rte_bbdev_e

drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c +1 -1
 		return -1;
 
 	/* make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	rte_bbdev_log_debug("DMA response desc %p", desc);
@@ -2691,7 +2691,7 @@ agx100_dequeue_ldpc_enc_one_op_cb(struct

fpga_5gnr_queue *q, struct rte_bbdev_en

drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c +1 -1
 		return -1;
 
 	/* make sure the response is read atomically. */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	rte_bbdev_log_debug("DMA response desc %p", desc);
@@ -2723,7 +2723,7 @@ vc_5gnr_dequeue_ldpc_dec_one_op_cb(struct

fpga_5gnr_queue *q, struct rte_bbdev_d

drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c +1 -1
 		return -1;
 
 	/* make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 #ifdef RTE_LIBRTE_BBDEV_DEBUG
 	vc_5gnr_print_dma_dec_desc_debug_info(desc);
@@ -2769,7 +2769,7 @@ agx100_dequeue_ldpc_dec_one_op_cb(struct

fpga_5gnr_queue *q, struct rte_bbdev_de

drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c +1 -1
 		return -1;
 
 	/* make sure the response is read atomically. */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 #ifdef RTE_LIBRTE_BBDEV_DEBUG
 	agx100_print_dma_dec_desc_debug_info(desc);
drivers/baseband/fpga_lte_fec/fpga_lte_fec.c +2 -2
index 04ac445820..cb3f29c10b 100644
@@ -2093,7 +2093,7 @@ dequeue_enc_one_op_cb(struct fpga_queue *q,
 struct rte_bbdev_enc_op **op,
 		return -1;
 
 	/* make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	rte_bbdev_log_debug("DMA response desc %p", desc);
@@ -2123,7 +2123,7 @@ dequeue_enc_one_op_tb(struct fpga_queue *q,
 struct rte_bbdev_enc_op **op,
 		return -1;
 
 	/* Make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	/* Verify if done bit in all CBs is set */
drivers/baseband/fpga_lte_fec/fpga_lte_fec.c +1 -1
 	cbs_in_op = desc->enc_req.cbs_in_op;
@@ -2135,7 +2135,7 @@ dequeue_enc_one_op_tb(struct fpga_queue *q,
 struct rte_bbdev_enc_op **op,
 	}
 
 	/* Make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	for (cb_idx = 0; cb_idx < cbs_in_op; ++cb_idx) {
drivers/baseband/fpga_lte_fec/fpga_lte_fec.c +1 -1
 		desc = q->ring_addr + ((q->head_free_desc + desc_offset +
@@ -2166,7 +2166,7 @@ dequeue_dec_one_op_cb(struct fpga_queue *q,
 struct rte_bbdev_dec_op **op,
 		return -1;
 
 	/* make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 #ifdef RTE_LIBRTE_BBDEV_DEBUG
drivers/baseband/fpga_lte_fec/fpga_lte_fec.c +1 -1
 	print_dma_dec_desc_debug_info(desc);
@@ -2201,7 +2201,7 @@ dequeue_dec_one_op_tb(struct fpga_queue *q,
 struct rte_bbdev_dec_op **op,
 		return -1;
 
 	/* Make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	/* Verify if done bit in all CBs is set */
drivers/baseband/fpga_lte_fec/fpga_lte_fec.c +1 -1
 	cbs_in_op = desc->dec_req.cbs_in_op;
@@ -2213,7 +2213,7 @@ dequeue_dec_one_op_tb(struct fpga_queue *q,
 struct rte_bbdev_dec_op **op,
 	}
 
 	/* Make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	for (cb_idx = 0; cb_idx < cbs_in_op; ++cb_idx) {

desc = q->ring_addr + ((q->head_free_desc + desc_offset +
--
2.53.0

#116 lore raw

PATCH v3 7/29 net/hinic: replace rte_smp_rmb

In reply to Stephen Hemminger

Replace deprecated rte_smp_rmb with equivalent rte_atomic_thread_fence(rte_memory_order_acquire).

---
 drivers/net/hinic/base/hinic_pmd_cmdq.c | 3 ++-
 drivers/net/hinic/base/hinic_pmd_mgmt.c | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/net/hinic/base/hinic_pmd_cmdq.c +2 -1
index 1816636c34..57af522f6a 100644
@@ -825,7 +825,8 @@ static int cmdq_sync_cmd_direct_resp(struct hinic_cmdq *cmdq,
 		goto cmdq_unlock;
 	}
 
-	rte_smp_rmb();	/* read error code after completion */
+	/* read error code after completion */
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	if (out_param) {
 		wqe_lcmd = &curr_wqe->wqe_lcmd;
drivers/net/hinic/base/hinic_pmd_mgmt.c +1 -1
index 6ecca407a1..f1a0b15c21 100644
@@ -459,7 +459,7 @@ hinic_pf_to_mgmt_sync(struct hinic_hwdev *hwdev,
 		goto unlock_sync_msg;
 	}
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 	if (recv_msg->msg_len && buf_out && out_size) {
 		if (recv_msg->msg_len <= *out_size) {
 			memcpy(buf_out, recv_msg->msg,
Signature · 1 line
2.53.0
#117 lore raw

PATCH v3 8/29 net/intel: replace rte_smp_rmb

In reply to Stephen Hemminger

Replace deprecated rte_smp_rmb with equivalent rte_atomic_thread_fence(rte_memory_order_acquire).

---
 drivers/net/intel/ice/ice_rxtx.c     | 2 +-
 drivers/net/intel/ixgbe/ixgbe_rxtx.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/intel/ice/ice_rxtx.c +1 -1
index b333444cbf..d01d869e1b 100644
@@ -1963,7 +1963,7 @@ ice_rx_scan_hw_ring(struct ci_rx_queue *rxq)
 		for (j = ICE_LOOK_AHEAD - 1; j >= 0; j--)
 			s[j] = rte_le_to_cpu_16(rxdp[j].wb.status_error0);
 
-		rte_smp_rmb();
+		rte_atomic_thread_fence(rte_memory_order_acquire);
 
 		/* Compute how many status bits were set */
 		for (j = 0, nb_dd = 0; j < ICE_LOOK_AHEAD; j++)
drivers/net/intel/ixgbe/ixgbe_rxtx.c +1 -1
index 60222693fe..ce0a3dde34 100644
@@ -1549,7 +1549,7 @@ ixgbe_rx_scan_hw_ring(struct ci_rx_queue *rxq)
 		for (j = 0; j < LOOK_AHEAD; j++)
 			s[j] = rte_le_to_cpu_32(rxdp[j].wb.upper.status_error);
 
-		rte_smp_rmb();
+		rte_atomic_thread_fence(rte_memory_order_acquire);
 
 		/* Compute how many status bits were set */
 		for (nb_dd = 0; nb_dd < LOOK_AHEAD &&
Signature · 1 line
2.53.0
#118 lore raw

PATCH v3 9/29 net/virtio: replace rte_smp_rmb

In reply to Stephen Hemminger

The x86 special case exists so that both arms of the weak_barriers test compile to the same thing and the compiler drops the branch. That only holds while the barrier is a plain compiler barrier, which rte_atomic_thread_fence(rte_memory_order_acquire) is not: it grows every function in virtio_rxtx.o and brings the branch back.

Use rte_io_rmb(), which is what the else arm already uses and is a compiler barrier on x86, keeping the generated code unchanged. The ordering is unchanged too: x86 does not reorder loads with loads.

---
 drivers/net/virtio/virtqueue.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/net/virtio/virtqueue.h +5 -5
index 1f0e6ae77e..ee21d43068 100644
@@ -445,15 +445,15 @@ virtqueue_nused(const struct virtqueue *vq)
 
 	if (vq->hw->weak_barriers) {
 	/**
-	 * x86 prefers to using rte_smp_rmb over rte_atomic_load_explicit as it
+	 * x86 prefers rte_io_rmb over rte_atomic_load_explicit as it
 	 * reports a slightly better perf, which comes from the saved
-	 * branch by the compiler.
-	 * The if and else branches are identical with the smp and io
-	 * barriers both defined as compiler barriers on x86.
+	 * branch by the compiler: on x86 this makes the two branches
+	 * identical, since rte_io_rmb() is only a compiler barrier and
+	 * loads are not reordered with other loads.
 	 */
 #ifdef RTE_ARCH_X86_64
 		idx = vq->vq_split.ring.used->idx;
-		rte_smp_rmb();
+		rte_io_rmb();
 #else
 		idx = rte_atomic_load_explicit(&(vq)->vq_split.ring.used->idx,
 				rte_memory_order_acquire);
Signature · 1 line
2.53.0
#119 lore raw

PATCH v3 10/29 net/thunderx: replace deprecated SMP barriers

In reply to Stephen Hemminger

Redefine the nicvf barrier wrappers as C11 fences and add an IO variant. The RBDR refill barrier orders descriptor writes in DMA memory against the doorbell register write, which is device
ordering: use the IO barrier there. The mailbox flag barriers are genuine inter thread ordering and become release/acquire fences.

---
 drivers/net/thunderx/base/nicvf_hw.c   | 3 ++-
 drivers/net/thunderx/base/nicvf_plat.h | 5 +++--
 2 files changed, 5 insertions(+), 3 deletions(-)
drivers/net/thunderx/base/nicvf_hw.c +2 -1
index 5b1abe2015..d1e31ffdaa 100644
@@ -499,7 +499,8 @@ nicvf_qset_rbdr_precharge(void *dev, struct nicvf *nic,
 			break;
 		}
 	}
-	nicvf_smp_wmb();
+	/* Descriptors must be visible to the device before the doorbell */
+	nicvf_io_wmb();
 	nicvf_queue_reg_write(nic, NIC_QSET_RBDR_0_1_DOOR, ridx, count);
 	rbdr->tail = nicvf_queue_reg_read(nic,
 				NIC_QSET_RBDR_0_1_TAIL, ridx) >> 3;
drivers/net/thunderx/base/nicvf_plat.h +3 -2
index 8421f57040..08ebb0cf62 100644
@@ -25,8 +25,9 @@
 
 /* barrier */
 #include <rte_atomic.h>
-#define nicvf_smp_wmb() rte_smp_wmb()
-#define nicvf_smp_rmb() rte_smp_rmb()
+#define nicvf_smp_wmb() rte_atomic_thread_fence(rte_memory_order_release)
+#define nicvf_smp_rmb() rte_atomic_thread_fence(rte_memory_order_acquire)
+#define nicvf_io_wmb() rte_io_wmb()
 
 /* utils */
 #include <rte_common.h>
Signature · 1 line
2.53.0
#120 lore raw

PATCH v3 11/29 stack: always use C11 memory model implementation

In reply to Stephen Hemminger

The generic and C11 lock-free stack implementations differ only in memory ordering. The generic version uses a full barrier where its own comments state an acquire fence is sufficient, and seq_cst for all length counter operations.

Only x86 and ThunderX still used the generic version. On x86 the switch removes a locked add per CAS attempt in push and pop; TSO provides the acquire semantics. On ThunderX the pop fence weakens from dmb ish to dmb ishld and the push fence goes away.

Measured on a 32-core x86 machine, stack_perf_autotest, cycles per operation, main versus the unified C11 version (n=9 each):

  Test              main          unified C11   delta
  single push/pop   46.62 +-0.30  33.41 +-0.10  -28%
  empty pop          1.47 +-0.01   0.98 +-0.01  -33%
  1 lcore, bulk 8    9.06 +-0.05   8.20 +-0.08  -10%
  1 lcore, bulk 32   6.09 +-0.02   6.15 +-0.03   +1%
  2 HT, bulk 8      42.05 +-0.31  39.24 +-0.52   -7%
  2 HT, bulk 32     11.92 +-0.13  11.89 +-0.10    0
  2 cores, bulk 8   78.90 +-0.60  72.96 +-1.11   -7%
  2 cores, bulk 32  20.74 +-1.56   7.70 +-0.13  -63%
  32 cores, bulk 8  6126 +-72     6121 +-89       0

32 cores, bulk 32 1953.9 +-2.9 1984.6 +-13.3 +1.6%

The C11 version is faster because it no longer issues the lock add of rte_smp_mb() on every CAS attempt.

Remove the generic version and use the C11 implementation everywhere.

---
 lib/stack/meson.build            |   1 -
 lib/stack/rte_stack_lf.h         |   4 -
 lib/stack/rte_stack_lf_generic.h | 153 -------------------------------
 3 files changed, 158 deletions(-)
 delete mode 100644 lib/stack/rte_stack_lf_generic.h
lib/stack/meson.build +0 -1
index 18177a742f..1fab46208f 100644
@@ -7,7 +7,6 @@ headers = files('rte_stack.h')
 indirect_headers += files(
         'rte_stack_std.h',
         'rte_stack_lf.h',
-        'rte_stack_lf_generic.h',
         'rte_stack_lf_c11.h',
         'rte_stack_lf_stubs.h',
 )
lib/stack/rte_stack_lf.h +0 -4
index f2b012cd0e..1bc6ee8f40 100644
@@ -8,11 +8,7 @@
 #if !(defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_ARM64))
 #include "rte_stack_lf_stubs.h"
 #else
-#ifdef RTE_USE_C11_MEM_MODEL
 #include "rte_stack_lf_c11.h"
-#else
-#include "rte_stack_lf_generic.h"
-#endif
 
 /**
  * Indicates that RTE_STACK_F_LF is supported.
lib/stack/rte_stack_lf_generic.h deleted +0 -153

153 lines not on this page · raw message

Signature · 1 line
2.53.0
#121 lore raw

PATCH v3 12/29 ring: replace SMP read barrier with C11 acquire fence

In reply to Stephen Hemminger

rte_smp_rmb() is deprecated. This code is only used where RTE_USE_C11_MEM_MODEL is unset: x86, ppc64, loongarch and ThunderX. The acquire fence generates the same code on x86 (a compiler barrier) and on ThunderX (dmb ishld). On ppc64 the barrier becomes lwsync instead of sync, which still orders load against load.

The gcc implementation itself is kept: unlike the lock-free stack, the in-tree comment records a 10% x86 performance drop with the C11 version, which needs re-measuring with current compilers before RTE_USE_C11_MEM_MODEL can be removed.

---
 lib/ring/rte_ring_gcc_pvt.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/ring/rte_ring_gcc_pvt.h +3 -3
index 340ece28c7..9c2c58824d 100644
@@ -55,10 +55,10 @@ __rte_ring_headtail_move_head_st(struct rte_ring_headtail *d,
 
 	*old_head = d->head;
 
-	/* add rmb barrier to avoid load/load reorder in weak
-	 * memory model. It is noop on x86
+	/* Acquire fence to avoid load/load reorder in weak
+	 * memory model. It is noop on x86.
 	 */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	/*
 	 *  The subtraction is done between two unsigned 32bits value
Signature · 1 line
2.53.0
Acked-by on v3 12/29
#122 lore raw

Re: [PATCH v3 12/29] ring: replace SMP read barrier with C11 acquire fence

Quoted 36 lines · Stephen Hemminger

rte_smp_rmb() is deprecated. This code is only used where RTE_USE_C11_MEM_MODEL is unset: x86, ppc64, loongarch and ThunderX. The acquire fence generates the same code on x86 (a compiler barrier) and on ThunderX (dmb ishld). On ppc64 the barrier becomes lwsync instead of sync, which still orders load against load.

The gcc implementation itself is kept: unlike the lock-free stack, the in-tree comment records a 10% x86 performance drop with the C11 version, which needs re-measuring with current compilers before RTE_USE_C11_MEM_MODEL can be removed.

---
  lib/ring/rte_ring_gcc_pvt.h | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
lib/ring/rte_ring_gcc_pvt.h +3 -3
index 340ece28c7..9c2c58824d 100644
@@ -55,10 +55,10 @@ __rte_ring_headtail_move_head_st(struct rte_ring_headtail *d,
 
  	*old_head = d->head;
 
-	/* add rmb barrier to avoid load/load reorder in weak
-	 * memory model. It is noop on x86
+	/* Acquire fence to avoid load/load reorder in weak
+	 * memory model. It is noop on x86.
  	 */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
  	/*
  	 *  The subtraction is done between two unsigned 32bits value
#123 lore raw

PATCH v3 13/29 crypto/virtio: update comment reference to rte_smp_rmb

In reply to Stephen Hemminger

The rte_smp_rmb helper is no longer used.

---
 drivers/crypto/virtio/virtqueue.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/crypto/virtio/virtqueue.h +4 -4
index 97a3ace48c..6ef40d3593 100644
@@ -302,11 +302,11 @@ virtqueue_nused(const struct virtqueue *vq)
 
 	if (vq->hw->weak_barriers) {
 	/**
-	 * x86 prefers to using rte_smp_rmb over rte_atomic_load_explicit as it
+	 * x86 prefers virtio_rmb over rte_atomic_load_explicit as it
 	 * reports a slightly better perf, which comes from the saved
-	 * branch by the compiler.
-	 * The if and else branches are identical with the smp and io
-	 * barriers both defined as compiler barriers on x86.
+	 * branch by the compiler: on x86 this makes the two branches
+	 * identical, since virtio_rmb(0) is rte_io_rmb(), only a
+	 * compiler barrier, and loads are not reordered with loads.
 	 */
 #ifdef RTE_ARCH_X86_64
 		idx = vq->vq_split.ring.used->idx;
Signature · 1 line
2.53.0
#124 lore raw

PATCH v3 14/29 crypto/caam_jr: replace rte_smp_rmb

In reply to Stephen Hemminger

Replace rte_smp_rmb with equivalent rte_atomic_thread_fence(rte_memory_order_acquire).

---
 drivers/crypto/caam_jr/caam_jr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/caam_jr/caam_jr.c +1 -1
index 104ce52d11..a7d314bfab 100644
@@ -572,7 +572,7 @@ hw_poll_job_ring(struct sec_job_ring_t *job_ring,
 		job_ring, job_ring->pidx, job_ring->cidx,
 		limit, number_of_jobs_available, jobs_no_to_notify);
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	while (jobs_no_to_notify > notified_descs_no) {
 		static uint64_t false_alarm;
Signature · 1 line
2.53.0
#125 lore raw

PATCH v3 15/29 crypto/caam_jr: use IO barrier before job ring doorbell

In reply to Stephen Hemminger

The barrier orders the input ring descriptor write in DMA memory against the MMIO doorbell write. That is device ordering, not SMP ordering, so rte_io_wmb() is the barrier that expresses it.

---
 drivers/crypto/caam_jr/caam_jr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/crypto/caam_jr/caam_jr.c +2 -1
index a7d314bfab..01a9bed1ff 100644
@@ -1451,7 +1451,8 @@ caam_jr_enqueue_op(struct rte_crypto_op *op, struct caam_jr_qp *qp)
 	/* Set ptr in input ring to current descriptor	*/
 	sec_write_addr(&ring->input_ring[ring->pidx],
 			(phys_addr_t)caam_jr_vtop_ctx(ctx, ctx->jobdes.desc));
-	rte_smp_wmb();
+	/* Descriptor must be visible to the device before the doorbell */
+	rte_io_wmb();
 
 	/* Notify HW that a new job is enqueued */
 	hw_enqueue_desc_on_job_ring(ring);
Signature · 1 line
2.53.0
#126 lore raw

PATCH v3 16/29 crypto/octeontx: use IO barrier before doorbell

In reply to Stephen Hemminger

The doorbell is written with rte_write64_relaxed(), so the barrier before it is what orders the queued instructions against the device. That is device ordering, not SMP ordering: use rte_io_wmb().

---
 drivers/crypto/octeontx/otx_cryptodev_hw_access.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/crypto/octeontx/otx_cryptodev_hw_access.h +2 -2
index 3104e6d31e..096dcf8f87 100644
@@ -203,8 +203,8 @@ static __rte_always_inline void
 otx_cpt_ring_dbell(struct cpt_instance *instance, uint16_t count)
 {
 	struct cpt_vf *cptvf = (struct cpt_vf *)instance;
-	/* Memory barrier to flush pending writes */
-	rte_smp_wmb();
+	/* Instructions must be visible to the device before the doorbell */
+	rte_io_wmb();
 	otx_cpt_write_vq_doorbell(cptvf, count);
 }
 
Signature · 1 line
2.53.0
#127 lore raw

PATCH v3 17/29 event/sw: fix unlinks in progress counter races

In reply to Stephen Hemminger

The counter is written by both the application thread (increment on unlink) and the scheduler (clear on ack) as a plain uint8_t. An increment is lost if it lands between the scheduler's test and clear, making rte_event_port_unlinks_in_progress() report completion before the scheduler has seen the unlink. On a weakly ordered CPU nothing orders the scheduler's cq map reads against the counter test, nor the application's reads against the counter reaching zero.

Make the counter atomic: release fetch-add on unlink, acquire load to read, and an acquire-release exchange to clear. The exchange cannot lose an increment that lands after the test, so the scheduler can keep its relaxed load of the counter first and take the locked read-modify-write only when there is an unlink to acknowledge.

Fixes bd5ac24fea88 ("event/sw: implement unlinks in progress function")
---
 drivers/event/sw/sw_evdev.c           |  8 +++++---
 drivers/event/sw/sw_evdev.h           |  2 +-
 drivers/event/sw/sw_evdev_scheduler.c | 17 ++++++++++++++---
 3 files changed, 20 insertions(+), 7 deletions(-)
drivers/event/sw/sw_evdev.c +5 -3
index a2f760a98d..87a8996f9d 100644
@@ -119,8 +119,9 @@ sw_port_unlink(struct rte_eventdev *dev, void *port, uint8_t queues[],
 		}
 	}
 
-	p->unlinks_in_progress += unlinked;
-	rte_smp_mb();
+	/* Pairs with the acquire exchange in the scheduler */
+	rte_atomic_fetch_add_explicit(&p->unlinks_in_progress, unlinked,
+				      rte_memory_order_release);
 
 	return unlinked;
 }
@@ -130,7 +131,8 @@ sw_port_unlinks_in_progress(struct rte_eventdev *dev, void *port)
 {
 	RTE_SET_USED(dev);
 	struct sw_port *p = port;
-	return p->unlinks_in_progress;
+	return rte_atomic_load_explicit(&p->unlinks_in_progress,
+					rte_memory_order_acquire);
 }
 
 static int
drivers/event/sw/sw_evdev.h +1 -1
index 5e49b08030..22da5d1622 100644
@@ -160,7 +160,7 @@ struct sw_port {
 	 * progress is read by the scheduler, no more events will be pushed to
 	 * the port - hence the scheduler core can just assign zero.
 	 */
-	uint8_t unlinks_in_progress;
+	RTE_ATOMIC(uint8_t) unlinks_in_progress;
 
 	int16_t is_directed; /** Takes from a single directed QID */
 	/**
drivers/event/sw/sw_evdev_scheduler.c +14 -3
index a5fdcf301b..207dee5854 100644
@@ -523,9 +523,20 @@ sw_event_schedule(struct rte_eventdev *dev)
 		do {
 			in_pkts = 0;
 			for (i = 0; i < sw->port_count; i++) {
-				/* ack the unlinks in progress as done */
-				if (sw->ports[i].unlinks_in_progress)
-					sw->ports[i].unlinks_in_progress = 0;
+				struct sw_port *p = &sw->ports[i];
+
+				/* Ack the unlinks in progress as done.
+				 * The exchange cannot lose an increment that
+				 * lands after the test, and its acquire orders
+				 * the cq map reads below after the unlinker's
+				 * map update. Nothing to synchronize with when
+				 * the counter reads zero, so test first and
+				 * keep the locked op off the common path.
+				 */
+				if (rte_atomic_load_explicit(&p->unlinks_in_progress,
+						rte_memory_order_relaxed) != 0)
+					rte_atomic_exchange_explicit(&p->unlinks_in_progress,
+						0, rte_memory_order_acq_rel);
 
 				if (sw->ports[i].is_directed)
 					in_pkts += sw_schedule_pull_port_dir(sw, i);
Signature · 1 line
2.53.0
#128 lore raw

PATCH v3 18/29 event/sw: replace SMP barriers with C11 atomics

In reply to Stephen Hemminger

The write barrier plus plain store publish patterns (cq map count, port initialized, device started) become release stores; the barrier after clearing started in sw_stop() becomes a release fence. All are control path.

The scheduler load of started is acquire, to complete the handshake with the release store in sw_start(). It runs once per service call, not per event.

Scheduler reads of cq_num_mapped_cqs stay plain loads: acquire loads would land in the inner scheduling loops on weakly ordered CPUs. The transient window where a new count is visible before the map entry on such CPUs predates this change and is unchanged by it; unlink is covered by the counter handshake.

---
 drivers/event/sw/sw_evdev.c           | 29 ++++++++++++++++++---------
 drivers/event/sw/sw_evdev_scheduler.c |  7 ++++++-
 2 files changed, 26 insertions(+), 10 deletions(-)
drivers/event/sw/sw_evdev.c +20 -9
index 87a8996f9d..165d8e3950 100644
@@ -84,8 +84,10 @@ sw_port_link(struct rte_eventdev *dev, void *port, const uint8_t queues[],
 		}
 
 		q->cq_map[q->cq_num_mapped_cqs] = p->id;
-		rte_smp_wmb();
-		q->cq_num_mapped_cqs++;
+		/* Release publishes the map entry before the new count */
+		rte_atomic_store_explicit(
+			(uint32_t __rte_atomic *)&q->cq_num_mapped_cqs,
+			q->cq_num_mapped_cqs + 1, rte_memory_order_release);
 	}
 	return i;
 }
@@ -105,8 +107,14 @@ sw_port_unlink(struct rte_eventdev *dev, void *port, uint8_t queues[],
 			if (q->cq_map[j] == p->id) {
 				q->cq_map[j] =
 					q->cq_map[q->cq_num_mapped_cqs - 1];
-				rte_smp_wmb();
-				q->cq_num_mapped_cqs--;
+				/* Release publishes the map update
+				 * before the new count
+				 */
+				rte_atomic_store_explicit(
+					(uint32_t __rte_atomic *)
+						&q->cq_num_mapped_cqs,
+					q->cq_num_mapped_cqs - 1,
+					rte_memory_order_release);
 				unlinked++;
 
 				p->num_qids_mapped--;
@@ -210,8 +218,9 @@ sw_port_setup(struct rte_eventdev *dev, uint8_t port_id,
 	}
 	dev->data->ports[port_id] = p;
 
-	rte_smp_wmb();
-	p->initialized = 1;
+	/* Release publishes the port setup before initialized flag */
+	rte_atomic_store_explicit((uint8_t __rte_atomic *)&p->initialized, 1,
+				  rte_memory_order_release);
 	return 0;
 }
 
@@ -817,8 +826,9 @@ sw_start(struct rte_eventdev *dev)
 	if (sw_xstats_init(sw) < 0)
 		return -EINVAL;
 
-	rte_smp_wmb();
-	sw->started = 1;
+	/* Release publishes device state before the started flag */
+	rte_atomic_store_explicit((uint8_t __rte_atomic *)&sw->started, 1,
+				  rte_memory_order_release);
 
 	return 0;
 }
@@ -847,7 +857,8 @@ sw_stop(struct rte_eventdev *dev)
 	sw_clean_qid_iqs(dev);
 	sw_xstats_uninit(sw);
 	sw->started = 0;
-	rte_smp_wmb();
+	/* Order the started store before re-enabling the service */
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	if (runstate == 1)
 		rte_service_runstate_set(sw->service_id, 1);
drivers/event/sw/sw_evdev_scheduler.c +6 -1
index 207dee5854..5b15c2a9ad 100644
@@ -513,7 +513,12 @@ sw_event_schedule(struct rte_eventdev *dev)
 	uint32_t i;
 
 	sw->sched_called++;
-	if (unlikely(!sw->started))
+	/* Acquire pairs with the release store in sw_start(), so the device
+	 * state it published is visible before any of it is used here. Once
+	 * per service call, not per event.
+	 */
+	if (unlikely(!rte_atomic_load_explicit((uint8_t __rte_atomic *)&sw->started,
+					       rte_memory_order_acquire)))
 		return -EAGAIN;
 
 	do {
Signature · 1 line
2.53.0
#129 lore raw

PATCH v3 19/29 test/barrier: convert to C11 atomics

In reply to Stephen Hemminger

rte_smp_mb() is removed by this series, so the barrier test loses one of its two cases. Replace it with rte_atomic_thread_fence(rte_memory_order_seq_cst), which on x86 is the hand written lock add that Konstantin pointed out is worth keeping covered. rte_mb() stays as the other case: the test cannot prove much about a barrier on any one architecture, but it does keep each one compiled and executed.

Convert the Peterson lock to explicit atomic accesses. The loads in the spin loop are relaxed, leaving the barrier under test as the only thing that keeps them after the stores. The store of victim needs release and not relaxed: the algorithm requires flag[self] to be visible before victim, and two relaxed stores let a weakly ordered CPU commit victim first, which admits both lcores into the critical section with nothing wrong in the barrier.

---
 app/test/test_barrier.c | 71 ++++++++++++++++++++++-------------------
 1 file changed, 39 insertions(+), 32 deletions(-)
app/test/test_barrier.c +39 -32
index 925a88b68a..29024f4242 100644
@@ -2,35 +2,35 @@
  * 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 the full barriers rte_mb() and
+ * rte_atomic_thread_fence(rte_memory_order_seq_cst).
+ * I.E. make sure that LOAD and STORE operations that precede the barrier
+ * 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 particular barrier takes.
+ */
 
+#include <errno.h>
 #include <stdio.h>
-#include <string.h>
 #include <stdint.h>
+#include <stdlib.h>
+#include <string.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_memory.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"
 
@@ -39,13 +39,13 @@
 
 enum plock_use_type {
 	USE_MB,
-	USE_SMP_MB,
+	USE_FENCE,
 	USE_NUM
 };
 
 struct plock {
-	volatile uint32_t flag[2];
-	volatile uint32_t victim;
+	RTE_ATOMIC(uint32_t) flag[2];
+	RTE_ATOMIC(uint32_t) victim;
 	enum plock_use_type utype;
 };
 
@@ -70,18 +70,20 @@ struct lcore_plock_test {
 };
 
 static inline void
-store_load_barrier(uint32_t utype)
+store_load_barrier(enum plock_use_type utype)
 {
 	if (utype == USE_MB)
 		rte_mb();
-	else if (utype == USE_SMP_MB)
-		rte_smp_mb();
 	else
-		RTE_VERIFY(0);
+		rte_atomic_thread_fence(rte_memory_order_seq_cst);
 }
 
 /*
  * Peterson lock implementation.
+ * The loads in the spin loop are relaxed on purpose: the barrier under
+ * test is the only thing keeping them after the stores above, so a
+ * barrier that fails to prevent store-load reordering shows up as two
+ * lcores in the critical section at once.
  */
 static void
 plock_lock(struct plock *l, uint32_t self)
@@ -90,22 +92,27 @@ 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);
+
+	/* Release so that the other lcore cannot see this lcore claim to be
+	 * the victim while its flag still reads zero, which would let both
+	 * lcores through.
+	 */
+	rte_atomic_store_explicit(&l->victim, self, rte_memory_order_release);
 
 	store_load_barrier(l->utype);
 
-	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();
+
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 }
 
 static void
 plock_unlock(struct plock *l, uint32_t self)
 {
-	rte_smp_wmb();
-	l->flag[self] = 0;
+	rte_atomic_store_explicit(&l->flag[self], 0, rte_memory_order_release);
 }
 
 static void
Signature · 1 line
2.53.0
#130 lore raw

PATCH v3 20/29 eal/x86: move optimized fence out of SMP barrier

In reply to Stephen Hemminger

rte_atomic_thread_fence() implemented the seq_cst case by calling the deprecated rte_smp_mb(). Invert the dependency: the lock add based fence moves into rte_atomic_thread_fence(), and rte_smp_mb() goes away with it since the test that was its last user is converted in the preceding patch. The optimization itself must stay; a plain seq_cst fence is an mfence, about twice the cost. No change in generated code.

---
 lib/eal/x86/include/rte_atomic.h | 37 ++++++++++++++------------------
 1 file changed, 16 insertions(+), 21 deletions(-)
lib/eal/x86/include/rte_atomic.h +16 -21
index 20a4baa575..a46bedb0f0 100644
@@ -60,23 +60,8 @@ extern "C" {
  * Basic idea is to use lock prefixed add with some dummy memory location
  * as the destination. From their experiments 128B(2 cache lines) below
  * current stack pointer looks like a good candidate.
- * So below we use that technique for rte_smp_mb() implementation.
  */
 
-static __rte_always_inline void
-rte_smp_mb(void)
-{
-#ifdef RTE_TOOLCHAIN_MSVC
-	_mm_mfence();
-#else
-#ifdef RTE_ARCH_I686
-	asm volatile("lock addl $0, -128(%%esp); " ::: "memory");
-#else
-	asm volatile("lock addl $0, -128(%%rsp); " ::: "memory");
-#endif
-#endif
-}
-
 #define rte_io_mb() rte_mb()
 
 #define rte_io_wmb() rte_compiler_barrier()
@@ -86,17 +71,27 @@ rte_smp_mb(void)
 /**
  * Synchronization fence between threads based on the specified memory order.
  *
- * On x86 the __rte_atomic_thread_fence(rte_memory_order_seq_cst) generates full 'mfence'
- * which is quite expensive. The optimized implementation of rte_smp_mb is
- * used instead.
+ * On x86 the __rte_atomic_thread_fence(rte_memory_order_seq_cst) generates
+ * a full 'mfence' which is quite expensive. The optimized lock add on a
+ * dummy stack location (see above) is used instead.
  */
 static __rte_always_inline void
 rte_atomic_thread_fence(rte_memory_order memorder)
 {
-	if (memorder == rte_memory_order_seq_cst)
-		rte_smp_mb();
-	else
+	if (memorder != rte_memory_order_seq_cst) {
 		__rte_atomic_thread_fence(memorder);
+		return;
+	}
+
+#ifdef RTE_TOOLCHAIN_MSVC
+	_mm_mfence();
+#else
+#ifdef RTE_ARCH_I686
+	asm volatile("lock addl $0, -128(%%esp); " ::: "memory");
+#else
+	asm volatile("lock addl $0, -128(%%rsp); " ::: "memory");
+#endif
+#endif
 }
 
 #ifdef __cplusplus
Signature · 1 line
2.53.0
#131 lore raw

PATCH v3 21/29 common/octeontx: remove redundant barrier in mbox

In reply to Stephen Hemminger

The SMP write barrier between writing the mailbox header and ringing the mailbox register is redundant: rte_write64() begins with rte_io_wmb(), which already orders the header write before the trigger, and does so against the device rather than only within the inner shareable domain.

---
 drivers/common/octeontx/octeontx_mbox.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/common/octeontx/octeontx_mbox.c +4 -2
index 9e0bbf453f..8b0da3a98e 100644
@@ -113,8 +113,10 @@ mbox_send_request(struct mbox *m, struct octeontx_mbox_hdr *hdr,
 
 	/* Write the msg header */
 	rte_write64(new_hdr.u64, ram_mbox_hdr);
-	rte_smp_wmb();
-	/* Notify PF about the new msg - write to MBOX reg generates PF IRQ */
+	/* Notify PF about the new msg - write to MBOX reg generates PF IRQ.
+	 * rte_write64() issues rte_io_wmb() which orders the header write
+	 * before the trigger; no separate barrier is needed.
+	 */
 	rte_write64(0, m->reg);
 }
 
Signature · 1 line
2.53.0
#132 lore raw

PATCH v3 22/29 mempool/octeontx: use IO barrier in pool destroy

In reply to Stephen Hemminger

The barrier flushes outstanding writes to the FPA pool before the teardown mailbox sequence. That is ordering against the device, so use rte_io_wmb(). Control path.

---
 drivers/mempool/octeontx/octeontx_fpavf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mempool/octeontx/octeontx_fpavf.c +2 -2
index 6cd0fc057f..7051422cb7 100644
@@ -616,8 +616,8 @@ octeontx_fpa_bufpool_destroy(uintptr_t handle, int node_id)
 
 	RTE_SET_USED(node_id);
 
-	/* Wait for all outstanding writes to be committed */
-	rte_smp_wmb();
+	/* Make outstanding pool writes visible to the device */
+	rte_io_wmb();
 
 	if (unlikely(!octeontx_fpa_handle_valid(handle)))
 		return -EINVAL;
Signature · 1 line
2.53.0
#133 lore raw

PATCH v3 23/29 event/octeontx: replace deprecated SMP barriers

In reply to Stephen Hemminger

The worker barriers order event payload writes in normal memory before the add work or tag switch store to the SSO device, so they are IO ordering: use rte_io_wmb(). The selftest barriers publish worker parameters before launching lcores; convert them to release fences.

---
 drivers/event/octeontx/ssovf_evdev_selftest.c | 6 +++---
 drivers/event/octeontx/ssovf_worker.c         | 8 ++++----
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/event/octeontx/ssovf_evdev_selftest.c +3 -3
index e51b89a31e..df8e710b57 100644
@@ -65,7 +65,7 @@ seqn_list_update(int val)
 		return -1;
 
 	seqn_list[seqn_list_index++] = val;
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 	return 0;
 }
 
@@ -636,7 +636,7 @@ launch_workers_and_wait(int (*main_worker)(void *),
 	param[0].sched_type = sched_type;
 	param[0].port = 0;
 	param[0].dequeue_tmo_ticks = dequeue_tmo_ticks;
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	w_lcore = rte_get_next_lcore(
 			/* start core */ -1,
@@ -649,7 +649,7 @@ launch_workers_and_wait(int (*main_worker)(void *),
 		param[port].sched_type = sched_type;
 		param[port].port = port;
 		param[port].dequeue_tmo_ticks = dequeue_tmo_ticks;
-		rte_smp_wmb();
+		rte_atomic_thread_fence(rte_memory_order_release);
 		w_lcore = rte_get_next_lcore(w_lcore, 1, 0);
 		rte_eal_remote_launch(worker, &param[port], w_lcore);
 	}
drivers/event/octeontx/ssovf_worker.c +4 -4
index 89b5dc056c..f3c6a0da5c 100644
@@ -59,10 +59,10 @@ ssows_fwd_group(struct ssows *ws, const struct rte_event *ev, const uint8_t grp)
 		newtag |= grp << 20;
 		newtag |= tag;
 		ssows_swtag_norm(ws, newtag, SSO_SYNC_ATOMIC);
-		rte_smp_wmb();
+		rte_io_wmb();
 		ssows_swtag_wait(ws);
 	} else {
-		rte_smp_wmb();
+		rte_io_wmb();
 	}
 	ssows_add_work(ws, event_ptr, tag, new_tt, grp);
 }
@@ -158,7 +158,7 @@ ssows_enq_burst(void *port, const struct rte_event ev[], uint16_t nb_events)
 
 	switch (ev->op) {
 	case RTE_EVENT_OP_NEW:
-		rte_smp_wmb();
+		rte_io_wmb();
 		ssows_new_event(ws, ev);
 		break;
 	case RTE_EVENT_OP_FORWARD:
@@ -179,7 +179,7 @@ ssows_enq_new_burst(void *port, const struct rte_event ev[], uint16_t nb_events)
 	uint16_t i;
 	struct ssows *ws = port;
 
-	rte_smp_wmb();
+	rte_io_wmb();
 	for (i = 0; i < nb_events; i++)
 		ssows_new_event(ws,  &ev[i]);
 
Signature · 1 line
2.53.0
#134 lore raw

PATCH v3 24/29 event/dpaa2: replace deprecated barrier in selftest

In reply to Stephen Hemminger

Publish worker parameters with a release fence before launching the lcores instead of the deprecated SMP write barrier.

---
 drivers/event/dpaa2/dpaa2_eventdev_selftest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/event/dpaa2/dpaa2_eventdev_selftest.c +2 -2
index 2c688bd194..b1e4bf6855 100644
@@ -526,7 +526,7 @@ launch_workers_and_wait(int (*main_worker)(void *),
 	param[0].sched_type = sched_type;
 	param[0].port = 0;
 	param[0].dequeue_tmo_ticks = dequeue_tmo_ticks;
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	w_lcore = rte_get_next_lcore(
 			/* start core */ -1,
@@ -539,7 +539,7 @@ launch_workers_and_wait(int (*main_worker)(void *),
 		param[port].sched_type = sched_type;
 		param[port].port = port;
 		param[port].dequeue_tmo_ticks = dequeue_tmo_ticks;
-		rte_smp_wmb();
+		rte_atomic_thread_fence(rte_memory_order_release);
 		w_lcore = rte_get_next_lcore(w_lcore, 1, 0);
 		rte_eal_remote_launch(workers, &param[port], w_lcore);
 	}
Signature · 1 line
2.53.0
#135 lore raw

PATCH v3 25/29 event/dsw: replace SMP barriers with release fences

In reply to Stephen Hemminger

All four barriers publish flow table or ring updates before a control message enqueue, which is release ordering. All are on the migration control path, not per event.

The fences may in fact be removable: the control messages travel through rte_ring, whose producer tail update is itself a release store covering the preceding writes. Left in place here to keep this a like for like conversion.

---
 drivers/event/dsw/dsw_event.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/event/dsw/dsw_event.c +4 -4
index 399d9f050e..82d3636b29 100644
@@ -339,7 +339,7 @@ dsw_port_handle_pause_flows(struct dsw_evdev *dsw, struct dsw_port *port,
 	/* Make sure any stores to the original port's in_ring is seen
 	 * before the ctl message.
 	 */
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	dsw_port_ctl_enqueue(&dsw->ports[originating_port_id], &cfm);
 }
@@ -821,7 +821,7 @@ dsw_port_move_parallel_flows(struct dsw_evdev *dsw,
 		}
 	}
 
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	dsw_port_end_emigration(dsw, source_port, RTE_SCHED_TYPE_PARALLEL);
 }
@@ -1190,7 +1190,7 @@ dsw_port_move_emigrating_flows(struct dsw_evdev *dsw,
 		    dest_port_id;
 	}
 
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	dsw_port_drain_in_ring(source_port);
 	dsw_port_forward_emigrated_flows(dsw, source_port);
@@ -1213,7 +1213,7 @@ dsw_port_move_emigrating_flows(struct dsw_evdev *dsw,
 	/* Flow table update and migration destination port's enqueues
 	 * must be seen before the control message.
 	 */
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	dsw_port_ctl_broadcast(dsw, source_port, DSW_CTL_UNPAUSE_REQ,
 			       source_port->emigration_target_qfs,
Signature · 1 line
2.53.0
#136 lore raw

PATCH v3 26/29 event/opdl: replace SMP barriers with C11 atomics

In reply to Stephen Hemminger

Publishing the port becomes a release store of the configured flag. Control path.

Drop the barrier after clearing started in opdl_stop(): no store follows it, and the datapath tests data->dev_started, not device->started.

---
 drivers/event/opdl/opdl_evdev.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/event/opdl/opdl_evdev.c +3 -5
index ffa65ef930..44a648a11a 100644
@@ -200,8 +200,9 @@ opdl_port_setup(struct rte_eventdev *dev,
 	p->queue_id = OPDL_INVALID_QID;
 	p->external_qid = OPDL_INVALID_QID;
 	dev->data->ports[port_id] = p;
-	rte_smp_wmb();
-	p->configured = 1;
+	/* Release publishes port setup before the configured flag */
+	rte_atomic_store_explicit((uint8_t __rte_atomic *)&p->configured, 1,
+				  rte_memory_order_release);
 	device->nb_ports++;
 	return 0;
 }
@@ -474,10 +475,7 @@ opdl_stop(struct rte_eventdev *dev)
 
 	destroy_queues_and_rings(dev);
 
-
 	device->started = 0;
-
-	rte_smp_wmb();
 }
 
 static int
Signature · 1 line
2.53.0
#137 lore raw

PATCH v3 27/29 net/virtio: replace deprecated barrier in avail index update

In reply to Stephen Hemminger

As with virtqueue_nused(), the x86 special case only pays off while both arms of the weak_barriers test compile to the same thing, which rules out rte_atomic_thread_fence(rte_memory_order_release). Use rte_io_wmb(), a compiler barrier on x86, where stores are not reordered with other stores.

---
 drivers/net/virtio/virtqueue.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/net/virtio/virtqueue.h +6 -6
index ee21d43068..8fd2999132 100644
@@ -474,14 +474,14 @@ static inline void
 vq_update_avail_idx(struct virtqueue *vq)
 {
 	if (vq->hw->weak_barriers) {
-	/* x86 prefers to using rte_smp_wmb over rte_atomic_store_explicit as
-	 * it reports a slightly better perf, which comes from the
-	 * saved branch by the compiler.
-	 * The if and else branches are identical with the smp and
-	 * io barriers both defined as compiler barriers on x86.
+	/* x86 prefers rte_io_wmb over rte_atomic_store_explicit as it
+	 * reports a slightly better perf, which comes from the saved
+	 * branch by the compiler: on x86 this makes the two branches
+	 * identical, since rte_io_wmb() is only a compiler barrier and
+	 * stores are not reordered with other stores.
 	 */
 #ifdef RTE_ARCH_X86_64
-		rte_smp_wmb();
+		rte_io_wmb();
 		vq->vq_split.ring.avail->idx = vq->vq_avail_idx;
 #else
 		rte_atomic_store_explicit(&vq->vq_split.ring.avail->idx,
Signature · 1 line
2.53.0
#138 lore raw

PATCH v3 28/29 eal: remove stale SMP barrier in rte_service

In reply to Stephen Hemminger

Leftover missed by the C11 atomics conversion of this file. The barrier pairs with nothing: no store follows it, and the next use of the lcore is synchronized by remote launch.

---
 lib/eal/common/rte_service.c | 1 -
 1 file changed, 1 deletion(-)
lib/eal/common/rte_service.c +0 -1
index d2ac9d3f14..0c6467285b 100644
@@ -795,7 +795,6 @@ rte_service_lcore_del(uint32_t lcore)
 
 	set_lcore_state(lcore, ROLE_RTE);
 
-	rte_smp_wmb();
 	return 0;
 }
 
Signature · 1 line
2.53.0
#139 lore raw

PATCH v3 29/29 eal: remove rte_smp_XX

In reply to Stephen Hemminger

These functions were marked for deprecation over five years ago and have no users left in the tree. Drop them from EAL, along with the deprecation notice, and record the replacements in the release notes.

Checkpatch no longer looks for them: now that the macros are gone, any remaining use is a compile error.

---
 devtools/checkpatches.sh               |  8 ----
 doc/guides/rel_notes/deprecation.rst   |  8 ----
 doc/guides/rel_notes/release_26_11.rst | 11 +++++
 lib/eal/arm/include/rte_atomic_32.h    |  6 ---
 lib/eal/arm/include/rte_atomic_64.h    |  6 ---
 lib/eal/include/generic/rte_atomic.h   | 61 --------------------------
 lib/eal/loongarch/include/rte_atomic.h |  6 ---
 lib/eal/ppc/include/rte_atomic.h       |  6 ---
 lib/eal/riscv/include/rte_atomic.h     |  6 ---
 lib/eal/x86/include/rte_atomic.h       |  4 --
 10 files changed, 11 insertions(+), 111 deletions(-)
devtools/checkpatches.sh +0 -8
index 466e06410a..c52fb5d1b6 100755
@@ -121,14 +121,6 @@ check_forbidden_additions() { # <patch>
 		-f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
 		"$1" || res=1
 
-	# refrain from new additions of rte_smp_[r/w]mb()
-	awk -v FOLDERS="lib drivers app examples" \
-		-v EXPRESSIONS="rte_smp_(r|w)?mb\\\(" \
-		-v RET_ON_FAIL=1 \
-		-v MESSAGE='Using rte_smp_[r/w]mb' \
-		-f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
-		"$1" || res=1
-
 	# refrain from using compiler __sync_xxx builtins
 	awk -v FOLDERS="lib drivers app examples" \
 		-v EXPRESSIONS="__sync_.*\\\(" \
doc/guides/rel_notes/deprecation.rst +0 -8
index 56a67c372e..600d789df8 100644
@@ -39,14 +39,6 @@ Deprecation Notices
   as part of its internal API. All drivers will be adjusted
   to use the new unified VFIO container device assignment API.
 
-* rte_smp_*mb: These APIs provide full barrier functionality. However, many
-  use cases do not require full barriers. To support such use cases, DPDK has
-  adopted atomic operations from
-  https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html. These
-  operations and a new wrapper ``rte_atomic_thread_fence`` instead of
-  ``__atomic_thread_fence`` must be used for patches that need to be merged in
-  20.08 onwards. This change will not introduce any performance degradation.
-
 * mempool: The ``flushthresh`` field in ``struct rte_mempool_cache`` is obsolete,
   and will be removed in DPDK 26.11.
 
doc/guides/rel_notes/release_26_11.rst +11 -0
index 16d3a90723..dd21c87afa 100644
@@ -182,6 +182,17 @@ Removed Items
   ``cmpset`` and ``exchange``). Use the C11 ``rte_atomic_*_explicit``
   operations instead.
 
+* Removed SMP memory barriers:
+
+  * ``rte_smp_mb()`` replaced with ``rte_atomic_thread_fence(rte_memory_order_seq_cst)``
+  * ``rte_smp_rmb()`` replaced with ``rte_atomic_thread_fence(rte_memory_order_acquire)``
+  * ``rte_smp_wmb()`` replaced with ``rte_atomic_thread_fence(rte_memory_order_release)``
+
+  Some call sites became release stores or acquire loads instead of a
+  standalone fence. Barriers that order CPU accesses against a device,
+  rather than against another CPU, should use ``rte_io_wmb()`` and
+  ``rte_io_rmb()`` instead.
+
 * ethdev: Removed support for ethdev queue stats mapping.
 
   ``rte_eth_dev_set_tx_queue_stats_mapping`` and ``rte_eth_dev_set_rx_queue_stats_mapping``
lib/eal/arm/include/rte_atomic_32.h +0 -6
index 696a539fef..4115271091 100644
@@ -17,12 +17,6 @@ extern "C" {
 
 #define	rte_rmb() __sync_synchronize()
 
-#define rte_smp_mb() rte_mb()
-
-#define rte_smp_wmb() rte_wmb()
-
-#define rte_smp_rmb() rte_rmb()
-
 #define rte_io_mb() rte_mb()
 
 #define rte_io_wmb() rte_wmb()
lib/eal/arm/include/rte_atomic_64.h +0 -6
index 9f790238df..604e777bcd 100644
@@ -20,12 +20,6 @@ extern "C" {
 
 #define rte_rmb() asm volatile("dmb oshld" : : : "memory")
 
-#define rte_smp_mb() asm volatile("dmb ish" : : : "memory")
-
-#define rte_smp_wmb() asm volatile("dmb ishst" : : : "memory")
-
-#define rte_smp_rmb() asm volatile("dmb ishld" : : : "memory")
-
 #define rte_io_mb() rte_mb()
 
 #define rte_io_wmb() rte_wmb()
lib/eal/include/generic/rte_atomic.h +0 -61

67 lines not on this page · raw message

lib/eal/loongarch/include/rte_atomic.h +0 -6
index 785a452c9e..a789e3ab4d 100644
@@ -18,12 +18,6 @@ extern "C" {
 
 #define rte_rmb()	rte_mb()
 
-#define rte_smp_mb()	rte_mb()
-
-#define rte_smp_wmb()	rte_mb()
-
-#define rte_smp_rmb()	rte_mb()
-
 #define rte_io_mb()	rte_mb()
 
 #define rte_io_wmb()	rte_mb()
lib/eal/ppc/include/rte_atomic.h +0 -6
index d3bd50a11a..1e5c1747e6 100644
@@ -24,12 +24,6 @@ extern "C" {
 
 #define	rte_rmb() asm volatile("sync" : : : "memory")
 
-#define rte_smp_mb() rte_mb()
-
-#define rte_smp_wmb() rte_wmb()
-
-#define rte_smp_rmb() rte_rmb()
-
 #define rte_io_mb() rte_mb()
 
 #define rte_io_wmb() rte_wmb()
lib/eal/riscv/include/rte_atomic.h +0 -6
index 061b175f33..04c40e4e9b 100644
@@ -23,12 +23,6 @@ extern "C" {
 
 #define rte_rmb()	asm volatile("fence r, r" : : : "memory")
 
-#define rte_smp_mb()	rte_mb()
-
-#define rte_smp_wmb()	rte_wmb()
-
-#define rte_smp_rmb()	rte_rmb()
-
 #define rte_io_mb()	asm volatile("fence iorw, iorw" : : : "memory")
 
 #define rte_io_wmb()	asm volatile("fence orw, ow" : : : "memory")
lib/eal/x86/include/rte_atomic.h +0 -4
index a46bedb0f0..0ed9421055 100644
@@ -23,10 +23,6 @@
 
 #define	rte_rmb() _mm_lfence()
 
-#define rte_smp_wmb() rte_compiler_barrier()
-
-#define rte_smp_rmb() rte_compiler_barrier()
-
 #ifdef __cplusplus
 extern "C" {
 #endif
Signature · 1 line
2.53.0
#140 lore raw

v4 cover remove rte_smp_XX barriers

In reply to Stephen Hemminger

This patch series completes the removal of rte_smp_XX barrier functions that was announced over five years ago (20.05).

In the process several race conditions were found and fixed. See patches 3, 4 and 17, marked with Fixes: and Cc: stable. Patch 2 is also marked for stable because 3 and 4 do not build with clang without it.

Most of this is mechanical with AI assistance, so strongly encourage maintainers to take a good look.

Barriers ordering memory writes against a device doorbell now use rte_io_wmb() rather than an SMP barrier; on arm64 that is dmb oshst instead of dmb ishst. In some cases the C11 form gives marginal performance gains.

The lock-free stack patch measured faster than the generic version it replaces, up to 63% on a 32-core x86 box; the numbers are in that patch's commit message.

Patch 19 keeps the Peterson lock test, converted to C11 atomics, with the seq_cst fence and rte_mb() as its two cases. It comes before patch 20, which holds the last rte_smp_mb() caller, so x86 builds with tests enabled stay bisectable. Tested on x86, arm and riscv; still untested on ppc and loongarch.

Patch 18 has no ack. Bruce, yours landed on 17; 18 changed since.

Left for follow-up: device read barriers in patches 6, 8 and 14 are acquire fences where rte_io_rmb() would match the write side (same generated code today, so no regression). And the net/thunderx mailbox flags in patch 10 are plain bitfields that need to be atomic, which is pre-existing.

v4 - rebase on main, which obsoleted the netvsc patch; address review
comments from Konstantin, Marat, David and Wei Hu; collect tags

Stephen Hemminger (29):
bpf: replace deprecated SMP barriers with C11 fences bus/vmbus: remove packed attribute from ring buffer bus/vmbus: fix ring buffer ordering on weakly ordered CPUs bus/vmbus: fix missing acquire on receive ring index bus/vmbus: replace SMP barriers with C11 memory fences drivers/baseband: convert rte_smp_rmb to fence net/hinic: replace rte_smp_rmb
net/intel: replace rte_smp_rmb
net/virtio: replace rte_smp_rmb
net/thunderx: replace deprecated SMP barriers
stack: always use C11 memory model implementation
ring: replace SMP read barrier with C11 acquire fence crypto/virtio: update comment reference to rte_smp_rmb crypto/caam_jr: replace rte_smp_rmb crypto/caam_jr: use IO barrier before job ring doorbell crypto/octeontx: use IO barrier before doorbell event/sw: fix unlinks in progress counter races event/sw: replace SMP barriers with C11 atomics test/barrier: convert to C11 atomics
eal/x86: move optimized fence out of SMP barrier common/octeontx: remove redundant barrier in mbox mempool/octeontx: use IO barrier in pool destroy event/octeontx: replace deprecated SMP barriers event/dpaa2: replace deprecated barrier in selftest event/dsw: replace SMP barriers with release fences event/opdl: replace SMP barriers with C11 atomics net/virtio: replace deprecated barrier in avail index update
eal: remove stale SMP barrier in rte_service
eal: remove rte_smp_XX

 app/test/test_barrier.c                       |  71 ++++----
 devtools/checkpatches.sh                      |   8 -
 doc/guides/rel_notes/deprecation.rst          |   8 -
 doc/guides/rel_notes/release_26_11.rst        |  11 ++
 .../fpga_5gnr_fec/rte_fpga_5gnr_fec.c         |   8 +-
 drivers/baseband/fpga_lte_fec/fpga_lte_fec.c  |  12 +-
 drivers/bus/vmbus/private.h                   |  12 +-
 drivers/bus/vmbus/rte_vmbus_reg.h             |   4 +-
 drivers/bus/vmbus/vmbus_bufring.c             |  22 +--
 drivers/bus/vmbus/vmbus_channel.c             |  13 +-
 drivers/common/octeontx/octeontx_mbox.c       |   6 +-
 drivers/crypto/caam_jr/caam_jr.c              |   5 +-
 .../crypto/octeontx/otx_cryptodev_hw_access.h |   4 +-
 drivers/crypto/virtio/virtqueue.h             |   8 +-
 drivers/event/dpaa2/dpaa2_eventdev_selftest.c |   4 +-
 drivers/event/dsw/dsw_event.c                 |   8 +-
 drivers/event/octeontx/ssovf_evdev_selftest.c |   6 +-
 drivers/event/octeontx/ssovf_worker.c         |   8 +-
 drivers/event/opdl/opdl_evdev.c               |   8 +-
 drivers/event/sw/sw_evdev.c                   |  37 +++--
 drivers/event/sw/sw_evdev.h                   |  11 +-
 drivers/event/sw/sw_evdev_scheduler.c         |  24 ++-
 drivers/mempool/octeontx/octeontx_fpavf.c     |   4 +-
 drivers/net/hinic/base/hinic_pmd_cmdq.c       |   3 +-
 drivers/net/hinic/base/hinic_pmd_mgmt.c       |   2 +-
 drivers/net/intel/ice/ice_rxtx.c              |   2 +-
 drivers/net/intel/ixgbe/ixgbe_rxtx.c          |   2 +-
 drivers/net/thunderx/base/nicvf_hw.c          |   3 +-
 drivers/net/thunderx/base/nicvf_plat.h        |   5 +-
 drivers/net/virtio/virtqueue.h                |  22 +--
 lib/bpf/bpf_pkt.c                             |  26 +--
 lib/eal/arm/include/rte_atomic_32.h           |   6 -
 lib/eal/arm/include/rte_atomic_64.h           |   6 -
 lib/eal/common/rte_service.c                  |   1 -
 lib/eal/include/generic/rte_atomic.h          |  61 -------
 lib/eal/loongarch/include/rte_atomic.h        |   6 -
 lib/eal/ppc/include/rte_atomic.h              |   6 -
 lib/eal/riscv/include/rte_atomic.h            |   6 -
 lib/eal/x86/include/rte_atomic.h              |  41 ++---
 lib/ring/rte_ring_gcc_pvt.h                   |   6 +-
 lib/stack/meson.build                         |   1 -
 lib/stack/rte_stack_lf.h                      |   4 -
 lib/stack/rte_stack_lf_generic.h              | 153 ------------------
 43 files changed, 226 insertions(+), 438 deletions(-)
 delete mode 100644 lib/stack/rte_stack_lf_generic.h
Signature · 1 line
2.53.0
#141 lore raw

PATCH v4 1/29 bpf: replace deprecated SMP barriers with C11 fences

Convert the rx/tx callback use counter from rte_smp_mb() and rte_smp_rmb() to C11 atomics.

The counter has a single writer per queue (MT_LOCKFREE tx is not handled, before or after), so use a relaxed load and store instead of a locked increment. Keep the seq_cst fence in inuse and wait for the counter/cb store-load pair. Use a release store in unuse paired with acquire loads in wait, so rte_bpf_destroy() is ordered after the last datapath use. Drop the extra fence in unload.

With enable_stdatomic, x86 now does one locked instruction per burst instead of three.

---
 lib/bpf/bpf_pkt.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)
lib/bpf/bpf_pkt.c +15 -11
index f072fdaaed..f6acc69d25 100644
@@ -80,9 +80,13 @@ static struct bpf_eth_cbh tx_cbh = {
 static __rte_always_inline void
 bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
 {
-	cbi->use++;
-	/* make sure no store/load reordering could happen */
-	rte_smp_mb();
+	uint32_t puse = rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed);
+
+	/* increment use count: does not need to be locked */
+	rte_atomic_store_explicit(&cbi->use, puse + 1, rte_memory_order_relaxed);
+
+	/* full barrier: count must be visible before cb is read */
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 }
 
 /*
@@ -91,9 +95,10 @@ bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
 static __rte_always_inline void
 bpf_eth_cbi_unuse(struct bpf_eth_cbi *cbi)
 {
-	/* make sure all previous loads are completed */
-	rte_smp_rmb();
-	cbi->use++;
+	uint32_t puse =	rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed);
+
+	/* release: pairs with the acquire bpf_eth_cbi_wait() */
+	rte_atomic_store_explicit(&cbi->use, puse + 1, rte_memory_order_release);
 }
 
 /*
@@ -104,15 +109,15 @@ bpf_eth_cbi_wait(const struct bpf_eth_cbi *cbi)
 {
 	uint32_t puse;
 
-	/* make sure all previous loads and stores are completed */
-	rte_smp_mb();
+	/* full barrier: cleared cb must be visible before counter is read */
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
-	puse = cbi->use;
+	puse = rte_atomic_load_explicit(&cbi->use, rte_memory_order_acquire);
 
 	/* in use, busy wait till current RX/TX iteration is finished */
 	if ((puse & BPF_ETH_CBI_INUSE) != 0) {
 		RTE_WAIT_UNTIL_MASKED((__rte_atomic uint32_t *)(uintptr_t)&cbi->use,
-			UINT32_MAX, !=, puse, rte_memory_order_relaxed);
+			UINT32_MAX, !=, puse, rte_memory_order_acquire);
 	}
 }
 
@@ -439,7 +444,6 @@ bpf_eth_cbi_unload(struct bpf_eth_cbi *bc)
 {
 	/* mark this cbi as empty */
 	bc->cb = NULL;
-	rte_smp_mb();
 
 	/* make sure datapath doesn't use bpf anymore, then destroy bpf */
 	bpf_eth_cbi_wait(bc);
Signature · 1 line
2.53.0
#142 lore raw

Re: [PATCH v4 01/29] bpf: replace deprecated SMP barriers with C11 fences

Hi Stephen,

Do you plan to make a stable revision of this patch to address https://bugs.dpdk.org/show_bug.cgi?id=2055 ?

Do you think we can just close it? There are no reports of this ever becoming a problem, and the probability seems very low.

#143 lore raw

PATCH v4 2/29 bus/vmbus: remove packed attribute from ring buffer

In reply to Stephen Hemminger

The attribute came from the FreeBSD structure this was copied from, which ends in a flexible array member for the ring data and is asserted to be page sized. DPDK computes the data offset from the page size instead and never declared that member, so nothing is left that packing affects: all remaining members are naturally aligned and the layout is identical without it.

Byte alignment does prevent atomic access to the ring indexes, which clang rejects with -Watomic-alignment. The write index store in vmbus_txbr_write() no longer needs a cast through uintptr_t to launder the alignment, so drop it and the comment explaining it.

This is not a fix on its own, so it carries no Fixes: tag, but the two ordering fixes that follow do not build with clang without it.

---
 drivers/bus/vmbus/rte_vmbus_reg.h | 4 ++--
 drivers/bus/vmbus/vmbus_bufring.c | 7 ++-----
 2 files changed, 4 insertions(+), 7 deletions(-)
drivers/bus/vmbus/rte_vmbus_reg.h +2 -2
index 6370a07f95..210328c877 100644
@@ -69,7 +69,7 @@ struct __rte_packed_begin vmbus_mon_page {
  * Buffer ring
  */
 
-struct __rte_packed_begin vmbus_bufring {
+struct vmbus_bufring {
 	volatile uint32_t windex;
 	volatile uint32_t rindex;
 
@@ -111,7 +111,7 @@ struct __rte_packed_begin vmbus_bufring {
 	 * page aligned and starts at rte_mem_page_size() from the beginning
 	 * of this structure
 	 */
-} __rte_packed_end;
+};
 
 /*
  * Channel packets
drivers/bus/vmbus/vmbus_bufring.c +2 -5
index dcd66390a3..b49725da3e 100644
@@ -160,11 +160,8 @@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen,
 	/* Wait for previous producer to publish their windex update */
 	rte_wait_until_equal_32(&vbr->windex, old_windex, rte_memory_order_acquire);
 
-	/* Publish our windex update; prior data writes ordered via release.
-	 * windex is 4-byte aligned in practice (struct is page-aligned, windex
-	 * at offset 0); cast launders the packed-struct alignment-1 attribute.
-	 */
-	rte_atomic_store_explicit((volatile __rte_atomic uint32_t *)(uintptr_t)&vbr->windex,
+	/* Publish our windex update; prior data writes ordered via release. */
+	rte_atomic_store_explicit((volatile uint32_t __rte_atomic *)&vbr->windex,
 				  next_windex, rte_memory_order_release);
 
 	/* If host had read all data before this, then need to signal */
Signature · 1 line
2.53.0
#144 lore raw

PATCH v4 3/29 bus/vmbus: fix ring buffer ordering on weakly ordered CPUs

In reply to Stephen Hemminger

The read index update in vmbus_rxbr_read() was only protected by a compiler barrier. On a weakly ordered architecture the store of rindex can become visible to the host before the data copy completes, allowing the host to reuse and overwrite ring data still being read. Use a release store for the read index.

On x86 no barrier instruction is added, only a different instruction schedule; on arm64 the store becomes stlr.

Fixes 831dba47bd36 ("bus/vmbus: add Hyper-V virtual bus support")
---
 drivers/bus/vmbus/vmbus_bufring.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/bus/vmbus/vmbus_bufring.c +7 -4
index b49725da3e..86dc446786 100644
@@ -238,10 +238,13 @@ vmbus_rxbr_read(struct vmbus_br *rbr, void *data, size_t dlen, size_t skip)
 	 */
 	rindex = vmbus_br_idxinc(rindex, sizeof(uint64_t), br_dsize);
 
-	/* Update the read index _after_ the channel packet is fetched.	 */
-	rte_compiler_barrier();
-
-	vbr->rindex = rindex;
+	/*
+	 * Update the read index after the channel packet is fetched.
+	 * Release store ensures the host can not observe the new read
+	 * index before the data copy is complete.
+	 */
+	rte_atomic_store_explicit((volatile uint32_t __rte_atomic *)&vbr->rindex,
+				  rindex, rte_memory_order_release);
 
 	return 0;
 }
Signature · 1 line
2.53.0
#145 lore raw

PATCH v4 4/29 bus/vmbus: fix missing acquire on receive ring index

In reply to Stephen Hemminger

The receive path checks available data by reading the write index and then copies ring data. The link between the two is only the comparison, a control dependency, which does not order load against load on a weakly ordered architecture: packet data can be read before the host has finished writing it. Load the write index with acquire, pairing with the host's release store. This is the equivalent of virt_rmb() in the Linux hv_pkt_iter code.

On x86 no barrier instruction is added and every affected function keeps its size; on arm64 the load becomes ldar.

Fixes 831dba47bd36 ("bus/vmbus: add Hyper-V virtual bus support")
---
 drivers/bus/vmbus/private.h | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/bus/vmbus/private.h +11 -1
index 6b7782724f..33545b6614 100644
@@ -12,6 +12,7 @@
 #include <bus_driver.h>
 #include <bus_vmbus_driver.h>
 #include <rte_log.h>
+#include <rte_stdatomic.h>
 #include <rte_eal_paging.h>
 #include <rte_vmbus_reg.h>
 
@@ -130,7 +131,16 @@ vmbus_br_availwrite(const struct vmbus_br *br, uint32_t windex)
 static inline uint32_t
 vmbus_br_availread(const struct vmbus_br *br)
 {
-	return br->dsize - vmbus_br_availwrite(br, br->vbr->windex);
+	uint32_t windex;
+
+	/* Pairs with the host's release store of the write index;
+	 * ring data must not be read before the index.
+	 */
+	windex = rte_atomic_load_explicit(
+		(volatile uint32_t __rte_atomic *)&br->vbr->windex,
+		rte_memory_order_acquire);
+
+	return br->dsize - vmbus_br_availwrite(br, windex);
 }
 
 int vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen,
Signature · 1 line
2.53.0
#146 lore raw

PATCH v4 5/29 bus/vmbus: replace SMP barriers with C11 memory fences

In reply to Stephen Hemminger

Full barriers order the preceding index store against the following load of the interrupt mask or pending size and stay seq_cst; read barriers become acquire fences. Same code generated on x86 and arm64.

The write barrier in rte_vmbus_chan_signal_tx() goes away instead. Every caller reaches it through vmbus_txbr_write(), which ends in vmbus_txbr_need_signal() and its full barrier, so the load of the interrupt mask is already ordered after the write index store.

---
 drivers/bus/vmbus/vmbus_bufring.c |  4 ++--
 drivers/bus/vmbus/vmbus_channel.c | 13 ++++++-------
 2 files changed, 8 insertions(+), 9 deletions(-)
drivers/bus/vmbus/vmbus_bufring.c +2 -2
index 86dc446786..95f03929cb 100644
@@ -58,11 +58,11 @@ void vmbus_br_setup(struct vmbus_br *br, void *buf, unsigned int blen)
 static inline bool
 vmbus_txbr_need_signal(const struct vmbus_bufring *vbr, uint32_t old_windex)
 {
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 	if (vbr->imask)
 		return false;
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	/*
 	 * This is the only case we need to signal when the
drivers/bus/vmbus/vmbus_channel.c +6 -7
index 6887fbad46..90ba3d1ef6 100644
@@ -104,10 +104,9 @@ rte_vmbus_chan_signal_tx(struct rte_vmbus_device *dev, const struct vmbus_channe
 {
 	const struct vmbus_br *tbr = &chan->txbr;
 
-	/* Make sure all updates are done before signaling host */
-	rte_smp_wmb();
-
-	/* If host is ignoring interrupts? */
+	/* vmbus_txbr_write() did a full barrier after the write index
+	 * update, no further ordering needed here.
+	 */
 	if (tbr->vbr->imask)
 		return;
 
@@ -211,7 +210,7 @@ bool rte_vmbus_chan_rx_empty(const struct vmbus_channel *channel)
 {
 	const struct vmbus_br *br = &channel->rxbr;
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 	return br->vbr->rindex == br->vbr->windex;
 }
 
@@ -229,13 +228,13 @@ void rte_vmbus_chan_signal_read(struct rte_vmbus_device *dev,
 		return;
 
 	/* Make sure reading of pending happens after new read index */
-	rte_smp_mb();
+	rte_atomic_thread_fence(rte_memory_order_seq_cst);
 
 	pending_sz = rbr->vbr->pending_send;
 	if (!pending_sz)
 		return;
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 	write_sz = vmbus_br_availwrite(rbr, rbr->vbr->windex);
 
 	/* If there was space before then host was not blocked */
Signature · 1 line
2.53.0
#147 lore raw

PATCH v4 6/29 drivers/baseband: convert rte_smp_rmb to fence

In reply to Stephen Hemminger

Replace deprecated rte_smp_rmb with equivalent rte_atomic_thread_fence(rte_memory_order_acquire).

---
 drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c |  8 ++++----
 drivers/baseband/fpga_lte_fec/fpga_lte_fec.c       | 12 ++++++------
 2 files changed, 10 insertions(+), 10 deletions(-)
drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c +4 -4
index 45bd171ca7..e804be4cea 100644
@@ -2662,7 +2662,7 @@ vc_5gnr_dequeue_ldpc_enc_one_op_cb(struct fpga_5gnr_queue *q, struct rte_bbdev_e
 		return -1;
 
 	/* make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	rte_bbdev_log_debug("DMA response desc %p", desc);
 
@@ -2691,7 +2691,7 @@ agx100_dequeue_ldpc_enc_one_op_cb(struct fpga_5gnr_queue *q, struct rte_bbdev_en
 		return -1;
 
 	/* make sure the response is read atomically. */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	rte_bbdev_log_debug("DMA response desc %p", desc);
 
@@ -2723,7 +2723,7 @@ vc_5gnr_dequeue_ldpc_dec_one_op_cb(struct fpga_5gnr_queue *q, struct rte_bbdev_d
 		return -1;
 
 	/* make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 #ifdef RTE_LIBRTE_BBDEV_DEBUG
 	vc_5gnr_print_dma_dec_desc_debug_info(desc);
@@ -2769,7 +2769,7 @@ agx100_dequeue_ldpc_dec_one_op_cb(struct fpga_5gnr_queue *q, struct rte_bbdev_de
 		return -1;
 
 	/* make sure the response is read atomically. */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 #ifdef RTE_LIBRTE_BBDEV_DEBUG
 	agx100_print_dma_dec_desc_debug_info(desc);
drivers/baseband/fpga_lte_fec/fpga_lte_fec.c +6 -6
index 04ac445820..cb3f29c10b 100644
@@ -2093,7 +2093,7 @@ dequeue_enc_one_op_cb(struct fpga_queue *q, struct rte_bbdev_enc_op **op,
 		return -1;
 
 	/* make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	rte_bbdev_log_debug("DMA response desc %p", desc);
 
@@ -2123,7 +2123,7 @@ dequeue_enc_one_op_tb(struct fpga_queue *q, struct rte_bbdev_enc_op **op,
 		return -1;
 
 	/* Make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	/* Verify if done bit in all CBs is set */
 	cbs_in_op = desc->enc_req.cbs_in_op;
@@ -2135,7 +2135,7 @@ dequeue_enc_one_op_tb(struct fpga_queue *q, struct rte_bbdev_enc_op **op,
 	}
 
 	/* Make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	for (cb_idx = 0; cb_idx < cbs_in_op; ++cb_idx) {
 		desc = q->ring_addr + ((q->head_free_desc + desc_offset +
@@ -2166,7 +2166,7 @@ dequeue_dec_one_op_cb(struct fpga_queue *q, struct rte_bbdev_dec_op **op,
 		return -1;
 
 	/* make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 #ifdef RTE_LIBRTE_BBDEV_DEBUG
 	print_dma_dec_desc_debug_info(desc);
@@ -2201,7 +2201,7 @@ dequeue_dec_one_op_tb(struct fpga_queue *q, struct rte_bbdev_dec_op **op,
 		return -1;
 
 	/* Make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	/* Verify if done bit in all CBs is set */
 	cbs_in_op = desc->dec_req.cbs_in_op;
@@ -2213,7 +2213,7 @@ dequeue_dec_one_op_tb(struct fpga_queue *q, struct rte_bbdev_dec_op **op,
 	}
 
 	/* Make sure the response is read atomically */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	for (cb_idx = 0; cb_idx < cbs_in_op; ++cb_idx) {
 		desc = q->ring_addr + ((q->head_free_desc + desc_offset +
Signature · 1 line
2.53.0
#148 lore raw

PATCH v4 7/29 net/hinic: replace rte_smp_rmb

In reply to Stephen Hemminger

Replace deprecated rte_smp_rmb with equivalent rte_atomic_thread_fence(rte_memory_order_acquire).

---
 drivers/net/hinic/base/hinic_pmd_cmdq.c | 3 ++-
 drivers/net/hinic/base/hinic_pmd_mgmt.c | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/net/hinic/base/hinic_pmd_cmdq.c +2 -1
index 1816636c34..57af522f6a 100644
@@ -825,7 +825,8 @@ static int cmdq_sync_cmd_direct_resp(struct hinic_cmdq *cmdq,
 		goto cmdq_unlock;
 	}
 
-	rte_smp_rmb();	/* read error code after completion */
+	/* read error code after completion */
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	if (out_param) {
 		wqe_lcmd = &curr_wqe->wqe_lcmd;
drivers/net/hinic/base/hinic_pmd_mgmt.c +1 -1
index 6ecca407a1..f1a0b15c21 100644
@@ -459,7 +459,7 @@ hinic_pf_to_mgmt_sync(struct hinic_hwdev *hwdev,
 		goto unlock_sync_msg;
 	}
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 	if (recv_msg->msg_len && buf_out && out_size) {
 		if (recv_msg->msg_len <= *out_size) {
 			memcpy(buf_out, recv_msg->msg,
Signature · 1 line
2.53.0
#149 lore raw

PATCH v4 8/29 net/intel: replace rte_smp_rmb

In reply to Stephen Hemminger

Replace deprecated rte_smp_rmb with equivalent rte_atomic_thread_fence(rte_memory_order_acquire).

---
 drivers/net/intel/ice/ice_rxtx.c     | 2 +-
 drivers/net/intel/ixgbe/ixgbe_rxtx.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/intel/ice/ice_rxtx.c +1 -1
index b333444cbf..d01d869e1b 100644
@@ -1963,7 +1963,7 @@ ice_rx_scan_hw_ring(struct ci_rx_queue *rxq)
 		for (j = ICE_LOOK_AHEAD - 1; j >= 0; j--)
 			s[j] = rte_le_to_cpu_16(rxdp[j].wb.status_error0);
 
-		rte_smp_rmb();
+		rte_atomic_thread_fence(rte_memory_order_acquire);
 
 		/* Compute how many status bits were set */
 		for (j = 0, nb_dd = 0; j < ICE_LOOK_AHEAD; j++)
drivers/net/intel/ixgbe/ixgbe_rxtx.c +1 -1
index 60222693fe..ce0a3dde34 100644
@@ -1549,7 +1549,7 @@ ixgbe_rx_scan_hw_ring(struct ci_rx_queue *rxq)
 		for (j = 0; j < LOOK_AHEAD; j++)
 			s[j] = rte_le_to_cpu_32(rxdp[j].wb.upper.status_error);
 
-		rte_smp_rmb();
+		rte_atomic_thread_fence(rte_memory_order_acquire);
 
 		/* Compute how many status bits were set */
 		for (nb_dd = 0; nb_dd < LOOK_AHEAD &&
Signature · 1 line
2.53.0
#150 lore raw

PATCH v4 9/29 net/virtio: replace rte_smp_rmb

In reply to Stephen Hemminger

The x86 special case exists so that both arms of the weak_barriers test compile to the same thing and the compiler drops the branch. That only holds while the barrier is a plain compiler barrier, which rte_atomic_thread_fence(rte_memory_order_acquire) is not: it grows every function in virtio_rxtx.o and brings the branch back.

Use rte_io_rmb(), which is what the else arm already uses and is a compiler barrier on x86, keeping the generated code unchanged. The ordering is unchanged too: x86 does not reorder loads with loads.

---
 drivers/net/virtio/virtqueue.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/net/virtio/virtqueue.h +5 -5
index 1f0e6ae77e..ee21d43068 100644
@@ -445,15 +445,15 @@ virtqueue_nused(const struct virtqueue *vq)
 
 	if (vq->hw->weak_barriers) {
 	/**
-	 * x86 prefers to using rte_smp_rmb over rte_atomic_load_explicit as it
+	 * x86 prefers rte_io_rmb over rte_atomic_load_explicit as it
 	 * reports a slightly better perf, which comes from the saved
-	 * branch by the compiler.
-	 * The if and else branches are identical with the smp and io
-	 * barriers both defined as compiler barriers on x86.
+	 * branch by the compiler: on x86 this makes the two branches
+	 * identical, since rte_io_rmb() is only a compiler barrier and
+	 * loads are not reordered with other loads.
 	 */
 #ifdef RTE_ARCH_X86_64
 		idx = vq->vq_split.ring.used->idx;
-		rte_smp_rmb();
+		rte_io_rmb();
 #else
 		idx = rte_atomic_load_explicit(&(vq)->vq_split.ring.used->idx,
 				rte_memory_order_acquire);
Signature · 1 line
2.53.0
#151 lore raw

PATCH v4 10/29 net/thunderx: replace deprecated SMP barriers

In reply to Stephen Hemminger

Redefine the nicvf barrier wrappers as C11 fences and add an IO variant. The RBDR refill barrier orders descriptor writes in DMA memory against the doorbell register write, which is device
ordering: use the IO barrier there.

The mailbox flag barriers are inter thread ordering and become release/acquire fences, matching what the old barriers did. Note the flags they order (pf_acked, pf_nacked) are plain bitfields sharing a byte with other fields, so a fence alone is not sufficient for them under C11; making them atomic is a pre-existing issue left for a separate patch.

---
 drivers/net/thunderx/base/nicvf_hw.c   | 3 ++-
 drivers/net/thunderx/base/nicvf_plat.h | 5 +++--
 2 files changed, 5 insertions(+), 3 deletions(-)
drivers/net/thunderx/base/nicvf_hw.c +2 -1
index 5b1abe2015..d1e31ffdaa 100644
@@ -499,7 +499,8 @@ nicvf_qset_rbdr_precharge(void *dev, struct nicvf *nic,
 			break;
 		}
 	}
-	nicvf_smp_wmb();
+	/* Descriptors must be visible to the device before the doorbell */
+	nicvf_io_wmb();
 	nicvf_queue_reg_write(nic, NIC_QSET_RBDR_0_1_DOOR, ridx, count);
 	rbdr->tail = nicvf_queue_reg_read(nic,
 				NIC_QSET_RBDR_0_1_TAIL, ridx) >> 3;
drivers/net/thunderx/base/nicvf_plat.h +3 -2
index 8421f57040..08ebb0cf62 100644
@@ -25,8 +25,9 @@
 
 /* barrier */
 #include <rte_atomic.h>
-#define nicvf_smp_wmb() rte_smp_wmb()
-#define nicvf_smp_rmb() rte_smp_rmb()
+#define nicvf_smp_wmb() rte_atomic_thread_fence(rte_memory_order_release)
+#define nicvf_smp_rmb() rte_atomic_thread_fence(rte_memory_order_acquire)
+#define nicvf_io_wmb() rte_io_wmb()
 
 /* utils */
 #include <rte_common.h>
Signature · 1 line
2.53.0
#152 lore raw

PATCH v4 11/29 stack: always use C11 memory model implementation

In reply to Stephen Hemminger

The generic and C11 lock-free stack implementations differ only in memory ordering. The generic version uses a full barrier where its own comments state an acquire fence is sufficient, and seq_cst for all length counter operations.

Only x86 and ThunderX still used the generic version. On x86 the switch removes a locked add per CAS attempt in push and pop; TSO provides the acquire semantics. On ThunderX the pop fence weakens from dmb ish to dmb ishld and the push fence goes away.

Measured on a 32-core x86 machine, stack_perf_autotest, cycles per operation, main versus the unified C11 version (n=9 each):

  Test              main          unified C11   delta
  single push/pop   46.62 +-0.30  33.41 +-0.10  -28%
  empty pop          1.47 +-0.01   0.98 +-0.01  -33%
  1 lcore, bulk 8    9.06 +-0.05   8.20 +-0.08  -10%
  1 lcore, bulk 32   6.09 +-0.02   6.15 +-0.03   +1%
  2 HT, bulk 8      42.05 +-0.31  39.24 +-0.52   -7%
  2 HT, bulk 32     11.92 +-0.13  11.89 +-0.10    0
  2 cores, bulk 8   78.90 +-0.60  72.96 +-1.11   -7%
  2 cores, bulk 32  20.74 +-1.56   7.70 +-0.13  -63%
  32 cores, bulk 8  6126 +-72     6121 +-89       0

32 cores, bulk 32 1953.9 +-2.9 1984.6 +-13.3 +1.6%

The C11 version is faster because it no longer issues the lock add of rte_smp_mb() on every CAS attempt.

Remove the generic version and use the C11 implementation everywhere.

---
 lib/stack/meson.build            |   1 -
 lib/stack/rte_stack_lf.h         |   4 -
 lib/stack/rte_stack_lf_generic.h | 153 -------------------------------
 3 files changed, 158 deletions(-)
 delete mode 100644 lib/stack/rte_stack_lf_generic.h
lib/stack/meson.build +0 -1
index 18177a742f..1fab46208f 100644
@@ -7,7 +7,6 @@ headers = files('rte_stack.h')
 indirect_headers += files(
         'rte_stack_std.h',
         'rte_stack_lf.h',
-        'rte_stack_lf_generic.h',
         'rte_stack_lf_c11.h',
         'rte_stack_lf_stubs.h',
 )
lib/stack/rte_stack_lf.h +0 -4
index f2b012cd0e..1bc6ee8f40 100644
@@ -8,11 +8,7 @@
 #if !(defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_ARM64))
 #include "rte_stack_lf_stubs.h"
 #else
-#ifdef RTE_USE_C11_MEM_MODEL
 #include "rte_stack_lf_c11.h"
-#else
-#include "rte_stack_lf_generic.h"
-#endif
 
 /**
  * Indicates that RTE_STACK_F_LF is supported.
lib/stack/rte_stack_lf_generic.h deleted +0 -153

153 lines not on this page · raw message

Signature · 1 line
2.53.0
#153 lore raw

PATCH v4 12/29 ring: replace SMP read barrier with C11 acquire fence

In reply to Stephen Hemminger

rte_smp_rmb() is deprecated. This code is only used where RTE_USE_C11_MEM_MODEL is unset: x86, ppc64, loongarch and ThunderX. The acquire fence generates the same code on x86 (a compiler barrier) and on ThunderX (dmb ishld). On ppc64 the barrier becomes lwsync instead of sync, which still orders load against load.

The gcc implementation itself is kept: unlike the lock-free stack, the in-tree comment records a 10% x86 performance drop with the C11 version, which needs re-measuring with current compilers before RTE_USE_C11_MEM_MODEL can be removed.

---
 lib/ring/rte_ring_gcc_pvt.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/ring/rte_ring_gcc_pvt.h +3 -3
index 340ece28c7..9c2c58824d 100644
@@ -55,10 +55,10 @@ __rte_ring_headtail_move_head_st(struct rte_ring_headtail *d,
 
 	*old_head = d->head;
 
-	/* add rmb barrier to avoid load/load reorder in weak
-	 * memory model. It is noop on x86
+	/* Acquire fence to avoid load/load reorder in weak
+	 * memory model. It is noop on x86.
 	 */
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	/*
 	 *  The subtraction is done between two unsigned 32bits value
Signature · 1 line
2.53.0
#154 lore raw

PATCH v4 13/29 crypto/virtio: update comment reference to rte_smp_rmb

In reply to Stephen Hemminger

The rte_smp_rmb helper is no longer used.

---
 drivers/crypto/virtio/virtqueue.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/crypto/virtio/virtqueue.h +4 -4
index 97a3ace48c..6ef40d3593 100644
@@ -302,11 +302,11 @@ virtqueue_nused(const struct virtqueue *vq)
 
 	if (vq->hw->weak_barriers) {
 	/**
-	 * x86 prefers to using rte_smp_rmb over rte_atomic_load_explicit as it
+	 * x86 prefers virtio_rmb over rte_atomic_load_explicit as it
 	 * reports a slightly better perf, which comes from the saved
-	 * branch by the compiler.
-	 * The if and else branches are identical with the smp and io
-	 * barriers both defined as compiler barriers on x86.
+	 * branch by the compiler: on x86 this makes the two branches
+	 * identical, since virtio_rmb(0) is rte_io_rmb(), only a
+	 * compiler barrier, and loads are not reordered with loads.
 	 */
 #ifdef RTE_ARCH_X86_64
 		idx = vq->vq_split.ring.used->idx;
Signature · 1 line
2.53.0
#155 lore raw

PATCH v4 14/29 crypto/caam_jr: replace rte_smp_rmb

In reply to Stephen Hemminger

Replace rte_smp_rmb with equivalent rte_atomic_thread_fence(rte_memory_order_acquire).

---
 drivers/crypto/caam_jr/caam_jr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/caam_jr/caam_jr.c +1 -1
index 104ce52d11..a7d314bfab 100644
@@ -572,7 +572,7 @@ hw_poll_job_ring(struct sec_job_ring_t *job_ring,
 		job_ring, job_ring->pidx, job_ring->cidx,
 		limit, number_of_jobs_available, jobs_no_to_notify);
 
-	rte_smp_rmb();
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 
 	while (jobs_no_to_notify > notified_descs_no) {
 		static uint64_t false_alarm;
Signature · 1 line
2.53.0
#156 lore raw

PATCH v4 15/29 crypto/caam_jr: use IO barrier before job ring doorbell

In reply to Stephen Hemminger

The barrier orders the input ring descriptor write in DMA memory against the MMIO doorbell write. That is device ordering, not SMP ordering, so rte_io_wmb() is the barrier that expresses it.

---
 drivers/crypto/caam_jr/caam_jr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/crypto/caam_jr/caam_jr.c +2 -1
index a7d314bfab..01a9bed1ff 100644
@@ -1451,7 +1451,8 @@ caam_jr_enqueue_op(struct rte_crypto_op *op, struct caam_jr_qp *qp)
 	/* Set ptr in input ring to current descriptor	*/
 	sec_write_addr(&ring->input_ring[ring->pidx],
 			(phys_addr_t)caam_jr_vtop_ctx(ctx, ctx->jobdes.desc));
-	rte_smp_wmb();
+	/* Descriptor must be visible to the device before the doorbell */
+	rte_io_wmb();
 
 	/* Notify HW that a new job is enqueued */
 	hw_enqueue_desc_on_job_ring(ring);
Signature · 1 line
2.53.0
#157 lore raw

PATCH v4 16/29 crypto/octeontx: use IO barrier before doorbell

In reply to Stephen Hemminger

The doorbell is written with rte_write64_relaxed(), so the barrier before it is what orders the queued instructions against the device. That is device ordering, not SMP ordering: use rte_io_wmb().

---
 drivers/crypto/octeontx/otx_cryptodev_hw_access.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/crypto/octeontx/otx_cryptodev_hw_access.h +2 -2
index 3104e6d31e..096dcf8f87 100644
@@ -203,8 +203,8 @@ static __rte_always_inline void
 otx_cpt_ring_dbell(struct cpt_instance *instance, uint16_t count)
 {
 	struct cpt_vf *cptvf = (struct cpt_vf *)instance;
-	/* Memory barrier to flush pending writes */
-	rte_smp_wmb();
+	/* Instructions must be visible to the device before the doorbell */
+	rte_io_wmb();
 	otx_cpt_write_vq_doorbell(cptvf, count);
 }
 
Signature · 1 line
2.53.0
#158 lore raw

PATCH v4 17/29 event/sw: fix unlinks in progress counter races

In reply to Stephen Hemminger

The counter is written by both the application thread (increment on unlink) and the scheduler (clear on ack) as a plain uint8_t. An increment is lost if it lands between the scheduler's test and clear, making rte_event_port_unlinks_in_progress() report completion before the scheduler has seen the unlink. On a weakly ordered CPU nothing orders the scheduler's cq map reads against the counter test, nor the application's reads against the counter reaching zero.

Make the counter atomic: release fetch-add on unlink, acquire load to read, and an acquire-release exchange to clear. The exchange cannot lose an increment that lands after the test, so the scheduler can keep its relaxed load of the counter first and take the locked read-modify-write only when there is an unlink to acknowledge.

Fixes bd5ac24fea88 ("event/sw: implement unlinks in progress function")
---
 drivers/event/sw/sw_evdev.c           |  8 +++++---
 drivers/event/sw/sw_evdev.h           | 11 +++++------
 drivers/event/sw/sw_evdev_scheduler.c | 17 ++++++++++++++---
 3 files changed, 24 insertions(+), 12 deletions(-)
drivers/event/sw/sw_evdev.c +5 -3
index a2f760a98d..87a8996f9d 100644
@@ -119,8 +119,9 @@ sw_port_unlink(struct rte_eventdev *dev, void *port, uint8_t queues[],
 		}
 	}
 
-	p->unlinks_in_progress += unlinked;
-	rte_smp_mb();
+	/* Pairs with the acquire exchange in the scheduler */
+	rte_atomic_fetch_add_explicit(&p->unlinks_in_progress, unlinked,
+				      rte_memory_order_release);
 
 	return unlinked;
 }
@@ -130,7 +131,8 @@ sw_port_unlinks_in_progress(struct rte_eventdev *dev, void *port)
 {
 	RTE_SET_USED(dev);
 	struct sw_port *p = port;
-	return p->unlinks_in_progress;
+	return rte_atomic_load_explicit(&p->unlinks_in_progress,
+					rte_memory_order_acquire);
 }
 
 static int
drivers/event/sw/sw_evdev.h +5 -6
index 5e49b08030..2c11d02911 100644
@@ -154,13 +154,12 @@ struct sw_port {
 	/* A numeric ID for the port */
 	uint8_t id;
 
-	/* An atomic counter for when the port has been unlinked, and the
-	 * scheduler has not yet acked this unlink - hence there may still be
-	 * events in the buffers going to the port. When the unlinks in
-	 * progress is read by the scheduler, no more events will be pushed to
-	 * the port - hence the scheduler core can just assign zero.
+	/* Count of unlinks the scheduler has not yet acked, so there may
+	 * still be events in the buffers going to the port. Incremented by
+	 * the unlinking thread, cleared by the scheduler with an exchange so
+	 * an increment racing with the ack is not lost.
 	 */
-	uint8_t unlinks_in_progress;
+	RTE_ATOMIC(uint8_t) unlinks_in_progress;
 
 	int16_t is_directed; /** Takes from a single directed QID */
 	/**
drivers/event/sw/sw_evdev_scheduler.c +14 -3
index a5fdcf301b..207dee5854 100644
@@ -523,9 +523,20 @@ sw_event_schedule(struct rte_eventdev *dev)
 		do {
 			in_pkts = 0;
 			for (i = 0; i < sw->port_count; i++) {
-				/* ack the unlinks in progress as done */
-				if (sw->ports[i].unlinks_in_progress)
-					sw->ports[i].unlinks_in_progress = 0;
+				struct sw_port *p = &sw->ports[i];
+
+				/* Ack the unlinks in progress as done.
+				 * The exchange cannot lose an increment that
+				 * lands after the test, and its acquire orders
+				 * the cq map reads below after the unlinker's
+				 * map update. Nothing to synchronize with when
+				 * the counter reads zero, so test first and
+				 * keep the locked op off the common path.
+				 */
+				if (rte_atomic_load_explicit(&p->unlinks_in_progress,
+						rte_memory_order_relaxed) != 0)
+					rte_atomic_exchange_explicit(&p->unlinks_in_progress,
+						0, rte_memory_order_acq_rel);
 
 				if (sw->ports[i].is_directed)
 					in_pkts += sw_schedule_pull_port_dir(sw, i);
Signature · 1 line
2.53.0
#159 lore raw

PATCH v4 18/29 event/sw: replace SMP barriers with C11 atomics

In reply to Stephen Hemminger

The write barrier plus plain store publish patterns (cq map count, port initialized, device started) become release stores; the barrier after clearing started in sw_stop() becomes a release fence. All are control path.

The scheduler load of started is acquire, to complete the handshake with the release store in sw_start(). It runs once per service call, not per event.

Scheduler reads of cq_num_mapped_cqs stay plain loads: acquire loads would land in the inner scheduling loops on weakly ordered CPUs. The transient window where a new count is visible before the map entry on such CPUs predates this change and is unchanged by it; unlink is covered by the counter handshake.

---
 drivers/event/sw/sw_evdev.c           | 29 ++++++++++++++++++---------
 drivers/event/sw/sw_evdev_scheduler.c |  7 ++++++-
 2 files changed, 26 insertions(+), 10 deletions(-)
drivers/event/sw/sw_evdev.c +20 -9
index 87a8996f9d..165d8e3950 100644
@@ -84,8 +84,10 @@ sw_port_link(struct rte_eventdev *dev, void *port, const uint8_t queues[],
 		}
 
 		q->cq_map[q->cq_num_mapped_cqs] = p->id;
-		rte_smp_wmb();
-		q->cq_num_mapped_cqs++;
+		/* Release publishes the map entry before the new count */
+		rte_atomic_store_explicit(
+			(uint32_t __rte_atomic *)&q->cq_num_mapped_cqs,
+			q->cq_num_mapped_cqs + 1, rte_memory_order_release);
 	}
 	return i;
 }
@@ -105,8 +107,14 @@ sw_port_unlink(struct rte_eventdev *dev, void *port, uint8_t queues[],
 			if (q->cq_map[j] == p->id) {
 				q->cq_map[j] =
 					q->cq_map[q->cq_num_mapped_cqs - 1];
-				rte_smp_wmb();
-				q->cq_num_mapped_cqs--;
+				/* Release publishes the map update
+				 * before the new count
+				 */
+				rte_atomic_store_explicit(
+					(uint32_t __rte_atomic *)
+						&q->cq_num_mapped_cqs,
+					q->cq_num_mapped_cqs - 1,
+					rte_memory_order_release);
 				unlinked++;
 
 				p->num_qids_mapped--;
@@ -210,8 +218,9 @@ sw_port_setup(struct rte_eventdev *dev, uint8_t port_id,
 	}
 	dev->data->ports[port_id] = p;
 
-	rte_smp_wmb();
-	p->initialized = 1;
+	/* Release publishes the port setup before initialized flag */
+	rte_atomic_store_explicit((uint8_t __rte_atomic *)&p->initialized, 1,
+				  rte_memory_order_release);
 	return 0;
 }
 
@@ -817,8 +826,9 @@ sw_start(struct rte_eventdev *dev)
 	if (sw_xstats_init(sw) < 0)
 		return -EINVAL;
 
-	rte_smp_wmb();
-	sw->started = 1;
+	/* Release publishes device state before the started flag */
+	rte_atomic_store_explicit((uint8_t __rte_atomic *)&sw->started, 1,
+				  rte_memory_order_release);
 
 	return 0;
 }
@@ -847,7 +857,8 @@ sw_stop(struct rte_eventdev *dev)
 	sw_clean_qid_iqs(dev);
 	sw_xstats_uninit(sw);
 	sw->started = 0;
-	rte_smp_wmb();
+	/* Order the started store before re-enabling the service */
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	if (runstate == 1)
 		rte_service_runstate_set(sw->service_id, 1);
drivers/event/sw/sw_evdev_scheduler.c +6 -1
index 207dee5854..5b15c2a9ad 100644
@@ -513,7 +513,12 @@ sw_event_schedule(struct rte_eventdev *dev)
 	uint32_t i;
 
 	sw->sched_called++;
-	if (unlikely(!sw->started))
+	/* Acquire pairs with the release store in sw_start(), so the device
+	 * state it published is visible before any of it is used here. Once
+	 * per service call, not per event.
+	 */
+	if (unlikely(!rte_atomic_load_explicit((uint8_t __rte_atomic *)&sw->started,
+					       rte_memory_order_acquire)))
 		return -EAGAIN;
 
 	do {
Signature · 1 line
2.53.0
#160 lore raw

PATCH v4 19/29 test/barrier: convert to C11 atomics

In reply to Stephen Hemminger

rte_smp_mb() is removed by this series, so the barrier test loses one of its two cases. Replace it with rte_atomic_thread_fence(rte_memory_order_seq_cst), which on x86 is the hand written lock add that Konstantin pointed out is worth keeping covered. rte_mb() stays as the other case: the test cannot prove much about a barrier on any one architecture, but it does keep each one compiled and executed.

Convert the Peterson lock to explicit atomic accesses. The loads in the spin loop are relaxed, leaving the barrier under test as the only thing that keeps them after the stores. The store of victim needs release and not relaxed: the algorithm requires flag[self] to be visible before victim, and two relaxed stores let a weakly ordered CPU commit victim first, which admits both lcores into the critical section with nothing wrong in the barrier.

---
 app/test/test_barrier.c | 71 ++++++++++++++++++++++-------------------
 1 file changed, 39 insertions(+), 32 deletions(-)
app/test/test_barrier.c +39 -32
index 925a88b68a..29024f4242 100644
@@ -2,35 +2,35 @@
  * 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 the full barriers rte_mb() and
+ * rte_atomic_thread_fence(rte_memory_order_seq_cst).
+ * I.E. make sure that LOAD and STORE operations that precede the barrier
+ * 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 particular barrier takes.
+ */
 
+#include <errno.h>
 #include <stdio.h>
-#include <string.h>
 #include <stdint.h>
+#include <stdlib.h>
+#include <string.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_memory.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"
 
@@ -39,13 +39,13 @@
 
 enum plock_use_type {
 	USE_MB,
-	USE_SMP_MB,
+	USE_FENCE,
 	USE_NUM
 };
 
 struct plock {
-	volatile uint32_t flag[2];
-	volatile uint32_t victim;
+	RTE_ATOMIC(uint32_t) flag[2];
+	RTE_ATOMIC(uint32_t) victim;
 	enum plock_use_type utype;
 };
 
@@ -70,18 +70,20 @@ struct lcore_plock_test {
 };
 
 static inline void
-store_load_barrier(uint32_t utype)
+store_load_barrier(enum plock_use_type utype)
 {
 	if (utype == USE_MB)
 		rte_mb();
-	else if (utype == USE_SMP_MB)
-		rte_smp_mb();
 	else
-		RTE_VERIFY(0);
+		rte_atomic_thread_fence(rte_memory_order_seq_cst);
 }
 
 /*
  * Peterson lock implementation.
+ * The loads in the spin loop are relaxed on purpose: the barrier under
+ * test is the only thing keeping them after the stores above, so a
+ * barrier that fails to prevent store-load reordering shows up as two
+ * lcores in the critical section at once.
  */
 static void
 plock_lock(struct plock *l, uint32_t self)
@@ -90,22 +92,27 @@ 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);
+
+	/* Release so that the other lcore cannot see this lcore claim to be
+	 * the victim while its flag still reads zero, which would let both
+	 * lcores through.
+	 */
+	rte_atomic_store_explicit(&l->victim, self, rte_memory_order_release);
 
 	store_load_barrier(l->utype);
 
-	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();
+
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 }
 
 static void
 plock_unlock(struct plock *l, uint32_t self)
 {
-	rte_smp_wmb();
-	l->flag[self] = 0;
+	rte_atomic_store_explicit(&l->flag[self], 0, rte_memory_order_release);
 }
 
 static void
Signature · 1 line
2.53.0
#161 lore raw

PATCH v4 20/29 eal/x86: move optimized fence out of SMP barrier

In reply to Stephen Hemminger

rte_atomic_thread_fence() implemented the seq_cst case by calling the deprecated rte_smp_mb(). Invert the dependency: the lock add based fence moves into rte_atomic_thread_fence(), and rte_smp_mb() goes away with it since the test that was its last user is converted in the preceding patch. The optimization itself must stay; a plain seq_cst fence is an mfence, about twice the cost. No change in generated code.

---
 lib/eal/x86/include/rte_atomic.h | 37 ++++++++++++++------------------
 1 file changed, 16 insertions(+), 21 deletions(-)
lib/eal/x86/include/rte_atomic.h +16 -21
index 20a4baa575..a46bedb0f0 100644
@@ -60,23 +60,8 @@ extern "C" {
  * Basic idea is to use lock prefixed add with some dummy memory location
  * as the destination. From their experiments 128B(2 cache lines) below
  * current stack pointer looks like a good candidate.
- * So below we use that technique for rte_smp_mb() implementation.
  */
 
-static __rte_always_inline void
-rte_smp_mb(void)
-{
-#ifdef RTE_TOOLCHAIN_MSVC
-	_mm_mfence();
-#else
-#ifdef RTE_ARCH_I686
-	asm volatile("lock addl $0, -128(%%esp); " ::: "memory");
-#else
-	asm volatile("lock addl $0, -128(%%rsp); " ::: "memory");
-#endif
-#endif
-}
-
 #define rte_io_mb() rte_mb()
 
 #define rte_io_wmb() rte_compiler_barrier()
@@ -86,17 +71,27 @@ rte_smp_mb(void)
 /**
  * Synchronization fence between threads based on the specified memory order.
  *
- * On x86 the __rte_atomic_thread_fence(rte_memory_order_seq_cst) generates full 'mfence'
- * which is quite expensive. The optimized implementation of rte_smp_mb is
- * used instead.
+ * On x86 the __rte_atomic_thread_fence(rte_memory_order_seq_cst) generates
+ * a full 'mfence' which is quite expensive. The optimized lock add on a
+ * dummy stack location (see above) is used instead.
  */
 static __rte_always_inline void
 rte_atomic_thread_fence(rte_memory_order memorder)
 {
-	if (memorder == rte_memory_order_seq_cst)
-		rte_smp_mb();
-	else
+	if (memorder != rte_memory_order_seq_cst) {
 		__rte_atomic_thread_fence(memorder);
+		return;
+	}
+
+#ifdef RTE_TOOLCHAIN_MSVC
+	_mm_mfence();
+#else
+#ifdef RTE_ARCH_I686
+	asm volatile("lock addl $0, -128(%%esp); " ::: "memory");
+#else
+	asm volatile("lock addl $0, -128(%%rsp); " ::: "memory");
+#endif
+#endif
 }
 
 #ifdef __cplusplus
Signature · 1 line
2.53.0
#162 lore raw

PATCH v4 21/29 common/octeontx: remove redundant barrier in mbox

In reply to Stephen Hemminger

The SMP write barrier between writing the mailbox header and ringing the mailbox register is redundant: rte_write64() begins with rte_io_wmb(), which already orders the header write before the trigger, and does so against the device rather than only within the inner shareable domain.

---
 drivers/common/octeontx/octeontx_mbox.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/common/octeontx/octeontx_mbox.c +4 -2
index 9e0bbf453f..8b0da3a98e 100644
@@ -113,8 +113,10 @@ mbox_send_request(struct mbox *m, struct octeontx_mbox_hdr *hdr,
 
 	/* Write the msg header */
 	rte_write64(new_hdr.u64, ram_mbox_hdr);
-	rte_smp_wmb();
-	/* Notify PF about the new msg - write to MBOX reg generates PF IRQ */
+	/* Notify PF about the new msg - write to MBOX reg generates PF IRQ.
+	 * rte_write64() issues rte_io_wmb() which orders the header write
+	 * before the trigger; no separate barrier is needed.
+	 */
 	rte_write64(0, m->reg);
 }
 
Signature · 1 line
2.53.0
#163 lore raw

PATCH v4 22/29 mempool/octeontx: use IO barrier in pool destroy

In reply to Stephen Hemminger

The barrier flushes outstanding writes to the FPA pool before the teardown mailbox sequence. That is ordering against the device, so use rte_io_wmb(). Control path.

---
 drivers/mempool/octeontx/octeontx_fpavf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mempool/octeontx/octeontx_fpavf.c +2 -2
index 6cd0fc057f..7051422cb7 100644
@@ -616,8 +616,8 @@ octeontx_fpa_bufpool_destroy(uintptr_t handle, int node_id)
 
 	RTE_SET_USED(node_id);
 
-	/* Wait for all outstanding writes to be committed */
-	rte_smp_wmb();
+	/* Make outstanding pool writes visible to the device */
+	rte_io_wmb();
 
 	if (unlikely(!octeontx_fpa_handle_valid(handle)))
 		return -EINVAL;
Signature · 1 line
2.53.0
#164 lore raw

PATCH v4 23/29 event/octeontx: replace deprecated SMP barriers

In reply to Stephen Hemminger

The worker barriers order event payload writes in normal memory before the add work or tag switch store to the SSO device, so they are IO ordering: use rte_io_wmb(). The selftest barriers publish worker parameters before launching lcores; convert them to release fences.

---
 drivers/event/octeontx/ssovf_evdev_selftest.c | 6 +++---
 drivers/event/octeontx/ssovf_worker.c         | 8 ++++----
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/event/octeontx/ssovf_evdev_selftest.c +3 -3
index e51b89a31e..df8e710b57 100644
@@ -65,7 +65,7 @@ seqn_list_update(int val)
 		return -1;
 
 	seqn_list[seqn_list_index++] = val;
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 	return 0;
 }
 
@@ -636,7 +636,7 @@ launch_workers_and_wait(int (*main_worker)(void *),
 	param[0].sched_type = sched_type;
 	param[0].port = 0;
 	param[0].dequeue_tmo_ticks = dequeue_tmo_ticks;
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	w_lcore = rte_get_next_lcore(
 			/* start core */ -1,
@@ -649,7 +649,7 @@ launch_workers_and_wait(int (*main_worker)(void *),
 		param[port].sched_type = sched_type;
 		param[port].port = port;
 		param[port].dequeue_tmo_ticks = dequeue_tmo_ticks;
-		rte_smp_wmb();
+		rte_atomic_thread_fence(rte_memory_order_release);
 		w_lcore = rte_get_next_lcore(w_lcore, 1, 0);
 		rte_eal_remote_launch(worker, &param[port], w_lcore);
 	}
drivers/event/octeontx/ssovf_worker.c +4 -4
index 89b5dc056c..f3c6a0da5c 100644
@@ -59,10 +59,10 @@ ssows_fwd_group(struct ssows *ws, const struct rte_event *ev, const uint8_t grp)
 		newtag |= grp << 20;
 		newtag |= tag;
 		ssows_swtag_norm(ws, newtag, SSO_SYNC_ATOMIC);
-		rte_smp_wmb();
+		rte_io_wmb();
 		ssows_swtag_wait(ws);
 	} else {
-		rte_smp_wmb();
+		rte_io_wmb();
 	}
 	ssows_add_work(ws, event_ptr, tag, new_tt, grp);
 }
@@ -158,7 +158,7 @@ ssows_enq_burst(void *port, const struct rte_event ev[], uint16_t nb_events)
 
 	switch (ev->op) {
 	case RTE_EVENT_OP_NEW:
-		rte_smp_wmb();
+		rte_io_wmb();
 		ssows_new_event(ws, ev);
 		break;
 	case RTE_EVENT_OP_FORWARD:
@@ -179,7 +179,7 @@ ssows_enq_new_burst(void *port, const struct rte_event ev[], uint16_t nb_events)
 	uint16_t i;
 	struct ssows *ws = port;
 
-	rte_smp_wmb();
+	rte_io_wmb();
 	for (i = 0; i < nb_events; i++)
 		ssows_new_event(ws,  &ev[i]);
 
Signature · 1 line
2.53.0
#165 lore raw

PATCH v4 24/29 event/dpaa2: replace deprecated barrier in selftest

In reply to Stephen Hemminger

Publish worker parameters with a release fence before launching the lcores instead of the deprecated SMP write barrier.

---
 drivers/event/dpaa2/dpaa2_eventdev_selftest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/event/dpaa2/dpaa2_eventdev_selftest.c +2 -2
index 2c688bd194..b1e4bf6855 100644
@@ -526,7 +526,7 @@ launch_workers_and_wait(int (*main_worker)(void *),
 	param[0].sched_type = sched_type;
 	param[0].port = 0;
 	param[0].dequeue_tmo_ticks = dequeue_tmo_ticks;
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	w_lcore = rte_get_next_lcore(
 			/* start core */ -1,
@@ -539,7 +539,7 @@ launch_workers_and_wait(int (*main_worker)(void *),
 		param[port].sched_type = sched_type;
 		param[port].port = port;
 		param[port].dequeue_tmo_ticks = dequeue_tmo_ticks;
-		rte_smp_wmb();
+		rte_atomic_thread_fence(rte_memory_order_release);
 		w_lcore = rte_get_next_lcore(w_lcore, 1, 0);
 		rte_eal_remote_launch(workers, &param[port], w_lcore);
 	}
Signature · 1 line
2.53.0
#166 lore raw

PATCH v4 25/29 event/dsw: replace SMP barriers with release fences

In reply to Stephen Hemminger

All four barriers publish flow table or ring updates before a control message enqueue, which is release ordering. All are on the migration control path, not per event.

The fences may in fact be removable: the control messages travel through rte_ring, whose producer tail update is itself a release store covering the preceding writes. Left in place here to keep this a like for like conversion.

---
 drivers/event/dsw/dsw_event.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/event/dsw/dsw_event.c +4 -4
index 399d9f050e..82d3636b29 100644
@@ -339,7 +339,7 @@ dsw_port_handle_pause_flows(struct dsw_evdev *dsw, struct dsw_port *port,
 	/* Make sure any stores to the original port's in_ring is seen
 	 * before the ctl message.
 	 */
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	dsw_port_ctl_enqueue(&dsw->ports[originating_port_id], &cfm);
 }
@@ -821,7 +821,7 @@ dsw_port_move_parallel_flows(struct dsw_evdev *dsw,
 		}
 	}
 
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	dsw_port_end_emigration(dsw, source_port, RTE_SCHED_TYPE_PARALLEL);
 }
@@ -1190,7 +1190,7 @@ dsw_port_move_emigrating_flows(struct dsw_evdev *dsw,
 		    dest_port_id;
 	}
 
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	dsw_port_drain_in_ring(source_port);
 	dsw_port_forward_emigrated_flows(dsw, source_port);
@@ -1213,7 +1213,7 @@ dsw_port_move_emigrating_flows(struct dsw_evdev *dsw,
 	/* Flow table update and migration destination port's enqueues
 	 * must be seen before the control message.
 	 */
-	rte_smp_wmb();
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	dsw_port_ctl_broadcast(dsw, source_port, DSW_CTL_UNPAUSE_REQ,
 			       source_port->emigration_target_qfs,
Signature · 1 line
2.53.0
#167 lore raw

PATCH v4 26/29 event/opdl: replace SMP barriers with C11 atomics

In reply to Stephen Hemminger

Publishing the port becomes a release store of the configured flag. Control path.

Drop the barrier after clearing started in opdl_stop(): no store follows it, and the datapath tests data->dev_started, not device->started.

---
 drivers/event/opdl/opdl_evdev.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/event/opdl/opdl_evdev.c +3 -5
index ffa65ef930..44a648a11a 100644
@@ -200,8 +200,9 @@ opdl_port_setup(struct rte_eventdev *dev,
 	p->queue_id = OPDL_INVALID_QID;
 	p->external_qid = OPDL_INVALID_QID;
 	dev->data->ports[port_id] = p;
-	rte_smp_wmb();
-	p->configured = 1;
+	/* Release publishes port setup before the configured flag */
+	rte_atomic_store_explicit((uint8_t __rte_atomic *)&p->configured, 1,
+				  rte_memory_order_release);
 	device->nb_ports++;
 	return 0;
 }
@@ -474,10 +475,7 @@ opdl_stop(struct rte_eventdev *dev)
 
 	destroy_queues_and_rings(dev);
 
-
 	device->started = 0;
-
-	rte_smp_wmb();
 }
 
 static int
Signature · 1 line
2.53.0
#168 lore raw

PATCH v4 27/29 net/virtio: replace deprecated barrier in avail index update

In reply to Stephen Hemminger

As with virtqueue_nused(), the x86 special case only pays off while both arms of the weak_barriers test compile to the same thing, which rules out rte_atomic_thread_fence(rte_memory_order_release). Use rte_io_wmb(), a compiler barrier on x86, where stores are not reordered with other stores.

---
 drivers/net/virtio/virtqueue.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/net/virtio/virtqueue.h +6 -6
index ee21d43068..8fd2999132 100644
@@ -474,14 +474,14 @@ static inline void
 vq_update_avail_idx(struct virtqueue *vq)
 {
 	if (vq->hw->weak_barriers) {
-	/* x86 prefers to using rte_smp_wmb over rte_atomic_store_explicit as
-	 * it reports a slightly better perf, which comes from the
-	 * saved branch by the compiler.
-	 * The if and else branches are identical with the smp and
-	 * io barriers both defined as compiler barriers on x86.
+	/* x86 prefers rte_io_wmb over rte_atomic_store_explicit as it
+	 * reports a slightly better perf, which comes from the saved
+	 * branch by the compiler: on x86 this makes the two branches
+	 * identical, since rte_io_wmb() is only a compiler barrier and
+	 * stores are not reordered with other stores.
 	 */
 #ifdef RTE_ARCH_X86_64
-		rte_smp_wmb();
+		rte_io_wmb();
 		vq->vq_split.ring.avail->idx = vq->vq_avail_idx;
 #else
 		rte_atomic_store_explicit(&vq->vq_split.ring.avail->idx,
Signature · 1 line
2.53.0
#169 lore raw

PATCH v4 28/29 eal: remove stale SMP barrier in rte_service

In reply to Stephen Hemminger

Leftover missed by the C11 atomics conversion of this file. The barrier pairs with nothing: no store follows it, and the next use of the lcore is synchronized by remote launch.

---
 lib/eal/common/rte_service.c | 1 -
 1 file changed, 1 deletion(-)
lib/eal/common/rte_service.c +0 -1
index 5c3a350ae8..cb07ce83fe 100644
@@ -795,7 +795,6 @@ rte_service_lcore_del(uint32_t lcore)
 
 	set_lcore_state(lcore, RTE_LCORE_ROLE_RTE);
 
-	rte_smp_wmb();
 	return 0;
 }
 
Signature · 1 line
2.53.0
#170 lore raw

PATCH v4 29/29 eal: remove rte_smp_XX

In reply to Stephen Hemminger

These functions were marked for deprecation over five years ago and have no users left in the tree. Drop them from EAL, along with the deprecation notice, and record the replacements in the release notes.

Checkpatch no longer looks for them: now that the macros are gone, any remaining use is a compile error.

---
 devtools/checkpatches.sh               |  8 ----
 doc/guides/rel_notes/deprecation.rst   |  8 ----
 doc/guides/rel_notes/release_26_11.rst | 11 +++++
 lib/eal/arm/include/rte_atomic_32.h    |  6 ---
 lib/eal/arm/include/rte_atomic_64.h    |  6 ---
 lib/eal/include/generic/rte_atomic.h   | 61 --------------------------
 lib/eal/loongarch/include/rte_atomic.h |  6 ---
 lib/eal/ppc/include/rte_atomic.h       |  6 ---
 lib/eal/riscv/include/rte_atomic.h     |  6 ---
 lib/eal/x86/include/rte_atomic.h       |  4 --
 10 files changed, 11 insertions(+), 111 deletions(-)
devtools/checkpatches.sh +0 -8
index 466e06410a..c52fb5d1b6 100755
@@ -121,14 +121,6 @@ check_forbidden_additions() { # <patch>
 		-f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
 		"$1" || res=1
 
-	# refrain from new additions of rte_smp_[r/w]mb()
-	awk -v FOLDERS="lib drivers app examples" \
-		-v EXPRESSIONS="rte_smp_(r|w)?mb\\\(" \
-		-v RET_ON_FAIL=1 \
-		-v MESSAGE='Using rte_smp_[r/w]mb' \
-		-f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
-		"$1" || res=1
-
 	# refrain from using compiler __sync_xxx builtins
 	awk -v FOLDERS="lib drivers app examples" \
 		-v EXPRESSIONS="__sync_.*\\\(" \
doc/guides/rel_notes/deprecation.rst +0 -8
index 49ee85fa4e..5cc7cc12e6 100644
@@ -29,14 +29,6 @@ Deprecation Notices
   Use the ``-S <service-corelist>`` parameter instead
   to specify the cores to be used for background services in DPDK.
 
-* rte_smp_*mb: These APIs provide full barrier functionality. However, many
-  use cases do not require full barriers. To support such use cases, DPDK has
-  adopted atomic operations from
-  https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html. These
-  operations and a new wrapper ``rte_atomic_thread_fence`` instead of
-  ``__atomic_thread_fence`` must be used for patches that need to be merged in
-  20.08 onwards. This change will not introduce any performance degradation.
-
 * mempool: The ``flushthresh`` field in ``struct rte_mempool_cache`` is obsolete,
   and will be removed in DPDK 26.11.
 
doc/guides/rel_notes/release_26_11.rst +11 -0
index 25301088bf..d4a1333fa6 100644
@@ -200,6 +200,17 @@ Removed Items
   ``cmpset`` and ``exchange``). Use the C11 ``rte_atomic_*_explicit``
   operations instead.
 
+* Removed SMP memory barriers:
+
+  * ``rte_smp_mb()`` replaced with ``rte_atomic_thread_fence(rte_memory_order_seq_cst)``
+  * ``rte_smp_rmb()`` replaced with ``rte_atomic_thread_fence(rte_memory_order_acquire)``
+  * ``rte_smp_wmb()`` replaced with ``rte_atomic_thread_fence(rte_memory_order_release)``
+
+  Some call sites became release stores or acquire loads instead of a
+  standalone fence. Barriers that order CPU accesses against a device,
+  rather than against another CPU, should use ``rte_io_wmb()`` and
+  ``rte_io_rmb()`` instead.
+
 * mempool: Removed the deprecated and obsolete ``flushthresh`` field
   from the ``rte_mempool_cache`` structure.
 
lib/eal/arm/include/rte_atomic_32.h +0 -6
index 696a539fef..4115271091 100644
@@ -17,12 +17,6 @@ extern "C" {
 
 #define	rte_rmb() __sync_synchronize()
 
-#define rte_smp_mb() rte_mb()
-
-#define rte_smp_wmb() rte_wmb()
-
-#define rte_smp_rmb() rte_rmb()
-
 #define rte_io_mb() rte_mb()
 
 #define rte_io_wmb() rte_wmb()
lib/eal/arm/include/rte_atomic_64.h +0 -6
index 9f790238df..604e777bcd 100644
@@ -20,12 +20,6 @@ extern "C" {
 
 #define rte_rmb() asm volatile("dmb oshld" : : : "memory")
 
-#define rte_smp_mb() asm volatile("dmb ish" : : : "memory")
-
-#define rte_smp_wmb() asm volatile("dmb ishst" : : : "memory")
-
-#define rte_smp_rmb() asm volatile("dmb ishld" : : : "memory")
-
 #define rte_io_mb() rte_mb()
 
 #define rte_io_wmb() rte_wmb()
lib/eal/include/generic/rte_atomic.h +0 -61

67 lines not on this page · raw message

lib/eal/loongarch/include/rte_atomic.h +0 -6
index 785a452c9e..a789e3ab4d 100644
@@ -18,12 +18,6 @@ extern "C" {
 
 #define rte_rmb()	rte_mb()
 
-#define rte_smp_mb()	rte_mb()
-
-#define rte_smp_wmb()	rte_mb()
-
-#define rte_smp_rmb()	rte_mb()
-
 #define rte_io_mb()	rte_mb()
 
 #define rte_io_wmb()	rte_mb()
lib/eal/ppc/include/rte_atomic.h +0 -6
index d3bd50a11a..1e5c1747e6 100644
@@ -24,12 +24,6 @@ extern "C" {
 
 #define	rte_rmb() asm volatile("sync" : : : "memory")
 
-#define rte_smp_mb() rte_mb()
-
-#define rte_smp_wmb() rte_wmb()
-
-#define rte_smp_rmb() rte_rmb()
-
 #define rte_io_mb() rte_mb()
 
 #define rte_io_wmb() rte_wmb()
lib/eal/riscv/include/rte_atomic.h +0 -6
index 061b175f33..04c40e4e9b 100644
@@ -23,12 +23,6 @@ extern "C" {
 
 #define rte_rmb()	asm volatile("fence r, r" : : : "memory")
 
-#define rte_smp_mb()	rte_mb()
-
-#define rte_smp_wmb()	rte_wmb()
-
-#define rte_smp_rmb()	rte_rmb()
-
 #define rte_io_mb()	asm volatile("fence iorw, iorw" : : : "memory")
 
 #define rte_io_wmb()	asm volatile("fence orw, ow" : : : "memory")
lib/eal/x86/include/rte_atomic.h +0 -4
index a46bedb0f0..0ed9421055 100644
@@ -23,10 +23,6 @@
 
 #define	rte_rmb() _mm_lfence()
 
-#define rte_smp_wmb() rte_compiler_barrier()
-
-#define rte_smp_rmb() rte_compiler_barrier()
-
 #ifdef __cplusplus
 extern "C" {
 #endif
Signature · 1 line
2.53.0
#171 lore raw

Re: [PATCH v4 00/29] remove rte_smp_XX barriers

In reply to Stephen Hemminger
Quoted 106 lines · Stephen Hemminger

This patch series completes the removal of rte_smp_XX barrier functions that was announced over five years ago (20.05).

In the process several race conditions were found and fixed. See patches 3, 4 and 17, marked with Fixes: and Cc: stable. Patch 2 is also marked for stable because 3 and 4 do not build with clang without it.

Most of this is mechanical with AI assistance, so strongly encourage maintainers to take a good look.

Barriers ordering memory writes against a device doorbell now use rte_io_wmb() rather than an SMP barrier; on arm64 that is dmb oshst instead of dmb ishst. In some cases the C11 form gives marginal performance gains.

The lock-free stack patch measured faster than the generic version it replaces, up to 63% on a 32-core x86 box; the numbers are in that patch's commit message.

Patch 19 keeps the Peterson lock test, converted to C11 atomics, with the seq_cst fence and rte_mb() as its two cases. It comes before patch 20, which holds the last rte_smp_mb() caller, so x86 builds with tests enabled stay bisectable. Tested on x86, arm and riscv; still untested on ppc and loongarch.

Patch 18 has no ack. Bruce, yours landed on 17; 18 changed since.

Left for follow-up: device read barriers in patches 6, 8 and 14 are acquire fences where rte_io_rmb() would match the write side (same generated code today, so no regression). And the net/thunderx mailbox flags in patch 10 are plain bitfields that need to be atomic, which is pre-existing.

v4 - rebase on main, which obsoleted the netvsc patch; address review
comments from Konstantin, Marat, David and Wei Hu; collect tags

Stephen Hemminger (29):
bpf: replace deprecated SMP barriers with C11 fences bus/vmbus: remove packed attribute from ring buffer bus/vmbus: fix ring buffer ordering on weakly ordered CPUs bus/vmbus: fix missing acquire on receive ring index bus/vmbus: replace SMP barriers with C11 memory fences drivers/baseband: convert rte_smp_rmb to fence net/hinic: replace rte_smp_rmb
net/intel: replace rte_smp_rmb
net/virtio: replace rte_smp_rmb
net/thunderx: replace deprecated SMP barriers
stack: always use C11 memory model implementation
ring: replace SMP read barrier with C11 acquire fence crypto/virtio: update comment reference to rte_smp_rmb crypto/caam_jr: replace rte_smp_rmb crypto/caam_jr: use IO barrier before job ring doorbell crypto/octeontx: use IO barrier before doorbell event/sw: fix unlinks in progress counter races event/sw: replace SMP barriers with C11 atomics test/barrier: convert to C11 atomics
eal/x86: move optimized fence out of SMP barrier common/octeontx: remove redundant barrier in mbox mempool/octeontx: use IO barrier in pool destroy event/octeontx: replace deprecated SMP barriers event/dpaa2: replace deprecated barrier in selftest event/dsw: replace SMP barriers with release fences event/opdl: replace SMP barriers with C11 atomics net/virtio: replace deprecated barrier in avail index update
eal: remove stale SMP barrier in rte_service
eal: remove rte_smp_XX

 app/test/test_barrier.c                       |  71 ++++----
 devtools/checkpatches.sh                      |   8 -
 doc/guides/rel_notes/deprecation.rst          |   8 -
 doc/guides/rel_notes/release_26_11.rst        |  11 ++
 .../fpga_5gnr_fec/rte_fpga_5gnr_fec.c         |   8 +-
 drivers/baseband/fpga_lte_fec/fpga_lte_fec.c  |  12 +-
 drivers/bus/vmbus/private.h                   |  12 +-
 drivers/bus/vmbus/rte_vmbus_reg.h             |   4 +-
 drivers/bus/vmbus/vmbus_bufring.c             |  22 +--
 drivers/bus/vmbus/vmbus_channel.c             |  13 +-
 drivers/common/octeontx/octeontx_mbox.c       |   6 +-
 drivers/crypto/caam_jr/caam_jr.c              |   5 +-
 .../crypto/octeontx/otx_cryptodev_hw_access.h |   4 +-
 drivers/crypto/virtio/virtqueue.h             |   8 +-
 drivers/event/dpaa2/dpaa2_eventdev_selftest.c |   4 +-
 drivers/event/dsw/dsw_event.c                 |   8 +-
 drivers/event/octeontx/ssovf_evdev_selftest.c |   6 +-
 drivers/event/octeontx/ssovf_worker.c         |   8 +-
 drivers/event/opdl/opdl_evdev.c               |   8 +-
 drivers/event/sw/sw_evdev.c                   |  37 +++--
 drivers/event/sw/sw_evdev.h                   |  11 +-
 drivers/event/sw/sw_evdev_scheduler.c         |  24 ++-
 drivers/mempool/octeontx/octeontx_fpavf.c     |   4 +-
 drivers/net/hinic/base/hinic_pmd_cmdq.c       |   3 +-
 drivers/net/hinic/base/hinic_pmd_mgmt.c       |   2 +-
 drivers/net/intel/ice/ice_rxtx.c              |   2 +-
 drivers/net/intel/ixgbe/ixgbe_rxtx.c          |   2 +-
 drivers/net/thunderx/base/nicvf_hw.c          |   3 +-
 drivers/net/thunderx/base/nicvf_plat.h        |   5 +-
 drivers/net/virtio/virtqueue.h                |  22 +--
 lib/bpf/bpf_pkt.c                             |  26 +--
 lib/eal/arm/include/rte_atomic_32.h           |   6 -
 lib/eal/arm/include/rte_atomic_64.h           |   6 -
 lib/eal/common/rte_service.c                  |   1 -
 lib/eal/include/generic/rte_atomic.h          |  61 -------
 lib/eal/loongarch/include/rte_atomic.h        |   6 -
 lib/eal/ppc/include/rte_atomic.h              |   6 -
Quoted 8 lines
 lib/eal/riscv/include/rte_atomic.h            |   6 -
 lib/eal/x86/include/rte_atomic.h              |  41 ++---
 lib/ring/rte_ring_gcc_pvt.h                   |   6 +-
 lib/stack/meson.build                         |   1 -
 lib/stack/rte_stack_lf.h                      |   4 -
 lib/stack/rte_stack_lf_generic.h              | 153 ------------------
 43 files changed, 226 insertions(+), 438 deletions(-)
 delete mode 100644 lib/stack/rte_stack_lf_generic.h

Thank you for this big cleanup.
Series applied.

Signature · 1 line
David Marchand