Skip to contentSkip to conversation

use __atomic operations returning previous value

PATCH Superseded Tyler Retzlaff 8 participants 47 messages Mar 2, 2023 – Apr 25, 2023

Subsystems (2)
lore
Share & tools
lore
#1 lore raw

PATCH 1/17 vhost: 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 lib/vhost/virtio_net.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/vhost/virtio_net.c +3 -3
index 51dc3c9..dc49a54 100644
@@ -298,7 +298,7 @@
 
 	vhost_log_cache_sync(dev, vq);
 
-	__atomic_add_fetch(&vq->used->idx, vq->shadow_used_idx,
+	__atomic_fetch_add(&vq->used->idx, vq->shadow_used_idx,
 			   __ATOMIC_RELEASE);
 	vq->shadow_used_idx = 0;
 	vhost_log_used_vring(dev, vq, offsetof(struct vring_used, idx),
@@ -2311,7 +2311,7 @@
 			vhost_vring_call_packed(dev, vq);
 		} else {
 			write_back_completed_descs_split(vq, n_descs);
-			__atomic_add_fetch(&vq->used->idx, n_descs, __ATOMIC_RELEASE);
+			__atomic_fetch_add(&vq->used->idx, n_descs, __ATOMIC_RELEASE);
 			vhost_vring_call_split(dev, vq);
 		}
 	} else {
@@ -3683,7 +3683,7 @@
 		vhost_vring_call_packed(dev, vq);
 	} else {
 		write_back_completed_descs_split(vq, nr_cpl_pkts);
-		__atomic_add_fetch(&vq->used->idx, nr_cpl_pkts, __ATOMIC_RELEASE);
+		__atomic_fetch_add(&vq->used->idx, nr_cpl_pkts, __ATOMIC_RELEASE);
 		vhost_vring_call_split(dev, vq);
 	}
 	vq->async->pkts_inflight_n -= nr_cpl_pkts;
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH 2/17 telemetry: 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 lib/telemetry/telemetry.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/telemetry/telemetry.c +3 -3
index 7bceadc..deba7f3 100644
@@ -391,7 +391,7 @@ struct socket {
 		bytes = read(s, buffer, sizeof(buffer) - 1);
 	}
 	close(s);
-	__atomic_sub_fetch(&v2_clients, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_sub(&v2_clients, 1, __ATOMIC_RELAXED);
 	return NULL;
 }
 
@@ -414,7 +414,7 @@ struct socket {
 				close(s_accepted);
 				continue;
 			}
-			__atomic_add_fetch(s->num_clients, 1,
+			__atomic_fetch_add(s->num_clients, 1,
 					__ATOMIC_RELAXED);
 		}
 		rc = pthread_create(&th, NULL, s->fn,
@@ -424,7 +424,7 @@ struct socket {
 				 strerror(rc));
 			close(s_accepted);
 			if (s->num_clients != NULL)
-				__atomic_sub_fetch(s->num_clients, 1,
+				__atomic_fetch_sub(s->num_clients, 1,
 						   __ATOMIC_RELAXED);
 			continue;
 		}
Signature · 1 line
1.8.3.1
#0 lore raw

cover use __atomic operations returning previous value

This series replaces uses of __atomic_{add,and,or,sub,xor}_fetch with __atomic_fetch_{add,and,or,sub,xor} intrinsics. The latter omits generation of code that is only needed if the returned value is actually used.

Additionally, this change simplifies adapting dpdk to standard atomics planned for 23.07 since __atomic_fetch_xxx can be trivially replaced with atomic_fetch_xxx whereas __atomic_xxx_fetch has no standard equivalent.

Tyler Retzlaff (17):
vhost: use previous value atomic fetch operations
telemetry: use previous value atomic fetch operations
stack: use previous value atomic fetch operations
eal: use previous value atomic fetch operations
distributor: use previous value atomic fetch operations
bbdev: use previous value atomic fetch operations examples/vhost: use previous value atomic fetch operations net/virtio: use previous value atomic fetch operations net/octeontx: use previous value atomic fetch operations net/mlx5: use previous value atomic fetch operations net/iavf: use previous value atomic fetch operations net/cxgbe: use previous value atomic fetch operations drivers/event: use previous value atomic fetch operations dma/skeleton: use previous value atomic fetch operations drivers/common: use previous value atomic fetch operations app/test: use previous value atomic fetch operations
test-eventdev: use previous value atomic fetch operations

 app/test-eventdev/test_order_common.h            |  2 +-
 app/test/test_lcores.c                           |  2 +-
 app/test/test_service_cores.c                    |  4 ++--
 drivers/common/cnxk/roc_nix_inl_dev.c            |  2 +-
 drivers/common/mlx5/mlx5_common_mr.c             |  2 +-
 drivers/common/mlx5/mlx5_common_utils.c          | 10 +++++-----
 drivers/common/mlx5/mlx5_malloc.c                | 16 ++++++++--------
 drivers/dma/skeleton/skeleton_dmadev.c           |  2 +-
 drivers/event/cnxk/cnxk_eventdev_selftest.c      | 12 ++++++------
 drivers/event/cnxk/cnxk_tim_worker.h             |  6 +++---
 drivers/event/dsw/dsw_event.c                    |  6 +++---
 drivers/event/octeontx/timvf_worker.h            |  6 +++---
 drivers/net/cxgbe/clip_tbl.c                     |  2 +-
 drivers/net/cxgbe/cxgbe_main.c                   | 12 ++++++------
 drivers/net/cxgbe/l2t.c                          |  4 ++--
 drivers/net/cxgbe/mps_tcam.c                     |  2 +-
 drivers/net/cxgbe/smt.c                          |  4 ++--
 drivers/net/iavf/iavf_vchnl.c                    |  6 +++---
 drivers/net/mlx5/linux/mlx5_verbs.c              |  2 +-
 drivers/net/mlx5/mlx5_flow.c                     |  6 +++---
 drivers/net/mlx5/mlx5_flow_dv.c                  |  4 ++--
 drivers/net/mlx5/mlx5_flow_flex.c                |  6 +++---
 drivers/net/mlx5/mlx5_flow_hw.c                  | 10 +++++-----
 drivers/net/mlx5/mlx5_flow_meter.c               | 20 ++++++++++----------
 drivers/net/mlx5/mlx5_rx.h                       |  2 +-
 drivers/net/octeontx/octeontx_ethdev.c           |  2 +-
 drivers/net/virtio/virtio_user/virtio_user_dev.c |  2 +-
 examples/vhost/main.c                            | 12 ++++++------
 examples/vhost/virtio_net.c                      |  4 ++--
 lib/bbdev/rte_bbdev.c                            |  2 +-
 lib/distributor/rte_distributor.c                |  2 +-
 lib/eal/common/eal_common_trace.c                |  8 ++++----
 lib/eal/common/rte_service.c                     |  8 ++++----
 lib/eal/ppc/include/rte_atomic.h                 | 16 ++++++++--------
 lib/stack/rte_stack_lf_c11.h                     |  2 +-
 lib/telemetry/telemetry.c                        |  6 +++---
 lib/vhost/virtio_net.c                           |  6 +++---
 37 files changed, 110 insertions(+), 110 deletions(-)
Signature · 1 line
1.8.3.1
#5 lore raw

PATCH 3/17 stack: use previous value atomic fetch operations

Use __atomic_fetch_{add,and,or,sub,xor} instead of __atomic_{add,and,or,sub,xor}_fetch when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 lib/stack/rte_stack_lf_c11.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/stack/rte_stack_lf_c11.h +1 -1
index 8403196..687a6f6 100644
@@ -66,7 +66,7 @@
 	/* Ensure the stack modifications are not reordered with respect
 	 * to the LIFO len update.
 	 */
-	__atomic_add_fetch(&list->len, num, __ATOMIC_RELEASE);
+	__atomic_fetch_add(&list->len, num, __ATOMIC_RELEASE);
 }
 
 static __rte_always_inline struct rte_stack_lf_elem *
Signature · 1 line
1.8.3.1
#6 lore raw

PATCH 4/17 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 lib/eal/common/eal_common_trace.c |  8 ++++----
 lib/eal/common/rte_service.c      |  8 ++++----
 lib/eal/ppc/include/rte_atomic.h  | 16 ++++++++--------
 3 files changed, 16 insertions(+), 16 deletions(-)
lib/eal/common/eal_common_trace.c +4 -4
index 75162b7..cb980af 100644
@@ -103,10 +103,10 @@ struct trace_point_head *
 trace_mode_set(rte_trace_point_t *t, enum rte_trace_mode mode)
 {
 	if (mode == RTE_TRACE_MODE_OVERWRITE)
-		__atomic_and_fetch(t, ~__RTE_TRACE_FIELD_ENABLE_DISCARD,
+		__atomic_fetch_and(t, ~__RTE_TRACE_FIELD_ENABLE_DISCARD,
 			__ATOMIC_RELEASE);
 	else
-		__atomic_or_fetch(t, __RTE_TRACE_FIELD_ENABLE_DISCARD,
+		__atomic_fetch_or(t, __RTE_TRACE_FIELD_ENABLE_DISCARD,
 			__ATOMIC_RELEASE);
 }
 
@@ -155,7 +155,7 @@ rte_trace_mode rte_trace_mode_get(void)
 
 	prev = __atomic_fetch_or(t, __RTE_TRACE_FIELD_ENABLE_MASK, __ATOMIC_RELEASE);
 	if ((prev & __RTE_TRACE_FIELD_ENABLE_MASK) == 0)
-		__atomic_add_fetch(&trace.status, 1, __ATOMIC_RELEASE);
+		__atomic_fetch_add(&trace.status, 1, __ATOMIC_RELEASE);
 	return 0;
 }
 
@@ -169,7 +169,7 @@ rte_trace_mode rte_trace_mode_get(void)
 
 	prev = __atomic_fetch_and(t, ~__RTE_TRACE_FIELD_ENABLE_MASK, __ATOMIC_RELEASE);
 	if ((prev & __RTE_TRACE_FIELD_ENABLE_MASK) != 0)
-		__atomic_sub_fetch(&trace.status, 1, __ATOMIC_RELEASE);
+		__atomic_fetch_sub(&trace.status, 1, __ATOMIC_RELEASE);
 	return 0;
 }
 
lib/eal/common/rte_service.c +4 -4
index 42ca1d0..7ab48f2 100644
@@ -464,11 +464,11 @@ struct core_state {
 	/* Increment num_mapped_cores to reflect that this core is
 	 * now mapped capable of running the service.
 	 */
-	__atomic_add_fetch(&s->num_mapped_cores, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&s->num_mapped_cores, 1, __ATOMIC_RELAXED);
 
 	int ret = service_run(id, cs, UINT64_MAX, s, serialize_mt_unsafe);
 
-	__atomic_sub_fetch(&s->num_mapped_cores, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_sub(&s->num_mapped_cores, 1, __ATOMIC_RELAXED);
 
 	return ret;
 }
@@ -638,12 +638,12 @@ struct core_state {
 
 		if (*set && !lcore_mapped) {
 			lcore_states[lcore].service_mask |= sid_mask;
-			__atomic_add_fetch(&rte_services[sid].num_mapped_cores,
+			__atomic_fetch_add(&rte_services[sid].num_mapped_cores,
 				1, __ATOMIC_RELAXED);
 		}
 		if (!*set && lcore_mapped) {
 			lcore_states[lcore].service_mask &= ~(sid_mask);
-			__atomic_sub_fetch(&rte_services[sid].num_mapped_cores,
+			__atomic_fetch_sub(&rte_services[sid].num_mapped_cores,
 				1, __ATOMIC_RELAXED);
 		}
 	}
lib/eal/ppc/include/rte_atomic.h +8 -8
index 663b4d3..2ab735b 100644
@@ -60,13 +60,13 @@ static inline int rte_atomic16_test_and_set(rte_atomic16_t *v)
 static inline void
 rte_atomic16_inc(rte_atomic16_t *v)
 {
-	__atomic_add_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE);
+	__atomic_fetch_add(&v->cnt, 1, __ATOMIC_ACQUIRE);
 }
 
 static inline void
 rte_atomic16_dec(rte_atomic16_t *v)
 {
-	__atomic_sub_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE);
+	__atomic_fetch_sub(&v->cnt, 1, __ATOMIC_ACQUIRE);
 }
 
 static inline int rte_atomic16_inc_and_test(rte_atomic16_t *v)
@@ -102,13 +102,13 @@ static inline int rte_atomic32_test_and_set(rte_atomic32_t *v)
 static inline void
 rte_atomic32_inc(rte_atomic32_t *v)
 {
-	__atomic_add_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE);
+	__atomic_fetch_add(&v->cnt, 1, __ATOMIC_ACQUIRE);
 }
 
 static inline void
 rte_atomic32_dec(rte_atomic32_t *v)
 {
-	__atomic_sub_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE);
+	__atomic_fetch_sub(&v->cnt, 1, __ATOMIC_ACQUIRE);
 }
 
 static inline int rte_atomic32_inc_and_test(rte_atomic32_t *v)
@@ -157,25 +157,25 @@ static inline int rte_atomic32_dec_and_test(rte_atomic32_t *v)
 static inline void
 rte_atomic64_add(rte_atomic64_t *v, int64_t inc)
 {
-	__atomic_add_fetch(&v->cnt, inc, __ATOMIC_ACQUIRE);
+	__atomic_fetch_add(&v->cnt, inc, __ATOMIC_ACQUIRE);
 }
 
 static inline void
 rte_atomic64_sub(rte_atomic64_t *v, int64_t dec)
 {
-	__atomic_sub_fetch(&v->cnt, dec, __ATOMIC_ACQUIRE);
+	__atomic_fetch_sub(&v->cnt, dec, __ATOMIC_ACQUIRE);
 }
 
 static inline void
 rte_atomic64_inc(rte_atomic64_t *v)
 {
-	__atomic_add_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE);
+	__atomic_fetch_add(&v->cnt, 1, __ATOMIC_ACQUIRE);
 }
 
 static inline void
 rte_atomic64_dec(rte_atomic64_t *v)
 {
-	__atomic_sub_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE);
+	__atomic_fetch_sub(&v->cnt, 1, __ATOMIC_ACQUIRE);
 }
 
 static inline int64_t
Signature · 1 line
1.8.3.1
#11 lore raw

PATCH 8/17 net/virtio: 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +1 -1
index f46a131..2b4607a 100644
@@ -1025,7 +1025,7 @@ int virtio_user_stop_device(struct virtio_user_dev *dev)
 		uep->id = desc_idx;
 		uep->len = n_descs;
 
-		__atomic_add_fetch(&vring->used->idx, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_add(&vring->used->idx, 1, __ATOMIC_RELAXED);
 	}
 }
 
Signature · 1 line
1.8.3.1
#7 lore raw

PATCH 5/17 distributor: 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 lib/distributor/rte_distributor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/distributor/rte_distributor.c +1 -1
index 3969b2e..68840ce 100644
@@ -200,7 +200,7 @@
 	 * we won't read any mbufs from there even if GET_BUF is set.
 	 * This allows distributor to retrieve in-flight already sent packets.
 	 */
