Skip to contentSkip to conversation

use rte atomic thread fence

PATCH Superseded Tyler Retzlaff 4 participants 19 messages Nov 2, 2023 – Feb 18, 2024

lore
Share & tools
lore
#0 lore raw

cover use rte atomic thread fence

Replace use of __atomic_thread_fence with __rte_atomic_thread_fence.

It may be appropriate to use rte_atomic_thread_fence instead but it will be up to maintainers to evaluate and make the change if appropriate.

Tyler Retzlaff (5):
distributor: use rte atomic thread fence
eal: use rte atomic thread fence
hash: use rte atomic thread fence
ring: use rte atomic thread fence
stack: use rte atomic thread fence

 lib/distributor/rte_distributor.c |  2 +-
 lib/eal/common/eal_common_trace.c |  2 +-
 lib/hash/rte_cuckoo_hash.c        | 10 +++++-----
 lib/ring/rte_ring_c11_pvt.h       |  4 ++--
 lib/stack/rte_stack_lf_c11.h      |  2 +-
 5 files changed, 10 insertions(+), 10 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/5 distributor: use rte atomic thread fence

Use __rte_atomic_thread_fence instead of directly using __atomic_thread_fence builtin gcc intrinsic

---
 lib/distributor/rte_distributor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/distributor/rte_distributor.c +1 -1
index 2ecb95c..848cf85 100644
@@ -187,7 +187,7 @@
 	}
 
 	/* Sync with distributor to acquire retptrs */
-	__atomic_thread_fence(rte_memory_order_acquire);
+	__rte_atomic_thread_fence(rte_memory_order_acquire);
 	for (i = 0; i < RTE_DIST_BURST_SIZE; i++)
 		/* Switch off the return bit first */
 		buf->retptr64[i] = 0;
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/5 eal: use rte atomic thread fence

In reply to Tyler Retzlaff

Use __rte_atomic_thread_fence instead of directly using __atomic_thread_fence builtin gcc intrinsic

---
 lib/eal/common/eal_common_trace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/eal/common/eal_common_trace.c +1 -1
index 6ad87fc..4a09cbf 100644
@@ -526,7 +526,7 @@ rte_trace_mode rte_trace_mode_get(void)
 
 	/* Add the trace point at tail */
 	STAILQ_INSERT_TAIL(&tp_list, tp, next);
-	__atomic_thread_fence(rte_memory_order_release);
+	__rte_atomic_thread_fence(rte_memory_order_release);
 
 	/* All Good !!! */
 	return 0;
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH 3/5 hash: use rte atomic thread fence

In reply to Tyler Retzlaff

Use __rte_atomic_thread_fence instead of directly using __atomic_thread_fence builtin gcc intrinsic

---
 lib/hash/rte_cuckoo_hash.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/hash/rte_cuckoo_hash.c +5 -5
index b2cf60d..ca350ed 100644
@@ -871,7 +871,7 @@ struct rte_hash *
 			/* The store to sig_current should not
 			 * move above the store to tbl_chng_cnt.
 			 */
-			__atomic_thread_fence(rte_memory_order_release);
+			__rte_atomic_thread_fence(rte_memory_order_release);
 		}
 
 		/* Need to swap current/alt sig to allow later
@@ -903,7 +903,7 @@ struct rte_hash *
 		/* The store to sig_current should not
 		 * move above the store to tbl_chng_cnt.
 		 */
-		__atomic_thread_fence(rte_memory_order_release);
+		__rte_atomic_thread_fence(rte_memory_order_release);
 	}
 
 	curr_bkt->sig_current[curr_slot] = sig;
@@ -1396,7 +1396,7 @@ struct rte_hash *
 		/* The loads of sig_current in search_one_bucket
 		 * should not move below the load from tbl_chng_cnt.
 		 */
