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 530FB41EA5; Wed, 15 Mar 2023 22:17:15 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8FBF342D52; Wed, 15 Mar 2023 22:16:04 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 72CB342686 for ; Wed, 15 Mar 2023 22:15:48 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id 5C56920C5A4D; Wed, 15 Mar 2023 14:15:46 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5C56920C5A4D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1678914947; bh=WRyPi+Y0K7PVxL8pIDxajZYQd0JEu7UkGRD/uC7eQNE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VZDPFwg8WEmJ4UpKiKh9PVcSbhQXsLBMhWqXbtG0Sb4FnvCu0zEll9rhXHOewaxph shIvzz7Ocjtyj1oKY0+srdg+nwNqmdDtq9vukYYUII538MnFkExKZvcmw7ltMSHyBr f5zRyFyNO5+m7IwUw3hYQexV+1V5S/jOinmqxBqQ= From: Tyler Retzlaff To: dev@dpdk.org Cc: Honnappa.Nagarahalli@arm.com, Ruifeng.Wang@arm.com, thomas@monjalon.net, Tyler Retzlaff Subject: [PATCH v2 13/16] eal: use previous value atomic fetch operations Date: Wed, 15 Mar 2023 14:15:42 -0700 Message-Id: <1678914945-10638-14-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1678914945-10638-1-git-send-email-roretzla@linux.microsoft.com> References: <1678486530-20688-1-git-send-email-roretzla@linux.microsoft.com> <1678914945-10638-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 --- lib/eal/include/generic/rte_rwlock.h | 8 ++++---- lib/eal/ppc/include/rte_atomic.h | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/eal/include/generic/rte_rwlock.h b/lib/eal/include/generic/rte_rwlock.h index d45c22c..71e2d8d 100644 --- a/lib/eal/include/generic/rte_rwlock.h +++ b/lib/eal/include/generic/rte_rwlock.h @@ -97,8 +97,8 @@ rte_pause(); /* Try to get read lock */ - x = __atomic_add_fetch(&rwl->cnt, RTE_RWLOCK_READ, - __ATOMIC_ACQUIRE); + x = __atomic_fetch_add(&rwl->cnt, RTE_RWLOCK_READ, + __ATOMIC_ACQUIRE) + RTE_RWLOCK_READ; /* If no writer, then acquire was successful */ if (likely(!(x & RTE_RWLOCK_MASK))) @@ -134,8 +134,8 @@ return -EBUSY; /* Try to get read lock */ - x = __atomic_add_fetch(&rwl->cnt, RTE_RWLOCK_READ, - __ATOMIC_ACQUIRE); + x = __atomic_fetch_add(&rwl->cnt, RTE_RWLOCK_READ, + __ATOMIC_ACQUIRE) + RTE_RWLOCK_READ; /* Back out if writer raced in */ if (unlikely(x & RTE_RWLOCK_MASK)) { diff --git a/lib/eal/ppc/include/rte_atomic.h b/lib/eal/ppc/include/rte_atomic.h index 663b4d3..ffabd98 100644 --- a/lib/eal/ppc/include/rte_atomic.h +++ b/lib/eal/ppc/include/rte_atomic.h @@ -71,12 +71,12 @@ static inline int rte_atomic16_test_and_set(rte_atomic16_t *v) static inline int rte_atomic16_inc_and_test(rte_atomic16_t *v) { - return __atomic_add_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0; + return __atomic_fetch_add(&v->cnt, 1, __ATOMIC_ACQUIRE) + 1 == 0; } static inline int rte_atomic16_dec_and_test(rte_atomic16_t *v) { - return __atomic_sub_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0; + return __atomic_fetch_sub(&v->cnt, 1, __ATOMIC_ACQUIRE) - 1 == 0; } static inline uint16_t @@ -113,12 +113,12 @@ static inline int rte_atomic32_test_and_set(rte_atomic32_t *v) static inline int rte_atomic32_inc_and_test(rte_atomic32_t *v) { - return __atomic_add_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0; + return __atomic_fetch_add(&v->cnt, 1, __ATOMIC_ACQUIRE) + 1 == 0; } static inline int rte_atomic32_dec_and_test(rte_atomic32_t *v) { - return __atomic_sub_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0; + return __atomic_fetch_sub(&v->cnt, 1, __ATOMIC_ACQUIRE) - 1 == 0; } static inline uint32_t @@ -181,23 +181,23 @@ static inline int rte_atomic32_dec_and_test(rte_atomic32_t *v) static inline int64_t rte_atomic64_add_return(rte_atomic64_t *v, int64_t inc) { - return __atomic_add_fetch(&v->cnt, inc, __ATOMIC_ACQUIRE); + return __atomic_fetch_add(&v->cnt, inc, __ATOMIC_ACQUIRE) + inc; } static inline int64_t rte_atomic64_sub_return(rte_atomic64_t *v, int64_t dec) { - return __atomic_sub_fetch(&v->cnt, dec, __ATOMIC_ACQUIRE); + return __atomic_fetch_sub(&v->cnt, dec, __ATOMIC_ACQUIRE) - dec; } static inline int rte_atomic64_inc_and_test(rte_atomic64_t *v) { - return __atomic_add_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0; + return __atomic_fetch_add(&v->cnt, 1, __ATOMIC_ACQUIRE) + 1 == 0; } static inline int rte_atomic64_dec_and_test(rte_atomic64_t *v) { - return __atomic_sub_fetch(&v->cnt, 1, __ATOMIC_ACQUIRE) == 0; + return __atomic_fetch_sub(&v->cnt, 1, __ATOMIC_ACQUIRE) - 1 == 0; } static inline int rte_atomic64_test_and_set(rte_atomic64_t *v) -- 1.8.3.1