[4/5] lib/stack: reload head when pop fails

Message ID 20200911152938.8019-5-steven.lariau@arm.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series lib/stack: improve lockfree C11 implementation |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Steven Lariau Sept. 11, 2020, 3:29 p.m. UTC
  List head must be loaded right before continue (when failed to
find the new head).
Without this, one thread might keep trying and failing to pop items
without ever loading the new correct head.

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>
---
 lib/librte_stack/rte_stack_lf_c11.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Comments

Eads, Gage Sept. 21, 2020, 5:16 p.m. UTC | #1
> -----Original Message-----
> From: Steven Lariau <steven.lariau@arm.com>
> Sent: Friday, September 11, 2020 10:30 AM
> To: Eads, Gage <gage.eads@intel.com>; Olivier Matz <olivier.matz@6wind.com>
> Cc: dev@dpdk.org; nd@arm.com; dharmik.thakkar@arm.com; Steven Lariau
> <steven.lariau@arm.com>
> Subject: [PATCH 4/5] lib/stack: reload head when pop fails
> 
> List head must be loaded right before continue (when failed to
> find the new head).
> Without this, one thread might keep trying and failing to pop items
> without ever loading the new correct head.
> 
> 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>

Good catch. Please add the following so the fix is considered for dpdk-stable:
Fixes: 7e6e609939a8 ("stack: add C11 atomic implementation")
Cc: stable@dpdk.org

Acked-by: Gage Eads <gage.eads@intel.com>

Thanks,
Gage
  

Patch

diff --git a/lib/librte_stack/rte_stack_lf_c11.h b/lib/librte_stack/rte_stack_lf_c11.h
index 2bc639419..adb9f590d 100644
--- a/lib/librte_stack/rte_stack_lf_c11.h
+++ b/lib/librte_stack/rte_stack_lf_c11.h
@@ -133,8 +133,10 @@  __rte_stack_lf_pop_elems(struct rte_stack_lf_list *list,
 		/* If NULL was encountered, the list was modified while
 		 * traversing it. Retry.
 		 */
-		if (i != num)
+		if (i != num) {
+			old_head = list->head;
 			continue;
+		}
 
 		new_head.top = tmp;
 		new_head.cnt = old_head.cnt + 1;