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 43A8C41DAF; Thu, 2 Mar 2023 01:49:23 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B80C942D4F; Thu, 2 Mar 2023 01:48:18 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id E6B2A427EE for ; Thu, 2 Mar 2023 01:48:03 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id A15BA20BC5F0; Wed, 1 Mar 2023 16:48:02 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com A15BA20BC5F0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1677718082; bh=MzKmYk5JmvrwSyVoDIHINoxiTSLeg2r7NfOum45qy/k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Knnu6sPvQ+8R4jOUQpt0xsG2Pc3Qr+mk2g4mADi2bUjNJBfUY7l+WhRMynPAfe2Nw IvFsO+NFHIjjdHNYt6ICD+apN3dQ5PyDqTufvQ88WRYFVT4GioKZPX04OAEZr2W8H6 lrRVB/J8HjHlDq5JDJs6lb0hPTOiCP+XavBfTBRo= From: Tyler Retzlaff To: dev@dpdk.org Cc: Honnappa.Nagarahalli@arm.com, thomas@monjalon.net, Tyler Retzlaff Subject: [PATCH 15/17] drivers/common: use previous value atomic fetch operations Date: Wed, 1 Mar 2023 16:47:46 -0800 Message-Id: <1677718068-2412-16-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1677718068-2412-1-git-send-email-roretzla@linux.microsoft.com> References: <1677718068-2412-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 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 --- 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(-) diff --git a/drivers/common/cnxk/roc_nix_inl_dev.c b/drivers/common/cnxk/roc_nix_inl_dev.c index 6f60961..45d6f62 100644 --- a/drivers/common/cnxk/roc_nix_inl_dev.c +++ b/drivers/common/cnxk/roc_nix_inl_dev.c @@ -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"); diff --git a/drivers/common/mlx5/mlx5_common_mr.c b/drivers/common/mlx5/mlx5_common_mr.c index 0e1d243..9ebe398 100644 --- a/drivers/common/mlx5/mlx5_common_mr.c +++ b/drivers/common/mlx5/mlx5_common_mr.c @@ -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); } /** diff --git a/drivers/common/mlx5/mlx5_common_utils.c b/drivers/common/mlx5/mlx5_common_utils.c index 58d744b..915a317 100644 --- a/drivers/common/mlx5/mlx5_common_utils.c +++ b/drivers/common/mlx5/mlx5_common_utils.c @@ -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; diff --git a/drivers/common/mlx5/mlx5_malloc.c b/drivers/common/mlx5/mlx5_malloc.c index cef3b88..c58c41d 100644 --- a/drivers/common/mlx5/mlx5_malloc.c +++ b/drivers/common/mlx5/mlx5_malloc.c @@ -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); -- 1.8.3.1