-	__atomic_or_fetch(&(buf->bufptr64[0]), RTE_DISTRIB_RETURN_BUF,
+	__atomic_fetch_or(&(buf->bufptr64[0]), RTE_DISTRIB_RETURN_BUF,
 		__ATOMIC_ACQ_REL);
 
 	/* set the RETURN_BUF on retptr64 even if we got no returns.
Signature · 1 line
1.8.3.1
#8 lore raw

PATCH 6/17 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 lib/bbdev/rte_bbdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bbdev/rte_bbdev.c +1 -1
index 1521cdb..69e099d 100644
@@ -208,7 +208,7 @@ struct rte_bbdev *
 		return NULL;
 	}
 
-	__atomic_add_fetch(&bbdev->data->process_cnt, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&bbdev->data->process_cnt, 1, __ATOMIC_RELAXED);
 	bbdev->data->dev_id = dev_id;
 	bbdev->state = RTE_BBDEV_INITIALIZED;
 
Signature · 1 line
1.8.3.1
#13 lore raw

PATCH 9/17 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 drivers/net/octeontx/octeontx_ethdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/octeontx/octeontx_ethdev.c +1 -1
index d52a3e7..e00298e 100644
@@ -1581,7 +1581,7 @@ static void build_xstat_names(struct rte_eth_xstat_name *xstat_names)
 	nic->pko_vfid = pko_vfid;
 	nic->port_id = port;
 	nic->evdev = evdev;
-	__atomic_add_fetch(&evdev_refcnt, 1, __ATOMIC_ACQUIRE);
+	__atomic_fetch_add(&evdev_refcnt, 1, __ATOMIC_ACQUIRE);
 
 	res = octeontx_port_open(nic);
 	if (res < 0)
Signature · 1 line
1.8.3.1
#9 lore raw

PATCH 7/17 examples/vhost: 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 examples/vhost/main.c       | 12 ++++++------
 examples/vhost/virtio_net.c |  4 ++--
 2 files changed, 8 insertions(+), 8 deletions(-)
examples/vhost/main.c +6 -6
index 42e53a0..bfe466f 100644
@@ -1048,9 +1048,9 @@ static unsigned check_ports_num(unsigned nb_ports)
 	}
 
 	if (enable_stats) {
-		__atomic_add_fetch(&dst_vdev->stats.rx_total_atomic, 1,
+		__atomic_fetch_add(&dst_vdev->stats.rx_total_atomic, 1,
 				__ATOMIC_SEQ_CST);
-		__atomic_add_fetch(&dst_vdev->stats.rx_atomic, ret,
+		__atomic_fetch_add(&dst_vdev->stats.rx_atomic, ret,
 				__ATOMIC_SEQ_CST);
 		src_vdev->stats.tx_total++;
 		src_vdev->stats.tx += ret;
@@ -1068,9 +1068,9 @@ static unsigned check_ports_num(unsigned nb_ports)
 	ret = vdev_queue_ops[vdev->vid].enqueue_pkt_burst(vdev, VIRTIO_RXQ, m, nr_xmit);
 
 	if (enable_stats) {
-		__atomic_add_fetch(&vdev->stats.rx_total_atomic, nr_xmit,
+		__atomic_fetch_add(&vdev->stats.rx_total_atomic, nr_xmit,
 				__ATOMIC_SEQ_CST);
-		__atomic_add_fetch(&vdev->stats.rx_atomic, ret,
+		__atomic_fetch_add(&vdev->stats.rx_atomic, ret,
 				__ATOMIC_SEQ_CST);
 	}
 
@@ -1400,9 +1400,9 @@ static void virtio_tx_offload(struct rte_mbuf *m)
 	}
 
 	if (enable_stats) {
-		__atomic_add_fetch(&vdev->stats.rx_total_atomic, rx_count,
+		__atomic_fetch_add(&vdev->stats.rx_total_atomic, rx_count,
 				__ATOMIC_SEQ_CST);
-		__atomic_add_fetch(&vdev->stats.rx_atomic, enqueue_count,
+		__atomic_fetch_add(&vdev->stats.rx_atomic, enqueue_count,
 				__ATOMIC_SEQ_CST);
 	}
 
examples/vhost/virtio_net.c +2 -2
index 1d4737f..514c8e0 100644
@@ -231,7 +231,7 @@
 			rte_prefetch0(&vr->desc[desc_indexes[i+1]]);
 	}
 
-	__atomic_add_fetch(&vr->used->idx, count, __ATOMIC_RELEASE);
+	__atomic_fetch_add(&vr->used->idx, count, __ATOMIC_RELEASE);
 	queue->last_used_idx += count;
 
 	rte_vhost_vring_call(dev->vid, queue_id);
@@ -442,7 +442,7 @@
 	queue->last_avail_idx += i;
 	queue->last_used_idx += i;
 
-	__atomic_add_fetch(&vr->used->idx, i, __ATOMIC_ACQ_REL);
+	__atomic_fetch_add(&vr->used->idx, i, __ATOMIC_ACQ_REL);
 
 	rte_vhost_vring_call(dev->vid, queue_id);
 
Signature · 1 line
1.8.3.1
#15 lore raw

PATCH 11/17 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 drivers/net/iavf/iavf_vchnl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/iavf/iavf_vchnl.c +3 -3
index 9adaadb..73875d7 100644
@@ -128,7 +128,7 @@ struct iavf_event_handler {
 	int err = pipe(handler->fd);
 #endif
 	if (err != 0) {
-		__atomic_sub_fetch(&handler->ndev, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED);
 		return -1;
 	}
 
@@ -137,7 +137,7 @@ struct iavf_event_handler {
 
 	if (rte_ctrl_thread_create(&handler->tid, "iavf-event-thread",
 				NULL, iavf_dev_event_handle, NULL)) {
-		__atomic_sub_fetch(&handler->ndev, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED);
 		return -1;
 	}
 
@@ -533,7 +533,7 @@ 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,
+					__atomic_fetch_sub(&vf->pend_cmd_count,
 							1, __ATOMIC_RELAXED);
 					if (cmd_count == 0)
 						_notify_cmd(vf, msg_ret);
Signature · 1 line
1.8.3.1
#23 lore raw

PATCH 17/17 test-eventdev: 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 app/test-eventdev/test_order_common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
app/test-eventdev/test_order_common.h +1 -1
index 92781d9..1507265 100644
@@ -113,7 +113,7 @@ struct test_order {
 	 */
 	expected_flow_seq[flow]++;
 	rte_pktmbuf_free(ev->mbuf);
-	__atomic_sub_fetch(outstand_pkts, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_sub(outstand_pkts, 1, __ATOMIC_RELAXED);
 }
 
 static __rte_always_inline void
Signature · 1 line
1.8.3.1
#18 lore raw

PATCH 12/17 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 drivers/net/cxgbe/clip_tbl.c   |  2 +-
 drivers/net/cxgbe/cxgbe_main.c | 12 ++++++------
 drivers/net/cxgbe/l2t.c        |  4 ++--
 drivers/net/cxgbe/mps_tcam.c   |  2 +-
 drivers/net/cxgbe/smt.c        |  4 ++--
 5 files changed, 12 insertions(+), 12 deletions(-)
drivers/net/cxgbe/clip_tbl.c +1 -1
index 072fc74..ce715f2 100644
@@ -129,7 +129,7 @@ static struct clip_entry *t4_clip_alloc(struct rte_eth_dev *dev,
 				ce->type = FILTER_TYPE_IPV4;
 			}
 		} else {
-			__atomic_add_fetch(&ce->refcnt, 1, __ATOMIC_RELAXED);
+			__atomic_fetch_add(&ce->refcnt, 1, __ATOMIC_RELAXED);
 		}
 		t4_os_unlock(&ce->lock);
 	}