-		__atomic_thread_fence(rte_memory_order_acquire);
+		__rte_atomic_thread_fence(rte_memory_order_acquire);
 		/* Re-read the table change counter to check if the
 		 * table has changed during search. If yes, re-do
 		 * the search.
@@ -1625,7 +1625,7 @@ struct rte_hash *
 				/* The store to sig_current should
 				 * not move above the store to tbl_chng_cnt.
 				 */
-				__atomic_thread_fence(rte_memory_order_release);
+				__rte_atomic_thread_fence(rte_memory_order_release);
 			}
 			last_bkt->sig_current[i] = NULL_SIGNATURE;
 			rte_atomic_store_explicit(&last_bkt->key_idx[i],
@@ -2216,7 +2216,7 @@ struct rte_hash *
 		/* The loads of sig_current in compare_signatures
 		 * should not move below the load from tbl_chng_cnt.
 		 */
-		__atomic_thread_fence(rte_memory_order_acquire);
+		__rte_atomic_thread_fence(rte_memory_order_acquire);
 		/* Re-read the table change counter to check if the
 		 * table has changed during search. If yes, re-do
 		 * the search.
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH 4/5 ring: use rte atomic thread fence

In reply to Tyler Retzlaff

Use __rte_atomic_thread_fence instead of directly using __atomic_thread_fence builtin gcc intrinsic

---
 lib/ring/rte_ring_c11_pvt.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/ring/rte_ring_c11_pvt.h +2 -2
index 5c10ad8..38a003d 100644
@@ -68,7 +68,7 @@
 		n = max;
 
 		/* Ensure the head is read before tail */
-		__atomic_thread_fence(rte_memory_order_acquire);
+		__rte_atomic_thread_fence(rte_memory_order_acquire);
 
 		/* load-acquire synchronize with store-release of ht->tail
 		 * in update_tail.
@@ -145,7 +145,7 @@
 		n = max;
 
 		/* Ensure the head is read before tail */
-		__atomic_thread_fence(rte_memory_order_acquire);
+		__rte_atomic_thread_fence(rte_memory_order_acquire);
 
 		/* this load-acquire synchronize with store-release of ht->tail
 		 * in update_tail.
Signature · 1 line
1.8.3.1
#5 lore raw

PATCH 5/5 stack: use rte atomic thread fence

In reply to Tyler Retzlaff

Use __rte_atomic_thread_fence instead of directly using __atomic_thread_fence builtin gcc intrinsic

---
 lib/stack/rte_stack_lf_c11.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/stack/rte_stack_lf_c11.h +1 -1
index 9cb6998..0f86434 100644
@@ -110,7 +110,7 @@
 		 * elements are properly ordered with respect to the head
 		 * pointer read.
 		 */
-		__atomic_thread_fence(rte_memory_order_acquire);
+		__rte_atomic_thread_fence(rte_memory_order_acquire);
 
 		rte_prefetch0(old_head.top);
 
Signature · 1 line
1.8.3.1
#6 lore raw
In reply to Tyler Retzlaff
Quoted 23 lines

From: Tyler Retzlaff [mailto:[email protected]]
Sent: Thursday, 2 November 2023 04.04

Replace use of __atomic_thread_fence with __rte_atomic_thread_fence.

It may be appropriate to use rte_atomic_thread_fence instead but it will be up to maintainers to evaluate and make the change if appropriate.

Tyler Retzlaff (5):
distributor: use rte atomic thread fence
eal: use rte atomic thread fence
hash: use rte atomic thread fence
ring: use rte atomic thread fence
stack: use rte atomic thread fence

 lib/distributor/rte_distributor.c |  2 +-
 lib/eal/common/eal_common_trace.c |  2 +-
 lib/hash/rte_cuckoo_hash.c        | 10 +++++-----
 lib/ring/rte_ring_c11_pvt.h       |  4 ++--
 lib/stack/rte_stack_lf_c11.h      |  2 +-
 5 files changed, 10 insertions(+), 10 deletions(-)
Quoted 2 lines

--
1.8.3.1

#7 lore raw
In reply to Tyler Retzlaff

02/11/2023 04:04, Tyler Retzlaff:

Quoted 4 lines

Replace use of __atomic_thread_fence with __rte_atomic_thread_fence.

It may be appropriate to use rte_atomic_thread_fence instead but it will be up to maintainers to evaluate and make the change if appropriate.

I don't understand the use of __rte_atomic_thread_fence which is supposed to be EAL-internal only, isn't it?

On x86, we have this:
static __rte_always_inline void rte_atomic_thread_fence(rte_memory_order memorder)

{
    if (memorder == rte_memory_order_seq_cst)
        rte_smp_mb();
    else
        __rte_atomic_thread_fence(memorder);
}

This is skipped if you use __rte_atomic_thread_fence() directly.

#8 lore raw
Quoted 12 lines · Thomas Monjalon

02/11/2023 04:04, Tyler Retzlaff:

Quoted 4 lines

Replace use of __atomic_thread_fence with __rte_atomic_thread_fence.

It may be appropriate to use rte_atomic_thread_fence instead but it will be up to maintainers to evaluate and make the change if appropriate.

I don't understand the use of __rte_atomic_thread_fence which is supposed to be EAL-internal only, isn't it?

On x86, we have this:
static __rte_always_inline void rte_atomic_thread_fence(rte_memory_order memorder)

Quoted 8 lines
{
    if (memorder == rte_memory_order_seq_cst)
        rte_smp_mb();
    else
        __rte_atomic_thread_fence(memorder);
}

This is skipped if you use __rte_atomic_thread_fence() directly.

correct. that is on purpose because the original code was skipping condition by using __atomic_thread_fence directly.

this series intends no functional change which is why the replacements are __rte_atomic_thread_fence instead of to rte_atomic_thread_fence.

i would encourage the maintainers to evaluate whether the code can use rte_atomic_thread_fence directly without functional regression.

ty

#9 lore raw

08/11/2023 19:49, Tyler Retzlaff:

Quoted 20 lines · Thomas Monjalon
Quoted 19 lines

02/11/2023 04:04, Tyler Retzlaff:

Quoted 4 lines

Replace use of __atomic_thread_fence with __rte_atomic_thread_fence.

It may be appropriate to use rte_atomic_thread_fence instead but it will be up to maintainers to evaluate and make the change if appropriate.

I don't understand the use of __rte_atomic_thread_fence which is supposed to be EAL-internal only, isn't it?

On x86, we have this:
static __rte_always_inline void rte_atomic_thread_fence(rte_memory_order memorder)

{
    if (memorder == rte_memory_order_seq_cst)
        rte_smp_mb();
    else
        __rte_atomic_thread_fence(memorder);
}
Quoted 4 lines
Quoted 1 line

This is skipped if you use __rte_atomic_thread_fence() directly.

correct. that is on purpose because the original code was skipping condition by using __atomic_thread_fence directly.

There is chance that it was not skipping on purpose.

Quoted 2 lines

this series intends no functional change which is why the replacements are __rte_atomic_thread_fence instead of to rte_atomic_thread_fence.

We should take this opportunity to simplify the code, I mean we should avoid having 3 functions for the same thing.

Quoted 2 lines

i would encourage the maintainers to evaluate whether the code can use rte_atomic_thread_fence directly without functional regression.

Let's do the change so the maintainers can review what is changed. Note it should have no impact if not using rte_memory_order_seq_cst. If we discover later that something is broken, we have time to fix it.

Note: lib/eal/include/rte_mcslock.h should not use __rte_atomic_thread_fence() and lib/lpm/rte_lpm.c should not use __atomic_thread_fence().

Can we replace and discourage all occurrences of __atomic_thread_fence() and __rte_atomic_thread_fence()? It would be simpler to recommend only rte_atomic_thread_fence().

Also in another patch, it would be nice to replace __ATOMIC_* with rte_memory_order_*, at least when used in rte_atomic_thread_fence().

#10 lore raw

v2 cover use rte atomic thread fence

In reply to Tyler Retzlaff

Replace use of __atomic_thread_fence with rte_atomic_thread_fence.

Notes:

The rest of lib/lpm will be converted to rte_atomic in a separate series (to be submitted soon).

There are existing checkpatches checks that catch use of both __atomic_thread_fence and __rte_atomic_thread_fence in new submissions.

v2:
* change series to use rte_atomic_thread_fence instead of __rte_atomic_thread_fence (internal)
* also change __atomic_thread_fence in lib/lpm

Tyler Retzlaff (6):
distributor: use rte atomic thread fence
eal: use rte atomic thread fence
hash: use rte atomic thread fence
ring: use rte atomic thread fence
stack: use rte atomic thread fence
lpm: use rte atomic thread fence

 lib/distributor/rte_distributor.c |  2 +-
 lib/eal/common/eal_common_trace.c |  2 +-
 lib/eal/include/rte_mcslock.h     |  4 ++--
 lib/hash/rte_cuckoo_hash.c        | 10 +++++-----
 lib/lpm/rte_lpm.c                 |  4 ++--
 lib/ring/rte_ring_c11_pvt.h       |  4 ++--
 lib/stack/rte_stack_lf_c11.h      |  2 +-
 7 files changed, 14 insertions(+), 14 deletions(-)
Signature · 1 line
1.8.3.1
#11 lore raw

PATCH v2 1/6 distributor: use rte atomic thread fence

Use rte_atomic_thread_fence instead of directly using __atomic_thread_fence builtin gcc intrinsic

---
 lib/distributor/rte_distributor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/distributor/rte_distributor.c +1 -1
index 2ecb95c..e842dc9 100644
@@ -187,7 +187,7 @@
 	}
 
 	/* Sync with distributor to acquire retptrs */
