[v2,3/5] lib/stack: remove redundant orderings for list->len
diff mbox series

Message ID 20200925174340.10014-4-steven.lariau@arm.com
State Accepted
Delegated to: David Marchand
Headers show
Series
  • lib/stack: improve lockfree C11 implementation
Related show

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Steven Lariau Sept. 25, 2020, 5:43 p.m. UTC
The load-acquire of list->len on pop function is redundant.
Only the CAS success needs to be load-acquire.
It synchronizes with the store release in push, to ensure that the
updated head is visible when the new length is visible.
Without this, one thread in pop could see the increased length but the
old list, which doesn't have enough items yet for pop to succeed.

Signed-off-by: Steven Lariau <steven.lariau@arm.com>
Reviewed-by: Dharmik Thakkar <dharmik.thakkar@arm.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
Acked-by: Gage Eads <gage.eads@intel.com>
---
 lib/librte_stack/rte_stack_lf_c11.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/lib/librte_stack/rte_stack_lf_c11.h b/lib/librte_stack/rte_stack_lf_c11.h
index 82b7287f1..2bc639419 100644
--- a/lib/librte_stack/rte_stack_lf_c11.h
+++ b/lib/librte_stack/rte_stack_lf_c11.h
@@ -80,7 +80,7 @@  __rte_stack_lf_pop_elems(struct rte_stack_lf_list *list,
 	int success;
 
 	/* Reserve num elements, if available */
-	len = __atomic_load_n(&list->len, __ATOMIC_ACQUIRE);
+	len = __atomic_load_n(&list->len, __ATOMIC_RELAXED);
 
 	while (1) {
 		/* Does the list contain enough elements? */
@@ -91,7 +91,7 @@  __rte_stack_lf_pop_elems(struct rte_stack_lf_list *list,
 		if (__atomic_compare_exchange_n(&list->len,
 						&len, len - num,
 						1, __ATOMIC_ACQUIRE,
-						__ATOMIC_ACQUIRE))
+						__ATOMIC_RELAXED))
 			break;
 	}