Skip to contentSkip to conversation

Add pause to empty spinloops

RFC Superseded Stephen Hemminger 2 participants 12 messages Jan 21 – Jun 9 Network drivers

lore
Share & tools
lore
#0 lore raw

cover Add pause to empty spinloops

On SMT systems, empty spinloops can cause excessive latency due to the spinning core consuming resources that could be used by other hardware threads. This series addresses this by adding rte_pause() calls to busy-wait loops in the cnxk drivers.

The first two patches fix existing empty spinloops in the net/cnxk and event/cnxk drivers. These were identified using a new coccinelle script that finds variations of the pattern:

    while (!atomic(&flag));

This is compile tested only! I don't have that hardware.

The third patch adds this coccinelle script to devtools/ so that similar issues can be detected and fixed automatically across the codebase.

The script handles multiple atomic API variants:
- Legacy rte_atomic*_read() functions
- C11 atomics via rte_atomic_load_explicit()
- GCC builtins via __atomic_load_n()
- Simple volatile variable checks

Stephen Hemminger (3):
net/cnxk: add pause to spinloops event/cnxk: add pause to spinloops devtools/cocci: add script to find empty spinloops

 devtools/cocci/fix_empty_spinloops.cocci | 165 +++++++++++++++++++++++
 drivers/event/cnxk/cn10k_worker.c        |   2 +-
 drivers/event/cnxk/cn20k_worker.c        |   2 +-
 drivers/event/cnxk/cnxk_tim_worker.h     |   4 +-
 drivers/net/cnxk/cn10k_tx.h              |   4 +-
 drivers/net/cnxk/cn20k_tx.h              |   4 +-
 6 files changed, 173 insertions(+), 8 deletions(-)
 create mode 100644 devtools/cocci/fix_empty_spinloops.cocci
Signature · 1 line
2.51.0
#1 lore raw

RFC 1/3 net/cnxk: add pause to spinloops

On SMT systems when a spinloop is done without a pause it may cause excessive latency. This problem was found by the fix_empty_spinloops coccinelle script.

This is compile tested only! I don't have this hardware.

---
 drivers/net/cnxk/cn10k_tx.h | 4 ++--
 drivers/net/cnxk/cn20k_tx.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/cnxk/cn10k_tx.h +2 -2
index be9e020ac5..3f4cad168c 100644
@@ -167,7 +167,7 @@ cn10k_nix_vwqe_wait_fc(struct cn10k_eth_txq *txq, uint16_t req)
 #else
 	RTE_SET_USED(pkts);
 	while (rte_atomic_load_explicit(&txq->fc_cache_pkts, rte_memory_order_relaxed) < 0)
-		;
+		rte_pause();
 #endif
 	cached = rte_atomic_fetch_sub_explicit(&txq->fc_cache_pkts, req, rte_memory_order_acquire) -
 		 req;
@@ -402,7 +402,7 @@ cn10k_nix_sec_fc_wait(struct cn10k_eth_txq *txq, uint16_t nb_pkts)
 #else
 	/* Wait for primary core to refill FC. */
 	while (rte_atomic_load_explicit(fc_sw, rte_memory_order_relaxed) < 0)
-		;
+		rte_pause();
 #endif
 
 	val = rte_atomic_fetch_sub_explicit(fc_sw, nb_pkts, rte_memory_order_acquire) - nb_pkts;
drivers/net/cnxk/cn20k_tx.h +2 -2
index 9e48744831..3dfad5fd5a 100644
@@ -165,7 +165,7 @@ cn20k_nix_vwqe_wait_fc(struct cn20k_eth_txq *txq, uint16_t req)
 #else
 	RTE_SET_USED(pkts);
 	while (rte_atomic_load_explicit(&txq->fc_cache_pkts, rte_memory_order_relaxed) < 0)
-		;
+		rte_pause();
 #endif
 	cached = rte_atomic_fetch_sub_explicit(&txq->fc_cache_pkts, req, rte_memory_order_acquire) -
 		 req;
@@ -392,7 +392,7 @@ cn20k_nix_sec_fc_wait(struct cn20k_eth_txq *txq, uint16_t nb_pkts)
 #else
 	/* Wait for primary core to refill FC. */
 	while (rte_atomic_load_explicit(fc_sw, rte_memory_order_relaxed) < 0)