drivers/net/cxgbe/cxgbe_main.c +6 -6
index f8dd833..c479454 100644
@@ -418,14 +418,14 @@ void cxgbe_remove_tid(struct tid_info *t, unsigned int chan, unsigned int tid,
 
 	if (t->tid_tab[tid]) {
 		t->tid_tab[tid] = NULL;
-		__atomic_sub_fetch(&t->conns_in_use, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(&t->conns_in_use, 1, __ATOMIC_RELAXED);
 		if (t->hash_base && tid >= t->hash_base) {
 			if (family == FILTER_TYPE_IPV4)
-				__atomic_sub_fetch(&t->hash_tids_in_use, 1,
+				__atomic_fetch_sub(&t->hash_tids_in_use, 1,
 						   __ATOMIC_RELAXED);
 		} else {
 			if (family == FILTER_TYPE_IPV4)
-				__atomic_sub_fetch(&t->tids_in_use, 1,
+				__atomic_fetch_sub(&t->tids_in_use, 1,
 						   __ATOMIC_RELAXED);
 		}
 	}
@@ -448,15 +448,15 @@ void cxgbe_insert_tid(struct tid_info *t, void *data, unsigned int tid,
 	t->tid_tab[tid] = data;
 	if (t->hash_base && tid >= t->hash_base) {
 		if (family == FILTER_TYPE_IPV4)
-			__atomic_add_fetch(&t->hash_tids_in_use, 1,
+			__atomic_fetch_add(&t->hash_tids_in_use, 1,
 					   __ATOMIC_RELAXED);
 	} else {
 		if (family == FILTER_TYPE_IPV4)
-			__atomic_add_fetch(&t->tids_in_use, 1,
+			__atomic_fetch_add(&t->tids_in_use, 1,
 					   __ATOMIC_RELAXED);
 	}
 
-	__atomic_add_fetch(&t->conns_in_use, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&t->conns_in_use, 1, __ATOMIC_RELAXED);
 }
 
 /**
drivers/net/cxgbe/l2t.c +2 -2
index 66f5789..21f4019 100644
@@ -15,7 +15,7 @@
 void cxgbe_l2t_release(struct l2t_entry *e)
 {
 	if (__atomic_load_n(&e->refcnt, __ATOMIC_RELAXED) != 0)
-		__atomic_sub_fetch(&e->refcnt, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(&e->refcnt, 1, __ATOMIC_RELAXED);
 }
 
 /**
@@ -162,7 +162,7 @@ static struct l2t_entry *t4_l2t_alloc_switching(struct rte_eth_dev *dev,
 				dev_debug(adap, "Failed to write L2T entry: %d",
 					  ret);
 		} else {
-			__atomic_add_fetch(&e->refcnt, 1, __ATOMIC_RELAXED);
+			__atomic_fetch_add(&e->refcnt, 1, __ATOMIC_RELAXED);
 		}
 		t4_os_unlock(&e->lock);
 	}
drivers/net/cxgbe/mps_tcam.c +1 -1
index abbf06e..017741f 100644
@@ -76,7 +76,7 @@ int cxgbe_mpstcam_alloc(struct port_info *pi, const u8 *eth_addr,
 	t4_os_write_lock(&mpstcam->lock);
 	entry = cxgbe_mpstcam_lookup(adap->mpstcam, eth_addr, mask);
 	if (entry) {
-		__atomic_add_fetch(&entry->refcnt, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_add(&entry->refcnt, 1, __ATOMIC_RELAXED);
 		t4_os_write_unlock(&mpstcam->lock);
 		return entry->idx;
 	}
drivers/net/cxgbe/smt.c +2 -2
index 810c757..4e14a73 100644
@@ -170,7 +170,7 @@ static struct smt_entry *t4_smt_alloc_switching(struct rte_eth_dev *dev,
 			e->state = SMT_STATE_SWITCHING;
 			__atomic_store_n(&e->refcnt, 1, __ATOMIC_RELAXED);
 		} else {
-			__atomic_add_fetch(&e->refcnt, 1, __ATOMIC_RELAXED);
+			__atomic_fetch_add(&e->refcnt, 1, __ATOMIC_RELAXED);
 		}
 		t4_os_unlock(&e->lock);
 	}
@@ -196,7 +196,7 @@ struct smt_entry *cxgbe_smt_alloc_switching(struct rte_eth_dev *dev, u8 *smac)
 void cxgbe_smt_release(struct smt_entry *e)
 {
 	if (__atomic_load_n(&e->refcnt, __ATOMIC_RELAXED) != 0)
-		__atomic_sub_fetch(&e->refcnt, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(&e->refcnt, 1, __ATOMIC_RELAXED);
 }
 
 /**
Signature · 1 line
1.8.3.1
#21 lore raw

PATCH 15/17 drivers/common: 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 drivers/common/cnxk/roc_nix_inl_dev.c   |  2 +-
 drivers/common/mlx5/mlx5_common_mr.c    |  2 +-
 drivers/common/mlx5/mlx5_common_utils.c | 10 +++++-----
 drivers/common/mlx5/mlx5_malloc.c       | 16 ++++++++--------
 4 files changed, 15 insertions(+), 15 deletions(-)
drivers/common/cnxk/roc_nix_inl_dev.c +1 -1
index 6f60961..45d6f62 100644
@@ -741,7 +741,7 @@
 			inl_dev->work_cb(&tmp, sa, (port_id << 8) | 0x1);
 			__atomic_store_n(ring_base + tail_l + 1, 0ULL,
 					 __ATOMIC_RELAXED);
-			__atomic_add_fetch((uint32_t *)ring_base, 1,
+			__atomic_fetch_add((uint32_t *)ring_base, 1,
 					   __ATOMIC_ACQ_REL);
 		} else
 			plt_err("Invalid SA");
drivers/common/mlx5/mlx5_common_mr.c +1 -1
index 0e1d243..9ebe398 100644
@@ -1650,7 +1650,7 @@ struct mlx5_mempool_get_extmem_data {
 	unsigned int i;
 
 	for (i = 0; i < mpr->mrs_n; i++)
-		__atomic_add_fetch(&mpr->mrs[i].refcnt, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_add(&mpr->mrs[i].refcnt, 1, __ATOMIC_RELAXED);
 }
 
 /**
drivers/common/mlx5/mlx5_common_utils.c +5 -5
index 58d744b..915a317 100644
@@ -217,7 +217,7 @@ struct mlx5_list_entry *
 		entry->lcore_idx = (uint32_t)lcore_index;
 		LIST_INSERT_HEAD(&l_inconst->cache[lcore_index]->h,
 				 entry, next);
-		__atomic_add_fetch(&l_inconst->count, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_add(&l_inconst->count, 1, __ATOMIC_RELAXED);
 		DRV_LOG(DEBUG, "MLX5 list %s c%d entry %p new: %u.",
 			l_const->name, lcore_index,
 			(void *)entry, entry->ref_cnt);
@@ -254,7 +254,7 @@ struct mlx5_list_entry *
 	l_inconst->gen_cnt++;
 	rte_rwlock_write_unlock(&l_inconst->lock);
 	LIST_INSERT_HEAD(&l_inconst->cache[lcore_index]->h, local_entry, next);
-	__atomic_add_fetch(&l_inconst->count, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&l_inconst->count, 1, __ATOMIC_RELAXED);
 	DRV_LOG(DEBUG, "mlx5 list %s entry %p new: %u.", l_const->name,
 		(void *)entry, entry->ref_cnt);
 	return local_entry;
@@ -294,11 +294,11 @@ struct mlx5_list_entry *
 		else
 			l_const->cb_remove(l_const->ctx, entry);
 	} else {
-		__atomic_add_fetch(&l_inconst->cache[entry->lcore_idx]->inv_cnt,
+		__atomic_fetch_add(&l_inconst->cache[entry->lcore_idx]->inv_cnt,
 				   1, __ATOMIC_RELAXED);
 	}
 	if (!l_const->lcores_share) {
-		__atomic_sub_fetch(&l_inconst->count, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(&l_inconst->count, 1, __ATOMIC_RELAXED);
 		DRV_LOG(DEBUG, "mlx5 list %s entry %p removed.",
 			l_const->name, (void *)entry);
 		return 0;
@@ -310,7 +310,7 @@ struct mlx5_list_entry *
 		LIST_REMOVE(gentry, next);
 		rte_rwlock_write_unlock(&l_inconst->lock);
 		l_const->cb_remove(l_const->ctx, gentry);
-		__atomic_sub_fetch(&l_inconst->count, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(&l_inconst->count, 1, __ATOMIC_RELAXED);
 		DRV_LOG(DEBUG, "mlx5 list %s entry %p removed.",
 			l_const->name, (void *)gentry);
 		return 0;
drivers/common/mlx5/mlx5_malloc.c +8 -8
index cef3b88..c58c41d 100644
@@ -99,7 +99,7 @@ struct mlx5_sys_mem {
 			rte_mem_virt2memseg_list(addr),
 			__ATOMIC_RELAXED);
 #ifdef RTE_LIBRTE_MLX5_DEBUG
-		__atomic_add_fetch(&mlx5_sys_mem.msl_update, 1,
+		__atomic_fetch_add(&mlx5_sys_mem.msl_update, 1,
 				   __ATOMIC_RELAXED);
 #endif
 	}
@@ -126,7 +126,7 @@ struct mlx5_sys_mem {
 		if (!rte_mem_virt2memseg_list(addr))
 			return false;
 #ifdef RTE_LIBRTE_MLX5_DEBUG
-		__atomic_add_fetch(&mlx5_sys_mem.msl_miss, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_add(&mlx5_sys_mem.msl_miss, 1, __ATOMIC_RELAXED);
 #endif
 	}
 	return true;
@@ -185,7 +185,7 @@ struct mlx5_sys_mem {
 		mlx5_mem_update_msl(addr);
 #ifdef RTE_LIBRTE_MLX5_DEBUG
 		if (addr)
-			__atomic_add_fetch(&mlx5_sys_mem.malloc_rte, 1,
+			__atomic_fetch_add(&mlx5_sys_mem.malloc_rte, 1,
 					   __ATOMIC_RELAXED);
 #endif
 		return addr;
@@ -199,7 +199,7 @@ struct mlx5_sys_mem {
 		addr = malloc(size);
 #ifdef RTE_LIBRTE_MLX5_DEBUG
 	if (addr)
-		__atomic_add_fetch(&mlx5_sys_mem.malloc_sys, 1,
+		__atomic_fetch_add(&mlx5_sys_mem.malloc_sys, 1,
 				   __ATOMIC_RELAXED);
 #endif
 	return addr;
@@ -233,7 +233,7 @@ struct mlx5_sys_mem {
 		mlx5_mem_update_msl(new_addr);
 #ifdef RTE_LIBRTE_MLX5_DEBUG
 		if (new_addr)
-			__atomic_add_fetch(&mlx5_sys_mem.realloc_rte, 1,
+			__atomic_fetch_add(&mlx5_sys_mem.realloc_rte, 1,
 					   __ATOMIC_RELAXED);
 #endif
 		return new_addr;
@@ -246,7 +246,7 @@ struct mlx5_sys_mem {
 	new_addr = realloc(addr, size);
 #ifdef RTE_LIBRTE_MLX5_DEBUG
 	if (new_addr)
-		__atomic_add_fetch(&mlx5_sys_mem.realloc_sys, 1,
+		__atomic_fetch_add(&mlx5_sys_mem.realloc_sys, 1,
 				   __ATOMIC_RELAXED);
 #endif
 	return new_addr;
@@ -259,13 +259,13 @@ struct mlx5_sys_mem {
 		return;
 	if (!mlx5_mem_is_rte(addr)) {
 #ifdef RTE_LIBRTE_MLX5_DEBUG
-		__atomic_add_fetch(&mlx5_sys_mem.free_sys, 1,
+		__atomic_fetch_add(&mlx5_sys_mem.free_sys, 1,
 				   __ATOMIC_RELAXED);
 #endif
 		mlx5_os_free(addr);
 	} else {
 #ifdef RTE_LIBRTE_MLX5_DEBUG
-		__atomic_add_fetch(&mlx5_sys_mem.free_rte, 1,
+		__atomic_fetch_add(&mlx5_sys_mem.free_rte, 1,
 				   __ATOMIC_RELAXED);
 #endif
 		rte_free(addr);
Signature · 1 line
1.8.3.1
#22 lore raw

PATCH 16/17 app/test: 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 app/test/test_lcores.c        | 2 +-
 app/test/test_service_cores.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
app/test/test_lcores.c +1 -1
index 5b43aa5..2c945b0 100644
@@ -40,7 +40,7 @@ static uint32_t thread_loop(void *arg)
 		t->state = Thread_ERROR;
 	}
 	/* Report register happened to the control thread. */
-	__atomic_add_fetch(t->registered_count, 1, __ATOMIC_RELEASE);
+	__atomic_fetch_add(t->registered_count, 1, __ATOMIC_RELEASE);
 
 	/* Wait for release from the control thread. */
 	while (__atomic_load_n(t->registered_count, __ATOMIC_ACQUIRE) != 0)
app/test/test_service_cores.c +2 -2
index 637fcd7..9175736 100644
@@ -751,12 +751,12 @@ static int32_t dummy_mt_safe_cb(void *args)
 	uint32_t *lock = &params[1];
 
 	while (!*done) {
-		__atomic_add_fetch(lock, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_add(lock, 1, __ATOMIC_RELAXED);
 		rte_delay_us(500);
 		if (__atomic_load_n(lock, __ATOMIC_RELAXED) > 1)
 			/* pass: second core has simultaneously incremented */
 			*done = 1;
-		__atomic_sub_fetch(lock, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(lock, 1, __ATOMIC_RELAXED);
 	}
 
 	return 0;
Signature · 1 line
1.8.3.1
#20 lore raw

PATCH 14/17 dma/skeleton: 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 drivers/dma/skeleton/skeleton_dmadev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/skeleton/skeleton_dmadev.c +1 -1
index 9b6da65..43e7052 100644
@@ -77,7 +77,7 @@
 
 		hw->zero_req_count = 0;
 		rte_memcpy(desc->dst, desc->src, desc->len);
-		__atomic_add_fetch(&hw->completed_count, 1, __ATOMIC_RELEASE);
+		__atomic_fetch_add(&hw->completed_count, 1, __ATOMIC_RELEASE);
 		(void)rte_ring_enqueue(hw->desc_completed, (void *)desc);
 	}
 
Signature · 1 line
1.8.3.1
#14 lore raw

PATCH 10/17 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 drivers/net/mlx5/linux/mlx5_verbs.c |  2 +-
 drivers/net/mlx5/mlx5_flow.c        |  6 +++---
 drivers/net/mlx5/mlx5_flow_dv.c     |  4 ++--
 drivers/net/mlx5/mlx5_flow_flex.c   |  6 +++---
 drivers/net/mlx5/mlx5_flow_hw.c     | 10 +++++-----
 drivers/net/mlx5/mlx5_flow_meter.c  | 20 ++++++++++----------
 drivers/net/mlx5/mlx5_rx.h          |  2 +-
 7 files changed, 25 insertions(+), 25 deletions(-)
drivers/net/mlx5/linux/mlx5_verbs.c +1 -1
index 67a7bec..c722613 100644
@@ -1159,7 +1159,7 @@
 		claim_zero(mlx5_glue->destroy_cq(sh->self_lb.ibv_cq));
 		sh->self_lb.ibv_cq = NULL;
 	}
-	(void)__atomic_sub_fetch(&sh->self_lb.refcnt, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_sub(&sh->self_lb.refcnt, 1, __ATOMIC_RELAXED);
 	return -rte_errno;
 #else
 	RTE_SET_USED(dev);
drivers/net/mlx5/mlx5_flow.c +3 -3
index a6a426c..1c51b29 100644
@@ -4451,7 +4451,7 @@ struct mlx5_translated_action_handle {
 			shared_rss = mlx5_ipool_get
 				(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
 									   idx);
-			__atomic_add_fetch(&shared_rss->refcnt, 1,
+			__atomic_fetch_add(&shared_rss->refcnt, 1,
 					   __ATOMIC_RELAXED);
 			return idx;
 		default:
@@ -7295,7 +7295,7 @@ struct mlx5_list_entry *
 	if (tunnel) {
 		flow->tunnel = 1;
 		flow->tunnel_id = tunnel->tunnel_id;
-		__atomic_add_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_add(&tunnel->refctn, 1, __ATOMIC_RELAXED);
 		mlx5_free(default_miss_ctx.queue);
 	}
 	mlx5_flow_pop_thread_workspace();
@@ -7306,7 +7306,7 @@ struct mlx5_list_entry *
 	flow_mreg_del_copy_action(dev, flow);
 	flow_drv_destroy(dev, flow);
 	if (rss_desc->shared_rss)
-		__atomic_sub_fetch(&((struct mlx5_shared_action_rss *)
+		__atomic_fetch_sub(&((struct mlx5_shared_action_rss *)
 			mlx5_ipool_get
 			(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
 			rss_desc->shared_rss))->refcnt, 1, __ATOMIC_RELAXED);
drivers/net/mlx5/mlx5_flow_dv.c +2 -2
index f93dd40..0233cde 100644
@@ -15143,7 +15143,7 @@ struct mlx5_list_entry *
 
 	shared_rss = mlx5_ipool_get
 			(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
-	__atomic_sub_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_sub(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
 }
 
 void
@@ -15734,7 +15734,7 @@ struct mlx5_list_entry *
 	/* Update queue with indirect table queue memoyr. */
 	origin->queue = shared_rss->ind_tbl->queues;
 	rte_spinlock_init(&shared_rss->action_rss_sl);
-	__atomic_add_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
 	rte_spinlock_lock(&priv->shared_act_sl);
 	ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
 		     &priv->rss_shared_actions, idx, shared_rss, next);
drivers/net/mlx5/mlx5_flow_flex.c +3 -3
index 35f2a99..a825274 100644
@@ -301,7 +301,7 @@
 		return ret;
 	}
 	if (acquire)
-		__atomic_add_fetch(&flex->refcnt, 1, __ATOMIC_RELEASE);
+		__atomic_fetch_add(&flex->refcnt, 1, __ATOMIC_RELEASE);
 	return ret;
 }
 
@@ -336,7 +336,7 @@
 		rte_errno = -EINVAL;
 		return -EINVAL;
 	}
-	__atomic_sub_fetch(&flex->refcnt, 1, __ATOMIC_RELEASE);
+	__atomic_fetch_sub(&flex->refcnt, 1, __ATOMIC_RELEASE);
 	return 0;
 }
 
@@ -1220,7 +1220,7 @@ struct rte_flow_item_flex_handle *
 	}
 	flex->devx_fp = container_of(ent, struct mlx5_flex_parser_devx, entry);
 	/* Mark initialized flex item valid. */
-	__atomic_add_fetch(&flex->refcnt, 1, __ATOMIC_RELEASE);
+	__atomic_fetch_add(&flex->refcnt, 1, __ATOMIC_RELEASE);
 	return (struct rte_flow_item_flex_handle *)flex;
 
 error:
drivers/net/mlx5/mlx5_flow_hw.c +5 -5
index a9c7045..159ebb5 100644
@@ -1406,7 +1406,7 @@ static rte_be32_t vlan_hdr_to_be32(const struct rte_flow_action *actions)
 				goto err;
 			acts->rule_acts[action_pos].action =
 				priv->hw_tag[!!attr->group];
-			__atomic_add_fetch(&priv->hws_mark_refcnt, 1, __ATOMIC_RELAXED);
+			__atomic_fetch_add(&priv->hws_mark_refcnt, 1, __ATOMIC_RELAXED);
 			flow_hw_rxq_flag_set(dev, true);
 			break;
 		case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
@@ -3162,13 +3162,13 @@ static rte_be32_t vlan_hdr_to_be32(const struct rte_flow_action *actions)
 at_error:
 	while (i--) {
 		__flow_hw_action_template_destroy(dev, &tbl->ats[i].acts);
-		__atomic_sub_fetch(&action_templates[i]->refcnt,
+		__atomic_fetch_sub(&action_templates[i]->refcnt,
 				   1, __ATOMIC_RELAXED);
 	}
 	i = nb_item_templates;
 it_error:
 	while (i--)
-		__atomic_sub_fetch(&item_templates[i]->refcnt,
+		__atomic_fetch_sub(&item_templates[i]->refcnt,
 				   1, __ATOMIC_RELAXED);
 error:
 	err = rte_errno;
@@ -3361,11 +3361,11 @@ static rte_be32_t vlan_hdr_to_be32(const struct rte_flow_action *actions)
 	}
 	LIST_REMOVE(table, next);
 	for (i = 0; i < table->nb_item_templates; i++)
-		__atomic_sub_fetch(&table->its[i]->refcnt,
+		__atomic_fetch_sub(&table->its[i]->refcnt,
 				   1, __ATOMIC_RELAXED);
 	for (i = 0; i < table->nb_action_templates; i++) {
 		__flow_hw_action_template_destroy(dev, &table->ats[i].acts);
-		__atomic_sub_fetch(&table->ats[i].action_template->refcnt,
+		__atomic_fetch_sub(&table->ats[i].action_template->refcnt,
 				   1, __ATOMIC_RELAXED);
 	}
 	mlx5dr_matcher_destroy(table->matcher);
drivers/net/mlx5/mlx5_flow_meter.c +10 -10
index 08f8aad..cb26a12 100644
@@ -1788,7 +1788,7 @@ struct mlx5_flow_meter_policy *
 			NULL, "Meter profile id not valid.");
 	/* Meter policy must exist. */
 	if (params->meter_policy_id == priv->sh->mtrmng->def_policy_id) {
-		__atomic_add_fetch
+		__atomic_fetch_add
 			(&priv->sh->mtrmng->def_policy_ref_cnt,
 			1, __ATOMIC_RELAXED);
 		domain_bitmap = MLX5_MTR_ALL_DOMAIN_BIT;
@@ -1870,7 +1870,7 @@ struct mlx5_flow_meter_policy *
 	fm->is_enable = params->meter_enable;
 	fm->shared = !!shared;
 	fm->color_aware = !!params->use_prev_mtr_color;
-	__atomic_add_fetch(&fm->profile->ref_cnt, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&fm->profile->ref_cnt, 1, __ATOMIC_RELAXED);
 	if (params->meter_policy_id == priv->sh->mtrmng->def_policy_id) {
 		fm->def_policy = 1;
 		fm->flow_ipool = mlx5_ipool_create(&flow_ipool_cfg);
@@ -1899,7 +1899,7 @@ struct mlx5_flow_meter_policy *
 	}
 	fm->active_state = params->meter_enable;
 	if (mtr_policy)
-		__atomic_add_fetch(&mtr_policy->ref_cnt, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_add(&mtr_policy->ref_cnt, 1, __ATOMIC_RELAXED);
 	return 0;
 error:
 	mlx5_flow_destroy_mtr_tbls(dev, fm);
@@ -1994,8 +1994,8 @@ struct mlx5_flow_meter_policy *
 			RTE_MTR_ERROR_TYPE_UNSPECIFIED,
 			NULL, "Failed to create devx meter.");
 	fm->active_state = params->meter_enable;
-	__atomic_add_fetch(&fm->profile->ref_cnt, 1, __ATOMIC_RELAXED);
-	__atomic_add_fetch(&policy->ref_cnt, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&fm->profile->ref_cnt, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&policy->ref_cnt, 1, __ATOMIC_RELAXED);
 	return 0;
 }
 
@@ -2017,7 +2017,7 @@ struct mlx5_flow_meter_policy *
 	if (fmp == NULL)
 		return -1;
 	/* Update dependencies. */
-	__atomic_sub_fetch(&fmp->ref_cnt, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_sub(&fmp->ref_cnt, 1, __ATOMIC_RELAXED);
 	fm->profile = NULL;
 	/* Remove from list. */
 	if (!priv->sh->meter_aso_en) {
@@ -2035,14 +2035,14 @@ struct mlx5_flow_meter_policy *
 	}
 	mlx5_flow_destroy_mtr_tbls(dev, fm);
 	if (fm->def_policy)
-		__atomic_sub_fetch(&priv->sh->mtrmng->def_policy_ref_cnt,
+		__atomic_fetch_sub(&priv->sh->mtrmng->def_policy_ref_cnt,
 				1, __ATOMIC_RELAXED);
 	if (priv->sh->meter_aso_en) {
 		if (!fm->def_policy) {
 			mtr_policy = mlx5_flow_meter_policy_find(dev,
 						fm->policy_id, NULL);
 			if (mtr_policy)
-				__atomic_sub_fetch(&mtr_policy->ref_cnt,
+				__atomic_fetch_sub(&mtr_policy->ref_cnt,
 						1, __ATOMIC_RELAXED);
 			fm->policy_id = 0;
 		}
@@ -2146,12 +2146,12 @@ struct mlx5_flow_meter_policy *
 					  RTE_MTR_ERROR_TYPE_UNSPECIFIED,
 					  NULL, "Meter object is being used.");
 	/* Destroy the meter profile. */
-	__atomic_sub_fetch(&fm->profile->ref_cnt,
+	__atomic_fetch_sub(&fm->profile->ref_cnt,
 						1, __ATOMIC_RELAXED);
 	/* Destroy the meter policy. */
 	policy = mlx5_flow_meter_policy_find(dev,
 			fm->policy_id, NULL);
-	__atomic_sub_fetch(&policy->ref_cnt,
+	__atomic_fetch_sub(&policy->ref_cnt,
 						1, __ATOMIC_RELAXED);
 	memset(fm, 0, sizeof(struct mlx5_flow_meter_info));
 	return 0;
drivers/net/mlx5/mlx5_rx.h +1 -1
index 6b42e27..ba62398 100644
@@ -539,7 +539,7 @@ uint16_t mlx5_rx_burst_mprq_vec(void *dpdk_rxq, struct rte_mbuf **pkts,
 		void *buf_addr;
 
 		/* Increment the refcnt of the whole chunk. */
-		__atomic_add_fetch(&buf->refcnt, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_add(&buf->refcnt, 1, __ATOMIC_RELAXED);
 		MLX5_ASSERT(__atomic_load_n(&buf->refcnt,
 			    __ATOMIC_RELAXED) <= strd_n + 1);
 		buf_addr = RTE_PTR_SUB(addr, RTE_PKTMBUF_HEADROOM);
Signature · 1 line
1.8.3.1
#19 lore raw

PATCH 13/17 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 drivers/event/cnxk/cnxk_eventdev_selftest.c | 12 ++++++------
 drivers/event/cnxk/cnxk_tim_worker.h        |  6 +++---
 drivers/event/dsw/dsw_event.c               |  6 +++---
 drivers/event/octeontx/timvf_worker.h       |  6 +++---
 4 files changed, 15 insertions(+), 15 deletions(-)
drivers/event/cnxk/cnxk_eventdev_selftest.c +6 -6
index 577c99b..95c0f1b 100644
@@ -554,7 +554,7 @@ typedef int (*validate_event_cb)(uint32_t index, uint8_t port,
 		ret = validate_event(&ev);
 		RTE_TEST_ASSERT_SUCCESS(ret, "Failed to validate event");
 		rte_pktmbuf_free(ev.mbuf);
-		__atomic_sub_fetch(total_events, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(total_events, 1, __ATOMIC_RELAXED);
 	}
 
 	return 0;
@@ -916,7 +916,7 @@ typedef int (*validate_event_cb)(uint32_t index, uint8_t port,
 
 			if (seqn_list_update(seqn) == 0) {
 				rte_pktmbuf_free(ev.mbuf);
-				__atomic_sub_fetch(total_events, 1,
+				__atomic_fetch_sub(total_events, 1,
 						   __ATOMIC_RELAXED);
 			} else {
 				plt_err("Failed to update seqn_list");
@@ -1072,7 +1072,7 @@ typedef int (*validate_event_cb)(uint32_t index, uint8_t port,
 
 			if (seqn_list_update(seqn) == 0) {
 				rte_pktmbuf_free(ev.mbuf);
-				__atomic_sub_fetch(total_events, 1,
+				__atomic_fetch_sub(total_events, 1,
 						   __ATOMIC_RELAXED);
 			} else {
 				plt_err("Failed to update seqn_list");
@@ -1217,7 +1217,7 @@ typedef int (*validate_event_cb)(uint32_t index, uint8_t port,
 
 		if (ev.sub_event_type == MAX_STAGES) { /* last stage */
 			rte_pktmbuf_free(ev.mbuf);
-			__atomic_sub_fetch(total_events, 1, __ATOMIC_RELAXED);
+			__atomic_fetch_sub(total_events, 1, __ATOMIC_RELAXED);
 		} else {
 			ev.event_type = RTE_EVENT_TYPE_CPU;
 			ev.sub_event_type++;
@@ -1293,7 +1293,7 @@ typedef int (*validate_event_cb)(uint32_t index, uint8_t port,
 
 		if (ev.queue_id == nr_queues - 1) { /* last stage */
 			rte_pktmbuf_free(ev.mbuf);
-			__atomic_sub_fetch(total_events, 1, __ATOMIC_RELAXED);
+			__atomic_fetch_sub(total_events, 1, __ATOMIC_RELAXED);
 		} else {
 			ev.event_type = RTE_EVENT_TYPE_CPU;
 			ev.queue_id++;
@@ -1338,7 +1338,7 @@ typedef int (*validate_event_cb)(uint32_t index, uint8_t port,
 
 		if (ev.queue_id == nr_queues - 1) { /* Last stage */
 			rte_pktmbuf_free(ev.mbuf);
-			__atomic_sub_fetch(total_events, 1, __ATOMIC_RELAXED);
+			__atomic_fetch_sub(total_events, 1, __ATOMIC_RELAXED);
 		} else {
 			ev.event_type = RTE_EVENT_TYPE_CPU;
 			ev.queue_id++;
drivers/event/cnxk/cnxk_tim_worker.h +3 -3
index a326d55..c087fe5 100644
@@ -102,19 +102,19 @@
 static inline void
 cnxk_tim_bkt_inc_nent(struct cnxk_tim_bkt *bktp)
 {
-	__atomic_add_fetch(&bktp->nb_entry, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&bktp->nb_entry, 1, __ATOMIC_RELAXED);
 }
 
 static inline void
 cnxk_tim_bkt_add_nent_relaxed(struct cnxk_tim_bkt *bktp, uint32_t v)
 {
-	__atomic_add_fetch(&bktp->nb_entry, v, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&bktp->nb_entry, v, __ATOMIC_RELAXED);
 }
 
 static inline void
 cnxk_tim_bkt_add_nent(struct cnxk_tim_bkt *bktp, uint32_t v)
 {
-	__atomic_add_fetch(&bktp->nb_entry, v, __ATOMIC_RELEASE);
+	__atomic_fetch_add(&bktp->nb_entry, v, __ATOMIC_RELEASE);
 }
 
 static inline uint64_t
drivers/event/dsw/dsw_event.c +3 -3
index 9932caf..89badca 100644
@@ -50,7 +50,7 @@
 
 	if (unlikely(new_total_on_loan > dsw->max_inflight)) {
 		/* Some other port took the last credits */
-		__atomic_sub_fetch(&dsw->credits_on_loan, acquired_credits,
+		__atomic_fetch_sub(&dsw->credits_on_loan, acquired_credits,
 				   __ATOMIC_RELAXED);
 		return false;
 	}
@@ -77,7 +77,7 @@
 
 		port->inflight_credits = leave_credits;
 
-		__atomic_sub_fetch(&dsw->credits_on_loan, return_credits,
+		__atomic_fetch_sub(&dsw->credits_on_loan, return_credits,
 				   __ATOMIC_RELAXED);
 
 		DSW_LOG_DP_PORT(DEBUG, port->id,
@@ -527,7 +527,7 @@ struct dsw_queue_flow_burst {
 	target_qfs[*targets_len] = *candidate_qf;
 	(*targets_len)++;
 
-	__atomic_add_fetch(&dsw->ports[candidate_port_id].immigration_load,
+	__atomic_fetch_add(&dsw->ports[candidate_port_id].immigration_load,
 			   candidate_flow_load, __ATOMIC_RELAXED);
 
 	return true;
drivers/event/octeontx/timvf_worker.h +3 -3
index 3f1e77f..ad98ca0 100644
@@ -108,7 +108,7 @@
 static inline void
 timr_bkt_dec_lock(struct tim_mem_bucket *bktp)
 {
-	__atomic_add_fetch(&bktp->lock, 0xff, __ATOMIC_ACQ_REL);
+	__atomic_fetch_add(&bktp->lock, 0xff, __ATOMIC_ACQ_REL);
 }
 
 static inline uint32_t
@@ -121,13 +121,13 @@
 static inline void
 timr_bkt_inc_nent(struct tim_mem_bucket *bktp)
 {
-	__atomic_add_fetch(&bktp->nb_entry, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&bktp->nb_entry, 1, __ATOMIC_RELAXED);
 }
 
 static inline void
 timr_bkt_add_nent(struct tim_mem_bucket *bktp, uint32_t v)
 {
-	__atomic_add_fetch(&bktp->nb_entry, v, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&bktp->nb_entry, v, __ATOMIC_RELAXED);
 }
 
 static inline uint64_t
Signature · 1 line
1.8.3.1
#16 lore raw

RE: [PATCH 11/17] net/iavf: use previous value atomic fetch operations

In reply to Tyler Retzlaff
Quoted 45 lines

-----Original Message-----
From: Tyler Retzlaff <[email protected]>
Sent: Thursday, March 2, 2023 8:48 AM
To: [email protected]
Cc: Honnappa Nagarahalli <[email protected]>; [email protected]; Tyler Retzlaff <[email protected]>
Subject: [PATCH 11/17] net/iavf: use previous value atomic fetch operations

Use __atomic_fetch_{add,and,or,sub,xor} instead of __atomic_{add,and,or,sub,xor}_fetch when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 drivers/net/iavf/iavf_vchnl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/iavf/iavf_vchnl.c index renamed from drivers/net/iavf/iavf_vchnl.c +0 -0

9adaadb..73875d7 100644

drivers/net/iavf/iavf_vchnl.c +2 -2
@@ -128,7 +128,7 @@ struct iavf_event_handler {
 	int err = pipe(handler->fd);
 #endif
 	if (err != 0) {
-		__atomic_sub_fetch(&handler->ndev, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED);
 		return -1;
 	}
 
@@ -137,7 +137,7 @@ struct iavf_event_handler {
 
 	if (rte_ctrl_thread_create(&handler->tid, "iavf-event-thread",
 				NULL, iavf_dev_event_handle, NULL)) {
-		__atomic_sub_fetch(&handler->ndev, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED);
 		return -1;
 	}
 

drivers/net/iavf/iavf_vchnl.c struct iavf_event_handler { · line 536

Quoted 5 lines
drivers/net/iavf/iavf_vchnl.c +1 -1
@@ -533,7 +533,7 @@ 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,
+					__atomic_fetch_sub(&vf->pend_cmd_count,

It doesn't apply here. The return value is used.
The rest of the series looks good to me.

Quoted 5 lines
drivers/net/iavf/iavf_vchnl.c +0 -1
 							1, __ATOMIC_RELAXED);
 					if (cmd_count == 0)
 						_notify_cmd(vf, msg_ret);
--

1.8.3.1

Acked-by on v1 2/17
#4 lore raw

Re: [PATCH 02/17] telemetry: use previous value atomic fetch operations

In reply to Tyler Retzlaff
Quoted 4 lines · Tyler Retzlaff

Use __atomic_fetch_{add,and,or,sub,xor} instead of __atomic_{add,and,or,sub,xor}_fetch when we have no interest in the result of the operation.

Quoted 8 lines

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---

#24 lore raw
In reply to Tyler Retzlaff
Quoted 6 lines

From: Tyler Retzlaff [mailto:[email protected]]
Sent: Thursday, 2 March 2023 01.48
To: [email protected]
Cc: [email protected]; [email protected]; Tyler Retzlaff
Subject: [PATCH 00/17] use __atomic operations returning previous value

Quoted 8 lines

This series replaces uses of __atomic_{add,and,or,sub,xor}_fetch with __atomic_fetch_{add,and,or,sub,xor} intrinsics. The latter omits generation of code that is only needed if the returned value is actually used.

Additionally, this change simplifies adapting dpdk to standard atomics planned for 23.07 since __atomic_fetch_xxx can be trivially replaced with atomic_fetch_xxx whereas __atomic_xxx_fetch has no standard equivalent.

Reviewed-by on v1 1/17
#2 lore raw

Re: [PATCH 01/17] vhost: use previous value atomic fetch operations

In reply to Tyler Retzlaff
Quoted 38 lines · Tyler Retzlaff

Use __atomic_fetch_{add,and,or,sub,xor} instead of __atomic_{add,and,or,sub,xor}_fetch when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
  lib/vhost/virtio_net.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
lib/vhost/virtio_net.c +2 -2
index 51dc3c9..dc49a54 100644
@@ -298,7 +298,7 @@
 
  	vhost_log_cache_sync(dev, vq);
 
-	__atomic_add_fetch(&vq->used->idx, vq->shadow_used_idx,
+	__atomic_fetch_add(&vq->used->idx, vq->shadow_used_idx,
  			   __ATOMIC_RELEASE);
  	vq->shadow_used_idx = 0;
  	vhost_log_used_vring(dev, vq, offsetof(struct vring_used, idx),
@@ -2311,7 +2311,7 @@
  			vhost_vring_call_packed(dev, vq);
  		} else {
  			write_back_completed_descs_split(vq, n_descs);
-			__atomic_add_fetch(&vq->used->idx, n_descs, __ATOMIC_RELEASE);
+			__atomic_fetch_add(&vq->used->idx, n_descs, __ATOMIC_RELEASE);
  			vhost_vring_call_split(dev, vq);
  		}
  	} else {

lib/vhost/virtio_net.c line 3689

Quoted 8 lines
lib/vhost/virtio_net.c +1 -1
@@ -3683,7 +3683,7 @@
  		vhost_vring_call_packed(dev, vq);
  	} else {
  		write_back_completed_descs_split(vq, nr_cpl_pkts);
-		__atomic_add_fetch(&vq->used->idx, nr_cpl_pkts, __ATOMIC_RELEASE);
+		__atomic_fetch_add(&vq->used->idx, nr_cpl_pkts, __ATOMIC_RELEASE);
  		vhost_vring_call_split(dev, vq);
  	}
  	vq->async->pkts_inflight_n -= nr_cpl_pkts;

Thanks,
Maxime

Reviewed-by on v1 7/17
#10 lore raw

Re: [PATCH 07/17] examples/vhost: use previous value atomic fetch operations

In reply to Tyler Retzlaff
Quoted 70 lines · Tyler Retzlaff

Use __atomic_fetch_{add,and,or,sub,xor} instead of __atomic_{add,and,or,sub,xor}_fetch when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
  examples/vhost/main.c       | 12 ++++++------
  examples/vhost/virtio_net.c |  4 ++--
  2 files changed, 8 insertions(+), 8 deletions(-)
examples/vhost/main.c +6 -6
index 42e53a0..bfe466f 100644
@@ -1048,9 +1048,9 @@ static unsigned check_ports_num(unsigned nb_ports)
  	}
 
  	if (enable_stats) {
-		__atomic_add_fetch(&dst_vdev->stats.rx_total_atomic, 1,
+		__atomic_fetch_add(&dst_vdev->stats.rx_total_atomic, 1,
  				__ATOMIC_SEQ_CST);
-		__atomic_add_fetch(&dst_vdev->stats.rx_atomic, ret,
+		__atomic_fetch_add(&dst_vdev->stats.rx_atomic, ret,
  				__ATOMIC_SEQ_CST);
  		src_vdev->stats.tx_total++;
  		src_vdev->stats.tx += ret;
@@ -1068,9 +1068,9 @@ static unsigned check_ports_num(unsigned nb_ports)
  	ret = vdev_queue_ops[vdev->vid].enqueue_pkt_burst(vdev, VIRTIO_RXQ, m, nr_xmit);
 
  	if (enable_stats) {
-		__atomic_add_fetch(&vdev->stats.rx_total_atomic, nr_xmit,
+		__atomic_fetch_add(&vdev->stats.rx_total_atomic, nr_xmit,
  				__ATOMIC_SEQ_CST);
-		__atomic_add_fetch(&vdev->stats.rx_atomic, ret,
+		__atomic_fetch_add(&vdev->stats.rx_atomic, ret,
  				__ATOMIC_SEQ_CST);
  	}
 
@@ -1400,9 +1400,9 @@ static void virtio_tx_offload(struct rte_mbuf *m)
  	}
 
  	if (enable_stats) {
-		__atomic_add_fetch(&vdev->stats.rx_total_atomic, rx_count,
+		__atomic_fetch_add(&vdev->stats.rx_total_atomic, rx_count,
  				__ATOMIC_SEQ_CST);
-		__atomic_add_fetch(&vdev->stats.rx_atomic, enqueue_count,
+		__atomic_fetch_add(&vdev->stats.rx_atomic, enqueue_count,
  				__ATOMIC_SEQ_CST);
  	}
 
examples/vhost/virtio_net.c +1 -1
index 1d4737f..514c8e0 100644
@@ -231,7 +231,7 @@
  			rte_prefetch0(&vr->desc[desc_indexes[i+1]]);
  	}
 
-	__atomic_add_fetch(&vr->used->idx, count, __ATOMIC_RELEASE);
+	__atomic_fetch_add(&vr->used->idx, count, __ATOMIC_RELEASE);
  	queue->last_used_idx += count;
 
  	rte_vhost_vring_call(dev->vid, queue_id);

examples/vhost/virtio_net.c line 448

Quoted 8 lines
examples/vhost/virtio_net.c +1 -1
@@ -442,7 +442,7 @@
  	queue->last_avail_idx += i;
  	queue->last_used_idx += i;
 
-	__atomic_add_fetch(&vr->used->idx, i, __ATOMIC_ACQ_REL);
+	__atomic_fetch_add(&vr->used->idx, i, __ATOMIC_ACQ_REL);
 
  	rte_vhost_vring_call(dev->vid, queue_id);
 

Thanks,
Maxime

Reviewed-by on v1 8/17
#12 lore raw

Re: [PATCH 08/17] net/virtio: use previous value atomic fetch operations

In reply to Tyler Retzlaff
Quoted 20 lines · Tyler Retzlaff

Use __atomic_fetch_{add,and,or,sub,xor} instead of __atomic_{add,and,or,sub,xor}_fetch when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
  drivers/net/virtio/virtio_user/virtio_user_dev.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +0 -0
index f46a131..2b4607a 100644

drivers/net/virtio/virtio_user/virtio_user_dev.c int virtio_user_stop_device(struct virtio_user_dev *dev) · line 1031

Quoted 8 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +1 -1
@@ -1025,7 +1025,7 @@ int virtio_user_stop_device(struct virtio_user_dev *dev)
  		uep->id = desc_idx;
  		uep->len = n_descs;
 
-		__atomic_add_fetch(&vring->used->idx, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_add(&vring->used->idx, 1, __ATOMIC_RELAXED);
  	}
  }
 

Thanks,
Maxime

#17 lore raw

Re: [PATCH 11/17] net/iavf: use previous value atomic fetch operations

In reply to Ruifeng Wang
Quoted 44 lines · Ruifeng Wang
Quoted 44 lines

-----Original Message-----
From: Tyler Retzlaff <[email protected]>
Sent: Thursday, March 2, 2023 8:48 AM
To: [email protected]
Cc: Honnappa Nagarahalli <[email protected]>; [email protected]; Tyler Retzlaff <[email protected]>
Subject: [PATCH 11/17] net/iavf: use previous value atomic fetch operations

Use __atomic_fetch_{add,and,or,sub,xor} instead of __atomic_{add,and,or,sub,xor}_fetch when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 drivers/net/iavf/iavf_vchnl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/iavf/iavf_vchnl.c index renamed from drivers/net/iavf/iavf_vchnl.c +0 -0

9adaadb..73875d7 100644

drivers/net/iavf/iavf_vchnl.c +2 -2
@@ -128,7 +128,7 @@ struct iavf_event_handler {
 	int err = pipe(handler->fd);
 #endif
 	if (err != 0) {
-		__atomic_sub_fetch(&handler->ndev, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED);
 		return -1;
 	}
 
@@ -137,7 +137,7 @@ struct iavf_event_handler {
 
 	if (rte_ctrl_thread_create(&handler->tid, "iavf-event-thread",
 				NULL, iavf_dev_event_handle, NULL)) {
-		__atomic_sub_fetch(&handler->ndev, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED);
 		return -1;
 	}
 
Quoted 9 lines

drivers/net/iavf/iavf_vchnl.c struct iavf_event_handler { · line 536

Quoted 6 lines
drivers/net/iavf/iavf_vchnl.c +1 -1
@@ -533,7 +533,7 @@ 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,
+					__atomic_fetch_sub(&vf->pend_cmd_count,

It doesn't apply here. The return value is used.
The rest of the series looks good to me.

oh, i was blind to the line wrapping. definitely not correct.

thanks for catching this, will submit v2 with it reverted.

Quoted 6 lines
Quoted 6 lines
drivers/net/iavf/iavf_vchnl.c +0 -1
 							1, __ATOMIC_RELAXED);
 					if (cmd_count == 0)
 						_notify_cmd(vf, msg_ret);
--

1.8.3.1

#26 lore raw

PATCH v2 1/17 vhost: 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 lib/vhost/virtio_net.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/vhost/virtio_net.c +3 -3
index 51dc3c9..dc49a54 100644
@@ -298,7 +298,7 @@
 
 	vhost_log_cache_sync(dev, vq);
 
-	__atomic_add_fetch(&vq->used->idx, vq->shadow_used_idx,
+	__atomic_fetch_add(&vq->used->idx, vq->shadow_used_idx,
 			   __ATOMIC_RELEASE);
 	vq->shadow_used_idx = 0;
 	vhost_log_used_vring(dev, vq, offsetof(struct vring_used, idx),
@@ -2311,7 +2311,7 @@
 			vhost_vring_call_packed(dev, vq);
 		} else {
 			write_back_completed_descs_split(vq, n_descs);
-			__atomic_add_fetch(&vq->used->idx, n_descs, __ATOMIC_RELEASE);
+			__atomic_fetch_add(&vq->used->idx, n_descs, __ATOMIC_RELEASE);
 			vhost_vring_call_split(dev, vq);
 		}
 	} else {
@@ -3683,7 +3683,7 @@
 		vhost_vring_call_packed(dev, vq);
 	} else {
 		write_back_completed_descs_split(vq, nr_cpl_pkts);
-		__atomic_add_fetch(&vq->used->idx, nr_cpl_pkts, __ATOMIC_RELEASE);
+		__atomic_fetch_add(&vq->used->idx, nr_cpl_pkts, __ATOMIC_RELEASE);
 		vhost_vring_call_split(dev, vq);
 	}
 	vq->async->pkts_inflight_n -= nr_cpl_pkts;
Signature · 1 line
1.8.3.1
#27 lore raw

PATCH v2 2/17 telemetry: 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 lib/telemetry/telemetry.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/telemetry/telemetry.c +3 -3
index 7bceadc..deba7f3 100644
@@ -391,7 +391,7 @@ struct socket {
 		bytes = read(s, buffer, sizeof(buffer) - 1);
 	}
 	close(s);
-	__atomic_sub_fetch(&v2_clients, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_sub(&v2_clients, 1, __ATOMIC_RELAXED);
 	return NULL;
 }
 
@@ -414,7 +414,7 @@ struct socket {
 				close(s_accepted);
 				continue;
 			}
-			__atomic_add_fetch(s->num_clients, 1,
+			__atomic_fetch_add(s->num_clients, 1,
 					__ATOMIC_RELAXED);
 		}
 		rc = pthread_create(&th, NULL, s->fn,
@@ -424,7 +424,7 @@ struct socket {
 				 strerror(rc));
 			close(s_accepted);
 			if (s->num_clients != NULL)
-				__atomic_sub_fetch(s->num_clients, 1,
+				__atomic_fetch_sub(s->num_clients, 1,
 						   __ATOMIC_RELAXED);
 			continue;
 		}
Signature · 1 line
1.8.3.1
#25 lore raw

v2 cover use __atomic operations returning previous 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. The latter omits generation of code that is only needed if the returned value is actually used.

Additionally, this change simplifies adapting dpdk to standard atomics planned for 23.07 since __atomic_fetch_xxx can be trivially replaced with atomic_fetch_xxx whereas __atomic_xxx_fetch has no standard equivalent.

v2:
net/iavf patch had one incorrect change to __atomic_fetch_sub from __atomic_sub_fetch the new value was assigned to a variable on the previous line so revert the change from the patch.

Tyler Retzlaff (17):
vhost: use previous value atomic fetch operations
telemetry: use previous value atomic fetch operations
stack: use previous value atomic fetch operations
eal: use previous value atomic fetch operations
distributor: use previous value atomic fetch operations
bbdev: use previous value atomic fetch operations examples/vhost: use previous value atomic fetch operations net/virtio: use previous value atomic fetch operations net/octeontx: use previous value atomic fetch operations net/mlx5: use previous value atomic fetch operations net/iavf: use previous value atomic fetch operations net/cxgbe: use previous value atomic fetch operations drivers/event: use previous value atomic fetch operations dma/skeleton: use previous value atomic fetch operations drivers/common: use previous value atomic fetch operations app/test: use previous value atomic fetch operations
test-eventdev: use previous value atomic fetch operations

 app/test-eventdev/test_order_common.h            |  2 +-
 app/test/test_lcores.c                           |  2 +-
 app/test/test_service_cores.c                    |  4 ++--
 drivers/common/cnxk/roc_nix_inl_dev.c            |  2 +-
 drivers/common/mlx5/mlx5_common_mr.c             |  2 +-
 drivers/common/mlx5/mlx5_common_utils.c          | 10 +++++-----
 drivers/common/mlx5/mlx5_malloc.c                | 16 ++++++++--------
 drivers/dma/skeleton/skeleton_dmadev.c           |  2 +-
 drivers/event/cnxk/cnxk_eventdev_selftest.c      | 12 ++++++------
 drivers/event/cnxk/cnxk_tim_worker.h             |  6 +++---
 drivers/event/dsw/dsw_event.c                    |  6 +++---
 drivers/event/octeontx/timvf_worker.h            |  6 +++---
 drivers/net/cxgbe/clip_tbl.c                     |  2 +-
 drivers/net/cxgbe/cxgbe_main.c                   | 12 ++++++------
 drivers/net/cxgbe/l2t.c                          |  4 ++--
 drivers/net/cxgbe/mps_tcam.c                     |  2 +-
 drivers/net/cxgbe/smt.c                          |  4 ++--
 drivers/net/iavf/iavf_vchnl.c                    |  4 ++--
 drivers/net/mlx5/linux/mlx5_verbs.c              |  2 +-
 drivers/net/mlx5/mlx5_flow.c                     |  6 +++---
 drivers/net/mlx5/mlx5_flow_dv.c                  |  4 ++--
 drivers/net/mlx5/mlx5_flow_flex.c                |  6 +++---
 drivers/net/mlx5/mlx5_flow_hw.c                  | 10 +++++-----
 drivers/net/mlx5/mlx5_flow_meter.c               | 20 ++++++++++----------
 drivers/net/mlx5/mlx5_rx.h                       |  2 +-
 drivers/net/octeontx/octeontx_ethdev.c           |  2 +-
 drivers/net/virtio/virtio_user/virtio_user_dev.c |  2 +-
 examples/vhost/main.c                            | 12 ++++++------
 examples/vhost/virtio_net.c                      |  4 ++--
 lib/bbdev/rte_bbdev.c                            |  2 +-
 lib/distributor/rte_distributor.c                |  2 +-
 lib/eal/common/eal_common_trace.c                |  8 ++++----
 lib/eal/common/rte_service.c                     |  8 ++++----
 lib/eal/ppc/include/rte_atomic.h                 | 16 ++++++++--------
 lib/stack/rte_stack_lf_c11.h                     |  2 +-
 lib/telemetry/telemetry.c                        |  6 +++---
 lib/vhost/virtio_net.c                           |  6 +++---
 37 files changed, 109 insertions(+), 109 deletions(-)
Signature · 1 line
1.8.3.1
#28 lore raw

PATCH v2 3/17 stack: use previous value atomic fetch operations

Use __atomic_fetch_{add,and,or,sub,xor} instead of __atomic_{add,and,or,sub,xor}_fetch when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 lib/stack/rte_stack_lf_c11.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/stack/rte_stack_lf_c11.h +1 -1
index 8403196..687a6f6 100644
@@ -66,7 +66,7 @@
 	/* Ensure the stack modifications are not reordered with respect
 	 * to the LIFO len update.
 	 */
-	__atomic_add_fetch(&list->len, num, __ATOMIC_RELEASE);
+	__atomic_fetch_add(&list->len, num, __ATOMIC_RELEASE);
 }
 
 static __rte_always_inline struct rte_stack_lf_elem *
Signature · 1 line
1.8.3.1
#30 lore raw

PATCH v2 5/17 distributor: 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 lib/distributor/rte_distributor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/distributor/rte_distributor.c +1 -1
index 3969b2e..68840ce 100644
@@ -200,7 +200,7 @@
 	 * we won't read any mbufs from there even if GET_BUF is set.
 	 * This allows distributor to retrieve in-flight already sent packets.
 	 */
-	__atomic_or_fetch(&(buf->bufptr64[0]), RTE_DISTRIB_RETURN_BUF,
+	__atomic_fetch_or(&(buf->bufptr64[0]), RTE_DISTRIB_RETURN_BUF,
 		__ATOMIC_ACQ_REL);
 
 	/* set the RETURN_BUF on retptr64 even if we got no returns.
Signature · 1 line
1.8.3.1
#29 lore raw

PATCH v2 4/17 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 lib/eal/common/eal_common_trace.c |  8 ++++----
 lib/eal/common/rte_service.c      |  8 ++++----
 lib/eal/ppc/include/rte_atomic.h  | 16 ++++++++--------
 3 files changed, 16 insertions(+), 16 deletions(-)
lib/eal/common/eal_common_trace.c +4 -4
index 75162b7..cb980af 100644
@@ -103,10 +103,10 @@ struct trace_point_head *
 trace_mode_set(rte_trace_point_t *t, enum rte_trace_mode mode)
 {
 	if (mode == RTE_TRACE_MODE_OVERWRITE)
-		__atomic_and_fetch(t, ~__RTE_TRACE_FIELD_ENABLE_DISCARD,
+		__atomic_fetch_and(t, ~__RTE_TRACE_FIELD_ENABLE_DISCARD,
 			__ATOMIC_RELEASE);
 	else
-		__atomic_or_fetch(t, __RTE_TRACE_FIELD_ENABLE_DISCARD,
+		__atomic_fetch_or(t, __RTE_TRACE_FIELD_ENABLE_DISCARD,
 			__ATOMIC_RELEASE);
 }
 
@@ -155,7 +155,7 @@ rte_trace_mode rte_trace_mode_get(void)
 
 	prev = __atomic_fetch_or(t, __RTE_TRACE_FIELD_ENABLE_MASK, __ATOMIC_RELEASE);
 	if ((prev & __RTE_TRACE_FIELD_ENABLE_MASK) == 0)
-		__atomic_add_fetch(&trace.status, 1, __ATOMIC_RELEASE);
+		__atomic_fetch_add(&trace.status, 1, __ATOMIC_RELEASE);
 	return 0;
 }
 
@@ -169,7 +169,7 @@ rte_trace_mode rte_trace_mode_get(void)
 
 	prev = __atomic_fetch_and(t, ~__RTE_TRACE_FIELD_ENABLE_MASK, __ATOMIC_RELEASE);
 	if ((prev & __RTE_TRACE_FIELD_ENABLE_MASK) != 0)
-		__atomic_sub_fetch(&trace.status, 1, __ATOMIC_RELEASE);
+		__atomic_fetch_sub(&trace.status, 1, __ATOMIC_RELEASE);
 	return 0;
 }
 
lib/eal/common/rte_service.c +4 -4
index 42ca1d0..7ab48f2 100644
@@ -464,11 +464,11 @@ struct core_state {
 	/* Increment num_mapped_cores to reflect that this core is
 	 * now mapped capable of running the service.
 	 */
-	__atomic_add_fetch(&s->num_mapped_cores, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&s->num_mapped_cores, 1, __ATOMIC_RELAXED);
 
 	int ret = service_run(id, cs, UINT64_MAX, s, serialize_mt_unsafe);
 
-	__atomic_sub_fetch(&s->num_mapped_cores, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_sub(&s->num_mapped_cores, 1, __ATOMIC_RELAXED);
 
 	return ret;
 }
@@ -638,12 +638,12 @@ struct core_state {
 
 		if (*set && !lcore_mapped) {
 			lcore_states[lcore].service_mask |= sid_mask;
-			__atomic_add_fetch(&rte_services[sid].num_mapped_cores,
+			__atomic_fetch_add(&rte_services[sid].num_mapped_cores,
 				1, __ATOMIC_RELAXED);
 		}
 		if (!*set && lcore_mapped) {
 			lcore_states[lcore].service_mask &= ~(sid_mask);
-			__atomic_sub_fetch(&rte_services[sid].num_mapped_cores,
+			__atomic_fetch_sub(&rte_services[sid].num_mapped_cores,
 				1, __ATOMIC_RELAXED);
 		}
 	}
lib/eal/ppc/include/rte_atomic.h +8 -8
index 663b4d3..2ab735b 100644
@@ -60,13 +60,13 @@ static inline int rte_atomic16_test_and_set(rte_atomic16_t *v)
 static inline void
 rte_atomic16_inc(rte_atomic16_t *v)
 {
-	__atomic_add_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE);
+	__atomic_fetch_add(&v->cnt, 1, __ATOMIC_ACQUIRE);
 }
 
 static inline void
 rte_atomic16_dec(rte_atomic16_t *v)
 {
-	__atomic_sub_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE);
+	__atomic_fetch_sub(&v->cnt, 1, __ATOMIC_ACQUIRE);
 }
 
 static inline int rte_atomic16_inc_and_test(rte_atomic16_t *v)
@@ -102,13 +102,13 @@ static inline int rte_atomic32_test_and_set(rte_atomic32_t *v)
 static inline void
 rte_atomic32_inc(rte_atomic32_t *v)
 {
-	__atomic_add_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE);
+	__atomic_fetch_add(&v->cnt, 1, __ATOMIC_ACQUIRE);
 }
 
 static inline void
 rte_atomic32_dec(rte_atomic32_t *v)
 {
-	__atomic_sub_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE);
+	__atomic_fetch_sub(&v->cnt, 1, __ATOMIC_ACQUIRE);
 }
 
 static inline int rte_atomic32_inc_and_test(rte_atomic32_t *v)
@@ -157,25 +157,25 @@ static inline int rte_atomic32_dec_and_test(rte_atomic32_t *v)
 static inline void
 rte_atomic64_add(rte_atomic64_t *v, int64_t inc)
 {
-	__atomic_add_fetch(&v->cnt, inc, __ATOMIC_ACQUIRE);
+	__atomic_fetch_add(&v->cnt, inc, __ATOMIC_ACQUIRE);
 }
 
 static inline void
 rte_atomic64_sub(rte_atomic64_t *v, int64_t dec)
 {
-	__atomic_sub_fetch(&v->cnt, dec, __ATOMIC_ACQUIRE);
+	__atomic_fetch_sub(&v->cnt, dec, __ATOMIC_ACQUIRE);
 }
 
 static inline void
 rte_atomic64_inc(rte_atomic64_t *v)
 {
-	__atomic_add_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE);
+	__atomic_fetch_add(&v->cnt, 1, __ATOMIC_ACQUIRE);
 }
 
 static inline void
 rte_atomic64_dec(rte_atomic64_t *v)
 {
-	__atomic_sub_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE);
+	__atomic_fetch_sub(&v->cnt, 1, __ATOMIC_ACQUIRE);
 }
 
 static inline int64_t
Signature · 1 line
1.8.3.1
#32 lore raw

PATCH v2 7/17 examples/vhost: 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 examples/vhost/main.c       | 12 ++++++------
 examples/vhost/virtio_net.c |  4 ++--
 2 files changed, 8 insertions(+), 8 deletions(-)
examples/vhost/main.c +6 -6
index 42e53a0..bfe466f 100644
@@ -1048,9 +1048,9 @@ static unsigned check_ports_num(unsigned nb_ports)
 	}
 
 	if (enable_stats) {
-		__atomic_add_fetch(&dst_vdev->stats.rx_total_atomic, 1,
+		__atomic_fetch_add(&dst_vdev->stats.rx_total_atomic, 1,
 				__ATOMIC_SEQ_CST);
-		__atomic_add_fetch(&dst_vdev->stats.rx_atomic, ret,
+		__atomic_fetch_add(&dst_vdev->stats.rx_atomic, ret,
 				__ATOMIC_SEQ_CST);
 		src_vdev->stats.tx_total++;
 		src_vdev->stats.tx += ret;
@@ -1068,9 +1068,9 @@ static unsigned check_ports_num(unsigned nb_ports)
 	ret = vdev_queue_ops[vdev->vid].enqueue_pkt_burst(vdev, VIRTIO_RXQ, m, nr_xmit);
 
 	if (enable_stats) {
-		__atomic_add_fetch(&vdev->stats.rx_total_atomic, nr_xmit,
+		__atomic_fetch_add(&vdev->stats.rx_total_atomic, nr_xmit,
 				__ATOMIC_SEQ_CST);
-		__atomic_add_fetch(&vdev->stats.rx_atomic, ret,
+		__atomic_fetch_add(&vdev->stats.rx_atomic, ret,
 				__ATOMIC_SEQ_CST);
 	}
 
@@ -1400,9 +1400,9 @@ static void virtio_tx_offload(struct rte_mbuf *m)
 	}
 
 	if (enable_stats) {
-		__atomic_add_fetch(&vdev->stats.rx_total_atomic, rx_count,
+		__atomic_fetch_add(&vdev->stats.rx_total_atomic, rx_count,
 				__ATOMIC_SEQ_CST);
-		__atomic_add_fetch(&vdev->stats.rx_atomic, enqueue_count,
+		__atomic_fetch_add(&vdev->stats.rx_atomic, enqueue_count,
 				__ATOMIC_SEQ_CST);
 	}
 
examples/vhost/virtio_net.c +2 -2
index 1d4737f..514c8e0 100644
@@ -231,7 +231,7 @@
 			rte_prefetch0(&vr->desc[desc_indexes[i+1]]);
 	}
 
-	__atomic_add_fetch(&vr->used->idx, count, __ATOMIC_RELEASE);
+	__atomic_fetch_add(&vr->used->idx, count, __ATOMIC_RELEASE);
 	queue->last_used_idx += count;
 
 	rte_vhost_vring_call(dev->vid, queue_id);
@@ -442,7 +442,7 @@
 	queue->last_avail_idx += i;
 	queue->last_used_idx += i;
 
-	__atomic_add_fetch(&vr->used->idx, i, __ATOMIC_ACQ_REL);
+	__atomic_fetch_add(&vr->used->idx, i, __ATOMIC_ACQ_REL);
 
 	rte_vhost_vring_call(dev->vid, queue_id);
 
Signature · 1 line
1.8.3.1
#36 lore raw

PATCH v2 11/17 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 drivers/net/iavf/iavf_vchnl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/iavf/iavf_vchnl.c +2 -2
index 9adaadb..6c04bd2 100644
@@ -128,7 +128,7 @@ struct iavf_event_handler {
 	int err = pipe(handler->fd);
 #endif
 	if (err != 0) {
-		__atomic_sub_fetch(&handler->ndev, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED);
 		return -1;
 	}
 
@@ -137,7 +137,7 @@ struct iavf_event_handler {
 
 	if (rte_ctrl_thread_create(&handler->tid, "iavf-event-thread",
 				NULL, iavf_dev_event_handle, NULL)) {
-		__atomic_sub_fetch(&handler->ndev, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED);
 		return -1;
 	}
 
Signature · 1 line
1.8.3.1
#37 lore raw

PATCH v2 12/17 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 drivers/net/cxgbe/clip_tbl.c   |  2 +-
 drivers/net/cxgbe/cxgbe_main.c | 12 ++++++------
 drivers/net/cxgbe/l2t.c        |  4 ++--
 drivers/net/cxgbe/mps_tcam.c   |  2 +-
 drivers/net/cxgbe/smt.c        |  4 ++--
 5 files changed, 12 insertions(+), 12 deletions(-)
drivers/net/cxgbe/clip_tbl.c +1 -1
index 072fc74..ce715f2 100644
@@ -129,7 +129,7 @@ static struct clip_entry *t4_clip_alloc(struct rte_eth_dev *dev,
 				ce->type = FILTER_TYPE_IPV4;
 			}
 		} else {
-			__atomic_add_fetch(&ce->refcnt, 1, __ATOMIC_RELAXED);
+			__atomic_fetch_add(&ce->refcnt, 1, __ATOMIC_RELAXED);
 		}
 		t4_os_unlock(&ce->lock);
 	}
drivers/net/cxgbe/cxgbe_main.c +6 -6
index f8dd833..c479454 100644
@@ -418,14 +418,14 @@ void cxgbe_remove_tid(struct tid_info *t, unsigned int chan, unsigned int tid,
 
 	if (t->tid_tab[tid]) {
 		t->tid_tab[tid] = NULL;
-		__atomic_sub_fetch(&t->conns_in_use, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(&t->conns_in_use, 1, __ATOMIC_RELAXED);
 		if (t->hash_base && tid >= t->hash_base) {
 			if (family == FILTER_TYPE_IPV4)
-				__atomic_sub_fetch(&t->hash_tids_in_use, 1,
+				__atomic_fetch_sub(&t->hash_tids_in_use, 1,
 						   __ATOMIC_RELAXED);
 		} else {
 			if (family == FILTER_TYPE_IPV4)
-				__atomic_sub_fetch(&t->tids_in_use, 1,
+				__atomic_fetch_sub(&t->tids_in_use, 1,
 						   __ATOMIC_RELAXED);
 		}
 	}
@@ -448,15 +448,15 @@ void cxgbe_insert_tid(struct tid_info *t, void *data, unsigned int tid,
 	t->tid_tab[tid] = data;
 	if (t->hash_base && tid >= t->hash_base) {
 		if (family == FILTER_TYPE_IPV4)
-			__atomic_add_fetch(&t->hash_tids_in_use, 1,
+			__atomic_fetch_add(&t->hash_tids_in_use, 1,
 					   __ATOMIC_RELAXED);
 	} else {
 		if (family == FILTER_TYPE_IPV4)
-			__atomic_add_fetch(&t->tids_in_use, 1,
+			__atomic_fetch_add(&t->tids_in_use, 1,
 					   __ATOMIC_RELAXED);
 	}
 
-	__atomic_add_fetch(&t->conns_in_use, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&t->conns_in_use, 1, __ATOMIC_RELAXED);
 }
 
 /**
drivers/net/cxgbe/l2t.c +2 -2
index 66f5789..21f4019 100644
@@ -15,7 +15,7 @@
 void cxgbe_l2t_release(struct l2t_entry *e)
 {
 	if (__atomic_load_n(&e->refcnt, __ATOMIC_RELAXED) != 0)
-		__atomic_sub_fetch(&e->refcnt, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(&e->refcnt, 1, __ATOMIC_RELAXED);
 }
 
 /**
@@ -162,7 +162,7 @@ static struct l2t_entry *t4_l2t_alloc_switching(struct rte_eth_dev *dev,
 				dev_debug(adap, "Failed to write L2T entry: %d",
 					  ret);
 		} else {
-			__atomic_add_fetch(&e->refcnt, 1, __ATOMIC_RELAXED);
+			__atomic_fetch_add(&e->refcnt, 1, __ATOMIC_RELAXED);
 		}
 		t4_os_unlock(&e->lock);
 	}
drivers/net/cxgbe/mps_tcam.c +1 -1
index abbf06e..017741f 100644
@@ -76,7 +76,7 @@ int cxgbe_mpstcam_alloc(struct port_info *pi, const u8 *eth_addr,
 	t4_os_write_lock(&mpstcam->lock);
 	entry = cxgbe_mpstcam_lookup(adap->mpstcam, eth_addr, mask);
 	if (entry) {
-		__atomic_add_fetch(&entry->refcnt, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_add(&entry->refcnt, 1, __ATOMIC_RELAXED);
 		t4_os_write_unlock(&mpstcam->lock);
 		return entry->idx;
 	}
drivers/net/cxgbe/smt.c +2 -2
index 810c757..4e14a73 100644
@@ -170,7 +170,7 @@ static struct smt_entry *t4_smt_alloc_switching(struct rte_eth_dev *dev,
 			e->state = SMT_STATE_SWITCHING;
 			__atomic_store_n(&e->refcnt, 1, __ATOMIC_RELAXED);
 		} else {
-			__atomic_add_fetch(&e->refcnt, 1, __ATOMIC_RELAXED);
+			__atomic_fetch_add(&e->refcnt, 1, __ATOMIC_RELAXED);
 		}
 		t4_os_unlock(&e->lock);
 	}
@@ -196,7 +196,7 @@ struct smt_entry *cxgbe_smt_alloc_switching(struct rte_eth_dev *dev, u8 *smac)
 void cxgbe_smt_release(struct smt_entry *e)
 {
 	if (__atomic_load_n(&e->refcnt, __ATOMIC_RELAXED) != 0)
-		__atomic_sub_fetch(&e->refcnt, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(&e->refcnt, 1, __ATOMIC_RELAXED);
 }
 
 /**
Signature · 1 line
1.8.3.1
#34 lore raw

PATCH v2 9/17 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 drivers/net/octeontx/octeontx_ethdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/octeontx/octeontx_ethdev.c +1 -1
index d52a3e7..e00298e 100644
@@ -1581,7 +1581,7 @@ static void build_xstat_names(struct rte_eth_xstat_name *xstat_names)
 	nic->pko_vfid = pko_vfid;
 	nic->port_id = port;
 	nic->evdev = evdev;
-	__atomic_add_fetch(&evdev_refcnt, 1, __ATOMIC_ACQUIRE);
+	__atomic_fetch_add(&evdev_refcnt, 1, __ATOMIC_ACQUIRE);
 
 	res = octeontx_port_open(nic);
 	if (res < 0)
Signature · 1 line
1.8.3.1
#35 lore raw

PATCH v2 10/17 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 drivers/net/mlx5/linux/mlx5_verbs.c |  2 +-
 drivers/net/mlx5/mlx5_flow.c        |  6 +++---
 drivers/net/mlx5/mlx5_flow_dv.c     |  4 ++--
 drivers/net/mlx5/mlx5_flow_flex.c   |  6 +++---
 drivers/net/mlx5/mlx5_flow_hw.c     | 10 +++++-----
 drivers/net/mlx5/mlx5_flow_meter.c  | 20 ++++++++++----------
 drivers/net/mlx5/mlx5_rx.h          |  2 +-
 7 files changed, 25 insertions(+), 25 deletions(-)
drivers/net/mlx5/linux/mlx5_verbs.c +1 -1
index 67a7bec..c722613 100644
@@ -1159,7 +1159,7 @@
 		claim_zero(mlx5_glue->destroy_cq(sh->self_lb.ibv_cq));
 		sh->self_lb.ibv_cq = NULL;
 	}
-	(void)__atomic_sub_fetch(&sh->self_lb.refcnt, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_sub(&sh->self_lb.refcnt, 1, __ATOMIC_RELAXED);
 	return -rte_errno;
 #else
 	RTE_SET_USED(dev);
drivers/net/mlx5/mlx5_flow.c +3 -3
index a6a426c..1c51b29 100644
@@ -4451,7 +4451,7 @@ struct mlx5_translated_action_handle {
 			shared_rss = mlx5_ipool_get
 				(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
 									   idx);
-			__atomic_add_fetch(&shared_rss->refcnt, 1,
+			__atomic_fetch_add(&shared_rss->refcnt, 1,
 					   __ATOMIC_RELAXED);
 			return idx;
 		default:
@@ -7295,7 +7295,7 @@ struct mlx5_list_entry *
 	if (tunnel) {
 		flow->tunnel = 1;
 		flow->tunnel_id = tunnel->tunnel_id;
-		__atomic_add_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_add(&tunnel->refctn, 1, __ATOMIC_RELAXED);
 		mlx5_free(default_miss_ctx.queue);
 	}
 	mlx5_flow_pop_thread_workspace();
@@ -7306,7 +7306,7 @@ struct mlx5_list_entry *
 	flow_mreg_del_copy_action(dev, flow);
 	flow_drv_destroy(dev, flow);
 	if (rss_desc->shared_rss)
-		__atomic_sub_fetch(&((struct mlx5_shared_action_rss *)
+		__atomic_fetch_sub(&((struct mlx5_shared_action_rss *)
 			mlx5_ipool_get
 			(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
 			rss_desc->shared_rss))->refcnt, 1, __ATOMIC_RELAXED);
drivers/net/mlx5/mlx5_flow_dv.c +2 -2
index f93dd40..0233cde 100644
@@ -15143,7 +15143,7 @@ struct mlx5_list_entry *
 
 	shared_rss = mlx5_ipool_get
 			(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
-	__atomic_sub_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_sub(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
 }
 
 void
@@ -15734,7 +15734,7 @@ struct mlx5_list_entry *
 	/* Update queue with indirect table queue memoyr. */
 	origin->queue = shared_rss->ind_tbl->queues;
 	rte_spinlock_init(&shared_rss->action_rss_sl);
-	__atomic_add_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
 	rte_spinlock_lock(&priv->shared_act_sl);
 	ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
 		     &priv->rss_shared_actions, idx, shared_rss, next);
drivers/net/mlx5/mlx5_flow_flex.c +3 -3
index 35f2a99..a825274 100644
@@ -301,7 +301,7 @@
 		return ret;
 	}
 	if (acquire)
-		__atomic_add_fetch(&flex->refcnt, 1, __ATOMIC_RELEASE);
+		__atomic_fetch_add(&flex->refcnt, 1, __ATOMIC_RELEASE);
 	return ret;
 }
 
@@ -336,7 +336,7 @@
 		rte_errno = -EINVAL;
 		return -EINVAL;
 	}
-	__atomic_sub_fetch(&flex->refcnt, 1, __ATOMIC_RELEASE);
+	__atomic_fetch_sub(&flex->refcnt, 1, __ATOMIC_RELEASE);
 	return 0;
 }
 
@@ -1220,7 +1220,7 @@ struct rte_flow_item_flex_handle *
 	}
 	flex->devx_fp = container_of(ent, struct mlx5_flex_parser_devx, entry);
 	/* Mark initialized flex item valid. */
-	__atomic_add_fetch(&flex->refcnt, 1, __ATOMIC_RELEASE);
+	__atomic_fetch_add(&flex->refcnt, 1, __ATOMIC_RELEASE);
 	return (struct rte_flow_item_flex_handle *)flex;
 
 error:
drivers/net/mlx5/mlx5_flow_hw.c +5 -5
index a9c7045..159ebb5 100644
@@ -1406,7 +1406,7 @@ static rte_be32_t vlan_hdr_to_be32(const struct rte_flow_action *actions)
 				goto err;
 			acts->rule_acts[action_pos].action =
 				priv->hw_tag[!!attr->group];
-			__atomic_add_fetch(&priv->hws_mark_refcnt, 1, __ATOMIC_RELAXED);
+			__atomic_fetch_add(&priv->hws_mark_refcnt, 1, __ATOMIC_RELAXED);
 			flow_hw_rxq_flag_set(dev, true);
 			break;
 		case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
@@ -3162,13 +3162,13 @@ static rte_be32_t vlan_hdr_to_be32(const struct rte_flow_action *actions)
 at_error:
 	while (i--) {
 		__flow_hw_action_template_destroy(dev, &tbl->ats[i].acts);
-		__atomic_sub_fetch(&action_templates[i]->refcnt,
+		__atomic_fetch_sub(&action_templates[i]->refcnt,
 				   1, __ATOMIC_RELAXED);
 	}
 	i = nb_item_templates;
 it_error:
 	while (i--)
-		__atomic_sub_fetch(&item_templates[i]->refcnt,
+		__atomic_fetch_sub(&item_templates[i]->refcnt,
 				   1, __ATOMIC_RELAXED);
 error:
 	err = rte_errno;
@@ -3361,11 +3361,11 @@ static rte_be32_t vlan_hdr_to_be32(const struct rte_flow_action *actions)
 	}
 	LIST_REMOVE(table, next);
 	for (i = 0; i < table->nb_item_templates; i++)
-		__atomic_sub_fetch(&table->its[i]->refcnt,
+		__atomic_fetch_sub(&table->its[i]->refcnt,
 				   1, __ATOMIC_RELAXED);
 	for (i = 0; i < table->nb_action_templates; i++) {
 		__flow_hw_action_template_destroy(dev, &table->ats[i].acts);
-		__atomic_sub_fetch(&table->ats[i].action_template->refcnt,
+		__atomic_fetch_sub(&table->ats[i].action_template->refcnt,
 				   1, __ATOMIC_RELAXED);
 	}
 	mlx5dr_matcher_destroy(table->matcher);
drivers/net/mlx5/mlx5_flow_meter.c +10 -10
index 08f8aad..cb26a12 100644
@@ -1788,7 +1788,7 @@ struct mlx5_flow_meter_policy *
 			NULL, "Meter profile id not valid.");
 	/* Meter policy must exist. */
 	if (params->meter_policy_id == priv->sh->mtrmng->def_policy_id) {
-		__atomic_add_fetch
+		__atomic_fetch_add
 			(&priv->sh->mtrmng->def_policy_ref_cnt,
 			1, __ATOMIC_RELAXED);
 		domain_bitmap = MLX5_MTR_ALL_DOMAIN_BIT;
@@ -1870,7 +1870,7 @@ struct mlx5_flow_meter_policy *
 	fm->is_enable = params->meter_enable;
 	fm->shared = !!shared;
 	fm->color_aware = !!params->use_prev_mtr_color;
-	__atomic_add_fetch(&fm->profile->ref_cnt, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&fm->profile->ref_cnt, 1, __ATOMIC_RELAXED);
 	if (params->meter_policy_id == priv->sh->mtrmng->def_policy_id) {
 		fm->def_policy = 1;
 		fm->flow_ipool = mlx5_ipool_create(&flow_ipool_cfg);
@@ -1899,7 +1899,7 @@ struct mlx5_flow_meter_policy *
 	}
 	fm->active_state = params->meter_enable;
 	if (mtr_policy)
-		__atomic_add_fetch(&mtr_policy->ref_cnt, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_add(&mtr_policy->ref_cnt, 1, __ATOMIC_RELAXED);
 	return 0;
 error:
 	mlx5_flow_destroy_mtr_tbls(dev, fm);
@@ -1994,8 +1994,8 @@ struct mlx5_flow_meter_policy *
 			RTE_MTR_ERROR_TYPE_UNSPECIFIED,
 			NULL, "Failed to create devx meter.");
 	fm->active_state = params->meter_enable;
-	__atomic_add_fetch(&fm->profile->ref_cnt, 1, __ATOMIC_RELAXED);
-	__atomic_add_fetch(&policy->ref_cnt, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&fm->profile->ref_cnt, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&policy->ref_cnt, 1, __ATOMIC_RELAXED);
 	return 0;
 }
 
@@ -2017,7 +2017,7 @@ struct mlx5_flow_meter_policy *
 	if (fmp == NULL)
 		return -1;
 	/* Update dependencies. */
-	__atomic_sub_fetch(&fmp->ref_cnt, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_sub(&fmp->ref_cnt, 1, __ATOMIC_RELAXED);
 	fm->profile = NULL;
 	/* Remove from list. */
 	if (!priv->sh->meter_aso_en) {
@@ -2035,14 +2035,14 @@ struct mlx5_flow_meter_policy *
 	}
 	mlx5_flow_destroy_mtr_tbls(dev, fm);
 	if (fm->def_policy)
-		__atomic_sub_fetch(&priv->sh->mtrmng->def_policy_ref_cnt,
+		__atomic_fetch_sub(&priv->sh->mtrmng->def_policy_ref_cnt,
 				1, __ATOMIC_RELAXED);
 	if (priv->sh->meter_aso_en) {
 		if (!fm->def_policy) {
 			mtr_policy = mlx5_flow_meter_policy_find(dev,
 						fm->policy_id, NULL);
 			if (mtr_policy)
-				__atomic_sub_fetch(&mtr_policy->ref_cnt,
+				__atomic_fetch_sub(&mtr_policy->ref_cnt,
 						1, __ATOMIC_RELAXED);
 			fm->policy_id = 0;
 		}
@@ -2146,12 +2146,12 @@ struct mlx5_flow_meter_policy *
 					  RTE_MTR_ERROR_TYPE_UNSPECIFIED,
 					  NULL, "Meter object is being used.");
 	/* Destroy the meter profile. */
-	__atomic_sub_fetch(&fm->profile->ref_cnt,
+	__atomic_fetch_sub(&fm->profile->ref_cnt,
 						1, __ATOMIC_RELAXED);
 	/* Destroy the meter policy. */
 	policy = mlx5_flow_meter_policy_find(dev,
 			fm->policy_id, NULL);
-	__atomic_sub_fetch(&policy->ref_cnt,
+	__atomic_fetch_sub(&policy->ref_cnt,
 						1, __ATOMIC_RELAXED);
 	memset(fm, 0, sizeof(struct mlx5_flow_meter_info));
 	return 0;
drivers/net/mlx5/mlx5_rx.h +1 -1
index 6b42e27..ba62398 100644
@@ -539,7 +539,7 @@ uint16_t mlx5_rx_burst_mprq_vec(void *dpdk_rxq, struct rte_mbuf **pkts,
 		void *buf_addr;
 
 		/* Increment the refcnt of the whole chunk. */
-		__atomic_add_fetch(&buf->refcnt, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_add(&buf->refcnt, 1, __ATOMIC_RELAXED);
 		MLX5_ASSERT(__atomic_load_n(&buf->refcnt,
 			    __ATOMIC_RELAXED) <= strd_n + 1);
 		buf_addr = RTE_PTR_SUB(addr, RTE_PKTMBUF_HEADROOM);
Signature · 1 line
1.8.3.1
#33 lore raw

PATCH v2 8/17 net/virtio: 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +1 -1
index f46a131..2b4607a 100644
@@ -1025,7 +1025,7 @@ int virtio_user_stop_device(struct virtio_user_dev *dev)
 		uep->id = desc_idx;
 		uep->len = n_descs;
 
-		__atomic_add_fetch(&vring->used->idx, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_add(&vring->used->idx, 1, __ATOMIC_RELAXED);
 	}
 }
 
Signature · 1 line
1.8.3.1
#31 lore raw

PATCH v2 6/17 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 lib/bbdev/rte_bbdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bbdev/rte_bbdev.c +1 -1
index 1521cdb..69e099d 100644
@@ -208,7 +208,7 @@ struct rte_bbdev *
 		return NULL;
 	}
 
-	__atomic_add_fetch(&bbdev->data->process_cnt, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&bbdev->data->process_cnt, 1, __ATOMIC_RELAXED);
 	bbdev->data->dev_id = dev_id;
 	bbdev->state = RTE_BBDEV_INITIALIZED;
 
Signature · 1 line
1.8.3.1
#40 lore raw

PATCH v2 14/17 dma/skeleton: 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 drivers/dma/skeleton/skeleton_dmadev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/skeleton/skeleton_dmadev.c +1 -1
index 9b6da65..43e7052 100644
@@ -77,7 +77,7 @@
 
 		hw->zero_req_count = 0;
 		rte_memcpy(desc->dst, desc->src, desc->len);
-		__atomic_add_fetch(&hw->completed_count, 1, __ATOMIC_RELEASE);
+		__atomic_fetch_add(&hw->completed_count, 1, __ATOMIC_RELEASE);
 		(void)rte_ring_enqueue(hw->desc_completed, (void *)desc);
 	}
 
Signature · 1 line
1.8.3.1
#43 lore raw

PATCH v2 17/17 test-eventdev: 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 app/test-eventdev/test_order_common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
app/test-eventdev/test_order_common.h +1 -1
index 92781d9..1507265 100644
@@ -113,7 +113,7 @@ struct test_order {
 	 */
 	expected_flow_seq[flow]++;
 	rte_pktmbuf_free(ev->mbuf);
-	__atomic_sub_fetch(outstand_pkts, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_sub(outstand_pkts, 1, __ATOMIC_RELAXED);
 }
 
 static __rte_always_inline void
Signature · 1 line
1.8.3.1
#38 lore raw

PATCH v2 13/17 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 drivers/event/cnxk/cnxk_eventdev_selftest.c | 12 ++++++------
 drivers/event/cnxk/cnxk_tim_worker.h        |  6 +++---
 drivers/event/dsw/dsw_event.c               |  6 +++---
 drivers/event/octeontx/timvf_worker.h       |  6 +++---
 4 files changed, 15 insertions(+), 15 deletions(-)
drivers/event/cnxk/cnxk_eventdev_selftest.c +6 -6
index 577c99b..95c0f1b 100644
@@ -554,7 +554,7 @@ typedef int (*validate_event_cb)(uint32_t index, uint8_t port,
 		ret = validate_event(&ev);
 		RTE_TEST_ASSERT_SUCCESS(ret, "Failed to validate event");
 		rte_pktmbuf_free(ev.mbuf);
-		__atomic_sub_fetch(total_events, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(total_events, 1, __ATOMIC_RELAXED);
 	}
 
 	return 0;
@@ -916,7 +916,7 @@ typedef int (*validate_event_cb)(uint32_t index, uint8_t port,
 
 			if (seqn_list_update(seqn) == 0) {
 				rte_pktmbuf_free(ev.mbuf);
-				__atomic_sub_fetch(total_events, 1,
+				__atomic_fetch_sub(total_events, 1,
 						   __ATOMIC_RELAXED);
 			} else {
 				plt_err("Failed to update seqn_list");
@@ -1072,7 +1072,7 @@ typedef int (*validate_event_cb)(uint32_t index, uint8_t port,
 
 			if (seqn_list_update(seqn) == 0) {
 				rte_pktmbuf_free(ev.mbuf);
-				__atomic_sub_fetch(total_events, 1,
+				__atomic_fetch_sub(total_events, 1,
 						   __ATOMIC_RELAXED);
 			} else {
 				plt_err("Failed to update seqn_list");
@@ -1217,7 +1217,7 @@ typedef int (*validate_event_cb)(uint32_t index, uint8_t port,
 
 		if (ev.sub_event_type == MAX_STAGES) { /* last stage */
 			rte_pktmbuf_free(ev.mbuf);
-			__atomic_sub_fetch(total_events, 1, __ATOMIC_RELAXED);
+			__atomic_fetch_sub(total_events, 1, __ATOMIC_RELAXED);
 		} else {
 			ev.event_type = RTE_EVENT_TYPE_CPU;
 			ev.sub_event_type++;
@@ -1293,7 +1293,7 @@ typedef int (*validate_event_cb)(uint32_t index, uint8_t port,
 
 		if (ev.queue_id == nr_queues - 1) { /* last stage */
 			rte_pktmbuf_free(ev.mbuf);
-			__atomic_sub_fetch(total_events, 1, __ATOMIC_RELAXED);
+			__atomic_fetch_sub(total_events, 1, __ATOMIC_RELAXED);
 		} else {
 			ev.event_type = RTE_EVENT_TYPE_CPU;
 			ev.queue_id++;
@@ -1338,7 +1338,7 @@ typedef int (*validate_event_cb)(uint32_t index, uint8_t port,
 
 		if (ev.queue_id == nr_queues - 1) { /* Last stage */
 			rte_pktmbuf_free(ev.mbuf);
-			__atomic_sub_fetch(total_events, 1, __ATOMIC_RELAXED);
+			__atomic_fetch_sub(total_events, 1, __ATOMIC_RELAXED);
 		} else {
 			ev.event_type = RTE_EVENT_TYPE_CPU;
 			ev.queue_id++;
drivers/event/cnxk/cnxk_tim_worker.h +3 -3
index a326d55..c087fe5 100644
@@ -102,19 +102,19 @@
 static inline void
 cnxk_tim_bkt_inc_nent(struct cnxk_tim_bkt *bktp)
 {
-	__atomic_add_fetch(&bktp->nb_entry, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&bktp->nb_entry, 1, __ATOMIC_RELAXED);
 }
 
 static inline void
 cnxk_tim_bkt_add_nent_relaxed(struct cnxk_tim_bkt *bktp, uint32_t v)
 {
-	__atomic_add_fetch(&bktp->nb_entry, v, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&bktp->nb_entry, v, __ATOMIC_RELAXED);
 }
 
 static inline void
 cnxk_tim_bkt_add_nent(struct cnxk_tim_bkt *bktp, uint32_t v)
 {
-	__atomic_add_fetch(&bktp->nb_entry, v, __ATOMIC_RELEASE);
+	__atomic_fetch_add(&bktp->nb_entry, v, __ATOMIC_RELEASE);
 }
 
 static inline uint64_t
drivers/event/dsw/dsw_event.c +3 -3
index 9932caf..89badca 100644
@@ -50,7 +50,7 @@
 
 	if (unlikely(new_total_on_loan > dsw->max_inflight)) {
 		/* Some other port took the last credits */
-		__atomic_sub_fetch(&dsw->credits_on_loan, acquired_credits,
+		__atomic_fetch_sub(&dsw->credits_on_loan, acquired_credits,
 				   __ATOMIC_RELAXED);
 		return false;
 	}
@@ -77,7 +77,7 @@
 
 		port->inflight_credits = leave_credits;
 
-		__atomic_sub_fetch(&dsw->credits_on_loan, return_credits,
+		__atomic_fetch_sub(&dsw->credits_on_loan, return_credits,
 				   __ATOMIC_RELAXED);
 
 		DSW_LOG_DP_PORT(DEBUG, port->id,
@@ -527,7 +527,7 @@ struct dsw_queue_flow_burst {
 	target_qfs[*targets_len] = *candidate_qf;
 	(*targets_len)++;
 
-	__atomic_add_fetch(&dsw->ports[candidate_port_id].immigration_load,
+	__atomic_fetch_add(&dsw->ports[candidate_port_id].immigration_load,
 			   candidate_flow_load, __ATOMIC_RELAXED);
 
 	return true;
drivers/event/octeontx/timvf_worker.h +3 -3
index 3f1e77f..ad98ca0 100644
@@ -108,7 +108,7 @@
 static inline void
 timr_bkt_dec_lock(struct tim_mem_bucket *bktp)
 {
-	__atomic_add_fetch(&bktp->lock, 0xff, __ATOMIC_ACQ_REL);
+	__atomic_fetch_add(&bktp->lock, 0xff, __ATOMIC_ACQ_REL);
 }
 
 static inline uint32_t
@@ -121,13 +121,13 @@
 static inline void
 timr_bkt_inc_nent(struct tim_mem_bucket *bktp)
 {
-	__atomic_add_fetch(&bktp->nb_entry, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&bktp->nb_entry, 1, __ATOMIC_RELAXED);
 }
 
 static inline void
 timr_bkt_add_nent(struct tim_mem_bucket *bktp, uint32_t v)
 {
-	__atomic_add_fetch(&bktp->nb_entry, v, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&bktp->nb_entry, v, __ATOMIC_RELAXED);
 }
 
 static inline uint64_t
Signature · 1 line
1.8.3.1
#42 lore raw

PATCH v2 16/17 app/test: 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 app/test/test_lcores.c        | 2 +-
 app/test/test_service_cores.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
app/test/test_lcores.c +1 -1
index 5b43aa5..2c945b0 100644
@@ -40,7 +40,7 @@ static uint32_t thread_loop(void *arg)
 		t->state = Thread_ERROR;
 	}
 	/* Report register happened to the control thread. */
-	__atomic_add_fetch(t->registered_count, 1, __ATOMIC_RELEASE);
+	__atomic_fetch_add(t->registered_count, 1, __ATOMIC_RELEASE);
 
 	/* Wait for release from the control thread. */
 	while (__atomic_load_n(t->registered_count, __ATOMIC_ACQUIRE) != 0)
app/test/test_service_cores.c +2 -2
index 637fcd7..9175736 100644
@@ -751,12 +751,12 @@ static int32_t dummy_mt_safe_cb(void *args)
 	uint32_t *lock = &params[1];
 
 	while (!*done) {
-		__atomic_add_fetch(lock, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_add(lock, 1, __ATOMIC_RELAXED);
 		rte_delay_us(500);
 		if (__atomic_load_n(lock, __ATOMIC_RELAXED) > 1)
 			/* pass: second core has simultaneously incremented */
 			*done = 1;
-		__atomic_sub_fetch(lock, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(lock, 1, __ATOMIC_RELAXED);
 	}
 
 	return 0;
Signature · 1 line
1.8.3.1
#41 lore raw

PATCH v2 15/17 drivers/common: 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 when we have no interest in the result of the operation.

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

---
 drivers/common/cnxk/roc_nix_inl_dev.c   |  2 +-
 drivers/common/mlx5/mlx5_common_mr.c    |  2 +-
 drivers/common/mlx5/mlx5_common_utils.c | 10 +++++-----
 drivers/common/mlx5/mlx5_malloc.c       | 16 ++++++++--------
 4 files changed, 15 insertions(+), 15 deletions(-)
drivers/common/cnxk/roc_nix_inl_dev.c +1 -1
index 6f60961..45d6f62 100644
@@ -741,7 +741,7 @@
 			inl_dev->work_cb(&tmp, sa, (port_id << 8) | 0x1);
 			__atomic_store_n(ring_base + tail_l + 1, 0ULL,
 					 __ATOMIC_RELAXED);
-			__atomic_add_fetch((uint32_t *)ring_base, 1,
+			__atomic_fetch_add((uint32_t *)ring_base, 1,
 					   __ATOMIC_ACQ_REL);
 		} else
 			plt_err("Invalid SA");
drivers/common/mlx5/mlx5_common_mr.c +1 -1
index 0e1d243..9ebe398 100644
@@ -1650,7 +1650,7 @@ struct mlx5_mempool_get_extmem_data {
 	unsigned int i;
 
 	for (i = 0; i < mpr->mrs_n; i++)
-		__atomic_add_fetch(&mpr->mrs[i].refcnt, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_add(&mpr->mrs[i].refcnt, 1, __ATOMIC_RELAXED);
 }
 
 /**
drivers/common/mlx5/mlx5_common_utils.c +5 -5
index 58d744b..915a317 100644
@@ -217,7 +217,7 @@ struct mlx5_list_entry *
 		entry->lcore_idx = (uint32_t)lcore_index;
 		LIST_INSERT_HEAD(&l_inconst->cache[lcore_index]->h,
 				 entry, next);
-		__atomic_add_fetch(&l_inconst->count, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_add(&l_inconst->count, 1, __ATOMIC_RELAXED);
 		DRV_LOG(DEBUG, "MLX5 list %s c%d entry %p new: %u.",
 			l_const->name, lcore_index,
 			(void *)entry, entry->ref_cnt);
@@ -254,7 +254,7 @@ struct mlx5_list_entry *
 	l_inconst->gen_cnt++;
 	rte_rwlock_write_unlock(&l_inconst->lock);
 	LIST_INSERT_HEAD(&l_inconst->cache[lcore_index]->h, local_entry, next);
-	__atomic_add_fetch(&l_inconst->count, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&l_inconst->count, 1, __ATOMIC_RELAXED);
 	DRV_LOG(DEBUG, "mlx5 list %s entry %p new: %u.", l_const->name,
 		(void *)entry, entry->ref_cnt);
 	return local_entry;
@@ -294,11 +294,11 @@ struct mlx5_list_entry *
 		else
 			l_const->cb_remove(l_const->ctx, entry);
 	} else {
-		__atomic_add_fetch(&l_inconst->cache[entry->lcore_idx]->inv_cnt,
+		__atomic_fetch_add(&l_inconst->cache[entry->lcore_idx]->inv_cnt,
 				   1, __ATOMIC_RELAXED);
 	}
 	if (!l_const->lcores_share) {
-		__atomic_sub_fetch(&l_inconst->count, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(&l_inconst->count, 1, __ATOMIC_RELAXED);
 		DRV_LOG(DEBUG, "mlx5 list %s entry %p removed.",
 			l_const->name, (void *)entry);
 		return 0;
@@ -310,7 +310,7 @@ struct mlx5_list_entry *
 		LIST_REMOVE(gentry, next);
 		rte_rwlock_write_unlock(&l_inconst->lock);
 		l_const->cb_remove(l_const->ctx, gentry);
-		__atomic_sub_fetch(&l_inconst->count, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(&l_inconst->count, 1, __ATOMIC_RELAXED);
 		DRV_LOG(DEBUG, "mlx5 list %s entry %p removed.",
 			l_const->name, (void *)gentry);
 		return 0;
drivers/common/mlx5/mlx5_malloc.c +8 -8
index cef3b88..c58c41d 100644
@@ -99,7 +99,7 @@ struct mlx5_sys_mem {
 			rte_mem_virt2memseg_list(addr),
 			__ATOMIC_RELAXED);
 #ifdef RTE_LIBRTE_MLX5_DEBUG
-		__atomic_add_fetch(&mlx5_sys_mem.msl_update, 1,
+		__atomic_fetch_add(&mlx5_sys_mem.msl_update, 1,
 				   __ATOMIC_RELAXED);
 #endif
 	}
@@ -126,7 +126,7 @@ struct mlx5_sys_mem {
 		if (!rte_mem_virt2memseg_list(addr))
 			return false;
 #ifdef RTE_LIBRTE_MLX5_DEBUG
-		__atomic_add_fetch(&mlx5_sys_mem.msl_miss, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_add(&mlx5_sys_mem.msl_miss, 1, __ATOMIC_RELAXED);
 #endif
 	}
 	return true;
@@ -185,7 +185,7 @@ struct mlx5_sys_mem {
 		mlx5_mem_update_msl(addr);
 #ifdef RTE_LIBRTE_MLX5_DEBUG
 		if (addr)
-			__atomic_add_fetch(&mlx5_sys_mem.malloc_rte, 1,
+			__atomic_fetch_add(&mlx5_sys_mem.malloc_rte, 1,
 					   __ATOMIC_RELAXED);
 #endif
 		return addr;
@@ -199,7 +199,7 @@ struct mlx5_sys_mem {
 		addr = malloc(size);
 #ifdef RTE_LIBRTE_MLX5_DEBUG
 	if (addr)
-		__atomic_add_fetch(&mlx5_sys_mem.malloc_sys, 1,
+		__atomic_fetch_add(&mlx5_sys_mem.malloc_sys, 1,
 				   __ATOMIC_RELAXED);
 #endif
 	return addr;
@@ -233,7 +233,7 @@ struct mlx5_sys_mem {
 		mlx5_mem_update_msl(new_addr);
 #ifdef RTE_LIBRTE_MLX5_DEBUG
 		if (new_addr)
-			__atomic_add_fetch(&mlx5_sys_mem.realloc_rte, 1,
+			__atomic_fetch_add(&mlx5_sys_mem.realloc_rte, 1,
 					   __ATOMIC_RELAXED);
 #endif
 		return new_addr;
@@ -246,7 +246,7 @@ struct mlx5_sys_mem {
 	new_addr = realloc(addr, size);
 #ifdef RTE_LIBRTE_MLX5_DEBUG
 	if (new_addr)
-		__atomic_add_fetch(&mlx5_sys_mem.realloc_sys, 1,
+		__atomic_fetch_add(&mlx5_sys_mem.realloc_sys, 1,
 				   __ATOMIC_RELAXED);
 #endif
 	return new_addr;
@@ -259,13 +259,13 @@ struct mlx5_sys_mem {
 		return;
 	if (!mlx5_mem_is_rte(addr)) {
 #ifdef RTE_LIBRTE_MLX5_DEBUG
-		__atomic_add_fetch(&mlx5_sys_mem.free_sys, 1,
+		__atomic_fetch_add(&mlx5_sys_mem.free_sys, 1,
 				   __ATOMIC_RELAXED);
 #endif
 		mlx5_os_free(addr);
 	} else {
 #ifdef RTE_LIBRTE_MLX5_DEBUG
-		__atomic_add_fetch(&mlx5_sys_mem.free_rte, 1,
+		__atomic_fetch_add(&mlx5_sys_mem.free_rte, 1,
 				   __ATOMIC_RELAXED);
 #endif
 		rte_free(addr);
Signature · 1 line
1.8.3.1
#44 lore raw
In reply to Tyler Retzlaff
Quoted 83 lines

-----Original Message-----
From: Tyler Retzlaff <[email protected]>
Sent: Friday, March 3, 2023 12:18 AM
To: [email protected]
Cc: Honnappa Nagarahalli <[email protected]>; [email protected]; [email protected]; [email protected]; Ruifeng Wang <[email protected]>; [email protected]; Tyler Retzlaff <[email protected]>
Subject: [PATCH v2 00/17] use __atomic operations returning previous value

This series replaces uses of __atomic_{add,and,or,sub,xor}_fetch with __atomic_fetch_{add,and,or,sub,xor} intrinsics. The latter omits generation of code that is only needed if the returned value is actually used.

Additionally, this change simplifies adapting dpdk to standard atomics planned for 23.07 since __atomic_fetch_xxx can be trivially replaced with atomic_fetch_xxx whereas __atomic_xxx_fetch has no standard equivalent.

v2:
net/iavf patch had one incorrect change to __atomic_fetch_sub from __atomic_sub_fetch the new value was assigned to a variable on the previous line so revert the change from the patch.

Tyler Retzlaff (17):
vhost: use previous value atomic fetch operations
telemetry: use previous value atomic fetch operations
stack: use previous value atomic fetch operations
eal: use previous value atomic fetch operations
distributor: use previous value atomic fetch operations
bbdev: use previous value atomic fetch operations examples/vhost: use previous value atomic fetch operations net/virtio: use previous value atomic fetch operations net/octeontx: use previous value atomic fetch operations net/mlx5: use previous value atomic fetch operations net/iavf: use previous value atomic fetch operations net/cxgbe: use previous value atomic fetch operations drivers/event: use previous value atomic fetch operations dma/skeleton: use previous value atomic fetch operations drivers/common: use previous value atomic fetch operations app/test: use previous value atomic fetch operations
test-eventdev: use previous value atomic fetch operations

 app/test-eventdev/test_order_common.h            |  2 +-
 app/test/test_lcores.c                           |  2 +-
 app/test/test_service_cores.c                    |  4 ++--
 drivers/common/cnxk/roc_nix_inl_dev.c            |  2 +-
 drivers/common/mlx5/mlx5_common_mr.c             |  2 +-
 drivers/common/mlx5/mlx5_common_utils.c          | 10 +++++-----
 drivers/common/mlx5/mlx5_malloc.c                | 16 ++++++++--------
 drivers/dma/skeleton/skeleton_dmadev.c           |  2 +-
 drivers/event/cnxk/cnxk_eventdev_selftest.c      | 12 ++++++------
 drivers/event/cnxk/cnxk_tim_worker.h             |  6 +++---
 drivers/event/dsw/dsw_event.c                    |  6 +++---
 drivers/event/octeontx/timvf_worker.h            |  6 +++---
 drivers/net/cxgbe/clip_tbl.c                     |  2 +-
 drivers/net/cxgbe/cxgbe_main.c                   | 12 ++++++------
 drivers/net/cxgbe/l2t.c                          |  4 ++--
 drivers/net/cxgbe/mps_tcam.c                     |  2 +-
 drivers/net/cxgbe/smt.c                          |  4 ++--
 drivers/net/iavf/iavf_vchnl.c                    |  4 ++--
 drivers/net/mlx5/linux/mlx5_verbs.c              |  2 +-
 drivers/net/mlx5/mlx5_flow.c                     |  6 +++---
 drivers/net/mlx5/mlx5_flow_dv.c                  |  4 ++--
 drivers/net/mlx5/mlx5_flow_flex.c                |  6 +++---
 drivers/net/mlx5/mlx5_flow_hw.c                  | 10 +++++-----
 drivers/net/mlx5/mlx5_flow_meter.c               | 20 ++++++++++----------
 drivers/net/mlx5/mlx5_rx.h                       |  2 +-
 drivers/net/octeontx/octeontx_ethdev.c           |  2 +-
 drivers/net/virtio/virtio_user/virtio_user_dev.c |  2 +-
 examples/vhost/main.c                            | 12 ++++++------
 examples/vhost/virtio_net.c                      |  4 ++--
 lib/bbdev/rte_bbdev.c                            |  2 +-
 lib/distributor/rte_distributor.c                |  2 +-
 lib/eal/common/eal_common_trace.c                |  8 ++++----
 lib/eal/common/rte_service.c                     |  8 ++++----
 lib/eal/ppc/include/rte_atomic.h                 | 16 ++++++++--------
 lib/stack/rte_stack_lf_c11.h                     |  2 +-
 lib/telemetry/telemetry.c                        |  6 +++---
 lib/vhost/virtio_net.c                           |  6 +++---
 37 files changed, 109 insertions(+), 109 deletions(-)
Quoted 2 lines

--
1.8.3.1

#45 lore raw
In reply to Tyler Retzlaff
Quoted 7 lines · Tyler Retzlaff

This series replaces uses of __atomic_{add,and,or,sub,xor}_fetch with __atomic_fetch_{add,and,or,sub,xor} intrinsics. The latter omits generation of code that is only needed if the returned value is actually used.

Additionally, this change simplifies adapting dpdk to standard atomics planned for 23.07 since __atomic_fetch_xxx can be trivially replaced with atomic_fetch_xxx whereas __atomic_xxx_fetch has no standard equivalent.

Quoted 2 lines

...

Quoted 1 line
Acked-by on v2 13/17
#39 lore raw

RE: [EXT] [PATCH v2 13/17] drivers/event: use previous value atomic fetch operations

In reply to Tyler Retzlaff
Quoted 4 lines

Use __atomic_fetch_{add,and,or,sub,xor} instead of __atomic_{add,and,or,sub,xor}_fetch when we have no interest in the result of the operation.

Quoted 8 lines

Reduces unnecessary codegen that provided the result of the atomic operation that was not used.

Change brings closer alignment with atomics available in C11 standard and will reduce review effort when they are integrated.

Quoted 176 lines
---
 drivers/event/cnxk/cnxk_eventdev_selftest.c | 12 ++++++------
 drivers/event/cnxk/cnxk_tim_worker.h        |  6 +++---
 drivers/event/dsw/dsw_event.c               |  6 +++---
 drivers/event/octeontx/timvf_worker.h       |  6 +++---
 4 files changed, 15 insertions(+), 15 deletions(-)
drivers/event/cnxk/cnxk_eventdev_selftest.c +1 -1
index 577c99b..95c0f1b 100644
@@ -554,7 +554,7 @@ typedef int (*validate_event_cb)(uint32_t index,
 uint8_t port,
 		ret = validate_event(&ev);
 		RTE_TEST_ASSERT_SUCCESS(ret, "Failed to validate event");
 		rte_pktmbuf_free(ev.mbuf);
-		__atomic_sub_fetch(total_events, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(total_events, 1, __ATOMIC_RELAXED);
 	}
 
drivers/event/cnxk/cnxk_eventdev_selftest.c +1 -1
 	return 0;
@@ -916,7 +916,7 @@ typedef int (*validate_event_cb)(uint32_t index,
 uint8_t port,
 
 			if (seqn_list_update(seqn) == 0) {
 				rte_pktmbuf_free(ev.mbuf);
-				__atomic_sub_fetch(total_events, 1,
+				__atomic_fetch_sub(total_events, 1,
 						   __ATOMIC_RELAXED);
 			} else {
drivers/event/cnxk/cnxk_eventdev_selftest.c +1 -1
 				plt_err("Failed to update seqn_list");
@@ -1072,7 +1072,7 @@ typedef int (*validate_event_cb)(uint32_t index,
 uint8_t port,
 
 			if (seqn_list_update(seqn) == 0) {
 				rte_pktmbuf_free(ev.mbuf);
-				__atomic_sub_fetch(total_events, 1,
+				__atomic_fetch_sub(total_events, 1,
 						   __ATOMIC_RELAXED);
 			} else {
drivers/event/cnxk/cnxk_eventdev_selftest.c +1 -1
 				plt_err("Failed to update seqn_list");
@@ -1217,7 +1217,7 @@ typedef int (*validate_event_cb)(uint32_t index,
 uint8_t port,
 
 		if (ev.sub_event_type == MAX_STAGES) { /* last stage */
 			rte_pktmbuf_free(ev.mbuf);
-			__atomic_sub_fetch(total_events, 1,
 __ATOMIC_RELAXED);
+			__atomic_fetch_sub(total_events, 1,
 __ATOMIC_RELAXED);
drivers/event/cnxk/cnxk_eventdev_selftest.c +1 -1
 		} else {
 			ev.event_type = RTE_EVENT_TYPE_CPU;
 			ev.sub_event_type++;
@@ -1293,7 +1293,7 @@ typedef int (*validate_event_cb)(uint32_t index,
 uint8_t port,
 
 		if (ev.queue_id == nr_queues - 1) { /* last stage */
 			rte_pktmbuf_free(ev.mbuf);
-			__atomic_sub_fetch(total_events, 1,
 __ATOMIC_RELAXED);
+			__atomic_fetch_sub(total_events, 1,
 __ATOMIC_RELAXED);
drivers/event/cnxk/cnxk_eventdev_selftest.c +1 -1
 		} else {
 			ev.event_type = RTE_EVENT_TYPE_CPU;
 			ev.queue_id++;
@@ -1338,7 +1338,7 @@ typedef int (*validate_event_cb)(uint32_t index,
 uint8_t port,
 
 		if (ev.queue_id == nr_queues - 1) { /* Last stage */
 			rte_pktmbuf_free(ev.mbuf);
-			__atomic_sub_fetch(total_events, 1,
 __ATOMIC_RELAXED);
+			__atomic_fetch_sub(total_events, 1,
 __ATOMIC_RELAXED);
drivers/event/cnxk/cnxk_eventdev_selftest.c +0 -0
 		} else {
 			ev.event_type = RTE_EVENT_TYPE_CPU;
 			ev.queue_id++;
drivers/event/cnxk/cnxk_tim_worker.h +3 -3
index a326d55..c087fe5 100644
@@ -102,19 +102,19 @@
 static inline void
 cnxk_tim_bkt_inc_nent(struct cnxk_tim_bkt *bktp)
 {
-	__atomic_add_fetch(&bktp->nb_entry, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&bktp->nb_entry, 1, __ATOMIC_RELAXED);
 }
 
 static inline void
 cnxk_tim_bkt_add_nent_relaxed(struct cnxk_tim_bkt *bktp, uint32_t v)
 {
-	__atomic_add_fetch(&bktp->nb_entry, v, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&bktp->nb_entry, v, __ATOMIC_RELAXED);
 }
 
 static inline void
 cnxk_tim_bkt_add_nent(struct cnxk_tim_bkt *bktp, uint32_t v)
 {
-	__atomic_add_fetch(&bktp->nb_entry, v, __ATOMIC_RELEASE);
+	__atomic_fetch_add(&bktp->nb_entry, v, __ATOMIC_RELEASE);
 }
 
 static inline uint64_t
drivers/event/dsw/dsw_event.c +1 -1
index 9932caf..89badca 100644
@@ -50,7 +50,7 @@
 
 	if (unlikely(new_total_on_loan > dsw->max_inflight)) {
 		/* Some other port took the last credits */
-		__atomic_sub_fetch(&dsw->credits_on_loan,
 acquired_credits,
+		__atomic_fetch_sub(&dsw->credits_on_loan,
 acquired_credits,
 				   __ATOMIC_RELAXED);
drivers/event/dsw/dsw_event.c +1 -1
 		return false;
 	}
@@ -77,7 +77,7 @@
 
 		port->inflight_credits = leave_credits;
 
-		__atomic_sub_fetch(&dsw->credits_on_loan,
 return_credits,
+		__atomic_fetch_sub(&dsw->credits_on_loan,
 return_credits,
 				   __ATOMIC_RELAXED);
drivers/event/dsw/dsw_event.c +1 -1
 		DSW_LOG_DP_PORT(DEBUG, port->id,
@@ -527,7 +527,7 @@ struct dsw_queue_flow_burst {
 	target_qfs[*targets_len] = *candidate_qf;
 	(*targets_len)++;
 
-	__atomic_add_fetch(&dsw-
 >ports[candidate_port_id].immigration_load,
+	__atomic_fetch_add(&dsw-
 >ports[candidate_port_id].immigration_load,
 			   candidate_flow_load, __ATOMIC_RELAXED);
drivers/event/dsw/dsw_event.c +0 -0
 	return true;
drivers/event/octeontx/timvf_worker.h +3 -4
index 3f1e77f..ad98ca0 100644
@@ -108,7 +108,7 @@
 static inline void
 timr_bkt_dec_lock(struct tim_mem_bucket *bktp)
 {
-	__atomic_add_fetch(&bktp->lock, 0xff, __ATOMIC_ACQ_REL);
+	__atomic_fetch_add(&bktp->lock, 0xff, __ATOMIC_ACQ_REL);
 }
 
 static inline uint32_t
@@ -121,13 +121,13 @@
 static inline void
 timr_bkt_inc_nent(struct tim_mem_bucket *bktp)
 {
-	__atomic_add_fetch(&bktp->nb_entry, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&bktp->nb_entry, 1, __ATOMIC_RELAXED);
 }
 
 static inline void
 timr_bkt_add_nent(struct tim_mem_bucket *bktp, uint32_t v)
 {
-	__atomic_add_fetch(&bktp->nb_entry, v, __ATOMIC_RELAXED);
+	__atomic_fetch_add(&bktp->nb_entry, v, __ATOMIC_RELAXED);
 }
 
 static inline uint64_t
--

1.8.3.1

#46 lore raw
In reply to Tyler Retzlaff
Quoted 66 lines · Tyler Retzlaff

This series replaces uses of __atomic_{add,and,or,sub,xor}_fetch with __atomic_fetch_{add,and,or,sub,xor} intrinsics. The latter omits generation of code that is only needed if the returned value is actually used.

Additionally, this change simplifies adapting dpdk to standard atomics planned for 23.07 since __atomic_fetch_xxx can be trivially replaced with atomic_fetch_xxx whereas __atomic_xxx_fetch has no standard equivalent.

v2:
net/iavf patch had one incorrect change to __atomic_fetch_sub from __atomic_sub_fetch the new value was assigned to a variable on the previous line so revert the change from the patch.

Tyler Retzlaff (17):
vhost: use previous value atomic fetch operations
telemetry: use previous value atomic fetch operations
stack: use previous value atomic fetch operations
eal: use previous value atomic fetch operations
distributor: use previous value atomic fetch operations
bbdev: use previous value atomic fetch operations examples/vhost: use previous value atomic fetch operations net/virtio: use previous value atomic fetch operations net/octeontx: use previous value atomic fetch operations net/mlx5: use previous value atomic fetch operations net/iavf: use previous value atomic fetch operations net/cxgbe: use previous value atomic fetch operations drivers/event: use previous value atomic fetch operations dma/skeleton: use previous value atomic fetch operations drivers/common: use previous value atomic fetch operations app/test: use previous value atomic fetch operations
test-eventdev: use previous value atomic fetch operations

 app/test-eventdev/test_order_common.h            |  2 +-
 app/test/test_lcores.c                           |  2 +-
 app/test/test_service_cores.c                    |  4 ++--
 drivers/common/cnxk/roc_nix_inl_dev.c            |  2 +-
 drivers/common/mlx5/mlx5_common_mr.c             |  2 +-
 drivers/common/mlx5/mlx5_common_utils.c          | 10 +++++-----
 drivers/common/mlx5/mlx5_malloc.c                | 16 ++++++++--------
 drivers/dma/skeleton/skeleton_dmadev.c           |  2 +-
 drivers/event/cnxk/cnxk_eventdev_selftest.c      | 12 ++++++------
 drivers/event/cnxk/cnxk_tim_worker.h             |  6 +++---
 drivers/event/dsw/dsw_event.c                    |  6 +++---
 drivers/event/octeontx/timvf_worker.h            |  6 +++---
 drivers/net/cxgbe/clip_tbl.c                     |  2 +-
 drivers/net/cxgbe/cxgbe_main.c                   | 12 ++++++------
 drivers/net/cxgbe/l2t.c                          |  4 ++--
 drivers/net/cxgbe/mps_tcam.c                     |  2 +-
 drivers/net/cxgbe/smt.c                          |  4 ++--
 drivers/net/iavf/iavf_vchnl.c                    |  4 ++--
 drivers/net/mlx5/linux/mlx5_verbs.c              |  2 +-
 drivers/net/mlx5/mlx5_flow.c                     |  6 +++---
 drivers/net/mlx5/mlx5_flow_dv.c                  |  4 ++--
 drivers/net/mlx5/mlx5_flow_flex.c                |  6 +++---
 drivers/net/mlx5/mlx5_flow_hw.c                  | 10 +++++-----
 drivers/net/mlx5/mlx5_flow_meter.c               | 20 ++++++++++----------
 drivers/net/mlx5/mlx5_rx.h                       |  2 +-
 drivers/net/octeontx/octeontx_ethdev.c           |  2 +-
 drivers/net/virtio/virtio_user/virtio_user_dev.c |  2 +-
 examples/vhost/main.c                            | 12 ++++++------
 examples/vhost/virtio_net.c                      |  4 ++--
 lib/bbdev/rte_bbdev.c                            |  2 +-
Quoted 8 lines
 lib/distributor/rte_distributor.c                |  2 +-
 lib/eal/common/eal_common_trace.c                |  8 ++++----
 lib/eal/common/rte_service.c                     |  8 ++++----
 lib/eal/ppc/include/rte_atomic.h                 | 16 ++++++++--------
 lib/stack/rte_stack_lf_c11.h                     |  2 +-
 lib/telemetry/telemetry.c                        |  6 +++---
 lib/vhost/virtio_net.c                           |  6 +++---
 37 files changed, 109 insertions(+), 109 deletions(-)

The changes are systematic and lgtm.
Series applied, thanks Tyler.

Signature · 1 line
David Marchand