-	__atomic_thread_fence(rte_memory_order_acquire);
+	rte_atomic_thread_fence(rte_memory_order_acquire);
 	for (i = 0; i < RTE_DIST_BURST_SIZE; i++)
 		/* Switch off the return bit first */
 		buf->retptr64[i] = 0;
Signature · 1 line
1.8.3.1
#12 lore raw

PATCH v2 2/6 eal: use rte atomic thread fence

In reply to Tyler Retzlaff

Use rte_atomic_thread_fence instead of directly using __atomic_thread_fence builtin gcc intrinsic

Update rte_mcslock.h to use rte_atomic_thread_fence instead of directly using internal __rte_atomic_thread_fence

---
 lib/eal/common/eal_common_trace.c | 2 +-
 lib/eal/include/rte_mcslock.h     | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
lib/eal/common/eal_common_trace.c +1 -1
index 6ad87fc..918f49b 100644
@@ -526,7 +526,7 @@ rte_trace_mode rte_trace_mode_get(void)
 
 	/* Add the trace point at tail */
 	STAILQ_INSERT_TAIL(&tp_list, tp, next);
-	__atomic_thread_fence(rte_memory_order_release);
+	rte_atomic_thread_fence(rte_memory_order_release);
 
 	/* All Good !!! */
 	return 0;