-		;
+		rte_pause();
 #endif
 
 	val = rte_atomic_fetch_sub_explicit(fc_sw, nb_pkts, rte_memory_order_acquire) - nb_pkts;
Signature · 1 line
2.51.0
#2 lore raw

RFC 2/3 event/cnxk: add pause to spinloops

In reply to Stephen Hemminger

On SMT systems when a spinloop is done without a pause it may cause excessive latency. This problem was found by the fix_empty_spinloops coccinelle script.

This is compile tested only! I don't have this hardware.

---
 drivers/event/cnxk/cn10k_worker.c    | 2 +-
 drivers/event/cnxk/cn20k_worker.c    | 2 +-
 drivers/event/cnxk/cnxk_tim_worker.h | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/event/cnxk/cn10k_worker.c +1 -1
index 80077ec8a1..69ac67115a 100644
@@ -93,7 +93,7 @@ sso_lmt_aw_wait_fc(struct cn10k_sso_hws *ws, int64_t req)
 
 retry:
 	while (rte_atomic_load_explicit(ws->fc_cache_space, rte_memory_order_relaxed) < 0)
-		;
+		rte_pause();
 
 	cached = rte_atomic_fetch_sub_explicit(ws->fc_cache_space, req, rte_memory_order_acquire) -
 		 req;
drivers/event/cnxk/cn20k_worker.c +1 -1
index 53daf3b4b0..49dfb2a28c 100644
@@ -93,7 +93,7 @@ sso_lmt_aw_wait_fc(struct cn20k_sso_hws *ws, int64_t req)
 
 retry:
 	while (rte_atomic_load_explicit(ws->fc_cache_space, rte_memory_order_relaxed) < 0)
-		;
+		rte_pause();
 
 	cached = rte_atomic_fetch_sub_explicit(ws->fc_cache_space, req, rte_memory_order_acquire) -
 		 req;
drivers/event/cnxk/cnxk_tim_worker.h +2 -2
index 09f84091ab..887c0800e2 100644
@@ -405,9 +405,9 @@ cnxk_tim_add_entry_mp(struct cnxk_tim_ring *const tim_ring,
 			     : [crem] "r"(&bkt->w1)
 			     : "memory");
 #else
