[v3,4/7] net/ice: replace rte atomics with GCC builtin atomics

Message ID 1679612036-30773-5-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series replace rte atomics with GCC builtin atomics |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Tyler Retzlaff March 23, 2023, 10:53 p.m. UTC
  Replace the use of rte_atomic.h types and functions, instead use GCC
supplied C++11 memory model builtins.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 drivers/net/ice/ice_dcf.c        |  1 -
 drivers/net/ice/ice_dcf_ethdev.c |  1 -
 drivers/net/ice/ice_ethdev.c     | 12 ++++++++----
 3 files changed, 8 insertions(+), 6 deletions(-)
  

Comments

David Marchand May 24, 2023, 8:10 p.m. UTC | #1
Hello Qiming, Qi,

Review please.

On Thu, Mar 23, 2023 at 11:54 PM Tyler Retzlaff
<roretzla@linux.microsoft.com> wrote:
>
> Replace the use of rte_atomic.h types and functions, instead use GCC
> supplied C++11 memory model builtins.
>
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> ---
>  drivers/net/ice/ice_dcf.c        |  1 -
>  drivers/net/ice/ice_dcf_ethdev.c |  1 -
>  drivers/net/ice/ice_ethdev.c     | 12 ++++++++----
>  3 files changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/ice/ice_dcf.c b/drivers/net/ice/ice_dcf.c
> index 1c3d22a..80d2cbd 100644
> --- a/drivers/net/ice/ice_dcf.c
> +++ b/drivers/net/ice/ice_dcf.c
> @@ -14,7 +14,6 @@
>  #include <rte_common.h>
>
>  #include <rte_pci.h>
> -#include <rte_atomic.h>
>  #include <rte_eal.h>
>  #include <rte_ether.h>
>  #include <ethdev_driver.h>
> diff --git a/drivers/net/ice/ice_dcf_ethdev.c b/drivers/net/ice/ice_dcf_ethdev.c
> index dcbf2af..13ff245 100644
> --- a/drivers/net/ice/ice_dcf_ethdev.c
> +++ b/drivers/net/ice/ice_dcf_ethdev.c
> @@ -11,7 +11,6 @@
>  #include <rte_interrupts.h>
>  #include <rte_debug.h>
>  #include <rte_pci.h>
> -#include <rte_atomic.h>
>  #include <rte_eal.h>
>  #include <rte_ether.h>
>  #include <ethdev_pci.h>
> diff --git a/drivers/net/ice/ice_ethdev.c b/drivers/net/ice/ice_ethdev.c
> index 9a88cf9..a04fca8 100644
> --- a/drivers/net/ice/ice_ethdev.c
> +++ b/drivers/net/ice/ice_ethdev.c
> @@ -3927,8 +3927,10 @@ static int ice_init_rss(struct ice_pf *pf)
>         struct rte_eth_link *dst = link;
>         struct rte_eth_link *src = &dev->data->dev_link;
>
> -       if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
> -                               *(uint64_t *)src) == 0)
> +       /* NOTE: review for potential ordering optimization */
> +       if (!__atomic_compare_exchange_n((uint64_t *)dst,
> +               (uint64_t *)dst, *(uint64_t *)src, 0,
> +               __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
>                 return -1;
>
>         return 0;
> @@ -3941,8 +3943,10 @@ static int ice_init_rss(struct ice_pf *pf)
>         struct rte_eth_link *dst = &dev->data->dev_link;
>         struct rte_eth_link *src = link;
>
> -       if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
> -                               *(uint64_t *)src) == 0)
> +       /* NOTE: review for potential ordering optimization */
> +       if (!__atomic_compare_exchange_n((uint64_t *)dst,
> +               (uint64_t *)dst, *(uint64_t *)src, 0,
> +               __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
>                 return -1;
>
>         return 0;
> --
> 1.8.3.1
>
  

Patch

diff --git a/drivers/net/ice/ice_dcf.c b/drivers/net/ice/ice_dcf.c
index 1c3d22a..80d2cbd 100644
--- a/drivers/net/ice/ice_dcf.c
+++ b/drivers/net/ice/ice_dcf.c
@@ -14,7 +14,6 @@ 
 #include <rte_common.h>
 
 #include <rte_pci.h>
-#include <rte_atomic.h>
 #include <rte_eal.h>
 #include <rte_ether.h>
 #include <ethdev_driver.h>
diff --git a/drivers/net/ice/ice_dcf_ethdev.c b/drivers/net/ice/ice_dcf_ethdev.c
index dcbf2af..13ff245 100644
--- a/drivers/net/ice/ice_dcf_ethdev.c
+++ b/drivers/net/ice/ice_dcf_ethdev.c
@@ -11,7 +11,6 @@ 
 #include <rte_interrupts.h>
 #include <rte_debug.h>
 #include <rte_pci.h>
-#include <rte_atomic.h>
 #include <rte_eal.h>
 #include <rte_ether.h>
 #include <ethdev_pci.h>
diff --git a/drivers/net/ice/ice_ethdev.c b/drivers/net/ice/ice_ethdev.c
index 9a88cf9..a04fca8 100644
--- a/drivers/net/ice/ice_ethdev.c
+++ b/drivers/net/ice/ice_ethdev.c
@@ -3927,8 +3927,10 @@  static int ice_init_rss(struct ice_pf *pf)
 	struct rte_eth_link *dst = link;
 	struct rte_eth_link *src = &dev->data->dev_link;
 
-	if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
-				*(uint64_t *)src) == 0)
+	/* NOTE: review for potential ordering optimization */
+	if (!__atomic_compare_exchange_n((uint64_t *)dst,
+		(uint64_t *)dst, *(uint64_t *)src, 0,
+		__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
 		return -1;
 
 	return 0;
@@ -3941,8 +3943,10 @@  static int ice_init_rss(struct ice_pf *pf)
 	struct rte_eth_link *dst = &dev->data->dev_link;
 	struct rte_eth_link *src = link;
 
-	if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
-				*(uint64_t *)src) == 0)
+	/* NOTE: review for potential ordering optimization */
+	if (!__atomic_compare_exchange_n((uint64_t *)dst,
+		(uint64_t *)dst, *(uint64_t *)src, 0,
+		__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
 		return -1;
 
 	return 0;