lib/eal/include/rte_mcslock.h +2 -2
index 2ca967f..0aeb1a0 100644
@@ -83,7 +83,7 @@
 	 * store to prev->next. Otherwise it will cause a deadlock. Need a
 	 * store-load barrier.
 	 */
-	__rte_atomic_thread_fence(rte_memory_order_acq_rel);
+	rte_atomic_thread_fence(rte_memory_order_acq_rel);
 	/* If the lock has already been acquired, it first atomically
 	 * places the node at the end of the queue and then proceeds
 	 * to spin on me->locked until the previous lock holder resets
@@ -117,7 +117,7 @@
 		 * while-loop first. This has the potential to cause a
 		 * deadlock. Need a load barrier.
 		 */
-		__rte_atomic_thread_fence(rte_memory_order_acquire);
+		rte_atomic_thread_fence(rte_memory_order_acquire);
 		/* More nodes added to the queue by other CPUs.
 		 * Wait until the next pointer is set.
 		 */
Signature · 1 line
1.8.3.1
#13 lore raw

PATCH v2 3/6 hash: use rte atomic thread fence

In reply to Tyler Retzlaff

Use rte_atomic_thread_fence instead of directly using __atomic_thread_fence builtin gcc intrinsic

---
 lib/hash/rte_cuckoo_hash.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/hash/rte_cuckoo_hash.c +5 -5
