From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id BD53F41E6D; Fri, 10 Mar 2023 23:16:55 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6A58442D36; Fri, 10 Mar 2023 23:15:51 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 1412240DD8 for ; Fri, 10 Mar 2023 23:15:37 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id EAEB22044735; Fri, 10 Mar 2023 14:15:35 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com EAEB22044735 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1678486535; bh=gfoZyEjJutfqnPQMIgbsZMuiF73RQDd48uZHDY6KFxw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KBWQxQpUFRtM2z8tLD0lCsofX4Q9BEyMExJESTwZlGe9uV7WIrAIxFkehTHYl+IJu PxnhEdNYQbYLrv6+ecqc+wBnNFzB9Lri2XOk13/CVsMigXq6fLbCKBUDhMr+boo0tN /fqaZ3KbgxMzsB5yjex2rXsZPqQO2cEcadvqiLeU= From: Tyler Retzlaff To: dev@dpdk.org Cc: Honnappa.Nagarahalli@arm.com, Ruifeng.Wang@arm.com, thomas@monjalon.net, Tyler Retzlaff Subject: [PATCH 09/16] net/mlx5: use previous value atomic fetch operations Date: Fri, 10 Mar 2023 14:15:23 -0800 Message-Id: <1678486530-20688-10-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1678486530-20688-1-git-send-email-roretzla@linux.microsoft.com> References: <1678486530-20688-1-git-send-email-roretzla@linux.microsoft.com> X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Use __atomic_fetch_{add,and,or,sub,xor} instead of __atomic_{add,and,or,sub,xor}_fetch adding the necessary code to allow consumption of the resulting value. Signed-off-by: Tyler Retzlaff --- drivers/net/mlx5/linux/mlx5_verbs.c | 2 +- drivers/net/mlx5/mlx5.c | 4 ++-- drivers/net/mlx5/mlx5_flow.c | 8 ++++---- drivers/net/mlx5/mlx5_flow_dv.c | 12 ++++++------ drivers/net/mlx5/mlx5_flow_hw.c | 14 +++++++------- drivers/net/mlx5/mlx5_hws_cnt.c | 4 ++-- drivers/net/mlx5/mlx5_rxq.c | 6 +++--- drivers/net/mlx5/mlx5_txq.c | 2 +- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/drivers/net/mlx5/linux/mlx5_verbs.c b/drivers/net/mlx5/linux/mlx5_verbs.c index 67a7bec..ee5d072 100644 --- a/drivers/net/mlx5/linux/mlx5_verbs.c +++ b/drivers/net/mlx5/linux/mlx5_verbs.c @@ -1183,7 +1183,7 @@ if (!priv->lb_used) return; MLX5_ASSERT(__atomic_load_n(&sh->self_lb.refcnt, __ATOMIC_RELAXED)); - if (!(__atomic_sub_fetch(&sh->self_lb.refcnt, 1, __ATOMIC_RELAXED))) { + if (!(__atomic_fetch_sub(&sh->self_lb.refcnt, 1, __ATOMIC_RELAXED) - 1)) { if (sh->self_lb.qp) { claim_zero(mlx5_glue->destroy_qp(sh->self_lb.qp)); sh->self_lb.qp = NULL; diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 41b1b12..044012d 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -1068,7 +1068,7 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list = DRV_LOG(ERR, "Dynamic flex parser is not supported"); return -ENOTSUP; } - if (__atomic_add_fetch(&priv->sh->srh_flex_parser.refcnt, 1, __ATOMIC_RELAXED) > 1) + if (__atomic_fetch_add(&priv->sh->srh_flex_parser.refcnt, 1, __ATOMIC_RELAXED) + 1 > 1) return 0; node.header_length_mode = MLX5_GRAPH_NODE_LEN_FIELD; @@ -1123,7 +1123,7 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list = struct mlx5_priv *priv = dev->data->dev_private; struct mlx5_internal_flex_parser_profile *fp = &priv->sh->srh_flex_parser; - if (__atomic_sub_fetch(&fp->refcnt, 1, __ATOMIC_RELAXED)) + if (__atomic_fetch_sub(&fp->refcnt, 1, __ATOMIC_RELAXED) - 1) return; if (fp->fp) mlx5_devx_cmd_destroy(fp->fp); diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index 75f7d87..0bf527e 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -7833,7 +7833,7 @@ struct rte_flow * tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id); RTE_VERIFY(tunnel); - if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED)) + if (!(__atomic_fetch_sub(&tunnel->refctn, 1, __ATOMIC_RELAXED) - 1)) mlx5_flow_tunnel_free(dev, tunnel); } flow_mreg_del_copy_action(dev, flow); @@ -9742,9 +9742,9 @@ struct mlx5_flow_workspace* __ATOMIC_RELAXED); continue; } - if (__atomic_add_fetch(&age_param->sec_since_last_hit, + if (__atomic_fetch_add(&age_param->sec_since_last_hit, time_delta, - __ATOMIC_RELAXED) <= age_param->timeout) + __ATOMIC_RELAXED) + time_delta <= age_param->timeout) continue; /** * Hold the lock first, or if between the @@ -11387,7 +11387,7 @@ struct tunnel_db_element_release_ctx { { struct tunnel_db_element_release_ctx *ctx = x; ctx->ret = 0; - if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED)) + if (!(__atomic_fetch_sub(&tunnel->refctn, 1, __ATOMIC_RELAXED) - 1)) mlx5_flow_tunnel_free(dev, tunnel); } diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c index ca26f39..f04160e 100644 --- a/drivers/net/mlx5/mlx5_flow_dv.c +++ b/drivers/net/mlx5/mlx5_flow_dv.c @@ -6723,8 +6723,8 @@ struct mlx5_list_entry * * indirect action API, shared info is 1 before the reduction, * so this condition is failed and function doesn't return here. */ - if (__atomic_sub_fetch(&cnt->shared_info.refcnt, 1, - __ATOMIC_RELAXED)) + if (__atomic_fetch_sub(&cnt->shared_info.refcnt, 1, + __ATOMIC_RELAXED) - 1) return; } cnt->pool = pool; @@ -12797,7 +12797,7 @@ struct mlx5_list_entry * struct mlx5_priv *priv = dev->data->dev_private; struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng; struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx); - uint32_t ret = __atomic_sub_fetch(&age->refcnt, 1, __ATOMIC_RELAXED); + uint32_t ret = __atomic_fetch_sub(&age->refcnt, 1, __ATOMIC_RELAXED) - 1; if (!ret) { flow_dv_aso_age_remove_from_age(dev, age); @@ -13193,7 +13193,7 @@ struct mlx5_list_entry * /* Cannot release when CT is in the ASO SQ. */ if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY) return -1; - ret = __atomic_sub_fetch(&ct->refcnt, 1, __ATOMIC_RELAXED); + ret = __atomic_fetch_sub(&ct->refcnt, 1, __ATOMIC_RELAXED) - 1; if (!ret) { if (ct->dr_action_orig) { #ifdef HAVE_MLX5_DR_ACTION_ASO_CT @@ -15582,8 +15582,8 @@ struct mlx5_list_entry * sh->geneve_tlv_option_resource; rte_spinlock_lock(&sh->geneve_tlv_opt_sl); if (geneve_opt_resource) { - if (!(__atomic_sub_fetch(&geneve_opt_resource->refcnt, 1, - __ATOMIC_RELAXED))) { + if (!(__atomic_fetch_sub(&geneve_opt_resource->refcnt, 1, + __ATOMIC_RELAXED) - 1)) { claim_zero(mlx5_devx_cmd_destroy (geneve_opt_resource->obj)); mlx5_free(sh->geneve_tlv_option_resource); diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c index 9392727..109aab1 100644 --- a/drivers/net/mlx5/mlx5_flow_hw.c +++ b/drivers/net/mlx5/mlx5_flow_hw.c @@ -458,7 +458,7 @@ static int flow_hw_translate_group(struct rte_eth_dev *dev, } if (acts->mark) - if (!__atomic_sub_fetch(&priv->hws_mark_refcnt, 1, __ATOMIC_RELAXED)) + if (!(__atomic_fetch_sub(&priv->hws_mark_refcnt, 1, __ATOMIC_RELAXED) - 1)) flow_hw_rxq_flag_set(dev, false); if (acts->jump) { @@ -3268,8 +3268,8 @@ static rte_be32_t vlan_hdr_to_be32(const struct rte_flow_action *actions) rte_errno = EINVAL; goto it_error; } - ret = __atomic_add_fetch(&item_templates[i]->refcnt, 1, - __ATOMIC_RELAXED); + ret = __atomic_fetch_add(&item_templates[i]->refcnt, 1, + __ATOMIC_RELAXED) + 1; if (ret <= 1) { rte_errno = EINVAL; goto it_error; @@ -3282,8 +3282,8 @@ static rte_be32_t vlan_hdr_to_be32(const struct rte_flow_action *actions) for (i = 0; i < nb_action_templates; i++) { uint32_t ret; - ret = __atomic_add_fetch(&action_templates[i]->refcnt, 1, - __ATOMIC_RELAXED); + ret = __atomic_fetch_add(&action_templates[i]->refcnt, 1, + __ATOMIC_RELAXED) + 1; if (ret <= 1) { rte_errno = EINVAL; goto at_error; @@ -7624,8 +7624,8 @@ void flow_hw_clear_tags_set(struct rte_eth_dev *dev) { uint32_t refcnt; - refcnt = __atomic_sub_fetch(&mlx5_flow_hw_flow_metadata_config_refcnt, 1, - __ATOMIC_RELAXED); + refcnt = __atomic_fetch_sub(&mlx5_flow_hw_flow_metadata_config_refcnt, 1, + __ATOMIC_RELAXED) - 1; if (refcnt > 0) return; mlx5_flow_hw_flow_metadata_esw_en = 0; diff --git a/drivers/net/mlx5/mlx5_hws_cnt.c b/drivers/net/mlx5/mlx5_hws_cnt.c index d6a017a..d98df68 100644 --- a/drivers/net/mlx5/mlx5_hws_cnt.c +++ b/drivers/net/mlx5/mlx5_hws_cnt.c @@ -192,8 +192,8 @@ } param->accumulator_hits = 0; } - if (__atomic_add_fetch(¶m->sec_since_last_hit, time_delta, - __ATOMIC_RELAXED) <= + if (__atomic_fetch_add(¶m->sec_since_last_hit, time_delta, + __ATOMIC_RELAXED) + time_delta <= __atomic_load_n(¶m->timeout, __ATOMIC_RELAXED)) continue; /* Prepare the relevant ring for this AGE parameter */ diff --git a/drivers/net/mlx5/mlx5_rxq.c b/drivers/net/mlx5/mlx5_rxq.c index 6e99c4d..ad8fd13 100644 --- a/drivers/net/mlx5/mlx5_rxq.c +++ b/drivers/net/mlx5/mlx5_rxq.c @@ -2042,7 +2042,7 @@ struct mlx5_rxq_priv * if (rxq == NULL) return 0; - return __atomic_sub_fetch(&rxq->refcnt, 1, __ATOMIC_RELAXED); + return __atomic_fetch_sub(&rxq->refcnt, 1, __ATOMIC_RELAXED) - 1; } /** @@ -2141,7 +2141,7 @@ struct mlx5_external_rxq * { struct mlx5_external_rxq *rxq = mlx5_ext_rxq_get(dev, idx); - return __atomic_sub_fetch(&rxq->refcnt, 1, __ATOMIC_RELAXED); + return __atomic_fetch_sub(&rxq->refcnt, 1, __ATOMIC_RELAXED) - 1; } /** @@ -2462,7 +2462,7 @@ struct mlx5_ind_table_obj * unsigned int ret; rte_rwlock_write_lock(&priv->ind_tbls_lock); - ret = __atomic_sub_fetch(&ind_tbl->refcnt, 1, __ATOMIC_RELAXED); + ret = __atomic_fetch_sub(&ind_tbl->refcnt, 1, __ATOMIC_RELAXED) - 1; if (!ret) LIST_REMOVE(ind_tbl, next); rte_rwlock_write_unlock(&priv->ind_tbls_lock); diff --git a/drivers/net/mlx5/mlx5_txq.c b/drivers/net/mlx5/mlx5_txq.c index 1e0e61a..8cb52b0 100644 --- a/drivers/net/mlx5/mlx5_txq.c +++ b/drivers/net/mlx5/mlx5_txq.c @@ -1203,7 +1203,7 @@ struct mlx5_txq_ctrl * if (priv->txqs == NULL || (*priv->txqs)[idx] == NULL) return 0; txq_ctrl = container_of((*priv->txqs)[idx], struct mlx5_txq_ctrl, txq); - if (__atomic_sub_fetch(&txq_ctrl->refcnt, 1, __ATOMIC_RELAXED) > 1) + if (__atomic_fetch_sub(&txq_ctrl->refcnt, 1, __ATOMIC_RELAXED) - 1 > 1) return 1; if (txq_ctrl->obj) { priv->obj_ops.txq_obj_release(txq_ctrl->obj); -- 1.8.3.1