DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tyler Retzlaff <roretzla@linux.microsoft.com>
To: dev@dpdk.org
Cc: Honnappa.Nagarahalli@arm.com, thomas@monjalon.net,
	Tyler Retzlaff <roretzla@linux.microsoft.com>
Subject: [PATCH 10/17] net/mlx5: use previous value atomic fetch operations
Date: Wed,  1 Mar 2023 16:47:41 -0800	[thread overview]
Message-ID: <1677718068-2412-11-git-send-email-roretzla@linux.microsoft.com> (raw)
In-Reply-To: <1677718068-2412-1-git-send-email-roretzla@linux.microsoft.com>

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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 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(-)

diff --git a/drivers/net/mlx5/linux/mlx5_verbs.c b/drivers/net/mlx5/linux/mlx5_verbs.c
index 67a7bec..c722613 100644
--- a/drivers/net/mlx5/linux/mlx5_verbs.c
+++ b/drivers/net/mlx5/linux/mlx5_verbs.c
@@ -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);
diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index a6a426c..1c51b29 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -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);
diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
index f93dd40..0233cde 100644
--- a/drivers/net/mlx5/mlx5_flow_dv.c
+++ b/drivers/net/mlx5/mlx5_flow_dv.c
@@ -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);
diff --git a/drivers/net/mlx5/mlx5_flow_flex.c b/drivers/net/mlx5/mlx5_flow_flex.c
index 35f2a99..a825274 100644
--- a/drivers/net/mlx5/mlx5_flow_flex.c
+++ b/drivers/net/mlx5/mlx5_flow_flex.c
@@ -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:
diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c
index a9c7045..159ebb5 100644
--- a/drivers/net/mlx5/mlx5_flow_hw.c
+++ b/drivers/net/mlx5/mlx5_flow_hw.c
@@ -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);
diff --git a/drivers/net/mlx5/mlx5_flow_meter.c b/drivers/net/mlx5/mlx5_flow_meter.c
index 08f8aad..cb26a12 100644
--- a/drivers/net/mlx5/mlx5_flow_meter.c
+++ b/drivers/net/mlx5/mlx5_flow_meter.c
@@ -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;
diff --git a/drivers/net/mlx5/mlx5_rx.h b/drivers/net/mlx5/mlx5_rx.h
index 6b42e27..ba62398 100644
--- a/drivers/net/mlx5/mlx5_rx.h
+++ b/drivers/net/mlx5/mlx5_rx.h
@@ -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);
-- 
1.8.3.1


  parent reply	other threads:[~2023-03-02  0:49 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-02  0:47 [PATCH 00/17] use __atomic operations returning previous value Tyler Retzlaff
2023-03-02  0:47 ` [PATCH 01/17] vhost: use previous value atomic fetch operations Tyler Retzlaff
2023-03-02 14:47   ` Maxime Coquelin
2023-03-02  0:47 ` [PATCH 02/17] telemetry: " Tyler Retzlaff
2023-03-02  9:34   ` Bruce Richardson
2023-03-02  0:47 ` [PATCH 03/17] stack: " Tyler Retzlaff
2023-03-02  0:47 ` [PATCH 04/17] eal: " Tyler Retzlaff
2023-03-02  0:47 ` [PATCH 05/17] distributor: " Tyler Retzlaff
2023-03-02  0:47 ` [PATCH 06/17] bbdev: " Tyler Retzlaff
2023-03-02  0:47 ` [PATCH 07/17] examples/vhost: " Tyler Retzlaff
2023-03-02 14:47   ` Maxime Coquelin
2023-03-02  0:47 ` [PATCH 08/17] net/virtio: " Tyler Retzlaff
2023-03-02 14:48   ` Maxime Coquelin
2023-03-02  0:47 ` [PATCH 09/17] net/octeontx: " Tyler Retzlaff
2023-03-02  0:47 ` Tyler Retzlaff [this message]
2023-03-02  0:47 ` [PATCH 11/17] net/iavf: " Tyler Retzlaff
2023-03-02  9:28   ` Ruifeng Wang
2023-03-02 15:50     ` Tyler Retzlaff
2023-03-02  0:47 ` [PATCH 12/17] net/cxgbe: " Tyler Retzlaff
2023-03-02  0:47 ` [PATCH 13/17] drivers/event: " Tyler Retzlaff
2023-03-02  0:47 ` [PATCH 14/17] dma/skeleton: " Tyler Retzlaff
2023-03-02  0:47 ` [PATCH 15/17] drivers/common: " Tyler Retzlaff
2023-03-02  0:47 ` [PATCH 16/17] app/test: " Tyler Retzlaff
2023-03-02  0:47 ` [PATCH 17/17] test-eventdev: " Tyler Retzlaff
2023-03-02 14:40 ` [PATCH 00/17] use __atomic operations returning previous value Morten Brørup
2023-03-02 16:18 ` [PATCH v2 " Tyler Retzlaff
2023-03-02 16:18   ` [PATCH v2 01/17] vhost: use previous value atomic fetch operations Tyler Retzlaff
2023-03-02 16:18   ` [PATCH v2 02/17] telemetry: " Tyler Retzlaff
2023-03-02 16:18   ` [PATCH v2 03/17] stack: " Tyler Retzlaff
2023-03-02 16:18   ` [PATCH v2 04/17] eal: " Tyler Retzlaff
2023-03-02 16:18   ` [PATCH v2 05/17] distributor: " Tyler Retzlaff
2023-03-02 16:18   ` [PATCH v2 06/17] bbdev: " Tyler Retzlaff
2023-03-02 16:18   ` [PATCH v2 07/17] examples/vhost: " Tyler Retzlaff
2023-03-02 16:18   ` [PATCH v2 08/17] net/virtio: " Tyler Retzlaff
2023-03-02 16:18   ` [PATCH v2 09/17] net/octeontx: " Tyler Retzlaff
2023-03-02 16:18   ` [PATCH v2 10/17] net/mlx5: " Tyler Retzlaff
2023-03-02 16:18   ` [PATCH v2 11/17] net/iavf: " Tyler Retzlaff
2023-03-02 16:18   ` [PATCH v2 12/17] net/cxgbe: " Tyler Retzlaff
2023-03-02 16:18   ` [PATCH v2 13/17] drivers/event: " Tyler Retzlaff
2023-03-13  7:02     ` [EXT] " Pavan Nikhilesh Bhagavatula
2023-03-02 16:18   ` [PATCH v2 14/17] dma/skeleton: " Tyler Retzlaff
2023-03-02 16:18   ` [PATCH v2 15/17] drivers/common: " Tyler Retzlaff
2023-03-02 16:18   ` [PATCH v2 16/17] app/test: " Tyler Retzlaff
2023-03-02 16:18   ` [PATCH v2 17/17] test-eventdev: " Tyler Retzlaff
2023-03-03  1:54   ` [PATCH v2 00/17] use __atomic operations returning previous value Ruifeng Wang
2023-03-03  2:33   ` fengchengwen
2023-04-25  9:10   ` David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1677718068-2412-11-git-send-email-roretzla@linux.microsoft.com \
    --to=roretzla@linux.microsoft.com \
    --cc=Honnappa.Nagarahalli@arm.com \
    --cc=dev@dpdk.org \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).