[PATCH 1/7] ring: replace rte atomics with GCC builtin atomics

Tyler Retzlaff roretzla at linux.microsoft.com
Fri Mar 17 21:36:13 CET 2023


On Fri, Mar 17, 2023 at 01:19:42PM -0700, Tyler Retzlaff wrote:
> Replace the use of rte_atomic.h types and functions, instead use GCC
> supplied C++11 memory model builtins.
> 
> Signed-off-by: Tyler Retzlaff <roretzla at linux.microsoft.com>
> ---
>  lib/ring/rte_ring_core.h        |  1 -
>  lib/ring/rte_ring_generic_pvt.h | 10 ++++++----
>  2 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/lib/ring/rte_ring_core.h b/lib/ring/rte_ring_core.h
> index 82b2370..b9c7860 100644
> --- a/lib/ring/rte_ring_core.h
> +++ b/lib/ring/rte_ring_core.h
> @@ -31,7 +31,6 @@
>  #include <rte_config.h>
>  #include <rte_memory.h>
>  #include <rte_lcore.h>
> -#include <rte_atomic.h>
>  #include <rte_branch_prediction.h>
>  #include <rte_memzone.h>
>  #include <rte_pause.h>
> diff --git a/lib/ring/rte_ring_generic_pvt.h b/lib/ring/rte_ring_generic_pvt.h
> index 5acb6e5..f9a15b6 100644
> --- a/lib/ring/rte_ring_generic_pvt.h
> +++ b/lib/ring/rte_ring_generic_pvt.h
> @@ -92,8 +92,9 @@
>  		if (is_sp)
>  			r->prod.head = *new_head, success = 1;
>  		else
> -			success = rte_atomic32_cmpset(&r->prod.head,
> -					*old_head, *new_head);
> +			success = __atomic_compare_exchange_n(&r->prod.head,
> +					old_head, *new_head, 0,
> +					__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
>  	} while (unlikely(success == 0));
>  	return n;
>  }
> @@ -162,8 +163,9 @@
>  			rte_smp_rmb();
>  			success = 1;
>  		} else {
> -			success = rte_atomic32_cmpset(&r->cons.head, *old_head,
> -					*new_head);
> +			success = __atomic_compare_exchange_n(&r->cons.head,
> +					old_head, *new_head, 0,
> +					__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
>  		}
>  	} while (unlikely(success == 0));
>  	return n;

just something i noticed and not related to this change.

i note that old_head for both __rte_ring_move_prod_head and
__rte_ring_move_con_head are performing a non-atomic load to
initialize `*old_head` probably not the best idea.


More information about the dev mailing list