Skip to contentSkip to conversation

use __atomic operations returning new value

PATCH Superseded Tyler Retzlaff 7 participants 59 messages Mar 10, 2023 – Apr 25, 2023 Network drivers

lore
Share & tools
lore
#0 lore raw

cover use __atomic operations returning new value

This series replaces uses of __atomic_{add,and,or,sub,xor}_fetch with __atomic_fetch_{add,and,or,sub,xor} intrinsics where the return value is used.

This series is being separated from the other similar series in an effort to reduce the chance of mistakes being spotted in review since the usages in this case consume the returned / new value.

Tyler Retzlaff (16):
app/test: use previous value atomic fetch operations common/cnxk: use previous value atomic fetch operations common/mlx5: use previous value atomic fetch operations drivers/event: use previous value atomic fetch operations net/af_xdp: use previous value atomic fetch operations net/cnxk: use previous value atomic fetch operations net/cxgbe: use previous value atomic fetch operations net/iavf: use previous value atomic fetch operations net/mlx5: use previous value atomic fetch operations net/octeontx: use previous value atomic fetch operations raw/ifpga: use previous value atomic fetch operations
bbdev: use previous value atomic fetch operations
eal: use previous value atomic fetch operations
ipsec: use previous value atomic fetch operations
mbuf: use previous value atomic fetch operations
rcu: use previous value atomic fetch operations

 app/test/test_ring_perf.c               |  2 +-
 drivers/common/cnxk/roc_ae.c            |  2 +-
 drivers/common/cnxk/roc_ae_fpm_tables.c |  2 +-
 drivers/common/cnxk/roc_npa.c           |  2 +-
 drivers/common/mlx5/linux/mlx5_nl.c     |  2 +-
 drivers/common/mlx5/mlx5_common_mr.c    |  8 ++++----
 drivers/common/mlx5/mlx5_common_utils.c |  8 ++++----
 drivers/event/cnxk/cnxk_tim_worker.h    |  2 +-
 drivers/event/dsw/dsw_event.c           |  4 ++--
 drivers/event/octeontx/timvf_worker.h   |  2 +-
 drivers/net/af_xdp/rte_eth_af_xdp.c     |  4 ++--
 drivers/net/cnxk/cn10k_tx.h             |  4 ++--
 drivers/net/cxgbe/clip_tbl.c            |  2 +-
 drivers/net/cxgbe/mps_tcam.c            |  2 +-
 drivers/net/iavf/iavf_vchnl.c           |  8 ++++----
 drivers/net/mlx5/linux/mlx5_verbs.c     |  2 +-
 drivers/net/mlx5/mlx5.c                 |  4 ++--
 drivers/net/mlx5/mlx5_flow.c            |  8 ++++----
 drivers/net/mlx5/mlx5_flow_dv.c         | 12 ++++++------
 drivers/net/mlx5/mlx5_flow_hw.c         | 14 +++++++-------
 drivers/net/mlx5/mlx5_hws_cnt.c         |  4 ++--
 drivers/net/mlx5/mlx5_rxq.c             |  6 +++---
 drivers/net/mlx5/mlx5_txq.c             |  2 +-
 drivers/net/octeontx/octeontx_ethdev.c  |  2 +-
 drivers/raw/ifpga/ifpga_rawdev.c        |  2 +-
 lib/bbdev/rte_bbdev.c                   |  4 ++--
 lib/eal/include/generic/rte_rwlock.h    |  8 ++++----
 lib/eal/ppc/include/rte_atomic.h        | 16 ++++++++--------
 lib/ipsec/ipsec_sqn.h                   |  2 +-
 lib/mbuf/rte_mbuf.h                     | 12 ++++++------
 lib/rcu/rte_rcu_qsbr.h                  |  2 +-
 31 files changed, 77 insertions(+), 77 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/16 app/test: use previous value atomic fetch operations

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.

---
 app/test/test_ring_perf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