-		while (rte_atomic_load_explicit((int64_t __rte_atomic *)&bkt->w1,
+		while (rte_atomic_load_explicit((int64_t __rte_atomic  *)&bkt->w1,
 						rte_memory_order_relaxed) < 0)
-			;
+			rte_pause();
 #endif
 		goto __retry;
 	} else if (!rem) {
Signature · 1 line
2.51.0
#3 lore raw

Re: [RFC 2/3] event/cnxk: add pause to spinloops

Quoted 5 lines · On Wed, 21 Jan 2026 10:05:43 -0800 Stephen Hemminger…
drivers/event/cnxk/cnxk_tim_worker.h +0 -0
index 09f84091ab..887c0800e2 100644

drivers/event/cnxk/cnxk_tim_worker.h cnxk_tim_add_entry_mp(struct cnxk_tim_ring *const tim_ring, · line 411

Quoted 9 lines
drivers/event/cnxk/cnxk_tim_worker.h +2 -2
@@ -405,9 +405,9 @@ cnxk_tim_add_entry_mp(struct cnxk_tim_ring *const tim_ring,
 			     : [crem] "r"(&bkt->w1)
 			     : "memory");
 #else
-		while (rte_atomic_load_explicit((int64_t __rte_atomic *)&bkt->w1,
+		while (rte_atomic_load_explicit((int64_t __rte_atomic  *)&bkt->w1,
 						rte_memory_order_relaxed) < 0)
-			;
+			rte_pause();
 #endif

I noticed while looking at the code there is assembly to do the wait for instructions. Why doesn't this driver use the rte_unit_equal_64 instead?

#4 lore raw

RFC 3/3 devtools/cocci: add script to find empty spinloops

In reply to Stephen Hemminger

This script finds and fixes many variations of the pattern:

   while (!atomic(&flag));

to add a rte_pause() to the loop.

This type of loop was causing failures in the standalone atomic tests on high core system. The script generalizes that to find other places with the same problem.

Script was autogenerated by AI and works but may cover more cases than really necessary.

---
 devtools/cocci/fix_empty_spinloops.cocci | 165 +++++++++++++++++++++++
 1 file changed, 165 insertions(+)
 create mode 100644 devtools/cocci/fix_empty_spinloops.cocci
devtools/cocci/fix_empty_spinloops.cocci new file +165 -0
new file mode 100644
index 0000000000..ff64b30eac
@@ -0,0 +1,165 @@
+// SPDX-License-Identifier: BSD-3-Clause
+// Find and fix empty spin loops that should call rte_pause()
+//
+// Empty spin loops waste CPU cycles and can cause performance issues.
+// This script finds various forms of busy-wait loops and adds rte_pause()
+// to give hints to the CPU and reduce power consumption.
+
+// Rule 1: Handle rte_atomic*_read() variants
+@fix_atomic_read@
+expression ptr, val;
+@@
+
+(
+- while (rte_atomic16_read(ptr) == val);
++ while (rte_atomic16_read(ptr) == val)
++     rte_pause();
+|
+- while (rte_atomic16_read(ptr) != val);
++ while (rte_atomic16_read(ptr) != val)
++     rte_pause();
+|
+- while (rte_atomic32_read(ptr) == val);
++ while (rte_atomic32_read(ptr) == val)
++     rte_pause();
+|
+- while (rte_atomic32_read(ptr) != val);
++ while (rte_atomic32_read(ptr) != val)
++     rte_pause();
+|
+- while (rte_atomic64_read(ptr) == val);
++ while (rte_atomic64_read(ptr) == val)
++     rte_pause();
+|
+- while (rte_atomic64_read(ptr) != val);
++ while (rte_atomic64_read(ptr) != val)
++     rte_pause();
+)
+
+// Rule 2: Handle rte_atomic*_read() with comparison operators
+@fix_atomic_cmp@
+expression ptr, val;
+@@
+
+(
+- while (rte_atomic16_read(ptr) < val);
++ while (rte_atomic16_read(ptr) < val)
++     rte_pause();
+|
+- while (rte_atomic16_read(ptr) > val);
++ while (rte_atomic16_read(ptr) > val)
++     rte_pause();
+|
+- while (rte_atomic32_read(ptr) < val);
++ while (rte_atomic32_read(ptr) < val)
++     rte_pause();
+|
+- while (rte_atomic32_read(ptr) > val);
++ while (rte_atomic32_read(ptr) > val)
++     rte_pause();
+|
+- while (rte_atomic64_read(ptr) < val);
++ while (rte_atomic64_read(ptr) < val)
++     rte_pause();
+|
+- while (rte_atomic64_read(ptr) > val);
++ while (rte_atomic64_read(ptr) > val)
++     rte_pause();
+)
+
+// Rule 3: Handle C11 atomics with rte_atomic_load_explicit()
+@fix_c11_atomic@
+expression ptr, order, val;
+@@
+
+(
+- while (rte_atomic_load_explicit(ptr, order) == val);
++ while (rte_atomic_load_explicit(ptr, order) == val)
++     rte_pause();
+|
+- while (rte_atomic_load_explicit(ptr, order) != val);
++ while (rte_atomic_load_explicit(ptr, order) != val)
++     rte_pause();
+|
+- while (rte_atomic_load_explicit(ptr, order) < val);
++ while (rte_atomic_load_explicit(ptr, order) < val)
++     rte_pause();
+|
+- while (rte_atomic_load_explicit(ptr, order) > val);
++ while (rte_atomic_load_explicit(ptr, order) > val)
++     rte_pause();
+)
+
+// Rule 4: Handle __atomic_load_n() directly
+@fix_gcc_atomic@
+expression ptr, order, val;
+@@
+
+(
+- while (__atomic_load_n(ptr, order) == val);
++ while (__atomic_load_n(ptr, order) == val)
++     rte_pause();
+|
+- while (__atomic_load_n(ptr, order) != val);
++ while (__atomic_load_n(ptr, order) != val)
++     rte_pause();
+|
+- while (__atomic_load_n(ptr, order) < val);
++ while (__atomic_load_n(ptr, order) < val)
++     rte_pause();
+|
+- while (__atomic_load_n(ptr, order) > val);
++ while (__atomic_load_n(ptr, order) > val)
++     rte_pause();
+)
+
+// Rule 5: Handle volatile variable reads (simple dereference)
+@fix_volatile@
+expression E;
+identifier v;
+@@
+
+(
+- while (*v == E);
++ while (*v == E)
++     rte_pause();
+|
+- while (*v != E);
++ while (*v != E)
++     rte_pause();
+|
+- while (*v < E);
++ while (*v < E)
++     rte_pause();
+|
+- while (*v > E);
++ while (*v > E)
++     rte_pause();
+|
+- while (v == E);
++ while (v == E)
++     rte_pause();
+|
+- while (v != E);
++ while (v != E)
++     rte_pause();
+)
+
+// Rule 6: Handle negated conditions
+@fix_negated@
+expression ptr, val;
+@@
+
+(
+- while (!rte_atomic32_read(ptr));
++ while (!rte_atomic32_read(ptr))
++     rte_pause();
+|
+- while (!rte_atomic64_read(ptr));
++ while (!rte_atomic64_read(ptr))
++     rte_pause();
+|
+- while (!rte_atomic_load_explicit(ptr, val));
++ while (!rte_atomic_load_explicit(ptr, val))
++     rte_pause();
+)
Signature · 1 line
2.51.0
#5 lore raw

v2 cover Add pause to empty spin loops

In reply to Stephen Hemminger

On SMT systems, empty spinloops can cause excessive latency due to the spinning core consuming resources that could be used by other hardware threads. This series addresses this by adding rte_pause() calls to busy-wait loops in the cnxk drivers.

The first two patches fix existing empty spinloops in the net/cnxk and event/cnxk drivers. These were identified using a new coccinelle script that finds variations of the pattern:

    while (!atomic(&flag));

The third patch adds this coccinelle script to devtools/ so that similar issues can be detected and fixed automatically.

v2 - rebase for 26.07

Stephen Hemminger (3):
net/cnxk: add pause to spinloops event/cnxk: add pause to spinloops devtools/cocci: add script to find empty spinloops

 devtools/cocci/fix_empty_spinloops.cocci | 165 +++++++++++++++++++++++
 drivers/event/cnxk/cn10k_worker.c        |   2 +-
 drivers/event/cnxk/cn20k_worker.c        |   2 +-
 drivers/event/cnxk/cnxk_tim_worker.h     |   4 +-
 drivers/net/cnxk/cn10k_tx.h              |   4 +-
 drivers/net/cnxk/cn20k_tx.h              |   4 +-
 6 files changed, 173 insertions(+), 8 deletions(-)
 create mode 100644 devtools/cocci/fix_empty_spinloops.cocci
Signature · 1 line
2.53.0
#6 lore raw

PATCH v2 1/3 net/cnxk: add pause to spinloops

On SMT systems when a spinloop is done without a pause it may cause excessive latency. This problem was found by the fix_empty_spinloops coccinelle script.

---
 drivers/net/cnxk/cn10k_tx.h | 4 ++--
 drivers/net/cnxk/cn20k_tx.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/cnxk/cn10k_tx.h +2 -2
index 8c912a1f35..7657b06190 100644
@@ -167,7 +167,7 @@ cn10k_nix_vwqe_wait_fc(struct cn10k_eth_txq *txq, uint16_t req)
 #else
 	RTE_SET_USED(pkts);
 	while (rte_atomic_load_explicit(&txq->fc_cache_pkts, rte_memory_order_relaxed) < 0)
-		;
+		rte_pause();
 #endif
 	cached = rte_atomic_fetch_sub_explicit(&txq->fc_cache_pkts, req, rte_memory_order_acquire) -
 		 req;
@@ -402,7 +402,7 @@ cn10k_nix_sec_fc_wait(struct cn10k_eth_txq *txq, uint16_t nb_pkts)
 #else
 	/* Wait for primary core to refill FC. */
 	while (rte_atomic_load_explicit(fc_sw, rte_memory_order_relaxed) < 0)
-		;
+		rte_pause();
 #endif
 
 	val = rte_atomic_fetch_sub_explicit(fc_sw, nb_pkts, rte_memory_order_acquire) - nb_pkts;
drivers/net/cnxk/cn20k_tx.h +2 -2
index 8e64d2e352..ac0b00ef31 100644
@@ -165,7 +165,7 @@ cn20k_nix_vwqe_wait_fc(struct cn20k_eth_txq *txq, uint16_t req)
 #else
 	RTE_SET_USED(pkts);
 	while (rte_atomic_load_explicit(&txq->fc_cache_pkts, rte_memory_order_relaxed) < 0)
-		;
+		rte_pause();
 #endif
 	cached = rte_atomic_fetch_sub_explicit(&txq->fc_cache_pkts, req, rte_memory_order_acquire) -
 		 req;
@@ -392,7 +392,7 @@ cn20k_nix_sec_fc_wait(struct cn20k_eth_txq *txq, uint16_t nb_pkts)
 #else
 	/* Wait for primary core to refill FC. */
 	while (rte_atomic_load_explicit(fc_sw, rte_memory_order_relaxed) < 0)
-		;
+		rte_pause();
 #endif
 
 	val = rte_atomic_fetch_sub_explicit(fc_sw, nb_pkts, rte_memory_order_acquire) - nb_pkts;
Signature · 1 line
2.53.0
#7 lore raw

PATCH v2 2/3 event/cnxk: add pause to spinloops

In reply to Stephen Hemminger

On SMT systems when a spinloop is done without a pause it may cause excessive latency. This problem was found by the fix_empty_spinloops coccinelle script.

---
 drivers/event/cnxk/cn10k_worker.c    | 2 +-
 drivers/event/cnxk/cn20k_worker.c    | 2 +-
 drivers/event/cnxk/cnxk_tim_worker.h | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/event/cnxk/cn10k_worker.c +1 -1
index 80077ec8a1..69ac67115a 100644
@@ -93,7 +93,7 @@ sso_lmt_aw_wait_fc(struct cn10k_sso_hws *ws, int64_t req)
 
 retry:
 	while (rte_atomic_load_explicit(ws->fc_cache_space, rte_memory_order_relaxed) < 0)
-		;
+		rte_pause();
 
 	cached = rte_atomic_fetch_sub_explicit(ws->fc_cache_space, req, rte_memory_order_acquire) -
 		 req;
drivers/event/cnxk/cn20k_worker.c +1 -1
index 53daf3b4b0..49dfb2a28c 100644
@@ -93,7 +93,7 @@ sso_lmt_aw_wait_fc(struct cn20k_sso_hws *ws, int64_t req)
 
 retry:
 	while (rte_atomic_load_explicit(ws->fc_cache_space, rte_memory_order_relaxed) < 0)
-		;
+		rte_pause();
 
 	cached = rte_atomic_fetch_sub_explicit(ws->fc_cache_space, req, rte_memory_order_acquire) -
 		 req;
drivers/event/cnxk/cnxk_tim_worker.h +2 -2
index 09f84091ab..887c0800e2 100644
@@ -405,9 +405,9 @@ cnxk_tim_add_entry_mp(struct cnxk_tim_ring *const tim_ring,
 			     : [crem] "r"(&bkt->w1)
 			     : "memory");
 #else
-		while (rte_atomic_load_explicit((int64_t __rte_atomic *)&bkt->w1,
+		while (rte_atomic_load_explicit((int64_t __rte_atomic  *)&bkt->w1,
 						rte_memory_order_relaxed) < 0)
-			;
+			rte_pause();
 #endif
 		goto __retry;
 	} else if (!rem) {
Signature · 1 line
2.53.0
#8 lore raw

Re: [PATCH v2 2/3] event/cnxk: add pause to spinloops

Quoted 6 lines · Stephen Hemminger

On SMT systems when a spinloop is done without a pause it may cause excessive latency. This problem was found by the fix_empty_spinloops coccinelle script.

rte_pause() translates to YIELD instruction. Since cnxk is an integrated SoC and it is a single threaded core, it won't help on anything other than adding one instruction bit more latency. In general 3/3 devtool is good. Please send a it separate version so that 3/3 patches can be merged through the main tree.

---------------
The YIELD instruction write up from ARMv8 manual.

YIELD is a hint instruction in the ARMv8-A architecture. It tells the CPU that the current hardware thread is doing nothing useful right now (typically spinning in a busy-wait loop), so the processor may reallocate shared execution resources to other hardware threads.

On SMT (multithreaded) cores, this can give sibling hardware threads more resources, improving overall throughput.
On most current single-threaded ARM cores, YIELD executes as a NOP — it has no microarchitectural effect, but it's architecturally valid and harmless. It does not put the core to sleep (unlike WFE/WFI). It's a pure hint: it never changes program correctness, only potentially performance/fairness.
-------------

#9 lore raw

Re: [PATCH v2 2/3] event/cnxk: add pause to spinloops

Quoted 7 lines · On Mon, 8 Jun 2026 21:19:20 +0530 Jerin Jacob <[email protected]> wrote:
Quoted 5 lines · Stephen Hemminger

On SMT systems when a spinloop is done without a pause it may cause excessive latency. This problem was found by the fix_empty_spinloops coccinelle script.

Quoted 7 lines
Quoted 1 line

rte_pause() translates to YIELD instruction. Since cnxk is an integrated SoC and it is a single threaded core, it won't help on anything other than adding one instruction bit more latency. In general 3/3 devtool is good. Please send a it separate version so that 3/3 patches can be merged through the main tree.

It matters if your SOC has SMT where two cores are sharing and one core is waiting for its partner.

#10 lore raw

Re: [PATCH v2 2/3] event/cnxk: add pause to spinloops

Quoted 20 lines · Stephen Hemminger
Quoted 7 lines · On Mon, 8 Jun 2026 21:19:20 +0530 Jerin Jacob <[email protected]> wrote:
Quoted 5 lines · Stephen Hemminger

On SMT systems when a spinloop is done without a pause it may cause excessive latency. This problem was found by the fix_empty_spinloops coccinelle script.

Quoted 7 lines
Quoted 1 line

rte_pause() translates to YIELD instruction. Since cnxk is an integrated SoC and it is a single threaded core, it won't help on anything other than adding one instruction bit more latency. In general 3/3 devtool is good. Please send a it separate version so that 3/3 patches can be merged through the main tree.

Quoted 2 lines

It matters if your SOC has SMT where two cores are sharing and one core is waiting for its partner.

Yes. As I mentioned earlier, it is not cnxk is not SMT so it will not be useful for cnxk.

#11 lore raw

PATCH v2 3/3 devtools/cocci: add script to find empty spinloops

In reply to Stephen Hemminger

This script finds and fixes many variations of the pattern:

   while (!atomic(&flag));

to add a rte_pause() to the loop.

This type of loop was causing failures in the standalone atomic tests on high core system. The script generalizes that to find other places with the same problem.

---
 devtools/cocci/fix_empty_spinloops.cocci | 165 +++++++++++++++++++++++
 1 file changed, 165 insertions(+)
 create mode 100644 devtools/cocci/fix_empty_spinloops.cocci
devtools/cocci/fix_empty_spinloops.cocci new file +165 -0
new file mode 100644
index 0000000000..ff64b30eac
@@ -0,0 +1,165 @@
+// SPDX-License-Identifier: BSD-3-Clause
+// Find and fix empty spin loops that should call rte_pause()
+//
+// Empty spin loops waste CPU cycles and can cause performance issues.
+// This script finds various forms of busy-wait loops and adds rte_pause()
+// to give hints to the CPU and reduce power consumption.
+
+// Rule 1: Handle rte_atomic*_read() variants
+@fix_atomic_read@
+expression ptr, val;
+@@
+
+(
+- while (rte_atomic16_read(ptr) == val);
++ while (rte_atomic16_read(ptr) == val)
++     rte_pause();
+|
+- while (rte_atomic16_read(ptr) != val);
++ while (rte_atomic16_read(ptr) != val)
++     rte_pause();
+|
+- while (rte_atomic32_read(ptr) == val);
++ while (rte_atomic32_read(ptr) == val)
++     rte_pause();
+|
+- while (rte_atomic32_read(ptr) != val);
++ while (rte_atomic32_read(ptr) != val)
++     rte_pause();
+|
+- while (rte_atomic64_read(ptr) == val);
++ while (rte_atomic64_read(ptr) == val)
++     rte_pause();
+|
+- while (rte_atomic64_read(ptr) != val);
++ while (rte_atomic64_read(ptr) != val)
++     rte_pause();
+)
+
+// Rule 2: Handle rte_atomic*_read() with comparison operators
+@fix_atomic_cmp@
+expression ptr, val;
+@@
+
+(
+- while (rte_atomic16_read(ptr) < val);
++ while (rte_atomic16_read(ptr) < val)
++     rte_pause();
+|
+- while (rte_atomic16_read(ptr) > val);
++ while (rte_atomic16_read(ptr) > val)
++     rte_pause();
+|
+- while (rte_atomic32_read(ptr) < val);
++ while (rte_atomic32_read(ptr) < val)
++     rte_pause();
+|
+- while (rte_atomic32_read(ptr) > val);
++ while (rte_atomic32_read(ptr) > val)
++     rte_pause();
+|
+- while (rte_atomic64_read(ptr) < val);
++ while (rte_atomic64_read(ptr) < val)
++     rte_pause();
+|
+- while (rte_atomic64_read(ptr) > val);
++ while (rte_atomic64_read(ptr) > val)
++     rte_pause();
+)
+
+// Rule 3: Handle C11 atomics with rte_atomic_load_explicit()
+@fix_c11_atomic@
+expression ptr, order, val;
+@@
+
+(
+- while (rte_atomic_load_explicit(ptr, order) == val);
++ while (rte_atomic_load_explicit(ptr, order) == val)
++     rte_pause();
+|
+- while (rte_atomic_load_explicit(ptr, order) != val);
++ while (rte_atomic_load_explicit(ptr, order) != val)
++     rte_pause();
+|
+- while (rte_atomic_load_explicit(ptr, order) < val);
++ while (rte_atomic_load_explicit(ptr, order) < val)
++     rte_pause();
+|
+- while (rte_atomic_load_explicit(ptr, order) > val);
++ while (rte_atomic_load_explicit(ptr, order) > val)
++     rte_pause();
+)
+
+// Rule 4: Handle __atomic_load_n() directly
+@fix_gcc_atomic@
+expression ptr, order, val;
+@@
+
+(
+- while (__atomic_load_n(ptr, order) == val);
++ while (__atomic_load_n(ptr, order) == val)
++     rte_pause();
+|
+- while (__atomic_load_n(ptr, order) != val);
++ while (__atomic_load_n(ptr, order) != val)
++     rte_pause();
+|
+- while (__atomic_load_n(ptr, order) < val);
++ while (__atomic_load_n(ptr, order) < val)
++     rte_pause();
+|
+- while (__atomic_load_n(ptr, order) > val);
++ while (__atomic_load_n(ptr, order) > val)
++     rte_pause();
+)
+
+// Rule 5: Handle volatile variable reads (simple dereference)
+@fix_volatile@
+expression E;
+identifier v;
+@@
+
+(
+- while (*v == E);
++ while (*v == E)
++     rte_pause();
+|
+- while (*v != E);
++ while (*v != E)
++     rte_pause();
+|
+- while (*v < E);
++ while (*v < E)
++     rte_pause();
+|
+- while (*v > E);
++ while (*v > E)
++     rte_pause();
+|
+- while (v == E);
++ while (v == E)
++     rte_pause();
+|
+- while (v != E);
++ while (v != E)
++     rte_pause();
+)
+
+// Rule 6: Handle negated conditions
+@fix_negated@
+expression ptr, val;
+@@
+
+(
+- while (!rte_atomic32_read(ptr));
++ while (!rte_atomic32_read(ptr))
++     rte_pause();
+|
+- while (!rte_atomic64_read(ptr));
++ while (!rte_atomic64_read(ptr))
++     rte_pause();
+|
+- while (!rte_atomic_load_explicit(ptr, val));
++ while (!rte_atomic_load_explicit(ptr, val))
++     rte_pause();
+)
Signature · 1 line
2.53.0