DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tyler Retzlaff <roretzla@linux.microsoft.com>
To: dev@dpdk.org
Cc: Honnappa.Nagarahalli@arm.com, Ruifeng.Wang@arm.com,
	thomas@monjalon.net,
	Tyler Retzlaff <roretzla@linux.microsoft.com>
Subject: [PATCH v2 13/16] eal: use previous value atomic fetch operations
Date: Wed, 15 Mar 2023 14:15:42 -0700	[thread overview]
Message-ID: <1678914945-10638-14-git-send-email-roretzla@linux.microsoft.com> (raw)
In-Reply-To: <1678914945-10638-1-git-send-email-roretzla@linux.microsoft.com>

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 <roretzla@linux.microsoft.com>
---
 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


  parent reply	other threads:[~2023-03-15 21:17 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-10 22:15 [PATCH 00/16] use __atomic operations returning new value Tyler Retzlaff
2023-03-10 22:15 ` [PATCH 01/16] app/test: use previous value atomic fetch operations Tyler Retzlaff
2023-03-10 22:15 ` [PATCH 02/16] common/cnxk: " Tyler Retzlaff
2023-03-10 22:15 ` [PATCH 03/16] common/mlx5: " Tyler Retzlaff
2023-03-10 22:15 ` [PATCH 04/16] drivers/event: " Tyler Retzlaff
2023-03-13  7:02   ` [EXT] " Pavan Nikhilesh Bhagavatula
2023-03-10 22:15 ` [PATCH 05/16] net/af_xdp: " Tyler Retzlaff
2023-03-10 22:15 ` [PATCH 06/16] net/cnxk: " Tyler Retzlaff
2023-03-13  6:45   ` [EXT] " Nithin Kumar Dabilpuram
2023-03-10 22:15 ` [PATCH 07/16] net/cxgbe: " Tyler Retzlaff
2023-03-10 22:15 ` [PATCH 08/16] net/iavf: " Tyler Retzlaff
2023-03-10 22:15 ` [PATCH 09/16] net/mlx5: " Tyler Retzlaff
2023-03-10 22:15 ` [PATCH 10/16] net/octeontx: " Tyler Retzlaff
2023-03-10 22:15 ` [PATCH 11/16] raw/ifpga: " Tyler Retzlaff
2023-03-10 22:15 ` [PATCH 12/16] bbdev: " Tyler Retzlaff
2023-03-10 22:15 ` [PATCH 13/16] eal: " Tyler Retzlaff
2023-03-10 22:15 ` [PATCH 14/16] ipsec: " Tyler Retzlaff
2023-03-10 22:15 ` [PATCH 15/16] mbuf: " Tyler Retzlaff
2023-03-10 22:15 ` [PATCH 16/16] rcu: " Tyler Retzlaff
2023-03-15 21:15 ` [PATCH v2 00/16] replace __atomic operations returning new value Tyler Retzlaff
2023-03-15 21:15   ` [PATCH v2 01/16] app/test: use previous value atomic fetch operations Tyler Retzlaff
2023-03-15 21:15   ` [PATCH v2 02/16] common/cnxk: " Tyler Retzlaff
2023-03-15 21:15   ` [PATCH v2 03/16] common/mlx5: " Tyler Retzlaff
2023-03-15 21:15   ` [PATCH v2 04/16] drivers/event: " Tyler Retzlaff
2023-03-15 21:15   ` [PATCH v2 05/16] net/af_xdp: " Tyler Retzlaff
2023-03-15 21:15   ` [PATCH v2 06/16] net/cnxk: " Tyler Retzlaff
2023-03-15 21:15   ` [PATCH v2 07/16] net/cxgbe: " Tyler Retzlaff
2023-03-15 21:15   ` [PATCH v2 08/16] net/iavf: " Tyler Retzlaff
2023-03-15 21:15   ` [PATCH v2 09/16] net/mlx5: " Tyler Retzlaff
2023-03-15 21:15   ` [PATCH v2 10/16] net/octeontx: " Tyler Retzlaff
2023-03-15 21:15   ` [PATCH v2 11/16] raw/ifpga: " Tyler Retzlaff
2023-03-15 21:15   ` [PATCH v2 12/16] bbdev: " Tyler Retzlaff
2023-03-15 21:15   ` Tyler Retzlaff [this message]
2023-03-15 21:15   ` [PATCH v2 14/16] ipsec: " Tyler Retzlaff
2023-03-15 21:15   ` [PATCH v2 15/16] mbuf: " Tyler Retzlaff
2023-03-15 21:15   ` [PATCH v2 16/16] rcu: " Tyler Retzlaff
2023-03-16 10:03   ` [PATCH v2 00/16] replace __atomic operations returning new value Bruce Richardson
2023-03-16 15:25     ` Thomas Monjalon
2023-03-16 16:17       ` Tyler Retzlaff
2023-04-18 18:11         ` Tyler Retzlaff
2023-03-20 10:24   ` Ruifeng Wang
2023-03-20 19:00 ` [PATCH v3 " Tyler Retzlaff
2023-03-20 19:00   ` [PATCH v3 01/16] app/test: use previous value atomic fetch operations Tyler Retzlaff
2023-03-20 19:00   ` [PATCH v3 02/16] common/cnxk: " Tyler Retzlaff
2023-03-20 19:00   ` [PATCH v3 03/16] common/mlx5: " Tyler Retzlaff
2023-03-20 19:00   ` [PATCH v3 04/16] drivers/event: " Tyler Retzlaff
2023-03-20 19:00   ` [PATCH v3 05/16] net/af_xdp: " Tyler Retzlaff
2023-03-20 19:00   ` [PATCH v3 06/16] net/cnxk: " Tyler Retzlaff
2023-03-20 19:00   ` [PATCH v3 07/16] net/cxgbe: " Tyler Retzlaff
2023-03-20 19:00   ` [PATCH v3 08/16] net/iavf: " Tyler Retzlaff
2023-03-20 19:00   ` [PATCH v3 09/16] net/mlx5: " Tyler Retzlaff
2023-03-20 19:00   ` [PATCH v3 10/16] net/octeontx: " Tyler Retzlaff
2023-03-20 19:00   ` [PATCH v3 11/16] raw/ifpga: " Tyler Retzlaff
2023-03-20 19:00   ` [PATCH v3 12/16] bbdev: " Tyler Retzlaff
2023-03-20 19:00   ` [PATCH v3 13/16] eal: " Tyler Retzlaff
2023-03-20 19:00   ` [PATCH v3 14/16] ipsec: " Tyler Retzlaff
2023-03-20 19:00   ` [PATCH v3 15/16] mbuf: " Tyler Retzlaff
2023-03-20 19:00   ` [PATCH v3 16/16] rcu: " Tyler Retzlaff
2023-04-25  9:10   ` [PATCH v3 00/16] replace __atomic operations returning new value David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1678914945-10638-14-git-send-email-roretzla@linux.microsoft.com \
    --to=roretzla@linux.microsoft.com \
    --cc=Honnappa.Nagarahalli@arm.com \
    --cc=Ruifeng.Wang@arm.com \
    --cc=dev@dpdk.org \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).