app/test/test_ring_perf.c +1 -1
index 2d8bb67..3972fd9 100644
@@ -186,7 +186,7 @@ struct thread_params {
 	void *burst = NULL;
 
 #ifdef RTE_USE_C11_MEM_MODEL
-	if (__atomic_add_fetch(&lcore_count, 1, __ATOMIC_RELAXED) != 2)
+	if (__atomic_fetch_add(&lcore_count, 1, __ATOMIC_RELAXED) + 1 != 2)
 #else
 	if (__sync_add_and_fetch(&lcore_count, 1) != 2)
 #endif
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/16 common/cnxk: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/common/cnxk/roc_ae.c            | 2 +-
 drivers/common/cnxk/roc_ae_fpm_tables.c | 2 +-
 drivers/common/cnxk/roc_npa.c           | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/common/cnxk/roc_ae.c +1 -1
index 929da05..336b927 100644
@@ -203,6 +203,6 @@ struct ae_ec_grp_tbl {
 
 	ec_grp = mz->addr;
 	/* Decrement number of devices using EC grp table */
-	if (__atomic_sub_fetch(&ec_grp->refcount, 1, __ATOMIC_SEQ_CST) == 0)
+	if (__atomic_fetch_sub(&ec_grp->refcount, 1, __ATOMIC_SEQ_CST) - 1 == 0)
 		plt_memzone_free(mz);
 }
drivers/common/cnxk/roc_ae_fpm_tables.c +1 -1
index afb2a50..f915702 100644
@@ -1135,6 +1135,6 @@ struct ae_fpm_tbl {
 
 	fpm = (struct ae_fpm_tbl *)mz->addr;
 	/* Decrement number of devices using FPM table */
-	if (__atomic_sub_fetch(&fpm->refcount, 1, __ATOMIC_SEQ_CST) == 0)
+	if (__atomic_fetch_sub(&fpm->refcount, 1, __ATOMIC_SEQ_CST) - 1 == 0)
 		plt_memzone_free(mz);
 }
drivers/common/cnxk/roc_npa.c +1 -1
index 69c3d8d..20637fb 100644
@@ -946,7 +946,7 @@
 		return NPA_ERR_ALLOC;
 
 	/* Not the last PCI device */
-	if (__atomic_sub_fetch(&idev->npa_refcnt, 1, __ATOMIC_SEQ_CST) != 0)
+	if (__atomic_fetch_sub(&idev->npa_refcnt, 1, __ATOMIC_SEQ_CST) - 1 != 0)
 		return 0;
 
 	npa_unregister_irqs(idev->npa);
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH 3/16 common/mlx5: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/common/mlx5/linux/mlx5_nl.c     | 2 +-
 drivers/common/mlx5/mlx5_common_mr.c    | 8 ++++----
 drivers/common/mlx5/mlx5_common_utils.c | 8 ++++----
 3 files changed, 9 insertions(+), 9 deletions(-)
drivers/common/mlx5/linux/mlx5_nl.c +1 -1
index 5d04857..33670bb 100644
@@ -178,7 +178,7 @@ struct mlx5_nl_port_info {
 uint32_t atomic_sn;
 
 /* Generate Netlink sequence number. */
-#define MLX5_NL_SN_GENERATE __atomic_add_fetch(&atomic_sn, 1, __ATOMIC_RELAXED)
+#define MLX5_NL_SN_GENERATE (__atomic_fetch_add(&atomic_sn, 1, __ATOMIC_RELAXED) + 1)
 
 /**
  * Opens a Netlink socket.
drivers/common/mlx5/mlx5_common_mr.c +4 -4
index 0e1d243..037a4d8 100644
@@ -58,8 +58,8 @@ struct mlx5_mempool_reg {
 
 	if (__atomic_load_n(&buf->refcnt, __ATOMIC_RELAXED) == 1) {
 		rte_mempool_put(buf->mp, buf);
-	} else if (unlikely(__atomic_sub_fetch(&buf->refcnt, 1,
-					       __ATOMIC_RELAXED) == 0)) {
+	} else if (unlikely(__atomic_fetch_sub(&buf->refcnt, 1,
+					       __ATOMIC_RELAXED) - 1 == 0)) {
 		__atomic_store_n(&buf->refcnt, 1, __ATOMIC_RELAXED);
 		rte_mempool_put(buf->mp, buf);
 	}
@@ -1665,8 +1665,8 @@ struct mlx5_mempool_get_extmem_data {
 	bool ret = false;
 
 	for (i = 0; i < mpr->mrs_n; i++)
-		ret |= __atomic_sub_fetch(&mpr->mrs[i].refcnt, 1,
-					  __ATOMIC_RELAXED) == 0;
+		ret |= __atomic_fetch_sub(&mpr->mrs[i].refcnt, 1,
+					  __ATOMIC_RELAXED) - 1 == 0;
 	return ret;
 }
 
drivers/common/mlx5/mlx5_common_utils.c +4 -4
index 58d744b..06b5b9b 100644
@@ -81,8 +81,8 @@ struct mlx5_list *
 	while (entry != NULL) {
 		if (l_const->cb_match(l_const->ctx, entry, ctx) == 0) {
 			if (reuse) {
-				ret = __atomic_add_fetch(&entry->ref_cnt, 1,
-							 __ATOMIC_RELAXED) - 1;
+				ret = __atomic_fetch_add(&entry->ref_cnt, 1,
+							 __ATOMIC_RELAXED);
 				DRV_LOG(DEBUG, "mlx5 list %s entry %p ref: %u.",
 					l_const->name, (void *)entry,
 					entry->ref_cnt);
@@ -285,7 +285,7 @@ struct mlx5_list_entry *
 {
 	struct mlx5_list_entry *gentry = entry->gentry;
 
-	if (__atomic_sub_fetch(&entry->ref_cnt, 1, __ATOMIC_RELAXED) != 0)
+	if (__atomic_fetch_sub(&entry->ref_cnt, 1, __ATOMIC_RELAXED) - 1 != 0)
 		return 1;
 	if (entry->lcore_idx == (uint32_t)lcore_idx) {
 		LIST_REMOVE(entry, next);
@@ -303,7 +303,7 @@ struct mlx5_list_entry *
 			l_const->name, (void *)entry);
 		return 0;
 	}
-	if (__atomic_sub_fetch(&gentry->ref_cnt, 1, __ATOMIC_RELAXED) != 0)
+	if (__atomic_fetch_sub(&gentry->ref_cnt, 1, __ATOMIC_RELAXED) - 1 != 0)
 		return 1;
 	rte_rwlock_write_lock(&l_inconst->lock);
 	if (likely(gentry->ref_cnt == 0)) {
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH 4/16 drivers/event: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/event/cnxk/cnxk_tim_worker.h  | 2 +-
 drivers/event/dsw/dsw_event.c         | 4 ++--
 drivers/event/octeontx/timvf_worker.h | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/event/cnxk/cnxk_tim_worker.h +1 -1
index a326d55..0bd66ec 100644
@@ -123,7 +123,7 @@
 	const uint64_t v =
 		~(TIM_BUCKET_W1_M_NUM_ENTRIES << TIM_BUCKET_W1_S_NUM_ENTRIES);
 
-	return __atomic_and_fetch(&bktp->w1, v, __ATOMIC_ACQ_REL);
+	return __atomic_fetch_and(&bktp->w1, v, __ATOMIC_ACQ_REL) & v;
 }
 
 static inline uint64_t
drivers/event/dsw/dsw_event.c +2 -2
index 9932caf..cbdc03f 100644
@@ -45,8 +45,8 @@
 	 * allocation.
 	 */
 	new_total_on_loan =
-	    __atomic_add_fetch(&dsw->credits_on_loan, acquired_credits,
-			       __ATOMIC_RELAXED);
+	    __atomic_fetch_add(&dsw->credits_on_loan, acquired_credits,
+			       __ATOMIC_RELAXED) + acquired_credits;
 
 	if (unlikely(new_total_on_loan > dsw->max_inflight)) {
 		/* Some other port took the last credits */
drivers/event/octeontx/timvf_worker.h +1 -1
index 3f1e77f..aa729f8 100644
@@ -135,7 +135,7 @@
 {
 	const uint64_t v = ~(TIM_BUCKET_W1_M_NUM_ENTRIES <<
 			TIM_BUCKET_W1_S_NUM_ENTRIES);
-	return __atomic_and_fetch(&bktp->w1, v, __ATOMIC_ACQ_REL);
+	return __atomic_fetch_and(&bktp->w1, v, __ATOMIC_ACQ_REL) & v;
 }
 
 static inline struct tim_mem_entry *
Signature · 1 line
1.8.3.1
Acked-by on v1 4/16
#5 lore raw

RE: [EXT] [PATCH 04/16] drivers/event: use previous value atomic fetch operations

Quoted 11 lines

-----Original Message-----
From: Tyler Retzlaff <[email protected]>
Sent: Saturday, March 11, 2023 3:45 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Tyler Retzlaff <[email protected]>
Subject: [EXT] [PATCH 04/16] drivers/event: use previous value atomic fetch operations

Quoted 8 lines

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.

Quoted 55 lines
---
 drivers/event/cnxk/cnxk_tim_worker.h  | 2 +-
 drivers/event/dsw/dsw_event.c         | 4 ++--
 drivers/event/octeontx/timvf_worker.h | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/event/cnxk/cnxk_tim_worker.h +1 -1
index a326d55..0bd66ec 100644
@@ -123,7 +123,7 @@
 	const uint64_t v =
 		~(TIM_BUCKET_W1_M_NUM_ENTRIES <<
 TIM_BUCKET_W1_S_NUM_ENTRIES);
 
-	return __atomic_and_fetch(&bktp->w1, v, __ATOMIC_ACQ_REL);
+	return __atomic_fetch_and(&bktp->w1, v, __ATOMIC_ACQ_REL) &
 v;
 }

static inline uint64_t

drivers/event/dsw/dsw_event.c +2 -2
index 9932caf..cbdc03f 100644
@@ -45,8 +45,8 @@
 	 * allocation.
 	 */
 	new_total_on_loan =
-	    __atomic_add_fetch(&dsw->credits_on_loan, acquired_credits,
-			       __ATOMIC_RELAXED);
+	    __atomic_fetch_add(&dsw->credits_on_loan, acquired_credits,
+			       __ATOMIC_RELAXED) + acquired_credits;
 
 	if (unlikely(new_total_on_loan > dsw->max_inflight)) {
 		/* Some other port took the last credits */
drivers/event/octeontx/timvf_worker.h +1 -1
index 3f1e77f..aa729f8 100644
@@ -135,7 +135,7 @@
 {
 	const uint64_t v = ~(TIM_BUCKET_W1_M_NUM_ENTRIES <<
 			TIM_BUCKET_W1_S_NUM_ENTRIES);
-	return __atomic_and_fetch(&bktp->w1, v, __ATOMIC_ACQ_REL);
+	return __atomic_fetch_and(&bktp->w1, v, __ATOMIC_ACQ_REL) &
 v;
 }
 

static inline struct tim_mem_entry *
--
1.8.3.1

#6 lore raw

PATCH 5/16 net/af_xdp: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +2 -2
index 2a20a69..c7786cc 100644
@@ -979,7 +979,7 @@ static int link_xdp_prog_with_dev(int ifindex, int fd, __u32 flags)
 			break;
 		xsk_socket__delete(rxq->xsk);
 
-		if (__atomic_sub_fetch(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE)
+		if (__atomic_fetch_sub(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE) - 1
 				== 0) {
 			(void)xsk_umem__delete(rxq->umem->umem);
 			xdp_umem_destroy(rxq->umem);
@@ -1710,7 +1710,7 @@ struct msg_internal {
 out_xsk:
 	xsk_socket__delete(rxq->xsk);
 out_umem:
-	if (__atomic_sub_fetch(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE) == 0)
+	if (__atomic_fetch_sub(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE) - 1 == 0)
 		xdp_umem_destroy(rxq->umem);
 
 	return ret;
Signature · 1 line
1.8.3.1
#7 lore raw

PATCH 6/16 net/cnxk: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/net/cnxk/cn10k_tx.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/cnxk/cn10k_tx.h +2 -2
index a72a803..c9ec01c 100644
@@ -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;
 
Signature · 1 line
1.8.3.1
Acked-by on v1 6/16
#8 lore raw

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

Quoted 45 lines

-----Original Message-----
From: Tyler Retzlaff <[email protected]>
Sent: Saturday, March 11, 2023 3:45 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Tyler Retzlaff <[email protected]>
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.

---
 drivers/net/cnxk/cn10k_tx.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/cnxk/cn10k_tx.h +1 -1
index a72a803..c9ec01c 100644
@@ -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) {
drivers/net/cnxk/cn10k_tx.h +1 -2
 		/* 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

#9 lore raw

PATCH 7/16 net/cxgbe: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/net/cxgbe/clip_tbl.c | 2 +-
 drivers/net/cxgbe/mps_tcam.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/cxgbe/clip_tbl.c +1 -1
index 072fc74..f64b922 100644
@@ -55,7 +55,7 @@ void cxgbe_clip_release(struct rte_eth_dev *dev, struct clip_entry *ce)
 	int ret;
 
 	t4_os_lock(&ce->lock);
-	if (__atomic_sub_fetch(&ce->refcnt, 1, __ATOMIC_RELAXED) == 0) {
+	if (__atomic_fetch_sub(&ce->refcnt, 1, __ATOMIC_RELAXED) - 1 == 0) {
 		ret = clip6_release_mbox(dev, ce->addr);
 		if (ret)
 			dev_debug(adap, "CLIP FW DEL CMD failed: %d", ret);
drivers/net/cxgbe/mps_tcam.c +1 -1
index abbf06e..c7cdf29 100644
@@ -195,7 +195,7 @@ int cxgbe_mpstcam_remove(struct port_info *pi, u16 idx)
 					   entry->mask, idx, 1, pi->port_id,
 					   false);
 	else
-		ret = __atomic_sub_fetch(&entry->refcnt, 1, __ATOMIC_RELAXED);
+		ret = __atomic_fetch_sub(&entry->refcnt, 1, __ATOMIC_RELAXED) - 1;
 
 	if (ret == 0) {
 		reset_mpstcam_entry(entry);
Signature · 1 line
1.8.3.1
#10 lore raw

PATCH 8/16 net/iavf: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/net/iavf/iavf_vchnl.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/iavf/iavf_vchnl.c +4 -4
index 9adaadb..51d4fc7 100644
@@ -120,7 +120,7 @@ struct iavf_event_handler {
 {
 	struct iavf_event_handler *handler = &event_handler;
 
-	if (__atomic_add_fetch(&handler->ndev, 1, __ATOMIC_RELAXED) != 1)
+	if (__atomic_fetch_add(&handler->ndev, 1, __ATOMIC_RELAXED) + 1 != 1)
 		return 0;
 #if defined(RTE_EXEC_ENV_IS_WINDOWS) && RTE_EXEC_ENV_IS_WINDOWS != 0
 	int err = _pipe(handler->fd, MAX_EVENT_PENDING, O_BINARY);
@@ -149,7 +149,7 @@ struct iavf_event_handler {
 {
 	struct iavf_event_handler *handler = &event_handler;
 
-	if (__atomic_sub_fetch(&handler->ndev, 1, __ATOMIC_RELAXED) != 0)
+	if (__atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED) - 1 != 0)
 		return;
 
 	int unused = pthread_cancel(handler->tid);
@@ -533,8 +533,8 @@ struct iavf_event_handler {
 				/* read message and it's expected one */
 				if (msg_opc == vf->pend_cmd) {
 					uint32_t cmd_count =
-					__atomic_sub_fetch(&vf->pend_cmd_count,
-							1, __ATOMIC_RELAXED);
+					__atomic_fetch_sub(&vf->pend_cmd_count,
+							1, __ATOMIC_RELAXED) - 1;
 					if (cmd_count == 0)
 						_notify_cmd(vf, msg_ret);
 				} else {
Signature · 1 line
1.8.3.1
#11 lore raw

PATCH 9/16 net/mlx5: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/net/mlx5/linux/mlx5_verbs.c |  2 +-
 drivers/net/mlx5/mlx5.c             |  4 ++--
 drivers/net/mlx5/mlx5_flow.c        |  8 ++++----
 drivers/net/mlx5/mlx5_flow_dv.c     | 12 ++++++------
 drivers/net/mlx5/mlx5_flow_hw.c     | 14 +++++++-------
 drivers/net/mlx5/mlx5_hws_cnt.c     |  4 ++--
 drivers/net/mlx5/mlx5_rxq.c         |  6 +++---
 drivers/net/mlx5/mlx5_txq.c         |  2 +-
 8 files changed, 26 insertions(+), 26 deletions(-)
drivers/net/mlx5/linux/mlx5_verbs.c +1 -1
index 67a7bec..ee5d072 100644
@@ -1183,7 +1183,7 @@
 	if (!priv->lb_used)
 		return;
 	MLX5_ASSERT(__atomic_load_n(&sh->self_lb.refcnt, __ATOMIC_RELAXED));
-	if (!(__atomic_sub_fetch(&sh->self_lb.refcnt, 1, __ATOMIC_RELAXED))) {
+	if (!(__atomic_fetch_sub(&sh->self_lb.refcnt, 1, __ATOMIC_RELAXED) - 1)) {
 		if (sh->self_lb.qp) {
 			claim_zero(mlx5_glue->destroy_qp(sh->self_lb.qp));
 			sh->self_lb.qp = NULL;
drivers/net/mlx5/mlx5.c +2 -2
index 41b1b12..044012d 100644
@@ -1068,7 +1068,7 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list =
 		DRV_LOG(ERR, "Dynamic flex parser is not supported");
 		return -ENOTSUP;
 	}
-	if (__atomic_add_fetch(&priv->sh->srh_flex_parser.refcnt, 1, __ATOMIC_RELAXED) > 1)
+	if (__atomic_fetch_add(&priv->sh->srh_flex_parser.refcnt, 1, __ATOMIC_RELAXED) + 1 > 1)
 		return 0;
 
 	node.header_length_mode = MLX5_GRAPH_NODE_LEN_FIELD;
@@ -1123,7 +1123,7 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list =
 	struct mlx5_priv *priv = dev->data->dev_private;
 	struct mlx5_internal_flex_parser_profile *fp = &priv->sh->srh_flex_parser;
 
-	if (__atomic_sub_fetch(&fp->refcnt, 1, __ATOMIC_RELAXED))
+	if (__atomic_fetch_sub(&fp->refcnt, 1, __ATOMIC_RELAXED) - 1)
 		return;
 	if (fp->fp)
 		mlx5_devx_cmd_destroy(fp->fp);
drivers/net/mlx5/mlx5_flow.c +4 -4
index 75f7d87..0bf527e 100644
@@ -7833,7 +7833,7 @@ struct rte_flow *
 
 		tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
 		RTE_VERIFY(tunnel);
-		if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
+		if (!(__atomic_fetch_sub(&tunnel->refctn, 1, __ATOMIC_RELAXED) - 1))
 			mlx5_flow_tunnel_free(dev, tunnel);
 	}
 	flow_mreg_del_copy_action(dev, flow);
@@ -9742,9 +9742,9 @@ struct mlx5_flow_workspace*
 					 __ATOMIC_RELAXED);
 			continue;
 		}
-		if (__atomic_add_fetch(&age_param->sec_since_last_hit,
+		if (__atomic_fetch_add(&age_param->sec_since_last_hit,
 				       time_delta,
-				       __ATOMIC_RELAXED) <= age_param->timeout)
+				       __ATOMIC_RELAXED) + time_delta <= age_param->timeout)
 			continue;
 		/**
 		 * Hold the lock first, or if between the
@@ -11387,7 +11387,7 @@ struct tunnel_db_element_release_ctx {
 {
 	struct tunnel_db_element_release_ctx *ctx = x;
 	ctx->ret = 0;
-	if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
+	if (!(__atomic_fetch_sub(&tunnel->refctn, 1, __ATOMIC_RELAXED) - 1))
 		mlx5_flow_tunnel_free(dev, tunnel);
 }
 
drivers/net/mlx5/mlx5_flow_dv.c +6 -6
index ca26f39..f04160e 100644
@@ -6723,8 +6723,8 @@ struct mlx5_list_entry *
 		 * indirect action API, shared info is 1 before the reduction,
 		 * so this condition is failed and function doesn't return here.
 		 */
-		if (__atomic_sub_fetch(&cnt->shared_info.refcnt, 1,
-				       __ATOMIC_RELAXED))
+		if (__atomic_fetch_sub(&cnt->shared_info.refcnt, 1,
+				       __ATOMIC_RELAXED) - 1)
 			return;
 	}
 	cnt->pool = pool;
@@ -12797,7 +12797,7 @@ struct mlx5_list_entry *
 	struct mlx5_priv *priv = dev->data->dev_private;
 	struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
 	struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx);
-	uint32_t ret = __atomic_sub_fetch(&age->refcnt, 1, __ATOMIC_RELAXED);
+	uint32_t ret = __atomic_fetch_sub(&age->refcnt, 1, __ATOMIC_RELAXED) - 1;
 
 	if (!ret) {
 		flow_dv_aso_age_remove_from_age(dev, age);
@@ -13193,7 +13193,7 @@ struct mlx5_list_entry *
 	/* Cannot release when CT is in the ASO SQ. */
 	if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY)
 		return -1;
-	ret = __atomic_sub_fetch(&ct->refcnt, 1, __ATOMIC_RELAXED);
+	ret = __atomic_fetch_sub(&ct->refcnt, 1, __ATOMIC_RELAXED) - 1;
 	if (!ret) {
 		if (ct->dr_action_orig) {
 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
@@ -15582,8 +15582,8 @@ struct mlx5_list_entry *
 				sh->geneve_tlv_option_resource;
 	rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
 	if (geneve_opt_resource) {
-		if (!(__atomic_sub_fetch(&geneve_opt_resource->refcnt, 1,
-					 __ATOMIC_RELAXED))) {
+		if (!(__atomic_fetch_sub(&geneve_opt_resource->refcnt, 1,
+					 __ATOMIC_RELAXED) - 1)) {
 			claim_zero(mlx5_devx_cmd_destroy
 					(geneve_opt_resource->obj));
 			mlx5_free(sh->geneve_tlv_option_resource);
drivers/net/mlx5/mlx5_flow_hw.c +7 -7
index 9392727..109aab1 100644
@@ -458,7 +458,7 @@ static int flow_hw_translate_group(struct rte_eth_dev *dev,
 	}
 
 	if (acts->mark)
-		if (!__atomic_sub_fetch(&priv->hws_mark_refcnt, 1, __ATOMIC_RELAXED))
+		if (!(__atomic_fetch_sub(&priv->hws_mark_refcnt, 1, __ATOMIC_RELAXED) - 1))
 			flow_hw_rxq_flag_set(dev, false);
 
 	if (acts->jump) {
@@ -3268,8 +3268,8 @@ static rte_be32_t vlan_hdr_to_be32(const struct rte_flow_action *actions)
 			rte_errno = EINVAL;
 			goto it_error;
 		}
-		ret = __atomic_add_fetch(&item_templates[i]->refcnt, 1,
-					 __ATOMIC_RELAXED);
+		ret = __atomic_fetch_add(&item_templates[i]->refcnt, 1,
+					 __ATOMIC_RELAXED) + 1;
 		if (ret <= 1) {
 			rte_errno = EINVAL;
 			goto it_error;
@@ -3282,8 +3282,8 @@ static rte_be32_t vlan_hdr_to_be32(const struct rte_flow_action *actions)
 	for (i = 0; i < nb_action_templates; i++) {
 		uint32_t ret;
 
-		ret = __atomic_add_fetch(&action_templates[i]->refcnt, 1,
-					 __ATOMIC_RELAXED);
+		ret = __atomic_fetch_add(&action_templates[i]->refcnt, 1,
+					 __ATOMIC_RELAXED) + 1;
 		if (ret <= 1) {
 			rte_errno = EINVAL;
 			goto at_error;
@@ -7624,8 +7624,8 @@ void flow_hw_clear_tags_set(struct rte_eth_dev *dev)
 {
 	uint32_t refcnt;
 
-	refcnt = __atomic_sub_fetch(&mlx5_flow_hw_flow_metadata_config_refcnt, 1,
-				    __ATOMIC_RELAXED);
+	refcnt = __atomic_fetch_sub(&mlx5_flow_hw_flow_metadata_config_refcnt, 1,
+				    __ATOMIC_RELAXED) - 1;
 	if (refcnt > 0)
 		return;
 	mlx5_flow_hw_flow_metadata_esw_en = 0;
drivers/net/mlx5/mlx5_hws_cnt.c +2 -2
index d6a017a..d98df68 100644
@@ -192,8 +192,8 @@
 			}
 			param->accumulator_hits = 0;
 		}
-		if (__atomic_add_fetch(&param->sec_since_last_hit, time_delta,
-				       __ATOMIC_RELAXED) <=
+		if (__atomic_fetch_add(&param->sec_since_last_hit, time_delta,
+				       __ATOMIC_RELAXED) + time_delta <=
 		   __atomic_load_n(&param->timeout, __ATOMIC_RELAXED))
 			continue;
 		/* Prepare the relevant ring for this AGE parameter */
drivers/net/mlx5/mlx5_rxq.c +3 -3
index 6e99c4d..ad8fd13 100644
@@ -2042,7 +2042,7 @@ struct mlx5_rxq_priv *
 
 	if (rxq == NULL)
 		return 0;
-	return __atomic_sub_fetch(&rxq->refcnt, 1, __ATOMIC_RELAXED);
+	return __atomic_fetch_sub(&rxq->refcnt, 1, __ATOMIC_RELAXED) - 1;
 }
 
 /**
@@ -2141,7 +2141,7 @@ struct mlx5_external_rxq *
 {
 	struct mlx5_external_rxq *rxq = mlx5_ext_rxq_get(dev, idx);
 
-	return __atomic_sub_fetch(&rxq->refcnt, 1, __ATOMIC_RELAXED);
+	return __atomic_fetch_sub(&rxq->refcnt, 1, __ATOMIC_RELAXED) - 1;
 }
 
 /**
@@ -2462,7 +2462,7 @@ struct mlx5_ind_table_obj *
 	unsigned int ret;
 
 	rte_rwlock_write_lock(&priv->ind_tbls_lock);
-	ret = __atomic_sub_fetch(&ind_tbl->refcnt, 1, __ATOMIC_RELAXED);
+	ret = __atomic_fetch_sub(&ind_tbl->refcnt, 1, __ATOMIC_RELAXED) - 1;
 	if (!ret)
 		LIST_REMOVE(ind_tbl, next);
 	rte_rwlock_write_unlock(&priv->ind_tbls_lock);
drivers/net/mlx5/mlx5_txq.c +1 -1
index 1e0e61a..8cb52b0 100644
@@ -1203,7 +1203,7 @@ struct mlx5_txq_ctrl *
 	if (priv->txqs == NULL || (*priv->txqs)[idx] == NULL)
 		return 0;
 	txq_ctrl = container_of((*priv->txqs)[idx], struct mlx5_txq_ctrl, txq);
-	if (__atomic_sub_fetch(&txq_ctrl->refcnt, 1, __ATOMIC_RELAXED) > 1)
+	if (__atomic_fetch_sub(&txq_ctrl->refcnt, 1, __ATOMIC_RELAXED) - 1 > 1)
 		return 1;
 	if (txq_ctrl->obj) {
 		priv->obj_ops.txq_obj_release(txq_ctrl->obj);
Signature · 1 line
1.8.3.1
#12 lore raw

PATCH 10/16 net/octeontx: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/net/octeontx/octeontx_ethdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/octeontx/octeontx_ethdev.c +1 -1
index d52a3e7..a21ed80 100644
@@ -559,7 +559,7 @@ enum octeontx_link_speed {
 		return 0;
 
 	/* Stopping/closing event device once all eth ports are closed. */
-	if (__atomic_sub_fetch(&evdev_refcnt, 1, __ATOMIC_ACQUIRE) == 0) {
+	if (__atomic_fetch_sub(&evdev_refcnt, 1, __ATOMIC_ACQUIRE) - 1 == 0) {
 		rte_event_dev_stop(nic->evdev);
 		rte_event_dev_close(nic->evdev);
 	}
Signature · 1 line
1.8.3.1
#13 lore raw

PATCH 11/16 raw/ifpga: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/raw/ifpga/ifpga_rawdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/raw/ifpga/ifpga_rawdev.c +1 -1
index 1020adc..ae3f79d 100644
@@ -573,7 +573,7 @@ static int set_surprise_link_check_aer(
 
 	dev->poll_enabled = 0;
 
-	if (!__atomic_sub_fetch(&ifpga_monitor_refcnt, 1, __ATOMIC_RELAXED) &&
+	if (!(__atomic_fetch_sub(&ifpga_monitor_refcnt, 1, __ATOMIC_RELAXED) - 1) &&
 		ifpga_monitor_start_thread) {
 		ret = pthread_cancel(ifpga_monitor_start_thread);
 		if (ret)
Signature · 1 line
1.8.3.1
#14 lore raw

PATCH 12/16 bbdev: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 lib/bbdev/rte_bbdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/bbdev/rte_bbdev.c +2 -2
index 1521cdb..9df0837 100644
@@ -250,8 +250,8 @@ struct rte_bbdev *
 	}
 
 	/* clear shared BBDev Data if no process is using the device anymore */
-	if (__atomic_sub_fetch(&bbdev->data->process_cnt, 1,
-			      __ATOMIC_RELAXED) == 0)
+	if (__atomic_fetch_sub(&bbdev->data->process_cnt, 1,
+			      __ATOMIC_RELAXED) - 1 == 0)
 		memset(bbdev->data, 0, sizeof(*bbdev->data));
 
 	memset(bbdev, 0, sizeof(*bbdev));
Signature · 1 line
1.8.3.1
#15 lore raw

PATCH 13/16 eal: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 lib/eal/include/generic/rte_rwlock.h |  8 ++++----
 lib/eal/ppc/include/rte_atomic.h     | 16 ++++++++--------
 2 files changed, 12 insertions(+), 12 deletions(-)
lib/eal/include/generic/rte_rwlock.h +4 -4
index d45c22c..71e2d8d 100644
@@ -97,8 +97,8 @@
 			rte_pause();
 
 		/* Try to get read lock */
-		x = __atomic_add_fetch(&rwl->cnt, RTE_RWLOCK_READ,
-				       __ATOMIC_ACQUIRE);
+		x = __atomic_fetch_add(&rwl->cnt, RTE_RWLOCK_READ,
+				       __ATOMIC_ACQUIRE) + RTE_RWLOCK_READ;
 
 		/* If no writer, then acquire was successful */
 		if (likely(!(x & RTE_RWLOCK_MASK)))
@@ -134,8 +134,8 @@
 		return -EBUSY;
 
 	/* Try to get read lock */
-	x = __atomic_add_fetch(&rwl->cnt, RTE_RWLOCK_READ,
-			       __ATOMIC_ACQUIRE);
+	x = __atomic_fetch_add(&rwl->cnt, RTE_RWLOCK_READ,
+			       __ATOMIC_ACQUIRE) + RTE_RWLOCK_READ;
 
 	/* Back out if writer raced in */
 	if (unlikely(x & RTE_RWLOCK_MASK)) {
lib/eal/ppc/include/rte_atomic.h +8 -8
index 663b4d3..ffabd98 100644
@@ -71,12 +71,12 @@ static inline int rte_atomic16_test_and_set(rte_atomic16_t *v)
 
 static inline int rte_atomic16_inc_and_test(rte_atomic16_t *v)
 {
-	return __atomic_add_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0;
+	return __atomic_fetch_add(&v->cnt, 1, __ATOMIC_ACQUIRE) + 1 == 0;
 }
 
 static inline int rte_atomic16_dec_and_test(rte_atomic16_t *v)
 {
-	return __atomic_sub_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0;
+	return __atomic_fetch_sub(&v->cnt, 1, __ATOMIC_ACQUIRE) - 1 == 0;
 }
 
 static inline uint16_t
@@ -113,12 +113,12 @@ static inline int rte_atomic32_test_and_set(rte_atomic32_t *v)
 
 static inline int rte_atomic32_inc_and_test(rte_atomic32_t *v)
 {
-	return __atomic_add_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0;
+	return __atomic_fetch_add(&v->cnt, 1, __ATOMIC_ACQUIRE) + 1 == 0;
 }
 
 static inline int rte_atomic32_dec_and_test(rte_atomic32_t *v)
 {
-	return __atomic_sub_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0;
+	return __atomic_fetch_sub(&v->cnt, 1, __ATOMIC_ACQUIRE) - 1 == 0;
 }
 
 static inline uint32_t
@@ -181,23 +181,23 @@ static inline int rte_atomic32_dec_and_test(rte_atomic32_t *v)
 static inline int64_t
 rte_atomic64_add_return(rte_atomic64_t *v, int64_t inc)
 {
-	return __atomic_add_fetch(&v->cnt, inc, __ATOMIC_ACQUIRE);
+	return __atomic_fetch_add(&v->cnt, inc, __ATOMIC_ACQUIRE) + inc;
 }
 
 static inline int64_t
 rte_atomic64_sub_return(rte_atomic64_t *v, int64_t dec)
 {
-	return __atomic_sub_fetch(&v->cnt, dec, __ATOMIC_ACQUIRE);
+	return __atomic_fetch_sub(&v->cnt, dec, __ATOMIC_ACQUIRE) - dec;
 }
 
 static inline int rte_atomic64_inc_and_test(rte_atomic64_t *v)
 {
-	return __atomic_add_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0;
+	return __atomic_fetch_add(&v->cnt, 1, __ATOMIC_ACQUIRE) + 1 == 0;
 }
 
 static inline int rte_atomic64_dec_and_test(rte_atomic64_t *v)
 {
-	return __atomic_sub_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0;
+	return __atomic_fetch_sub(&v->cnt, 1, __ATOMIC_ACQUIRE) - 1 == 0;
 }
 
 static inline int rte_atomic64_test_and_set(rte_atomic64_t *v)
Signature · 1 line
1.8.3.1
#16 lore raw

PATCH 14/16 ipsec: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 lib/ipsec/ipsec_sqn.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/ipsec/ipsec_sqn.h +1 -1
index 2636cb1..505950e 100644
@@ -128,7 +128,7 @@
 
 	n = *num;
 	if (SQN_ATOMIC(sa))
-		sqn = __atomic_add_fetch(&sa->sqn.outb, n, __ATOMIC_RELAXED);
+		sqn = __atomic_fetch_add(&sa->sqn.outb, n, __ATOMIC_RELAXED) + n;
 	else {
 		sqn = sa->sqn.outb + n;
 		sa->sqn.outb = sqn;
Signature · 1 line
1.8.3.1
#17 lore raw

PATCH 15/16 mbuf: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 lib/mbuf/rte_mbuf.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
lib/mbuf/rte_mbuf.h +6 -6
index 3a82eb1..5da4cbe 100644
@@ -381,8 +381,8 @@ struct rte_pktmbuf_pool_private {
 static inline uint16_t
 __rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value)
 {
-	return __atomic_add_fetch(&m->refcnt, (uint16_t)value,
-				 __ATOMIC_ACQ_REL);
+	return __atomic_fetch_add(&m->refcnt, (uint16_t)value,
+				 __ATOMIC_ACQ_REL) + (uint16_t)value;
 }
 
 /**
@@ -502,8 +502,8 @@ struct rte_pktmbuf_pool_private {
 		return (uint16_t)value;
 	}
 
-	return __atomic_add_fetch(&shinfo->refcnt, (uint16_t)value,
-				 __ATOMIC_ACQ_REL);
+	return __atomic_fetch_add(&shinfo->refcnt, (uint16_t)value,
+				 __ATOMIC_ACQ_REL) + (uint16_t)value;
 }
 
 /** Mbuf prefetch */
@@ -1315,8 +1315,8 @@ static inline int __rte_pktmbuf_pinned_extbuf_decref(struct rte_mbuf *m)
 	 * Direct usage of add primitive to avoid
 	 * duplication of comparing with one.
 	 */
-	if (likely(__atomic_add_fetch(&shinfo->refcnt, (uint16_t)-1,
-				     __ATOMIC_ACQ_REL)))
+	if (likely(__atomic_fetch_add(&shinfo->refcnt, (uint16_t)-1,
+				     __ATOMIC_ACQ_REL) + (uint16_t)-1))
 		return 1;
 
 	/* Reinitialize counter before mbuf freeing. */
Signature · 1 line
1.8.3.1
#18 lore raw

PATCH 16/16 rcu: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 lib/rcu/rte_rcu_qsbr.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/rcu/rte_rcu_qsbr.h +1 -1
index ccae5d5..1aa078e 100644
@@ -462,7 +462,7 @@ struct rte_rcu_qsbr_dq_parameters {
 	 * structure are visible to the workers before the token
 	 * update is visible.
 	 */
-	t = __atomic_add_fetch(&v->token, 1, __ATOMIC_RELEASE);
+	t = __atomic_fetch_add(&v->token, 1, __ATOMIC_RELEASE) + 1;
 
 	return t;
 }
Signature · 1 line
1.8.3.1
#19 lore raw

v2 cover replace __atomic operations returning new value

In reply to Tyler Retzlaff

This series replaces uses of __atomic_{add,and,or,sub,xor}_fetch with __atomic_fetch_{add,and,or,sub,xor} intrinsics where the new value is used.

This series is being separated from the other similar series in an effort to reduce the chance of mistakes being spotted in review since the usages in this case consume the returned / new value.

v2:
* remove unnecessary casts of signed to unsigned arguments when using generic __atomic builtins.
* remove inappropriate cast of signed negative value on addend.

Tyler Retzlaff (16):
app/test: use previous value atomic fetch operations common/cnxk: use previous value atomic fetch operations common/mlx5: use previous value atomic fetch operations drivers/event: use previous value atomic fetch operations net/af_xdp: use previous value atomic fetch operations net/cnxk: use previous value atomic fetch operations net/cxgbe: use previous value atomic fetch operations net/iavf: use previous value atomic fetch operations net/mlx5: use previous value atomic fetch operations net/octeontx: use previous value atomic fetch operations raw/ifpga: use previous value atomic fetch operations
bbdev: use previous value atomic fetch operations
eal: use previous value atomic fetch operations
ipsec: use previous value atomic fetch operations
mbuf: use previous value atomic fetch operations
rcu: use previous value atomic fetch operations

 app/test/test_ring_perf.c               |  2 +-
 drivers/common/cnxk/roc_ae.c            |  2 +-
 drivers/common/cnxk/roc_ae_fpm_tables.c |  2 +-
 drivers/common/cnxk/roc_npa.c           |  2 +-
 drivers/common/mlx5/linux/mlx5_nl.c     |  2 +-
 drivers/common/mlx5/mlx5_common_mr.c    |  8 ++++----
 drivers/common/mlx5/mlx5_common_utils.c |  8 ++++----
 drivers/event/cnxk/cnxk_tim_worker.h    |  2 +-
 drivers/event/dsw/dsw_event.c           |  4 ++--
 drivers/event/octeontx/timvf_worker.h   |  2 +-
 drivers/net/af_xdp/rte_eth_af_xdp.c     |  4 ++--
 drivers/net/cnxk/cn10k_tx.h             |  4 ++--
 drivers/net/cxgbe/clip_tbl.c            |  2 +-
 drivers/net/cxgbe/mps_tcam.c            |  2 +-
 drivers/net/iavf/iavf_vchnl.c           |  8 ++++----
 drivers/net/mlx5/linux/mlx5_verbs.c     |  2 +-
 drivers/net/mlx5/mlx5.c                 |  4 ++--
 drivers/net/mlx5/mlx5_flow.c            |  8 ++++----
 drivers/net/mlx5/mlx5_flow_dv.c         | 12 ++++++------
 drivers/net/mlx5/mlx5_flow_hw.c         | 14 +++++++-------
 drivers/net/mlx5/mlx5_hws_cnt.c         |  4 ++--
 drivers/net/mlx5/mlx5_rxq.c             |  6 +++---
 drivers/net/mlx5/mlx5_txq.c             |  2 +-
 drivers/net/octeontx/octeontx_ethdev.c  |  2 +-
 drivers/raw/ifpga/ifpga_rawdev.c        |  2 +-
 lib/bbdev/rte_bbdev.c                   |  4 ++--
 lib/eal/include/generic/rte_rwlock.h    |  8 ++++----
 lib/eal/ppc/include/rte_atomic.h        | 16 ++++++++--------
 lib/ipsec/ipsec_sqn.h                   |  2 +-
 lib/mbuf/rte_mbuf.h                     | 12 ++++++------
 lib/rcu/rte_rcu_qsbr.h                  |  2 +-
 31 files changed, 77 insertions(+), 77 deletions(-)
Signature · 1 line
1.8.3.1
#20 lore raw

PATCH v2 1/16 app/test: use previous value atomic fetch operations

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.

---
 app/test/test_ring_perf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
app/test/test_ring_perf.c +1 -1
index 2d8bb67..3972fd9 100644
@@ -186,7 +186,7 @@ struct thread_params {
 	void *burst = NULL;
 
 #ifdef RTE_USE_C11_MEM_MODEL
-	if (__atomic_add_fetch(&lcore_count, 1, __ATOMIC_RELAXED) != 2)
+	if (__atomic_fetch_add(&lcore_count, 1, __ATOMIC_RELAXED) + 1 != 2)
 #else
 	if (__sync_add_and_fetch(&lcore_count, 1) != 2)
 #endif
Signature · 1 line
1.8.3.1
#21 lore raw

PATCH v2 2/16 common/cnxk: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/common/cnxk/roc_ae.c            | 2 +-
 drivers/common/cnxk/roc_ae_fpm_tables.c | 2 +-
 drivers/common/cnxk/roc_npa.c           | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/common/cnxk/roc_ae.c +1 -1
index 929da05..336b927 100644
@@ -203,6 +203,6 @@ struct ae_ec_grp_tbl {
 
 	ec_grp = mz->addr;
 	/* Decrement number of devices using EC grp table */
-	if (__atomic_sub_fetch(&ec_grp->refcount, 1, __ATOMIC_SEQ_CST) == 0)
+	if (__atomic_fetch_sub(&ec_grp->refcount, 1, __ATOMIC_SEQ_CST) - 1 == 0)
 		plt_memzone_free(mz);
 }
drivers/common/cnxk/roc_ae_fpm_tables.c +1 -1
index afb2a50..f915702 100644
@@ -1135,6 +1135,6 @@ struct ae_fpm_tbl {
 
 	fpm = (struct ae_fpm_tbl *)mz->addr;
 	/* Decrement number of devices using FPM table */
-	if (__atomic_sub_fetch(&fpm->refcount, 1, __ATOMIC_SEQ_CST) == 0)
+	if (__atomic_fetch_sub(&fpm->refcount, 1, __ATOMIC_SEQ_CST) - 1 == 0)
 		plt_memzone_free(mz);
 }
drivers/common/cnxk/roc_npa.c +1 -1
index 69c3d8d..20637fb 100644
@@ -946,7 +946,7 @@
 		return NPA_ERR_ALLOC;
 
 	/* Not the last PCI device */
-	if (__atomic_sub_fetch(&idev->npa_refcnt, 1, __ATOMIC_SEQ_CST) != 0)
+	if (__atomic_fetch_sub(&idev->npa_refcnt, 1, __ATOMIC_SEQ_CST) - 1 != 0)
 		return 0;
 
 	npa_unregister_irqs(idev->npa);
Signature · 1 line
1.8.3.1
#22 lore raw

PATCH v2 3/16 common/mlx5: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/common/mlx5/linux/mlx5_nl.c     | 2 +-
 drivers/common/mlx5/mlx5_common_mr.c    | 8 ++++----
 drivers/common/mlx5/mlx5_common_utils.c | 8 ++++----
 3 files changed, 9 insertions(+), 9 deletions(-)
drivers/common/mlx5/linux/mlx5_nl.c +1 -1
index 5d04857..33670bb 100644
@@ -178,7 +178,7 @@ struct mlx5_nl_port_info {
 uint32_t atomic_sn;
 
 /* Generate Netlink sequence number. */
-#define MLX5_NL_SN_GENERATE __atomic_add_fetch(&atomic_sn, 1, __ATOMIC_RELAXED)
+#define MLX5_NL_SN_GENERATE (__atomic_fetch_add(&atomic_sn, 1, __ATOMIC_RELAXED) + 1)
 
 /**
  * Opens a Netlink socket.
drivers/common/mlx5/mlx5_common_mr.c +4 -4
index 0e1d243..037a4d8 100644
@@ -58,8 +58,8 @@ struct mlx5_mempool_reg {
 
 	if (__atomic_load_n(&buf->refcnt, __ATOMIC_RELAXED) == 1) {
 		rte_mempool_put(buf->mp, buf);
-	} else if (unlikely(__atomic_sub_fetch(&buf->refcnt, 1,
-					       __ATOMIC_RELAXED) == 0)) {
+	} else if (unlikely(__atomic_fetch_sub(&buf->refcnt, 1,
+					       __ATOMIC_RELAXED) - 1 == 0)) {
 		__atomic_store_n(&buf->refcnt, 1, __ATOMIC_RELAXED);
 		rte_mempool_put(buf->mp, buf);
 	}
@@ -1665,8 +1665,8 @@ struct mlx5_mempool_get_extmem_data {
 	bool ret = false;
 
 	for (i = 0; i < mpr->mrs_n; i++)
-		ret |= __atomic_sub_fetch(&mpr->mrs[i].refcnt, 1,
-					  __ATOMIC_RELAXED) == 0;
+		ret |= __atomic_fetch_sub(&mpr->mrs[i].refcnt, 1,
+					  __ATOMIC_RELAXED) - 1 == 0;
 	return ret;
 }
 
drivers/common/mlx5/mlx5_common_utils.c +4 -4
index 58d744b..06b5b9b 100644
@@ -81,8 +81,8 @@ struct mlx5_list *
 	while (entry != NULL) {
 		if (l_const->cb_match(l_const->ctx, entry, ctx) == 0) {
 			if (reuse) {
-				ret = __atomic_add_fetch(&entry->ref_cnt, 1,
-							 __ATOMIC_RELAXED) - 1;
+				ret = __atomic_fetch_add(&entry->ref_cnt, 1,
+							 __ATOMIC_RELAXED);
 				DRV_LOG(DEBUG, "mlx5 list %s entry %p ref: %u.",
 					l_const->name, (void *)entry,
 					entry->ref_cnt);
@@ -285,7 +285,7 @@ struct mlx5_list_entry *
 {
 	struct mlx5_list_entry *gentry = entry->gentry;
 
-	if (__atomic_sub_fetch(&entry->ref_cnt, 1, __ATOMIC_RELAXED) != 0)
+	if (__atomic_fetch_sub(&entry->ref_cnt, 1, __ATOMIC_RELAXED) - 1 != 0)
 		return 1;
 	if (entry->lcore_idx == (uint32_t)lcore_idx) {
 		LIST_REMOVE(entry, next);
@@ -303,7 +303,7 @@ struct mlx5_list_entry *
 			l_const->name, (void *)entry);
 		return 0;
 	}
-	if (__atomic_sub_fetch(&gentry->ref_cnt, 1, __ATOMIC_RELAXED) != 0)
+	if (__atomic_fetch_sub(&gentry->ref_cnt, 1, __ATOMIC_RELAXED) - 1 != 0)
 		return 1;
 	rte_rwlock_write_lock(&l_inconst->lock);
 	if (likely(gentry->ref_cnt == 0)) {
Signature · 1 line
1.8.3.1
#23 lore raw

PATCH v2 4/16 drivers/event: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/event/cnxk/cnxk_tim_worker.h  | 2 +-
 drivers/event/dsw/dsw_event.c         | 4 ++--
 drivers/event/octeontx/timvf_worker.h | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/event/cnxk/cnxk_tim_worker.h +1 -1
index a326d55..0bd66ec 100644
@@ -123,7 +123,7 @@
 	const uint64_t v =
 		~(TIM_BUCKET_W1_M_NUM_ENTRIES << TIM_BUCKET_W1_S_NUM_ENTRIES);
 
-	return __atomic_and_fetch(&bktp->w1, v, __ATOMIC_ACQ_REL);
+	return __atomic_fetch_and(&bktp->w1, v, __ATOMIC_ACQ_REL) & v;
 }
 
 static inline uint64_t
drivers/event/dsw/dsw_event.c +2 -2
index 9932caf..cbdc03f 100644
@@ -45,8 +45,8 @@
 	 * allocation.
 	 */
 	new_total_on_loan =
-	    __atomic_add_fetch(&dsw->credits_on_loan, acquired_credits,
-			       __ATOMIC_RELAXED);
+	    __atomic_fetch_add(&dsw->credits_on_loan, acquired_credits,
+			       __ATOMIC_RELAXED) + acquired_credits;
 
 	if (unlikely(new_total_on_loan > dsw->max_inflight)) {
 		/* Some other port took the last credits */
drivers/event/octeontx/timvf_worker.h +1 -1
index 3f1e77f..aa729f8 100644
@@ -135,7 +135,7 @@
 {
 	const uint64_t v = ~(TIM_BUCKET_W1_M_NUM_ENTRIES <<
 			TIM_BUCKET_W1_S_NUM_ENTRIES);
-	return __atomic_and_fetch(&bktp->w1, v, __ATOMIC_ACQ_REL);
+	return __atomic_fetch_and(&bktp->w1, v, __ATOMIC_ACQ_REL) & v;
 }
 
 static inline struct tim_mem_entry *
Signature · 1 line
1.8.3.1
#24 lore raw

PATCH v2 5/16 net/af_xdp: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +2 -2
index 2a20a69..c7786cc 100644
@@ -979,7 +979,7 @@ static int link_xdp_prog_with_dev(int ifindex, int fd, __u32 flags)
 			break;
 		xsk_socket__delete(rxq->xsk);
 
-		if (__atomic_sub_fetch(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE)
+		if (__atomic_fetch_sub(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE) - 1
 				== 0) {
 			(void)xsk_umem__delete(rxq->umem->umem);
 			xdp_umem_destroy(rxq->umem);
@@ -1710,7 +1710,7 @@ struct msg_internal {
 out_xsk:
 	xsk_socket__delete(rxq->xsk);
 out_umem:
-	if (__atomic_sub_fetch(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE) == 0)
+	if (__atomic_fetch_sub(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE) - 1 == 0)
 		xdp_umem_destroy(rxq->umem);
 
 	return ret;
Signature · 1 line
1.8.3.1
#25 lore raw

PATCH v2 6/16 net/cnxk: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/net/cnxk/cn10k_tx.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/cnxk/cn10k_tx.h +2 -2
index a72a803..c9ec01c 100644
@@ -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;
 
Signature · 1 line
1.8.3.1
#26 lore raw

PATCH v2 7/16 net/cxgbe: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/net/cxgbe/clip_tbl.c | 2 +-
 drivers/net/cxgbe/mps_tcam.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/cxgbe/clip_tbl.c +1 -1
index 072fc74..f64b922 100644
@@ -55,7 +55,7 @@ void cxgbe_clip_release(struct rte_eth_dev *dev, struct clip_entry *ce)
 	int ret;
 
 	t4_os_lock(&ce->lock);
-	if (__atomic_sub_fetch(&ce->refcnt, 1, __ATOMIC_RELAXED) == 0) {
+	if (__atomic_fetch_sub(&ce->refcnt, 1, __ATOMIC_RELAXED) - 1 == 0) {
 		ret = clip6_release_mbox(dev, ce->addr);
 		if (ret)
 			dev_debug(adap, "CLIP FW DEL CMD failed: %d", ret);
drivers/net/cxgbe/mps_tcam.c +1 -1
index abbf06e..c7cdf29 100644
@@ -195,7 +195,7 @@ int cxgbe_mpstcam_remove(struct port_info *pi, u16 idx)
 					   entry->mask, idx, 1, pi->port_id,
 					   false);
 	else
-		ret = __atomic_sub_fetch(&entry->refcnt, 1, __ATOMIC_RELAXED);
+		ret = __atomic_fetch_sub(&entry->refcnt, 1, __ATOMIC_RELAXED) - 1;
 
 	if (ret == 0) {
 		reset_mpstcam_entry(entry);
Signature · 1 line
1.8.3.1
#27 lore raw

PATCH v2 8/16 net/iavf: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/net/iavf/iavf_vchnl.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/iavf/iavf_vchnl.c +4 -4
index 9adaadb..51d4fc7 100644
@@ -120,7 +120,7 @@ struct iavf_event_handler {
 {
 	struct iavf_event_handler *handler = &event_handler;
 
-	if (__atomic_add_fetch(&handler->ndev, 1, __ATOMIC_RELAXED) != 1)
+	if (__atomic_fetch_add(&handler->ndev, 1, __ATOMIC_RELAXED) + 1 != 1)
 		return 0;
 #if defined(RTE_EXEC_ENV_IS_WINDOWS) && RTE_EXEC_ENV_IS_WINDOWS != 0
 	int err = _pipe(handler->fd, MAX_EVENT_PENDING, O_BINARY);
@@ -149,7 +149,7 @@ struct iavf_event_handler {
 {
 	struct iavf_event_handler *handler = &event_handler;
 
-	if (__atomic_sub_fetch(&handler->ndev, 1, __ATOMIC_RELAXED) != 0)
+	if (__atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED) - 1 != 0)
 		return;
 
 	int unused = pthread_cancel(handler->tid);
@@ -533,8 +533,8 @@ struct iavf_event_handler {
 				/* read message and it's expected one */
 				if (msg_opc == vf->pend_cmd) {
 					uint32_t cmd_count =
-					__atomic_sub_fetch(&vf->pend_cmd_count,
-							1, __ATOMIC_RELAXED);
+					__atomic_fetch_sub(&vf->pend_cmd_count,
+							1, __ATOMIC_RELAXED) - 1;
 					if (cmd_count == 0)
 						_notify_cmd(vf, msg_ret);
 				} else {
Signature · 1 line
1.8.3.1
#28 lore raw

PATCH v2 9/16 net/mlx5: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/net/mlx5/linux/mlx5_verbs.c |  2 +-
 drivers/net/mlx5/mlx5.c             |  4 ++--
 drivers/net/mlx5/mlx5_flow.c        |  8 ++++----
 drivers/net/mlx5/mlx5_flow_dv.c     | 12 ++++++------
 drivers/net/mlx5/mlx5_flow_hw.c     | 14 +++++++-------
 drivers/net/mlx5/mlx5_hws_cnt.c     |  4 ++--
 drivers/net/mlx5/mlx5_rxq.c         |  6 +++---
 drivers/net/mlx5/mlx5_txq.c         |  2 +-
 8 files changed, 26 insertions(+), 26 deletions(-)
drivers/net/mlx5/linux/mlx5_verbs.c +1 -1
index 67a7bec..ee5d072 100644
@@ -1183,7 +1183,7 @@
 	if (!priv->lb_used)
 		return;
 	MLX5_ASSERT(__atomic_load_n(&sh->self_lb.refcnt, __ATOMIC_RELAXED));
-	if (!(__atomic_sub_fetch(&sh->self_lb.refcnt, 1, __ATOMIC_RELAXED))) {
+	if (!(__atomic_fetch_sub(&sh->self_lb.refcnt, 1, __ATOMIC_RELAXED) - 1)) {
 		if (sh->self_lb.qp) {
 			claim_zero(mlx5_glue->destroy_qp(sh->self_lb.qp));
 			sh->self_lb.qp = NULL;
drivers/net/mlx5/mlx5.c +2 -2
index 41b1b12..044012d 100644
@@ -1068,7 +1068,7 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list =
 		DRV_LOG(ERR, "Dynamic flex parser is not supported");
 		return -ENOTSUP;
 	}
-	if (__atomic_add_fetch(&priv->sh->srh_flex_parser.refcnt, 1, __ATOMIC_RELAXED) > 1)
+	if (__atomic_fetch_add(&priv->sh->srh_flex_parser.refcnt, 1, __ATOMIC_RELAXED) + 1 > 1)
 		return 0;
 
 	node.header_length_mode = MLX5_GRAPH_NODE_LEN_FIELD;
@@ -1123,7 +1123,7 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list =
 	struct mlx5_priv *priv = dev->data->dev_private;
 	struct mlx5_internal_flex_parser_profile *fp = &priv->sh->srh_flex_parser;
 
-	if (__atomic_sub_fetch(&fp->refcnt, 1, __ATOMIC_RELAXED))
+	if (__atomic_fetch_sub(&fp->refcnt, 1, __ATOMIC_RELAXED) - 1)
 		return;
 	if (fp->fp)
 		mlx5_devx_cmd_destroy(fp->fp);
drivers/net/mlx5/mlx5_flow.c +4 -4
index 2514b33..332008e 100644
@@ -7833,7 +7833,7 @@ struct rte_flow *
 
 		tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
 		RTE_VERIFY(tunnel);
-		if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
+		if (!(__atomic_fetch_sub(&tunnel->refctn, 1, __ATOMIC_RELAXED) - 1))
 			mlx5_flow_tunnel_free(dev, tunnel);
 	}
 	flow_mreg_del_copy_action(dev, flow);
@@ -9742,9 +9742,9 @@ struct mlx5_flow_workspace*
 					 __ATOMIC_RELAXED);
 			continue;
 		}
-		if (__atomic_add_fetch(&age_param->sec_since_last_hit,
+		if (__atomic_fetch_add(&age_param->sec_since_last_hit,
 				       time_delta,
-				       __ATOMIC_RELAXED) <= age_param->timeout)
+				       __ATOMIC_RELAXED) + time_delta <= age_param->timeout)
 			continue;
 		/**
 		 * Hold the lock first, or if between the
@@ -11387,7 +11387,7 @@ struct tunnel_db_element_release_ctx {
 {
 	struct tunnel_db_element_release_ctx *ctx = x;
 	ctx->ret = 0;
-	if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
+	if (!(__atomic_fetch_sub(&tunnel->refctn, 1, __ATOMIC_RELAXED) - 1))
 		mlx5_flow_tunnel_free(dev, tunnel);
 }
 
drivers/net/mlx5/mlx5_flow_dv.c +6 -6
index ca26f39..f04160e 100644
@@ -6723,8 +6723,8 @@ struct mlx5_list_entry *
 		 * indirect action API, shared info is 1 before the reduction,
 		 * so this condition is failed and function doesn't return here.
 		 */
-		if (__atomic_sub_fetch(&cnt->shared_info.refcnt, 1,
-				       __ATOMIC_RELAXED))
+		if (__atomic_fetch_sub(&cnt->shared_info.refcnt, 1,
+				       __ATOMIC_RELAXED) - 1)
 			return;
 	}
 	cnt->pool = pool;
@@ -12797,7 +12797,7 @@ struct mlx5_list_entry *
 	struct mlx5_priv *priv = dev->data->dev_private;
 	struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
 	struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx);
-	uint32_t ret = __atomic_sub_fetch(&age->refcnt, 1, __ATOMIC_RELAXED);
+	uint32_t ret = __atomic_fetch_sub(&age->refcnt, 1, __ATOMIC_RELAXED) - 1;
 
 	if (!ret) {
 		flow_dv_aso_age_remove_from_age(dev, age);
@@ -13193,7 +13193,7 @@ struct mlx5_list_entry *
 	/* Cannot release when CT is in the ASO SQ. */
 	if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY)
 		return -1;
-	ret = __atomic_sub_fetch(&ct->refcnt, 1, __ATOMIC_RELAXED);
+	ret = __atomic_fetch_sub(&ct->refcnt, 1, __ATOMIC_RELAXED) - 1;
 	if (!ret) {
 		if (ct->dr_action_orig) {
 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
@@ -15582,8 +15582,8 @@ struct mlx5_list_entry *
 				sh->geneve_tlv_option_resource;
 	rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
 	if (geneve_opt_resource) {
-		if (!(__atomic_sub_fetch(&geneve_opt_resource->refcnt, 1,
-					 __ATOMIC_RELAXED))) {
+		if (!(__atomic_fetch_sub(&geneve_opt_resource->refcnt, 1,
+					 __ATOMIC_RELAXED) - 1)) {
 			claim_zero(mlx5_devx_cmd_destroy
 					(geneve_opt_resource->obj));
 			mlx5_free(sh->geneve_tlv_option_resource);
drivers/net/mlx5/mlx5_flow_hw.c +7 -7
index 9392727..109aab1 100644
@@ -458,7 +458,7 @@ static int flow_hw_translate_group(struct rte_eth_dev *dev,
 	}
 
 	if (acts->mark)
-		if (!__atomic_sub_fetch(&priv->hws_mark_refcnt, 1, __ATOMIC_RELAXED))
+		if (!(__atomic_fetch_sub(&priv->hws_mark_refcnt, 1, __ATOMIC_RELAXED) - 1))
 			flow_hw_rxq_flag_set(dev, false);
 
 	if (acts->jump) {
@@ -3268,8 +3268,8 @@ static rte_be32_t vlan_hdr_to_be32(const struct rte_flow_action *actions)
 			rte_errno = EINVAL;
 			goto it_error;
 		}
-		ret = __atomic_add_fetch(&item_templates[i]->refcnt, 1,
-					 __ATOMIC_RELAXED);
+		ret = __atomic_fetch_add(&item_templates[i]->refcnt, 1,
+					 __ATOMIC_RELAXED) + 1;
 		if (ret <= 1) {
 			rte_errno = EINVAL;
 			goto it_error;
@@ -3282,8 +3282,8 @@ static rte_be32_t vlan_hdr_to_be32(const struct rte_flow_action *actions)
 	for (i = 0; i < nb_action_templates; i++) {
 		uint32_t ret;
 
-		ret = __atomic_add_fetch(&action_templates[i]->refcnt, 1,
-					 __ATOMIC_RELAXED);
+		ret = __atomic_fetch_add(&action_templates[i]->refcnt, 1,
+					 __ATOMIC_RELAXED) + 1;
 		if (ret <= 1) {
 			rte_errno = EINVAL;
 			goto at_error;
@@ -7624,8 +7624,8 @@ void flow_hw_clear_tags_set(struct rte_eth_dev *dev)
 {
 	uint32_t refcnt;
 
-	refcnt = __atomic_sub_fetch(&mlx5_flow_hw_flow_metadata_config_refcnt, 1,
-				    __ATOMIC_RELAXED);
+	refcnt = __atomic_fetch_sub(&mlx5_flow_hw_flow_metadata_config_refcnt, 1,
+				    __ATOMIC_RELAXED) - 1;
 	if (refcnt > 0)
 		return;
 	mlx5_flow_hw_flow_metadata_esw_en = 0;
drivers/net/mlx5/mlx5_hws_cnt.c +2 -2
index d6a017a..d98df68 100644
@@ -192,8 +192,8 @@
 			}
 			param->accumulator_hits = 0;
 		}
-		if (__atomic_add_fetch(&param->sec_since_last_hit, time_delta,
-				       __ATOMIC_RELAXED) <=
+		if (__atomic_fetch_add(&param->sec_since_last_hit, time_delta,
+				       __ATOMIC_RELAXED) + time_delta <=
 		   __atomic_load_n(&param->timeout, __ATOMIC_RELAXED))
 			continue;
 		/* Prepare the relevant ring for this AGE parameter */
drivers/net/mlx5/mlx5_rxq.c +3 -3
index 6e99c4d..ad8fd13 100644
@@ -2042,7 +2042,7 @@ struct mlx5_rxq_priv *
 
 	if (rxq == NULL)
 		return 0;
-	return __atomic_sub_fetch(&rxq->refcnt, 1, __ATOMIC_RELAXED);
+	return __atomic_fetch_sub(&rxq->refcnt, 1, __ATOMIC_RELAXED) - 1;
 }
 
 /**
@@ -2141,7 +2141,7 @@ struct mlx5_external_rxq *
 {
 	struct mlx5_external_rxq *rxq = mlx5_ext_rxq_get(dev, idx);
 
-	return __atomic_sub_fetch(&rxq->refcnt, 1, __ATOMIC_RELAXED);
+	return __atomic_fetch_sub(&rxq->refcnt, 1, __ATOMIC_RELAXED) - 1;
 }
 
 /**
@@ -2462,7 +2462,7 @@ struct mlx5_ind_table_obj *
 	unsigned int ret;
 
 	rte_rwlock_write_lock(&priv->ind_tbls_lock);
-	ret = __atomic_sub_fetch(&ind_tbl->refcnt, 1, __ATOMIC_RELAXED);
+	ret = __atomic_fetch_sub(&ind_tbl->refcnt, 1, __ATOMIC_RELAXED) - 1;
 	if (!ret)
 		LIST_REMOVE(ind_tbl, next);
 	rte_rwlock_write_unlock(&priv->ind_tbls_lock);
drivers/net/mlx5/mlx5_txq.c +1 -1
index 1e0e61a..8cb52b0 100644
@@ -1203,7 +1203,7 @@ struct mlx5_txq_ctrl *
 	if (priv->txqs == NULL || (*priv->txqs)[idx] == NULL)
 		return 0;
 	txq_ctrl = container_of((*priv->txqs)[idx], struct mlx5_txq_ctrl, txq);
-	if (__atomic_sub_fetch(&txq_ctrl->refcnt, 1, __ATOMIC_RELAXED) > 1)
+	if (__atomic_fetch_sub(&txq_ctrl->refcnt, 1, __ATOMIC_RELAXED) - 1 > 1)
 		return 1;
 	if (txq_ctrl->obj) {
 		priv->obj_ops.txq_obj_release(txq_ctrl->obj);
Signature · 1 line
1.8.3.1
#29 lore raw

PATCH v2 10/16 net/octeontx: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/net/octeontx/octeontx_ethdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/octeontx/octeontx_ethdev.c +1 -1
index d52a3e7..a21ed80 100644
@@ -559,7 +559,7 @@ enum octeontx_link_speed {
 		return 0;
 
 	/* Stopping/closing event device once all eth ports are closed. */
-	if (__atomic_sub_fetch(&evdev_refcnt, 1, __ATOMIC_ACQUIRE) == 0) {
+	if (__atomic_fetch_sub(&evdev_refcnt, 1, __ATOMIC_ACQUIRE) - 1 == 0) {
 		rte_event_dev_stop(nic->evdev);
 		rte_event_dev_close(nic->evdev);
 	}
Signature · 1 line
1.8.3.1
#30 lore raw

PATCH v2 11/16 raw/ifpga: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/raw/ifpga/ifpga_rawdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/raw/ifpga/ifpga_rawdev.c +1 -1
index 1020adc..ae3f79d 100644
@@ -573,7 +573,7 @@ static int set_surprise_link_check_aer(
 
 	dev->poll_enabled = 0;
 
-	if (!__atomic_sub_fetch(&ifpga_monitor_refcnt, 1, __ATOMIC_RELAXED) &&
+	if (!(__atomic_fetch_sub(&ifpga_monitor_refcnt, 1, __ATOMIC_RELAXED) - 1) &&
 		ifpga_monitor_start_thread) {
 		ret = pthread_cancel(ifpga_monitor_start_thread);
 		if (ret)
Signature · 1 line
1.8.3.1
#31 lore raw

PATCH v2 12/16 bbdev: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 lib/bbdev/rte_bbdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/bbdev/rte_bbdev.c +2 -2
index 1521cdb..9df0837 100644
@@ -250,8 +250,8 @@ struct rte_bbdev *
 	}
 
 	/* clear shared BBDev Data if no process is using the device anymore */
-	if (__atomic_sub_fetch(&bbdev->data->process_cnt, 1,
-			      __ATOMIC_RELAXED) == 0)
+	if (__atomic_fetch_sub(&bbdev->data->process_cnt, 1,
+			      __ATOMIC_RELAXED) - 1 == 0)
 		memset(bbdev->data, 0, sizeof(*bbdev->data));
 
 	memset(bbdev, 0, sizeof(*bbdev));
Signature · 1 line
1.8.3.1
#32 lore raw

PATCH v2 13/16 eal: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 lib/eal/include/generic/rte_rwlock.h |  8 ++++----
 lib/eal/ppc/include/rte_atomic.h     | 16 ++++++++--------
 2 files changed, 12 insertions(+), 12 deletions(-)
lib/eal/include/generic/rte_rwlock.h +4 -4
index d45c22c..71e2d8d 100644
@@ -97,8 +97,8 @@
 			rte_pause();
 
 		/* Try to get read lock */
-		x = __atomic_add_fetch(&rwl->cnt, RTE_RWLOCK_READ,
-				       __ATOMIC_ACQUIRE);
+		x = __atomic_fetch_add(&rwl->cnt, RTE_RWLOCK_READ,
+				       __ATOMIC_ACQUIRE) + RTE_RWLOCK_READ;
 
 		/* If no writer, then acquire was successful */
 		if (likely(!(x & RTE_RWLOCK_MASK)))
@@ -134,8 +134,8 @@
 		return -EBUSY;
 
 	/* Try to get read lock */
-	x = __atomic_add_fetch(&rwl->cnt, RTE_RWLOCK_READ,
-			       __ATOMIC_ACQUIRE);
+	x = __atomic_fetch_add(&rwl->cnt, RTE_RWLOCK_READ,
+			       __ATOMIC_ACQUIRE) + RTE_RWLOCK_READ;
 
 	/* Back out if writer raced in */
 	if (unlikely(x & RTE_RWLOCK_MASK)) {
lib/eal/ppc/include/rte_atomic.h +8 -8
index 663b4d3..ffabd98 100644
@@ -71,12 +71,12 @@ static inline int rte_atomic16_test_and_set(rte_atomic16_t *v)
 
 static inline int rte_atomic16_inc_and_test(rte_atomic16_t *v)
 {
-	return __atomic_add_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0;
+	return __atomic_fetch_add(&v->cnt, 1, __ATOMIC_ACQUIRE) + 1 == 0;
 }
 
 static inline int rte_atomic16_dec_and_test(rte_atomic16_t *v)
 {
-	return __atomic_sub_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0;
+	return __atomic_fetch_sub(&v->cnt, 1, __ATOMIC_ACQUIRE) - 1 == 0;
 }
 
 static inline uint16_t
@@ -113,12 +113,12 @@ static inline int rte_atomic32_test_and_set(rte_atomic32_t *v)
 
 static inline int rte_atomic32_inc_and_test(rte_atomic32_t *v)
 {
-	return __atomic_add_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0;
+	return __atomic_fetch_add(&v->cnt, 1, __ATOMIC_ACQUIRE) + 1 == 0;
 }
 
 static inline int rte_atomic32_dec_and_test(rte_atomic32_t *v)
 {
-	return __atomic_sub_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0;
+	return __atomic_fetch_sub(&v->cnt, 1, __ATOMIC_ACQUIRE) - 1 == 0;
 }
 
 static inline uint32_t
@@ -181,23 +181,23 @@ static inline int rte_atomic32_dec_and_test(rte_atomic32_t *v)
 static inline int64_t
 rte_atomic64_add_return(rte_atomic64_t *v, int64_t inc)
 {
-	return __atomic_add_fetch(&v->cnt, inc, __ATOMIC_ACQUIRE);
+	return __atomic_fetch_add(&v->cnt, inc, __ATOMIC_ACQUIRE) + inc;
 }
 
 static inline int64_t
 rte_atomic64_sub_return(rte_atomic64_t *v, int64_t dec)
 {
-	return __atomic_sub_fetch(&v->cnt, dec, __ATOMIC_ACQUIRE);
+	return __atomic_fetch_sub(&v->cnt, dec, __ATOMIC_ACQUIRE) - dec;
 }
 
 static inline int rte_atomic64_inc_and_test(rte_atomic64_t *v)
 {
-	return __atomic_add_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0;
+	return __atomic_fetch_add(&v->cnt, 1, __ATOMIC_ACQUIRE) + 1 == 0;
 }
 
 static inline int rte_atomic64_dec_and_test(rte_atomic64_t *v)
 {
-	return __atomic_sub_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0;
+	return __atomic_fetch_sub(&v->cnt, 1, __ATOMIC_ACQUIRE) - 1 == 0;
 }
 
 static inline int rte_atomic64_test_and_set(rte_atomic64_t *v)
Signature · 1 line
1.8.3.1
#33 lore raw

PATCH v2 14/16 ipsec: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 lib/ipsec/ipsec_sqn.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/ipsec/ipsec_sqn.h +1 -1
index 2636cb1..505950e 100644
@@ -128,7 +128,7 @@
 
 	n = *num;
 	if (SQN_ATOMIC(sa))
-		sqn = __atomic_add_fetch(&sa->sqn.outb, n, __ATOMIC_RELAXED);
+		sqn = __atomic_fetch_add(&sa->sqn.outb, n, __ATOMIC_RELAXED) + n;
 	else {
 		sqn = sa->sqn.outb + n;
 		sa->sqn.outb = sqn;
Signature · 1 line
1.8.3.1
#34 lore raw

PATCH v2 15/16 mbuf: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 lib/mbuf/rte_mbuf.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
lib/mbuf/rte_mbuf.h +6 -6
index 3a82eb1..e5ab4a4 100644
@@ -381,8 +381,8 @@ struct rte_pktmbuf_pool_private {
 static inline uint16_t
 __rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value)
 {
-	return __atomic_add_fetch(&m->refcnt, (uint16_t)value,
-				 __ATOMIC_ACQ_REL);
+	return __atomic_fetch_add(&m->refcnt, value,
+				 __ATOMIC_ACQ_REL) + value;
 }
 
 /**
@@ -502,8 +502,8 @@ struct rte_pktmbuf_pool_private {
 		return (uint16_t)value;
 	}
 
-	return __atomic_add_fetch(&shinfo->refcnt, (uint16_t)value,
-				 __ATOMIC_ACQ_REL);
+	return __atomic_fetch_add(&shinfo->refcnt, value,
+				 __ATOMIC_ACQ_REL) + value;
 }
 
 /** Mbuf prefetch */
@@ -1315,8 +1315,8 @@ static inline int __rte_pktmbuf_pinned_extbuf_decref(struct rte_mbuf *m)
 	 * Direct usage of add primitive to avoid
 	 * duplication of comparing with one.
 	 */
-	if (likely(__atomic_add_fetch(&shinfo->refcnt, (uint16_t)-1,
-				     __ATOMIC_ACQ_REL)))
+	if (likely(__atomic_fetch_add(&shinfo->refcnt, -1,
+				     __ATOMIC_ACQ_REL) - 1))
 		return 1;
 
 	/* Reinitialize counter before mbuf freeing. */
Signature · 1 line
1.8.3.1
#35 lore raw

PATCH v2 16/16 rcu: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 lib/rcu/rte_rcu_qsbr.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/rcu/rte_rcu_qsbr.h +1 -1
index ccae5d5..1aa078e 100644
@@ -462,7 +462,7 @@ struct rte_rcu_qsbr_dq_parameters {
 	 * structure are visible to the workers before the token
 	 * update is visible.
 	 */
-	t = __atomic_add_fetch(&v->token, 1, __ATOMIC_RELEASE);
+	t = __atomic_fetch_add(&v->token, 1, __ATOMIC_RELEASE) + 1;
 
 	return t;
 }
Signature · 1 line
1.8.3.1
#36 lore raw

Re: [PATCH v2 00/16] replace __atomic operations returning new value

In reply to Tyler Retzlaff
Quoted 22 lines · Tyler Retzlaff

This series replaces uses of __atomic_{add,and,or,sub,xor}_fetch with __atomic_fetch_{add,and,or,sub,xor} intrinsics where the new value is used.

This series is being separated from the other similar series in an effort to reduce the chance of mistakes being spotted in review since the usages in this case consume the returned / new value.

v2:
* remove unnecessary casts of signed to unsigned arguments when using generic __atomic builtins.
* remove inappropriate cast of signed negative value on addend.

Tyler Retzlaff (16):
app/test: use previous value atomic fetch operations common/cnxk: use previous value atomic fetch operations common/mlx5: use previous value atomic fetch operations drivers/event: use previous value atomic fetch operations net/af_xdp: use previous value atomic fetch operations net/cnxk: use previous value atomic fetch operations net/cxgbe: use previous value atomic fetch operations net/iavf: use previous value atomic fetch operations

Quoted 9 lines

net/mlx5: use previous value atomic fetch operations net/octeontx: use previous value atomic fetch operations raw/ifpga: use previous value atomic fetch operations
bbdev: use previous value atomic fetch operations
eal: use previous value atomic fetch operations
ipsec: use previous value atomic fetch operations
mbuf: use previous value atomic fetch operations
rcu: use previous value atomic fetch operations

I am wondering how we go about ensuring that we don't introduce any more of these atomic_X_fetch intrinsics. Is there some way we can add a compiler warning for them or have a checkpatch check, for example?

#37 lore raw

Re: [PATCH v2 00/16] replace __atomic operations returning new value

16/03/2023 11:03, Bruce Richardson:

Quoted 4 lines · Tyler Retzlaff
Quoted 3 lines

This series replaces uses of __atomic_{add,and,or,sub,xor}_fetch with __atomic_fetch_{add,and,or,sub,xor} intrinsics where the new value is used.

[...]

Quoted 18 lines
Quoted 9 lines

Tyler Retzlaff (16):
app/test: use previous value atomic fetch operations common/cnxk: use previous value atomic fetch operations common/mlx5: use previous value atomic fetch operations drivers/event: use previous value atomic fetch operations net/af_xdp: use previous value atomic fetch operations net/cnxk: use previous value atomic fetch operations net/cxgbe: use previous value atomic fetch operations net/iavf: use previous value atomic fetch operations

Quoted 9 lines

net/mlx5: use previous value atomic fetch operations net/octeontx: use previous value atomic fetch operations raw/ifpga: use previous value atomic fetch operations
bbdev: use previous value atomic fetch operations
eal: use previous value atomic fetch operations
ipsec: use previous value atomic fetch operations
mbuf: use previous value atomic fetch operations
rcu: use previous value atomic fetch operations

Quoted 3 lines

I am wondering how we go about ensuring that we don't introduce any more of these atomic_X_fetch intrinsics. Is there some way we can add a compiler warning for them or have a checkpatch check, for example?

In devtools/checkpatches.sh, we are checking for these patterns:

	rte_atomic[0-9][0-9]_.*\(
	__atomic_thread_fence\(

Feel free to add more "forbidden patterns".

#38 lore raw

Re: [PATCH v2 00/16] replace __atomic operations returning new value

Quoted 28 lines · Thomas Monjalon

16/03/2023 11:03, Bruce Richardson:

Quoted 4 lines · Tyler Retzlaff
Quoted 3 lines

This series replaces uses of __atomic_{add,and,or,sub,xor}_fetch with __atomic_fetch_{add,and,or,sub,xor} intrinsics where the new value is used.

[...]

Quoted 18 lines
Quoted 9 lines

Tyler Retzlaff (16):
app/test: use previous value atomic fetch operations common/cnxk: use previous value atomic fetch operations common/mlx5: use previous value atomic fetch operations drivers/event: use previous value atomic fetch operations net/af_xdp: use previous value atomic fetch operations net/cnxk: use previous value atomic fetch operations net/cxgbe: use previous value atomic fetch operations net/iavf: use previous value atomic fetch operations

Quoted 9 lines

net/mlx5: use previous value atomic fetch operations net/octeontx: use previous value atomic fetch operations raw/ifpga: use previous value atomic fetch operations
bbdev: use previous value atomic fetch operations
eal: use previous value atomic fetch operations
ipsec: use previous value atomic fetch operations
mbuf: use previous value atomic fetch operations
rcu: use previous value atomic fetch operations

Quoted 3 lines

I am wondering how we go about ensuring that we don't introduce any more of these atomic_X_fetch intrinsics. Is there some way we can add a compiler warning for them or have a checkpatch check, for example?

Quoted 7 lines

In devtools/checkpatches.sh, we are checking for these patterns:

	rte_atomic[0-9][0-9]_.*\(
	__atomic_thread_fence\(

Feel free to add more "forbidden patterns".

yes, i was going to do this before end of week but got interrupted by other work. i will introduce a patch for checkpatches.sh standalone asap that can be merged before these changes.

#39 lore raw

Re: [PATCH v2 00/16] replace __atomic operations returning new value

Quoted 33 lines · Tyler Retzlaff
Quoted 32 lines · Thomas Monjalon

16/03/2023 11:03, Bruce Richardson:

Quoted 4 lines · Tyler Retzlaff
Quoted 3 lines

This series replaces uses of __atomic_{add,and,or,sub,xor}_fetch with __atomic_fetch_{add,and,or,sub,xor} intrinsics where the new value is used.

[...]

Quoted 18 lines
Quoted 9 lines

Tyler Retzlaff (16):
app/test: use previous value atomic fetch operations common/cnxk: use previous value atomic fetch operations common/mlx5: use previous value atomic fetch operations drivers/event: use previous value atomic fetch operations net/af_xdp: use previous value atomic fetch operations net/cnxk: use previous value atomic fetch operations net/cxgbe: use previous value atomic fetch operations net/iavf: use previous value atomic fetch operations

Quoted 9 lines

net/mlx5: use previous value atomic fetch operations net/octeontx: use previous value atomic fetch operations raw/ifpga: use previous value atomic fetch operations
bbdev: use previous value atomic fetch operations
eal: use previous value atomic fetch operations
ipsec: use previous value atomic fetch operations
mbuf: use previous value atomic fetch operations
rcu: use previous value atomic fetch operations

Quoted 3 lines

I am wondering how we go about ensuring that we don't introduce any more of these atomic_X_fetch intrinsics. Is there some way we can add a compiler warning for them or have a checkpatch check, for example?

In devtools/checkpatches.sh, we are checking for these patterns:

	rte_atomic[0-9][0-9]_.*\(
	__atomic_thread_fence\(
Quoted 7 lines
Quoted 3 lines

Feel free to add more "forbidden patterns".

yes, i was going to do this before end of week but got interrupted by other work. i will introduce a patch for checkpatches.sh standalone asap that can be merged before these changes.

just fyi, there is a series up for this.

https://patchwork.dpdk.org/project/dpdk/list/?series=27613

#40 lore raw

RE: [PATCH v2 00/16] replace __atomic operations returning new value

In reply to Tyler Retzlaff
Quoted 71 lines

-----Original Message-----
From: Tyler Retzlaff <[email protected]>
Sent: Thursday, March 16, 2023 5:15 AM
To: [email protected]
Cc: Honnappa Nagarahalli <[email protected]>; Ruifeng Wang <[email protected]>; [email protected]; Tyler Retzlaff <[email protected]>
Subject: [PATCH v2 00/16] replace __atomic operations returning new value

This series replaces uses of __atomic_{add,and,or,sub,xor}_fetch with __atomic_fetch_{add,and,or,sub,xor} intrinsics where the new value is used.

This series is being separated from the other similar series in an effort to reduce the chance of mistakes being spotted in review since the usages in this case consume the returned / new value.

v2:
* remove unnecessary casts of signed to unsigned arguments when using generic __atomic builtins.
* remove inappropriate cast of signed negative value on addend.

Tyler Retzlaff (16):
app/test: use previous value atomic fetch operations common/cnxk: use previous value atomic fetch operations common/mlx5: use previous value atomic fetch operations drivers/event: use previous value atomic fetch operations net/af_xdp: use previous value atomic fetch operations net/cnxk: use previous value atomic fetch operations net/cxgbe: use previous value atomic fetch operations net/iavf: use previous value atomic fetch operations net/mlx5: use previous value atomic fetch operations net/octeontx: use previous value atomic fetch operations raw/ifpga: use previous value atomic fetch operations
bbdev: use previous value atomic fetch operations
eal: use previous value atomic fetch operations
ipsec: use previous value atomic fetch operations
mbuf: use previous value atomic fetch operations
rcu: use previous value atomic fetch operations

 app/test/test_ring_perf.c               |  2 +-
 drivers/common/cnxk/roc_ae.c            |  2 +-
 drivers/common/cnxk/roc_ae_fpm_tables.c |  2 +-
 drivers/common/cnxk/roc_npa.c           |  2 +-
 drivers/common/mlx5/linux/mlx5_nl.c     |  2 +-
 drivers/common/mlx5/mlx5_common_mr.c    |  8 ++++----
 drivers/common/mlx5/mlx5_common_utils.c |  8 ++++----
 drivers/event/cnxk/cnxk_tim_worker.h    |  2 +-
 drivers/event/dsw/dsw_event.c           |  4 ++--
 drivers/event/octeontx/timvf_worker.h   |  2 +-
 drivers/net/af_xdp/rte_eth_af_xdp.c     |  4 ++--
 drivers/net/cnxk/cn10k_tx.h             |  4 ++--
 drivers/net/cxgbe/clip_tbl.c            |  2 +-
 drivers/net/cxgbe/mps_tcam.c            |  2 +-
 drivers/net/iavf/iavf_vchnl.c           |  8 ++++----
 drivers/net/mlx5/linux/mlx5_verbs.c     |  2 +-
 drivers/net/mlx5/mlx5.c                 |  4 ++--
 drivers/net/mlx5/mlx5_flow.c            |  8 ++++----
 drivers/net/mlx5/mlx5_flow_dv.c         | 12 ++++++------
 drivers/net/mlx5/mlx5_flow_hw.c         | 14 +++++++-------
 drivers/net/mlx5/mlx5_hws_cnt.c         |  4 ++--
 drivers/net/mlx5/mlx5_rxq.c             |  6 +++---
 drivers/net/mlx5/mlx5_txq.c             |  2 +-
 drivers/net/octeontx/octeontx_ethdev.c  |  2 +-
 drivers/raw/ifpga/ifpga_rawdev.c        |  2 +-
 lib/bbdev/rte_bbdev.c                   |  4 ++--
 lib/eal/include/generic/rte_rwlock.h    |  8 ++++----
 lib/eal/ppc/include/rte_atomic.h        | 16 ++++++++--------
 lib/ipsec/ipsec_sqn.h                   |  2 +-
 lib/mbuf/rte_mbuf.h                     | 12 ++++++------
 lib/rcu/rte_rcu_qsbr.h                  |  2 +-
 31 files changed, 77 insertions(+), 77 deletions(-)
Quoted 2 lines

--
1.8.3.1

#41 lore raw

v3 cover replace __atomic operations returning new value

In reply to Tyler Retzlaff

This series replaces uses of __atomic_{add,and,or,sub,xor}_fetch with __atomic_fetch_{add,and,or,sub,xor} intrinsics where the new value is used.

This series is being separated from the other similar series in an effort to reduce the chance of mistakes being spotted in review since the usages in this case consume the returned / new value.

v3:
* incorporate Reviewed-by and Acked-by received so far
* rebase series on -rc3 to get a fresh CI run

v2:
* remove unnecessary casts of signed to unsigned arguments when using generic __atomic builtins.
* remove inappropriate cast of signed negative value on addend.

*** BLURB HERE ***

Tyler Retzlaff (16):
app/test: use previous value atomic fetch operations common/cnxk: use previous value atomic fetch operations common/mlx5: use previous value atomic fetch operations drivers/event: use previous value atomic fetch operations net/af_xdp: use previous value atomic fetch operations net/cnxk: use previous value atomic fetch operations net/cxgbe: use previous value atomic fetch operations net/iavf: use previous value atomic fetch operations net/mlx5: use previous value atomic fetch operations net/octeontx: use previous value atomic fetch operations raw/ifpga: use previous value atomic fetch operations
bbdev: use previous value atomic fetch operations
eal: use previous value atomic fetch operations
ipsec: use previous value atomic fetch operations
mbuf: use previous value atomic fetch operations
rcu: use previous value atomic fetch operations

 app/test/test_ring_perf.c               |  2 +-
 drivers/common/cnxk/roc_ae.c            |  2 +-
 drivers/common/cnxk/roc_ae_fpm_tables.c |  2 +-
 drivers/common/cnxk/roc_npa.c           |  2 +-
 drivers/common/mlx5/linux/mlx5_nl.c     |  2 +-
 drivers/common/mlx5/mlx5_common_mr.c    |  8 ++++----
 drivers/common/mlx5/mlx5_common_utils.c |  8 ++++----
 drivers/event/cnxk/cnxk_tim_worker.h    |  2 +-
 drivers/event/dsw/dsw_event.c           |  4 ++--
 drivers/event/octeontx/timvf_worker.h   |  2 +-
 drivers/net/af_xdp/rte_eth_af_xdp.c     |  4 ++--
 drivers/net/cnxk/cn10k_tx.h             |  4 ++--
 drivers/net/cxgbe/clip_tbl.c            |  2 +-
 drivers/net/cxgbe/mps_tcam.c            |  2 +-
 drivers/net/iavf/iavf_vchnl.c           |  8 ++++----
 drivers/net/mlx5/linux/mlx5_verbs.c     |  2 +-
 drivers/net/mlx5/mlx5.c                 |  4 ++--
 drivers/net/mlx5/mlx5_flow.c            |  8 ++++----
 drivers/net/mlx5/mlx5_flow_dv.c         | 12 ++++++------
 drivers/net/mlx5/mlx5_flow_hw.c         | 14 +++++++-------
 drivers/net/mlx5/mlx5_hws_cnt.c         |  4 ++--
 drivers/net/mlx5/mlx5_rxq.c             |  6 +++---
 drivers/net/mlx5/mlx5_txq.c             |  2 +-
 drivers/net/octeontx/octeontx_ethdev.c  |  2 +-
 drivers/raw/ifpga/ifpga_rawdev.c        |  2 +-
 lib/bbdev/rte_bbdev.c                   |  4 ++--
 lib/eal/include/generic/rte_rwlock.h    |  8 ++++----
 lib/eal/ppc/include/rte_atomic.h        | 16 ++++++++--------
 lib/ipsec/ipsec_sqn.h                   |  2 +-
 lib/mbuf/rte_mbuf.h                     | 12 ++++++------
 lib/rcu/rte_rcu_qsbr.h                  |  2 +-
 31 files changed, 77 insertions(+), 77 deletions(-)
Signature · 1 line
1.8.3.1
#42 lore raw

PATCH v3 1/16 app/test: use previous value atomic fetch operations

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.

---
 app/test/test_ring_perf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
app/test/test_ring_perf.c +1 -1
index 2d8bb67..3972fd9 100644
@@ -186,7 +186,7 @@ struct thread_params {
 	void *burst = NULL;
 
 #ifdef RTE_USE_C11_MEM_MODEL
-	if (__atomic_add_fetch(&lcore_count, 1, __ATOMIC_RELAXED) != 2)
+	if (__atomic_fetch_add(&lcore_count, 1, __ATOMIC_RELAXED) + 1 != 2)
 #else
 	if (__sync_add_and_fetch(&lcore_count, 1) != 2)
 #endif
Signature · 1 line
1.8.3.1
#43 lore raw

PATCH v3 2/16 common/cnxk: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/common/cnxk/roc_ae.c            | 2 +-
 drivers/common/cnxk/roc_ae_fpm_tables.c | 2 +-
 drivers/common/cnxk/roc_npa.c           | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/common/cnxk/roc_ae.c +1 -1
index 929da05..336b927 100644
@@ -203,6 +203,6 @@ struct ae_ec_grp_tbl {
 
 	ec_grp = mz->addr;
 	/* Decrement number of devices using EC grp table */
-	if (__atomic_sub_fetch(&ec_grp->refcount, 1, __ATOMIC_SEQ_CST) == 0)
+	if (__atomic_fetch_sub(&ec_grp->refcount, 1, __ATOMIC_SEQ_CST) - 1 == 0)
 		plt_memzone_free(mz);
 }
drivers/common/cnxk/roc_ae_fpm_tables.c +1 -1
index afb2a50..f915702 100644
@@ -1135,6 +1135,6 @@ struct ae_fpm_tbl {
 
 	fpm = (struct ae_fpm_tbl *)mz->addr;
 	/* Decrement number of devices using FPM table */
-	if (__atomic_sub_fetch(&fpm->refcount, 1, __ATOMIC_SEQ_CST) == 0)
+	if (__atomic_fetch_sub(&fpm->refcount, 1, __ATOMIC_SEQ_CST) - 1 == 0)
 		plt_memzone_free(mz);
 }
drivers/common/cnxk/roc_npa.c +1 -1
index 69c3d8d..20637fb 100644
@@ -946,7 +946,7 @@
 		return NPA_ERR_ALLOC;
 
 	/* Not the last PCI device */
-	if (__atomic_sub_fetch(&idev->npa_refcnt, 1, __ATOMIC_SEQ_CST) != 0)
+	if (__atomic_fetch_sub(&idev->npa_refcnt, 1, __ATOMIC_SEQ_CST) - 1 != 0)
 		return 0;
 
 	npa_unregister_irqs(idev->npa);
Signature · 1 line
1.8.3.1
#44 lore raw

PATCH v3 3/16 common/mlx5: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/common/mlx5/linux/mlx5_nl.c     | 2 +-
 drivers/common/mlx5/mlx5_common_mr.c    | 8 ++++----
 drivers/common/mlx5/mlx5_common_utils.c | 8 ++++----
 3 files changed, 9 insertions(+), 9 deletions(-)
drivers/common/mlx5/linux/mlx5_nl.c +1 -1
index 5d04857..33670bb 100644
@@ -178,7 +178,7 @@ struct mlx5_nl_port_info {
 uint32_t atomic_sn;
 
 /* Generate Netlink sequence number. */
-#define MLX5_NL_SN_GENERATE __atomic_add_fetch(&atomic_sn, 1, __ATOMIC_RELAXED)
+#define MLX5_NL_SN_GENERATE (__atomic_fetch_add(&atomic_sn, 1, __ATOMIC_RELAXED) + 1)
 
 /**
  * Opens a Netlink socket.
drivers/common/mlx5/mlx5_common_mr.c +4 -4
index 0e1d243..037a4d8 100644
@@ -58,8 +58,8 @@ struct mlx5_mempool_reg {
 
 	if (__atomic_load_n(&buf->refcnt, __ATOMIC_RELAXED) == 1) {
 		rte_mempool_put(buf->mp, buf);
-	} else if (unlikely(__atomic_sub_fetch(&buf->refcnt, 1,
-					       __ATOMIC_RELAXED) == 0)) {
+	} else if (unlikely(__atomic_fetch_sub(&buf->refcnt, 1,
+					       __ATOMIC_RELAXED) - 1 == 0)) {
 		__atomic_store_n(&buf->refcnt, 1, __ATOMIC_RELAXED);
 		rte_mempool_put(buf->mp, buf);
 	}
@@ -1665,8 +1665,8 @@ struct mlx5_mempool_get_extmem_data {
 	bool ret = false;
 
 	for (i = 0; i < mpr->mrs_n; i++)
-		ret |= __atomic_sub_fetch(&mpr->mrs[i].refcnt, 1,
-					  __ATOMIC_RELAXED) == 0;
+		ret |= __atomic_fetch_sub(&mpr->mrs[i].refcnt, 1,
+					  __ATOMIC_RELAXED) - 1 == 0;
 	return ret;
 }
 
drivers/common/mlx5/mlx5_common_utils.c +4 -4
index 58d744b..06b5b9b 100644
@@ -81,8 +81,8 @@ struct mlx5_list *
 	while (entry != NULL) {
 		if (l_const->cb_match(l_const->ctx, entry, ctx) == 0) {
 			if (reuse) {
-				ret = __atomic_add_fetch(&entry->ref_cnt, 1,
-							 __ATOMIC_RELAXED) - 1;
+				ret = __atomic_fetch_add(&entry->ref_cnt, 1,
+							 __ATOMIC_RELAXED);
 				DRV_LOG(DEBUG, "mlx5 list %s entry %p ref: %u.",
 					l_const->name, (void *)entry,
 					entry->ref_cnt);
@@ -285,7 +285,7 @@ struct mlx5_list_entry *
 {
 	struct mlx5_list_entry *gentry = entry->gentry;
 
-	if (__atomic_sub_fetch(&entry->ref_cnt, 1, __ATOMIC_RELAXED) != 0)
+	if (__atomic_fetch_sub(&entry->ref_cnt, 1, __ATOMIC_RELAXED) - 1 != 0)
 		return 1;
 	if (entry->lcore_idx == (uint32_t)lcore_idx) {
 		LIST_REMOVE(entry, next);
@@ -303,7 +303,7 @@ struct mlx5_list_entry *
 			l_const->name, (void *)entry);
 		return 0;
 	}
-	if (__atomic_sub_fetch(&gentry->ref_cnt, 1, __ATOMIC_RELAXED) != 0)
+	if (__atomic_fetch_sub(&gentry->ref_cnt, 1, __ATOMIC_RELAXED) - 1 != 0)
 		return 1;
 	rte_rwlock_write_lock(&l_inconst->lock);
 	if (likely(gentry->ref_cnt == 0)) {
Signature · 1 line
1.8.3.1
#45 lore raw

PATCH v3 4/16 drivers/event: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/event/cnxk/cnxk_tim_worker.h  | 2 +-
 drivers/event/dsw/dsw_event.c         | 4 ++--
 drivers/event/octeontx/timvf_worker.h | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/event/cnxk/cnxk_tim_worker.h +1 -1
index a326d55..0bd66ec 100644
@@ -123,7 +123,7 @@
 	const uint64_t v =
 		~(TIM_BUCKET_W1_M_NUM_ENTRIES << TIM_BUCKET_W1_S_NUM_ENTRIES);
 
-	return __atomic_and_fetch(&bktp->w1, v, __ATOMIC_ACQ_REL);
+	return __atomic_fetch_and(&bktp->w1, v, __ATOMIC_ACQ_REL) & v;
 }
 
 static inline uint64_t
drivers/event/dsw/dsw_event.c +2 -2
index 9932caf..cbdc03f 100644
@@ -45,8 +45,8 @@
 	 * allocation.
 	 */
 	new_total_on_loan =
-	    __atomic_add_fetch(&dsw->credits_on_loan, acquired_credits,
-			       __ATOMIC_RELAXED);
+	    __atomic_fetch_add(&dsw->credits_on_loan, acquired_credits,
+			       __ATOMIC_RELAXED) + acquired_credits;
 
 	if (unlikely(new_total_on_loan > dsw->max_inflight)) {
 		/* Some other port took the last credits */
drivers/event/octeontx/timvf_worker.h +1 -1
index 3f1e77f..aa729f8 100644
@@ -135,7 +135,7 @@
 {
 	const uint64_t v = ~(TIM_BUCKET_W1_M_NUM_ENTRIES <<
 			TIM_BUCKET_W1_S_NUM_ENTRIES);
-	return __atomic_and_fetch(&bktp->w1, v, __ATOMIC_ACQ_REL);
+	return __atomic_fetch_and(&bktp->w1, v, __ATOMIC_ACQ_REL) & v;
 }
 
 static inline struct tim_mem_entry *
Signature · 1 line
1.8.3.1
#46 lore raw

PATCH v3 5/16 net/af_xdp: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +2 -2
index 2a20a69..c7786cc 100644
@@ -979,7 +979,7 @@ static int link_xdp_prog_with_dev(int ifindex, int fd, __u32 flags)
 			break;
 		xsk_socket__delete(rxq->xsk);
 
-		if (__atomic_sub_fetch(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE)
+		if (__atomic_fetch_sub(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE) - 1
 				== 0) {
 			(void)xsk_umem__delete(rxq->umem->umem);
 			xdp_umem_destroy(rxq->umem);
@@ -1710,7 +1710,7 @@ struct msg_internal {
 out_xsk:
 	xsk_socket__delete(rxq->xsk);
 out_umem:
-	if (__atomic_sub_fetch(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE) == 0)
+	if (__atomic_fetch_sub(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE) - 1 == 0)
 		xdp_umem_destroy(rxq->umem);
 
 	return ret;
Signature · 1 line
1.8.3.1
#47 lore raw

PATCH v3 6/16 net/cnxk: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/net/cnxk/cn10k_tx.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/cnxk/cn10k_tx.h +2 -2
index a72a803..c9ec01c 100644
@@ -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;
 
Signature · 1 line
1.8.3.1
#48 lore raw

PATCH v3 7/16 net/cxgbe: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/net/cxgbe/clip_tbl.c | 2 +-
 drivers/net/cxgbe/mps_tcam.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/cxgbe/clip_tbl.c +1 -1
index 072fc74..f64b922 100644
@@ -55,7 +55,7 @@ void cxgbe_clip_release(struct rte_eth_dev *dev, struct clip_entry *ce)
 	int ret;
 
 	t4_os_lock(&ce->lock);
-	if (__atomic_sub_fetch(&ce->refcnt, 1, __ATOMIC_RELAXED) == 0) {
+	if (__atomic_fetch_sub(&ce->refcnt, 1, __ATOMIC_RELAXED) - 1 == 0) {
 		ret = clip6_release_mbox(dev, ce->addr);
 		if (ret)
 			dev_debug(adap, "CLIP FW DEL CMD failed: %d", ret);
drivers/net/cxgbe/mps_tcam.c +1 -1
index abbf06e..c7cdf29 100644
@@ -195,7 +195,7 @@ int cxgbe_mpstcam_remove(struct port_info *pi, u16 idx)
 					   entry->mask, idx, 1, pi->port_id,
 					   false);
 	else
-		ret = __atomic_sub_fetch(&entry->refcnt, 1, __ATOMIC_RELAXED);
+		ret = __atomic_fetch_sub(&entry->refcnt, 1, __ATOMIC_RELAXED) - 1;
 
 	if (ret == 0) {
 		reset_mpstcam_entry(entry);
Signature · 1 line
1.8.3.1
#49 lore raw

PATCH v3 8/16 net/iavf: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/net/iavf/iavf_vchnl.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/iavf/iavf_vchnl.c +4 -4
index 9adaadb..51d4fc7 100644
@@ -120,7 +120,7 @@ struct iavf_event_handler {
 {
 	struct iavf_event_handler *handler = &event_handler;
 
-	if (__atomic_add_fetch(&handler->ndev, 1, __ATOMIC_RELAXED) != 1)
+	if (__atomic_fetch_add(&handler->ndev, 1, __ATOMIC_RELAXED) + 1 != 1)
 		return 0;
 #if defined(RTE_EXEC_ENV_IS_WINDOWS) && RTE_EXEC_ENV_IS_WINDOWS != 0
 	int err = _pipe(handler->fd, MAX_EVENT_PENDING, O_BINARY);
@@ -149,7 +149,7 @@ struct iavf_event_handler {
 {
 	struct iavf_event_handler *handler = &event_handler;
 
-	if (__atomic_sub_fetch(&handler->ndev, 1, __ATOMIC_RELAXED) != 0)
+	if (__atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED) - 1 != 0)
 		return;
 
 	int unused = pthread_cancel(handler->tid);
@@ -533,8 +533,8 @@ struct iavf_event_handler {
 				/* read message and it's expected one */
 				if (msg_opc == vf->pend_cmd) {
 					uint32_t cmd_count =
-					__atomic_sub_fetch(&vf->pend_cmd_count,
-							1, __ATOMIC_RELAXED);
+					__atomic_fetch_sub(&vf->pend_cmd_count,
+							1, __ATOMIC_RELAXED) - 1;
 					if (cmd_count == 0)
 						_notify_cmd(vf, msg_ret);
 				} else {
Signature · 1 line
1.8.3.1
#50 lore raw

PATCH v3 9/16 net/mlx5: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/net/mlx5/linux/mlx5_verbs.c |  2 +-
 drivers/net/mlx5/mlx5.c             |  4 ++--
 drivers/net/mlx5/mlx5_flow.c        |  8 ++++----
 drivers/net/mlx5/mlx5_flow_dv.c     | 12 ++++++------
 drivers/net/mlx5/mlx5_flow_hw.c     | 14 +++++++-------
 drivers/net/mlx5/mlx5_hws_cnt.c     |  4 ++--
 drivers/net/mlx5/mlx5_rxq.c         |  6 +++---
 drivers/net/mlx5/mlx5_txq.c         |  2 +-
 8 files changed, 26 insertions(+), 26 deletions(-)
drivers/net/mlx5/linux/mlx5_verbs.c +1 -1
index 67a7bec..ee5d072 100644
@@ -1183,7 +1183,7 @@
 	if (!priv->lb_used)
 		return;
 	MLX5_ASSERT(__atomic_load_n(&sh->self_lb.refcnt, __ATOMIC_RELAXED));
-	if (!(__atomic_sub_fetch(&sh->self_lb.refcnt, 1, __ATOMIC_RELAXED))) {
+	if (!(__atomic_fetch_sub(&sh->self_lb.refcnt, 1, __ATOMIC_RELAXED) - 1)) {
 		if (sh->self_lb.qp) {
 			claim_zero(mlx5_glue->destroy_qp(sh->self_lb.qp));
 			sh->self_lb.qp = NULL;
drivers/net/mlx5/mlx5.c +2 -2
index 41b1b12..044012d 100644
@@ -1068,7 +1068,7 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list =
 		DRV_LOG(ERR, "Dynamic flex parser is not supported");
 		return -ENOTSUP;
 	}
-	if (__atomic_add_fetch(&priv->sh->srh_flex_parser.refcnt, 1, __ATOMIC_RELAXED) > 1)
+	if (__atomic_fetch_add(&priv->sh->srh_flex_parser.refcnt, 1, __ATOMIC_RELAXED) + 1 > 1)
 		return 0;
 
 	node.header_length_mode = MLX5_GRAPH_NODE_LEN_FIELD;
@@ -1123,7 +1123,7 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list =
 	struct mlx5_priv *priv = dev->data->dev_private;
 	struct mlx5_internal_flex_parser_profile *fp = &priv->sh->srh_flex_parser;
 
-	if (__atomic_sub_fetch(&fp->refcnt, 1, __ATOMIC_RELAXED))
+	if (__atomic_fetch_sub(&fp->refcnt, 1, __ATOMIC_RELAXED) - 1)
 		return;
 	if (fp->fp)
 		mlx5_devx_cmd_destroy(fp->fp);
drivers/net/mlx5/mlx5_flow.c +4 -4
index 19f7f92..c742675 100644
@@ -7833,7 +7833,7 @@ struct rte_flow *
 
 		tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
 		RTE_VERIFY(tunnel);
-		if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
+		if (!(__atomic_fetch_sub(&tunnel->refctn, 1, __ATOMIC_RELAXED) - 1))
 			mlx5_flow_tunnel_free(dev, tunnel);
 	}
 	flow_mreg_del_copy_action(dev, flow);
@@ -9746,9 +9746,9 @@ struct mlx5_flow_workspace*
 					 __ATOMIC_RELAXED);
 			continue;
 		}
-		if (__atomic_add_fetch(&age_param->sec_since_last_hit,
+		if (__atomic_fetch_add(&age_param->sec_since_last_hit,
 				       time_delta,
-				       __ATOMIC_RELAXED) <= age_param->timeout)
+				       __ATOMIC_RELAXED) + time_delta <= age_param->timeout)
 			continue;
 		/**
 		 * Hold the lock first, or if between the
@@ -11391,7 +11391,7 @@ struct tunnel_db_element_release_ctx {
 {
 	struct tunnel_db_element_release_ctx *ctx = x;
 	ctx->ret = 0;
-	if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
+	if (!(__atomic_fetch_sub(&tunnel->refctn, 1, __ATOMIC_RELAXED) - 1))
 		mlx5_flow_tunnel_free(dev, tunnel);
 }
 
drivers/net/mlx5/mlx5_flow_dv.c +6 -6
index ca26f39..f04160e 100644
@@ -6723,8 +6723,8 @@ struct mlx5_list_entry *
 		 * indirect action API, shared info is 1 before the reduction,
 		 * so this condition is failed and function doesn't return here.
 		 */
-		if (__atomic_sub_fetch(&cnt->shared_info.refcnt, 1,
-				       __ATOMIC_RELAXED))
+		if (__atomic_fetch_sub(&cnt->shared_info.refcnt, 1,
+				       __ATOMIC_RELAXED) - 1)
 			return;
 	}
 	cnt->pool = pool;
@@ -12797,7 +12797,7 @@ struct mlx5_list_entry *
 	struct mlx5_priv *priv = dev->data->dev_private;
 	struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
 	struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx);
-	uint32_t ret = __atomic_sub_fetch(&age->refcnt, 1, __ATOMIC_RELAXED);
+	uint32_t ret = __atomic_fetch_sub(&age->refcnt, 1, __ATOMIC_RELAXED) - 1;
 
 	if (!ret) {
 		flow_dv_aso_age_remove_from_age(dev, age);
@@ -13193,7 +13193,7 @@ struct mlx5_list_entry *
 	/* Cannot release when CT is in the ASO SQ. */
 	if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY)
 		return -1;
-	ret = __atomic_sub_fetch(&ct->refcnt, 1, __ATOMIC_RELAXED);
+	ret = __atomic_fetch_sub(&ct->refcnt, 1, __ATOMIC_RELAXED) - 1;
 	if (!ret) {
 		if (ct->dr_action_orig) {
 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
@@ -15582,8 +15582,8 @@ struct mlx5_list_entry *
 				sh->geneve_tlv_option_resource;
 	rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
 	if (geneve_opt_resource) {
-		if (!(__atomic_sub_fetch(&geneve_opt_resource->refcnt, 1,
-					 __ATOMIC_RELAXED))) {
+		if (!(__atomic_fetch_sub(&geneve_opt_resource->refcnt, 1,
+					 __ATOMIC_RELAXED) - 1)) {
 			claim_zero(mlx5_devx_cmd_destroy
 					(geneve_opt_resource->obj));
 			mlx5_free(sh->geneve_tlv_option_resource);
drivers/net/mlx5/mlx5_flow_hw.c +7 -7
index a4328a9..8882fc7 100644
@@ -458,7 +458,7 @@ static int flow_hw_translate_group(struct rte_eth_dev *dev,
 	}
 
 	if (acts->mark)
-		if (!__atomic_sub_fetch(&priv->hws_mark_refcnt, 1, __ATOMIC_RELAXED))
+		if (!(__atomic_fetch_sub(&priv->hws_mark_refcnt, 1, __ATOMIC_RELAXED) - 1))
 			flow_hw_rxq_flag_set(dev, false);
 
 	if (acts->jump) {
@@ -3268,8 +3268,8 @@ static rte_be32_t vlan_hdr_to_be32(const struct rte_flow_action *actions)
 			rte_errno = EINVAL;
 			goto it_error;
 		}
-		ret = __atomic_add_fetch(&item_templates[i]->refcnt, 1,
-					 __ATOMIC_RELAXED);
+		ret = __atomic_fetch_add(&item_templates[i]->refcnt, 1,
+					 __ATOMIC_RELAXED) + 1;
 		if (ret <= 1) {
 			rte_errno = EINVAL;
 			goto it_error;
@@ -3282,8 +3282,8 @@ static rte_be32_t vlan_hdr_to_be32(const struct rte_flow_action *actions)
 	for (i = 0; i < nb_action_templates; i++) {
 		uint32_t ret;
 
-		ret = __atomic_add_fetch(&action_templates[i]->refcnt, 1,
-					 __ATOMIC_RELAXED);
+		ret = __atomic_fetch_add(&action_templates[i]->refcnt, 1,
+					 __ATOMIC_RELAXED) + 1;
 		if (ret <= 1) {
 			rte_errno = EINVAL;
 			goto at_error;
@@ -7726,8 +7726,8 @@ void flow_hw_clear_tags_set(struct rte_eth_dev *dev)
 {
 	uint32_t refcnt;
 
-	refcnt = __atomic_sub_fetch(&mlx5_flow_hw_flow_metadata_config_refcnt, 1,
-				    __ATOMIC_RELAXED);
+	refcnt = __atomic_fetch_sub(&mlx5_flow_hw_flow_metadata_config_refcnt, 1,
+				    __ATOMIC_RELAXED) - 1;
 	if (refcnt > 0)
 		return;
 	mlx5_flow_hw_flow_metadata_esw_en = 0;
drivers/net/mlx5/mlx5_hws_cnt.c +2 -2
index d6a017a..d98df68 100644
@@ -192,8 +192,8 @@
 			}
 			param->accumulator_hits = 0;
 		}
-		if (__atomic_add_fetch(&param->sec_since_last_hit, time_delta,
-				       __ATOMIC_RELAXED) <=
+		if (__atomic_fetch_add(&param->sec_since_last_hit, time_delta,
+				       __ATOMIC_RELAXED) + time_delta <=
 		   __atomic_load_n(&param->timeout, __ATOMIC_RELAXED))
 			continue;
 		/* Prepare the relevant ring for this AGE parameter */
drivers/net/mlx5/mlx5_rxq.c +3 -3
index 6e99c4d..ad8fd13 100644
@@ -2042,7 +2042,7 @@ struct mlx5_rxq_priv *
 
 	if (rxq == NULL)
 		return 0;
-	return __atomic_sub_fetch(&rxq->refcnt, 1, __ATOMIC_RELAXED);
+	return __atomic_fetch_sub(&rxq->refcnt, 1, __ATOMIC_RELAXED) - 1;
 }
 
 /**
@@ -2141,7 +2141,7 @@ struct mlx5_external_rxq *
 {
 	struct mlx5_external_rxq *rxq = mlx5_ext_rxq_get(dev, idx);
 
-	return __atomic_sub_fetch(&rxq->refcnt, 1, __ATOMIC_RELAXED);
+	return __atomic_fetch_sub(&rxq->refcnt, 1, __ATOMIC_RELAXED) - 1;
 }
 
 /**
@@ -2462,7 +2462,7 @@ struct mlx5_ind_table_obj *
 	unsigned int ret;
 
 	rte_rwlock_write_lock(&priv->ind_tbls_lock);
-	ret = __atomic_sub_fetch(&ind_tbl->refcnt, 1, __ATOMIC_RELAXED);
+	ret = __atomic_fetch_sub(&ind_tbl->refcnt, 1, __ATOMIC_RELAXED) - 1;
 	if (!ret)
 		LIST_REMOVE(ind_tbl, next);
 	rte_rwlock_write_unlock(&priv->ind_tbls_lock);
drivers/net/mlx5/mlx5_txq.c +1 -1
index 1e0e61a..8cb52b0 100644
@@ -1203,7 +1203,7 @@ struct mlx5_txq_ctrl *
 	if (priv->txqs == NULL || (*priv->txqs)[idx] == NULL)
 		return 0;
 	txq_ctrl = container_of((*priv->txqs)[idx], struct mlx5_txq_ctrl, txq);
-	if (__atomic_sub_fetch(&txq_ctrl->refcnt, 1, __ATOMIC_RELAXED) > 1)
+	if (__atomic_fetch_sub(&txq_ctrl->refcnt, 1, __ATOMIC_RELAXED) - 1 > 1)
 		return 1;
 	if (txq_ctrl->obj) {
 		priv->obj_ops.txq_obj_release(txq_ctrl->obj);
Signature · 1 line
1.8.3.1
#51 lore raw

PATCH v3 10/16 net/octeontx: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/net/octeontx/octeontx_ethdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/octeontx/octeontx_ethdev.c +1 -1
index d52a3e7..a21ed80 100644
@@ -559,7 +559,7 @@ enum octeontx_link_speed {
 		return 0;
 
 	/* Stopping/closing event device once all eth ports are closed. */
-	if (__atomic_sub_fetch(&evdev_refcnt, 1, __ATOMIC_ACQUIRE) == 0) {
+	if (__atomic_fetch_sub(&evdev_refcnt, 1, __ATOMIC_ACQUIRE) - 1 == 0) {
 		rte_event_dev_stop(nic->evdev);
 		rte_event_dev_close(nic->evdev);
 	}
Signature · 1 line
1.8.3.1
#52 lore raw

PATCH v3 11/16 raw/ifpga: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 drivers/raw/ifpga/ifpga_rawdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/raw/ifpga/ifpga_rawdev.c +1 -1
index 1020adc..ae3f79d 100644
@@ -573,7 +573,7 @@ static int set_surprise_link_check_aer(
 
 	dev->poll_enabled = 0;
 
-	if (!__atomic_sub_fetch(&ifpga_monitor_refcnt, 1, __ATOMIC_RELAXED) &&
+	if (!(__atomic_fetch_sub(&ifpga_monitor_refcnt, 1, __ATOMIC_RELAXED) - 1) &&
 		ifpga_monitor_start_thread) {
 		ret = pthread_cancel(ifpga_monitor_start_thread);
 		if (ret)
Signature · 1 line
1.8.3.1
#53 lore raw

PATCH v3 12/16 bbdev: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 lib/bbdev/rte_bbdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/bbdev/rte_bbdev.c +2 -2
index 1521cdb..9df0837 100644
@@ -250,8 +250,8 @@ struct rte_bbdev *
 	}
 
 	/* clear shared BBDev Data if no process is using the device anymore */
-	if (__atomic_sub_fetch(&bbdev->data->process_cnt, 1,
-			      __ATOMIC_RELAXED) == 0)
+	if (__atomic_fetch_sub(&bbdev->data->process_cnt, 1,
+			      __ATOMIC_RELAXED) - 1 == 0)
 		memset(bbdev->data, 0, sizeof(*bbdev->data));
 
 	memset(bbdev, 0, sizeof(*bbdev));
Signature · 1 line
1.8.3.1
#54 lore raw

PATCH v3 13/16 eal: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 lib/eal/include/generic/rte_rwlock.h |  8 ++++----
 lib/eal/ppc/include/rte_atomic.h     | 16 ++++++++--------
 2 files changed, 12 insertions(+), 12 deletions(-)
lib/eal/include/generic/rte_rwlock.h +4 -4
index d45c22c..71e2d8d 100644
@@ -97,8 +97,8 @@
 			rte_pause();
 
 		/* Try to get read lock */
-		x = __atomic_add_fetch(&rwl->cnt, RTE_RWLOCK_READ,
-				       __ATOMIC_ACQUIRE);
+		x = __atomic_fetch_add(&rwl->cnt, RTE_RWLOCK_READ,
+				       __ATOMIC_ACQUIRE) + RTE_RWLOCK_READ;
 
 		/* If no writer, then acquire was successful */
 		if (likely(!(x & RTE_RWLOCK_MASK)))
@@ -134,8 +134,8 @@
 		return -EBUSY;
 
 	/* Try to get read lock */
-	x = __atomic_add_fetch(&rwl->cnt, RTE_RWLOCK_READ,
-			       __ATOMIC_ACQUIRE);
+	x = __atomic_fetch_add(&rwl->cnt, RTE_RWLOCK_READ,
+			       __ATOMIC_ACQUIRE) + RTE_RWLOCK_READ;
 
 	/* Back out if writer raced in */
 	if (unlikely(x & RTE_RWLOCK_MASK)) {
lib/eal/ppc/include/rte_atomic.h +8 -8
index 663b4d3..ffabd98 100644
@@ -71,12 +71,12 @@ static inline int rte_atomic16_test_and_set(rte_atomic16_t *v)
 
 static inline int rte_atomic16_inc_and_test(rte_atomic16_t *v)
 {
-	return __atomic_add_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0;
+	return __atomic_fetch_add(&v->cnt, 1, __ATOMIC_ACQUIRE) + 1 == 0;
 }
 
 static inline int rte_atomic16_dec_and_test(rte_atomic16_t *v)
 {
-	return __atomic_sub_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0;
+	return __atomic_fetch_sub(&v->cnt, 1, __ATOMIC_ACQUIRE) - 1 == 0;
 }
 
 static inline uint16_t
@@ -113,12 +113,12 @@ static inline int rte_atomic32_test_and_set(rte_atomic32_t *v)
 
 static inline int rte_atomic32_inc_and_test(rte_atomic32_t *v)
 {
-	return __atomic_add_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0;
+	return __atomic_fetch_add(&v->cnt, 1, __ATOMIC_ACQUIRE) + 1 == 0;
 }
 
 static inline int rte_atomic32_dec_and_test(rte_atomic32_t *v)
 {
-	return __atomic_sub_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0;
+	return __atomic_fetch_sub(&v->cnt, 1, __ATOMIC_ACQUIRE) - 1 == 0;
 }
 
 static inline uint32_t
@@ -181,23 +181,23 @@ static inline int rte_atomic32_dec_and_test(rte_atomic32_t *v)
 static inline int64_t
 rte_atomic64_add_return(rte_atomic64_t *v, int64_t inc)
 {
-	return __atomic_add_fetch(&v->cnt, inc, __ATOMIC_ACQUIRE);
+	return __atomic_fetch_add(&v->cnt, inc, __ATOMIC_ACQUIRE) + inc;
 }
 
 static inline int64_t
 rte_atomic64_sub_return(rte_atomic64_t *v, int64_t dec)
 {
-	return __atomic_sub_fetch(&v->cnt, dec, __ATOMIC_ACQUIRE);
+	return __atomic_fetch_sub(&v->cnt, dec, __ATOMIC_ACQUIRE) - dec;
 }
 
 static inline int rte_atomic64_inc_and_test(rte_atomic64_t *v)
 {
-	return __atomic_add_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0;
+	return __atomic_fetch_add(&v->cnt, 1, __ATOMIC_ACQUIRE) + 1 == 0;
 }
 
 static inline int rte_atomic64_dec_and_test(rte_atomic64_t *v)
 {
-	return __atomic_sub_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0;
+	return __atomic_fetch_sub(&v->cnt, 1, __ATOMIC_ACQUIRE) - 1 == 0;
 }
 
 static inline int rte_atomic64_test_and_set(rte_atomic64_t *v)
Signature · 1 line
1.8.3.1
#55 lore raw

PATCH v3 14/16 ipsec: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 lib/ipsec/ipsec_sqn.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/ipsec/ipsec_sqn.h +1 -1
index 2636cb1..505950e 100644
@@ -128,7 +128,7 @@
 
 	n = *num;
 	if (SQN_ATOMIC(sa))
-		sqn = __atomic_add_fetch(&sa->sqn.outb, n, __ATOMIC_RELAXED);
+		sqn = __atomic_fetch_add(&sa->sqn.outb, n, __ATOMIC_RELAXED) + n;
 	else {
 		sqn = sa->sqn.outb + n;
 		sa->sqn.outb = sqn;
Signature · 1 line
1.8.3.1
#56 lore raw

PATCH v3 15/16 mbuf: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 lib/mbuf/rte_mbuf.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
lib/mbuf/rte_mbuf.h +6 -6
index bc41eac..913c459 100644
@@ -381,8 +381,8 @@ struct rte_pktmbuf_pool_private {
 static inline uint16_t
 __rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value)
 {
-	return __atomic_add_fetch(&m->refcnt, (uint16_t)value,
-				 __ATOMIC_ACQ_REL);
+	return __atomic_fetch_add(&m->refcnt, value,
+				 __ATOMIC_ACQ_REL) + value;
 }
 
 /**
@@ -502,8 +502,8 @@ struct rte_pktmbuf_pool_private {
 		return (uint16_t)value;
 	}
 
-	return __atomic_add_fetch(&shinfo->refcnt, (uint16_t)value,
-				 __ATOMIC_ACQ_REL);
+	return __atomic_fetch_add(&shinfo->refcnt, value,
+				 __ATOMIC_ACQ_REL) + value;
 }
 
 /** Mbuf prefetch */
@@ -1315,8 +1315,8 @@ static inline int __rte_pktmbuf_pinned_extbuf_decref(struct rte_mbuf *m)
 	 * Direct usage of add primitive to avoid
 	 * duplication of comparing with one.
 	 */
-	if (likely(__atomic_add_fetch(&shinfo->refcnt, (uint16_t)-1,
-				     __ATOMIC_ACQ_REL)))
+	if (likely(__atomic_fetch_add(&shinfo->refcnt, -1,
+				     __ATOMIC_ACQ_REL) - 1))
 		return 1;
 
 	/* Reinitialize counter before mbuf freeing. */
Signature · 1 line
1.8.3.1
#57 lore raw

PATCH v3 16/16 rcu: use previous value atomic fetch operations

In reply to Tyler Retzlaff

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.

---
 lib/rcu/rte_rcu_qsbr.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/rcu/rte_rcu_qsbr.h +1 -1
index ccae5d5..1aa078e 100644
@@ -462,7 +462,7 @@ struct rte_rcu_qsbr_dq_parameters {
 	 * structure are visible to the workers before the token
 	 * update is visible.
 	 */
-	t = __atomic_add_fetch(&v->token, 1, __ATOMIC_RELEASE);
+	t = __atomic_fetch_add(&v->token, 1, __ATOMIC_RELEASE) + 1;
 
 	return t;
 }
Signature · 1 line
1.8.3.1
#58 lore raw

Re: [PATCH v3 00/16] replace __atomic operations returning new value

In reply to Tyler Retzlaff
Quoted 60 lines · Tyler Retzlaff

This series replaces uses of __atomic_{add,and,or,sub,xor}_fetch with __atomic_fetch_{add,and,or,sub,xor} intrinsics where the new value is used.

This series is being separated from the other similar series in an effort to reduce the chance of mistakes being spotted in review since the usages in this case consume the returned / new value.

v3:
* incorporate Reviewed-by and Acked-by received so far
* rebase series on -rc3 to get a fresh CI run

v2:
* remove unnecessary casts of signed to unsigned arguments when using generic __atomic builtins.
* remove inappropriate cast of signed negative value on addend.

Tyler Retzlaff (16):
app/test: use previous value atomic fetch operations common/cnxk: use previous value atomic fetch operations common/mlx5: use previous value atomic fetch operations drivers/event: use previous value atomic fetch operations net/af_xdp: use previous value atomic fetch operations net/cnxk: use previous value atomic fetch operations net/cxgbe: use previous value atomic fetch operations net/iavf: use previous value atomic fetch operations net/mlx5: use previous value atomic fetch operations net/octeontx: use previous value atomic fetch operations raw/ifpga: use previous value atomic fetch operations
bbdev: use previous value atomic fetch operations
eal: use previous value atomic fetch operations
ipsec: use previous value atomic fetch operations
mbuf: use previous value atomic fetch operations
rcu: use previous value atomic fetch operations

 app/test/test_ring_perf.c               |  2 +-
 drivers/common/cnxk/roc_ae.c            |  2 +-
 drivers/common/cnxk/roc_ae_fpm_tables.c |  2 +-
 drivers/common/cnxk/roc_npa.c           |  2 +-
 drivers/common/mlx5/linux/mlx5_nl.c     |  2 +-
 drivers/common/mlx5/mlx5_common_mr.c    |  8 ++++----
 drivers/common/mlx5/mlx5_common_utils.c |  8 ++++----
 drivers/event/cnxk/cnxk_tim_worker.h    |  2 +-
 drivers/event/dsw/dsw_event.c           |  4 ++--
 drivers/event/octeontx/timvf_worker.h   |  2 +-
 drivers/net/af_xdp/rte_eth_af_xdp.c     |  4 ++--
 drivers/net/cnxk/cn10k_tx.h             |  4 ++--
 drivers/net/cxgbe/clip_tbl.c            |  2 +-
 drivers/net/cxgbe/mps_tcam.c            |  2 +-
 drivers/net/iavf/iavf_vchnl.c           |  8 ++++----
 drivers/net/mlx5/linux/mlx5_verbs.c     |  2 +-
 drivers/net/mlx5/mlx5.c                 |  4 ++--
 drivers/net/mlx5/mlx5_flow.c            |  8 ++++----
 drivers/net/mlx5/mlx5_flow_dv.c         | 12 ++++++------
 drivers/net/mlx5/mlx5_flow_hw.c         | 14 +++++++-------
 drivers/net/mlx5/mlx5_hws_cnt.c         |  4 ++--
 drivers/net/mlx5/mlx5_rxq.c             |  6 +++---
 drivers/net/mlx5/mlx5_txq.c             |  2 +-
 drivers/net/octeontx/octeontx_ethdev.c  |  2 +-
Quoted 9 lines
 drivers/raw/ifpga/ifpga_rawdev.c        |  2 +-
 lib/bbdev/rte_bbdev.c                   |  4 ++--
 lib/eal/include/generic/rte_rwlock.h    |  8 ++++----
 lib/eal/ppc/include/rte_atomic.h        | 16 ++++++++--------
 lib/ipsec/ipsec_sqn.h                   |  2 +-
 lib/mbuf/rte_mbuf.h                     | 12 ++++++------
 lib/rcu/rte_rcu_qsbr.h                  |  2 +-
 31 files changed, 77 insertions(+), 77 deletions(-)

LGTM.
Series applied, thanks.

Signature · 1 line
David Marchand