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 A8DCE41E6D; Fri, 10 Mar 2023 23:16:04 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 51B8142B7E; Fri, 10 Mar 2023 23:15:42 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 58E4F40ED9 for ; Fri, 10 Mar 2023 23:15:36 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id A11432044728; Fri, 10 Mar 2023 14:15:35 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com A11432044728 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1678486535; bh=AiPSJbJTqUPb8O0FYv4kyX/7isrZ/oFbFet8HdS1saE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hztNO+v8q6YFzUTrlLQhi8r36wivr38Y0k14oUgnDbk943h1cuuXup9/v2l8ASO3V hJ0QZi1uaF7eNl37RIE96LMvrhYsupPPc81lZJHya1chL+qdFtABXP3pmgPVAjG5t7 9i3yLZF7EFZHvKinJMfJ8/jEc0A3g1bSB8nHKjv8= From: Tyler Retzlaff To: dev@dpdk.org Cc: Honnappa.Nagarahalli@arm.com, Ruifeng.Wang@arm.com, thomas@monjalon.net, Tyler Retzlaff Subject: [PATCH 03/16] common/mlx5: use previous value atomic fetch operations Date: Fri, 10 Mar 2023 14:15:17 -0800 Message-Id: <1678486530-20688-4-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/common/mlx5/linux/mlx5_nl.c | 2 +- drivers/common/mlx5/mlx5_common_mr.c | 8 ++++---- drivers/common/mlx5/mlx5_common_utils.c | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/common/mlx5/linux/mlx5_nl.c b/drivers/common/mlx5/linux/mlx5_nl.c index 5d04857..33670bb 100644 --- a/drivers/common/mlx5/linux/mlx5_nl.c +++ b/drivers/common/mlx5/linux/mlx5_nl.c @@ -178,7 +178,7 @@ struct mlx5_nl_port_info { uint32_t atomic_sn; /* Generate Netlink sequence number. */ -#define MLX5_NL_SN_GENERATE __atomic_add_fetch(&atomic_sn, 1, __ATOMIC_RELAXED) +#define MLX5_NL_SN_GENERATE (__atomic_fetch_add(&atomic_sn, 1, __ATOMIC_RELAXED) + 1) /** * Opens a Netlink socket. diff --git a/drivers/common/mlx5/mlx5_common_mr.c b/drivers/common/mlx5/mlx5_common_mr.c index 0e1d243..037a4d8 100644 --- a/drivers/common/mlx5/mlx5_common_mr.c +++ b/drivers/common/mlx5/mlx5_common_mr.c @@ -58,8 +58,8 @@ struct mlx5_mempool_reg { if (__atomic_load_n(&buf->refcnt, __ATOMIC_RELAXED) == 1) { rte_mempool_put(buf->mp, buf); - } else if (unlikely(__atomic_sub_fetch(&buf->refcnt, 1, - __ATOMIC_RELAXED) == 0)) { + } else if (unlikely(__atomic_fetch_sub(&buf->refcnt, 1, + __ATOMIC_RELAXED) - 1 == 0)) { __atomic_store_n(&buf->refcnt, 1, __ATOMIC_RELAXED); rte_mempool_put(buf->mp, buf); } @@ -1665,8 +1665,8 @@ struct mlx5_mempool_get_extmem_data { bool ret = false; for (i = 0; i < mpr->mrs_n; i++) - ret |= __atomic_sub_fetch(&mpr->mrs[i].refcnt, 1, - __ATOMIC_RELAXED) == 0; + ret |= __atomic_fetch_sub(&mpr->mrs[i].refcnt, 1, + __ATOMIC_RELAXED) - 1 == 0; return ret; } diff --git a/drivers/common/mlx5/mlx5_common_utils.c b/drivers/common/mlx5/mlx5_common_utils.c index 58d744b..06b5b9b 100644 --- a/drivers/common/mlx5/mlx5_common_utils.c +++ b/drivers/common/mlx5/mlx5_common_utils.c @@ -81,8 +81,8 @@ struct mlx5_list * while (entry != NULL) { if (l_const->cb_match(l_const->ctx, entry, ctx) == 0) { if (reuse) { - ret = __atomic_add_fetch(&entry->ref_cnt, 1, - __ATOMIC_RELAXED) - 1; + ret = __atomic_fetch_add(&entry->ref_cnt, 1, + __ATOMIC_RELAXED); DRV_LOG(DEBUG, "mlx5 list %s entry %p ref: %u.", l_const->name, (void *)entry, entry->ref_cnt); @@ -285,7 +285,7 @@ struct mlx5_list_entry * { struct mlx5_list_entry *gentry = entry->gentry; - if (__atomic_sub_fetch(&entry->ref_cnt, 1, __ATOMIC_RELAXED) != 0) + if (__atomic_fetch_sub(&entry->ref_cnt, 1, __ATOMIC_RELAXED) - 1 != 0) return 1; if (entry->lcore_idx == (uint32_t)lcore_idx) { LIST_REMOVE(entry, next); @@ -303,7 +303,7 @@ struct mlx5_list_entry * l_const->name, (void *)entry); return 0; } - if (__atomic_sub_fetch(&gentry->ref_cnt, 1, __ATOMIC_RELAXED) != 0) + if (__atomic_fetch_sub(&gentry->ref_cnt, 1, __ATOMIC_RELAXED) - 1 != 0) return 1; rte_rwlock_write_lock(&l_inconst->lock); if (likely(gentry->ref_cnt == 0)) { -- 1.8.3.1