index 7045675..9cf9464 100644
@@ -878,7 +878,7 @@ struct rte_hash *
 			/* The store to sig_current should not
 			 * move above the store to tbl_chng_cnt.
 			 */
-			__atomic_thread_fence(rte_memory_order_release);
+			rte_atomic_thread_fence(rte_memory_order_release);
 		}
 
 		/* Need to swap current/alt sig to allow later
@@ -910,7 +910,7 @@ struct rte_hash *
 		/* The store to sig_current should not
 		 * move above the store to tbl_chng_cnt.
 		 */
-		__atomic_thread_fence(rte_memory_order_release);
+		rte_atomic_thread_fence(rte_memory_order_release);
 	}
 
 	curr_bkt->sig_current[curr_slot] = sig;
@@ -1403,7 +1403,7 @@ struct rte_hash *
 		/* The loads of sig_current in search_one_bucket
 		 * should not move below the load from tbl_chng_cnt.
 		 */
-		__atomic_thread_fence(rte_memory_order_acquire);
+		rte_atomic_thread_fence(rte_memory_order_acquire);
 		/* Re-read the table change counter to check if the
 		 * table has changed during search. If yes, re-do
 		 * the search.
@@ -1632,7 +1632,7 @@ struct rte_hash *
 				/* The store to sig_current should
 				 * not move above the store to tbl_chng_cnt.
 				 */
-				__atomic_thread_fence(rte_memory_order_release);
+				rte_atomic_thread_fence(rte_memory_order_release);
 			}
 			last_bkt->sig_current[i] = NULL_SIGNATURE;
 			rte_atomic_store_explicit(&last_bkt->key_idx[i],
@@ -2223,7 +2223,7 @@ struct rte_hash *
 		/* The loads of sig_current in compare_signatures
 		 * should not move below the load from tbl_chng_cnt.
 		 */
-		__atomic_thread_fence(rte_memory_order_acquire);
+		rte_atomic_thread_fence(rte_memory_order_acquire);
 		/* Re-read the table change counter to check if the
 		 * table has changed during search. If yes, re-do
 		 * the search.
Signature · 1 line
1.8.3.1
#14 lore raw

PATCH v2 4/6 ring: use rte atomic thread fence

In reply to Tyler Retzlaff

Use rte_atomic_thread_fence instead of directly using __atomic_thread_fence builtin gcc intrinsic

---
 lib/ring/rte_ring_c11_pvt.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/ring/rte_ring_c11_pvt.h +2 -2
index 5c10ad8..629b2d9 100644
@@ -68,7 +68,7 @@
 		n = max;
 
 		/* Ensure the head is read before tail */
-		__atomic_thread_fence(rte_memory_order_acquire);
+		rte_atomic_thread_fence(rte_memory_order_acquire);
 
 		/* load-acquire synchronize with store-release of ht->tail
 		 * in update_tail.
@@ -145,7 +145,7 @@
 		n = max;
 
 		/* Ensure the head is read before tail */
-		__atomic_thread_fence(rte_memory_order_acquire);
+		rte_atomic_thread_fence(rte_memory_order_acquire);
 
 		/* this load-acquire synchronize with store-release of ht->tail
 		 * in update_tail.
Signature · 1 line
1.8.3.1
#15 lore raw

PATCH v2 5/6 stack: use rte atomic thread fence

In reply to Tyler Retzlaff

Use rte_atomic_thread_fence instead of directly using __atomic_thread_fence builtin gcc intrinsic

---
 lib/stack/rte_stack_lf_c11.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/stack/rte_stack_lf_c11.h +1 -1
index 9cb6998..60d46e9 100644
@@ -110,7 +110,7 @@
 		 * elements are properly ordered with respect to the head
 		 * pointer read.
 		 */
-		__atomic_thread_fence(rte_memory_order_acquire);
+		rte_atomic_thread_fence(rte_memory_order_acquire);
 
 		rte_prefetch0(old_head.top);
 
Signature · 1 line
1.8.3.1
#16 lore raw

PATCH v2 6/6 lpm: use rte atomic thread fence

In reply to Tyler Retzlaff

Use rte_atomic_thread_fence instead of directly using __atomic_thread_fence builtin gcc intrinsic

---
 lib/lpm/rte_lpm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/lpm/rte_lpm.c +2 -2
index 363058e..9633d63 100644
@@ -1116,7 +1116,7 @@ struct rte_lpm *
 		 * Prevent the free of the tbl8 group from hoisting.
 		 */
 		i_lpm->lpm.tbl24[tbl24_index].valid = 0;
-		__atomic_thread_fence(__ATOMIC_RELEASE);
+		rte_atomic_thread_fence(rte_memory_order_release);
 		status = tbl8_free(i_lpm, tbl8_group_start);
 	} else if (tbl8_recycle_index > -1) {
 		/* Update tbl24 entry. */
@@ -1132,7 +1132,7 @@ struct rte_lpm *
 		 */
 		__atomic_store(&i_lpm->lpm.tbl24[tbl24_index], &new_tbl24_entry,
 				__ATOMIC_RELAXED);
-		__atomic_thread_fence(__ATOMIC_RELEASE);
+		rte_atomic_thread_fence(rte_memory_order_release);
 		status = tbl8_free(i_lpm, tbl8_group_start);
 	}
 #undef group_idx
