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 3479941DB5; Thu, 2 Mar 2023 17:20:26 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 08BC342D6D; Thu, 2 Mar 2023 17:18:50 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 58059400D6 for ; Thu, 2 Mar 2023 17:18:32 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id B0AA220BC5F6; Thu, 2 Mar 2023 08:18:30 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com B0AA220BC5F6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1677773910; bh=ljFx2P3N/4vgRyj/Y2Nq+Ee3KmCc5zul79Tc0Zy0hf0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q7RMI93tPqcx+bkaqRpuKvoBJw/9XLxTfg2oN7AMS/0ufVmB2K6S1jxem4sRWvjoG mP2SGYKVNc+vSfLw/O7Xro5YX2rzXOR85MjfRyVvnnRO+KToIQzxEXPI9ga5EFWZ3v YenZbXqX9MN85QV9nsQcKy62dDeNr81EvuQk8x7M= From: Tyler Retzlaff To: dev@dpdk.org Cc: Honnappa.Nagarahalli@arm.com, thomas@monjalon.net, bruce.richardson@intel.com, mb@smartsharesystems.com, Ruifeng.Wang@arm.com, maxime.coquelin@redhat.com, Tyler Retzlaff Subject: [PATCH v2 15/17] drivers/common: use previous value atomic fetch operations Date: Thu, 2 Mar 2023 08:18:20 -0800 Message-Id: <1677773902-5167-16-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1677773902-5167-1-git-send-email-roretzla@linux.microsoft.com> References: <1677718068-2412-1-git-send-email-roretzla@linux.microsoft.com> <1677773902-5167-1-git-send-email-roretzla@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Acked-by: Morten Brørup --- 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