[06/16] net/cnxk: use previous value atomic fetch operations

Message ID 1678486530-20688-7-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series use __atomic operations returning new value |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Tyler Retzlaff March 10, 2023, 10:15 p.m. UTC
  Use __atomic_fetch_{add,and,or,sub,xor} instead of
__atomic_{add,and,or,sub,xor}_fetch adding the necessary code to
allow consumption of the resulting value.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 drivers/net/cnxk/cn10k_tx.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Nithin Dabilpuram March 13, 2023, 6:45 a.m. UTC | #1
Acked-by:  Nithin Dabilpuram <ndabilpuram@marvell.com>

> -----Original Message-----
> From: Tyler Retzlaff <roretzla@linux.microsoft.com>
> Sent: Saturday, March 11, 2023 3:45 AM
> To: dev@dpdk.org
> Cc: Honnappa.Nagarahalli@arm.com; Ruifeng.Wang@arm.com; thomas@monjalon.net;
> Tyler Retzlaff <roretzla@linux.microsoft.com>
> Subject: [EXT] [PATCH 06/16] net/cnxk: use previous value atomic fetch operations
> 
> External Email
> 
> ----------------------------------------------------------------------
> Use __atomic_fetch_{add,and,or,sub,xor} instead of
> __atomic_{add,and,or,sub,xor}_fetch adding the necessary code to
> allow consumption of the resulting value.
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> ---
>  drivers/net/cnxk/cn10k_tx.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/cnxk/cn10k_tx.h b/drivers/net/cnxk/cn10k_tx.h
> index a72a803..c9ec01c 100644
> --- a/drivers/net/cnxk/cn10k_tx.h
> +++ b/drivers/net/cnxk/cn10k_tx.h
> @@ -108,7 +108,7 @@
>  retry:
>  	while (__atomic_load_n(&txq->fc_cache_pkts, __ATOMIC_RELAXED) < 0)
>  		;
> -	cached = __atomic_sub_fetch(&txq->fc_cache_pkts, req, __ATOMIC_ACQUIRE);
> +	cached = __atomic_fetch_sub(&txq->fc_cache_pkts, req, __ATOMIC_ACQUIRE) -
> req;
>  	/* Check if there is enough space, else update and retry. */
>  	if (cached < 0) {
>  		/* Check if we have space else retry. */
> @@ -302,7 +302,7 @@
> 
>  again:
>  	fc_sw = txq->cpt_fc_sw;
> -	val = __atomic_sub_fetch(fc_sw, nb_pkts, __ATOMIC_RELAXED);
> +	val = __atomic_fetch_sub(fc_sw, nb_pkts, __ATOMIC_RELAXED) - nb_pkts;
>  	if (likely(val >= 0))
>  		return;
> 
> --
> 1.8.3.1
  

Patch

diff --git a/drivers/net/cnxk/cn10k_tx.h b/drivers/net/cnxk/cn10k_tx.h
index a72a803..c9ec01c 100644
--- a/drivers/net/cnxk/cn10k_tx.h
+++ b/drivers/net/cnxk/cn10k_tx.h
@@ -108,7 +108,7 @@ 
 retry:
 	while (__atomic_load_n(&txq->fc_cache_pkts, __ATOMIC_RELAXED) < 0)
 		;
-	cached = __atomic_sub_fetch(&txq->fc_cache_pkts, req, __ATOMIC_ACQUIRE);
+	cached = __atomic_fetch_sub(&txq->fc_cache_pkts, req, __ATOMIC_ACQUIRE) - req;
 	/* Check if there is enough space, else update and retry. */
 	if (cached < 0) {
 		/* Check if we have space else retry. */
@@ -302,7 +302,7 @@ 
 
 again:
 	fc_sw = txq->cpt_fc_sw;
-	val = __atomic_sub_fetch(fc_sw, nb_pkts, __ATOMIC_RELAXED);
+	val = __atomic_fetch_sub(fc_sw, nb_pkts, __ATOMIC_RELAXED) - nb_pkts;
 	if (likely(val >= 0))
 		return;