Signature · 1 line
1.8.3.1
#17 lore raw
In reply to Tyler Retzlaff
Quoted 33 lines · Tyler Retzlaff

Replace use of __atomic_thread_fence with rte_atomic_thread_fence.

Notes:

The rest of lib/lpm will be converted to rte_atomic in a separate series (to be submitted soon).

There are existing checkpatches checks that catch use of both __atomic_thread_fence and __rte_atomic_thread_fence in new submissions.

v2:
* change series to use rte_atomic_thread_fence instead of __rte_atomic_thread_fence (internal)
* also change __atomic_thread_fence in lib/lpm

Tyler Retzlaff (6):
distributor: use rte atomic thread fence
eal: use rte atomic thread fence
hash: use rte atomic thread fence
ring: use rte atomic thread fence
stack: use rte atomic thread fence
lpm: use rte atomic thread fence

 lib/distributor/rte_distributor.c |  2 +-
 lib/eal/common/eal_common_trace.c |  2 +-
 lib/eal/include/rte_mcslock.h     |  4 ++--
 lib/hash/rte_cuckoo_hash.c        | 10 +++++-----
 lib/lpm/rte_lpm.c                 |  4 ++--
 lib/ring/rte_ring_c11_pvt.h       |  4 ++--
 lib/stack/rte_stack_lf_c11.h      |  2 +-
 7 files changed, 14 insertions(+), 14 deletions(-)
#18 lore raw
Quoted 24 lines
Quoted 16 lines

Replace use of __atomic_thread_fence with rte_atomic_thread_fence.

Notes:

The rest of lib/lpm will be converted to rte_atomic in a separate series (to be submitted soon).

There are existing checkpatches checks that catch use of both __atomic_thread_fence and __rte_atomic_thread_fence in new submissions.

v2:
* change series to use rte_atomic_thread_fence instead of __rte_atomic_thread_fence (internal)
* also change __atomic_thread_fence in lib/lpm

Quoted 7 lines

Tyler Retzlaff (6):
distributor: use rte atomic thread fence
eal: use rte atomic thread fence
hash: use rte atomic thread fence
ring: use rte atomic thread fence
stack: use rte atomic thread fence
lpm: use rte atomic thread fence

Quoted 1 line

Squashed and applied, thanks.