[v2,4/4] ethdev: use C11 atomic builtins for link status update
diff mbox series

Message ID 1600244628-13062-5-git-send-email-phil.yang@arm.com
State Superseded
Delegated to: David Marchand
Headers show
Series
  • use C11 atomic builtins for libs
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/travis-robot success Travis build: passed
ci/iol-testing success Testing PASS
ci/checkpatch success coding style OK

Commit Message

Phil Yang Sept. 16, 2020, 8:23 a.m. UTC
Since rte_atomicXX APIs are not allowed to be used, use C11 atomic
builtins for link status update.

Signed-off-by: Phil Yang <phil.yang@arm.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
---
 lib/librte_ethdev/rte_ethdev_driver.h | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

Comments

Andrew Rybchenko Sept. 17, 2020, 4:08 p.m. UTC | #1
On 9/16/20 11:23 AM, Phil Yang wrote:
> Since rte_atomicXX APIs are not allowed to be used, use C11 atomic
> builtins for link status update.
> 
> Signed-off-by: Phil Yang <phil.yang@arm.com>
> Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
> Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>

Acked-by: Andrew Rybchenko <arybchenko@solarflare.com>

Patch
diff mbox series

diff --git a/lib/librte_ethdev/rte_ethdev_driver.h b/lib/librte_ethdev/rte_ethdev_driver.h
index 13fd049..ebaf6da 100644
--- a/lib/librte_ethdev/rte_ethdev_driver.h
+++ b/lib/librte_ethdev/rte_ethdev_driver.h
@@ -216,8 +216,7 @@  static inline int
 rte_eth_linkstatus_set(struct rte_eth_dev *dev,
 		       const struct rte_eth_link *new_link)
 {
-	volatile uint64_t *dev_link
-		 = (volatile uint64_t *)&(dev->data->dev_link);
+	uint64_t *dev_link = (uint64_t *)&(dev->data->dev_link);
 	union {
 		uint64_t val64;
 		struct rte_eth_link link;
@@ -225,8 +224,8 @@  rte_eth_linkstatus_set(struct rte_eth_dev *dev,
 
 	RTE_BUILD_BUG_ON(sizeof(*new_link) != sizeof(uint64_t));
 
-	orig.val64 = rte_atomic64_exchange(dev_link,
-					   *(const uint64_t *)new_link);
+	orig.val64 = __atomic_exchange_n(dev_link, *(const uint64_t *)new_link,
+					__ATOMIC_SEQ_CST);
 
 	return (orig.link.link_status == new_link->link_status) ? -1 : 0;
 }
@@ -244,20 +243,12 @@  static inline void
 rte_eth_linkstatus_get(const struct rte_eth_dev *dev,
 		       struct rte_eth_link *link)
 {
-	volatile uint64_t *src = (uint64_t *)&(dev->data->dev_link);
+	uint64_t *src = (uint64_t *)&(dev->data->dev_link);
 	uint64_t *dst = (uint64_t *)link;
 
 	RTE_BUILD_BUG_ON(sizeof(*link) != sizeof(uint64_t));
 
-#ifdef __LP64__
-	/* if cpu arch has 64 bit unsigned lon then implicitly atomic */
-	*dst = *src;
-#else
-	/* can't use rte_atomic64_read because it returns signed int */
-	do {
-		*dst = *src;
-	} while (!rte_atomic64_cmpset(src, *dst, *dst));
-#endif
+	*dst = __atomic_load_n(src, __ATOMIC_SEQ_CST);
 }
 
 /**