DPDK patches and discussions
 help / color / mirror / Atom feed
From: David Marchand <david.marchand@redhat.com>
To: Phil Yang <phil.yang@arm.com>
Cc: dev <dev@dpdk.org>,
	Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>,
	 "Ruifeng Wang (Arm Technology China)" <Ruifeng.Wang@arm.com>,
	nd <nd@arm.com>, Bruce Richardson <bruce.richardson@intel.com>
Subject: Re: [dpdk-dev] [PATCH v2 1/4] eal: use C11 atomic builtins for already initialized check
Date: Wed, 23 Sep 2020 15:06:48 +0200
Message-ID: <CAJFAV8xJ6em=wonORV2zdDgrJSQ8XdcdBcyFZ-r0X-UkOf_4aA@mail.gmail.com> (raw)
In-Reply-To: <1600244628-13062-2-git-send-email-phil.yang@arm.com>

On Wed, Sep 16, 2020 at 10:24 AM Phil Yang <phil.yang@arm.com> wrote:
>
> Since rte_atomicXX APIs are not allowed to be used, use C11 builtins to
> check if EAL is already initialized.
>
> Signed-off-by: Phil Yang <phil.yang@arm.com>
> Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
> ---
>  lib/librte_eal/freebsd/eal.c | 18 ++++++++++--------
>  lib/librte_eal/linux/eal.c   | 20 +++++++++++---------
>  2 files changed, 21 insertions(+), 17 deletions(-)
>
> diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c
> index 798add0..9f4c7bb 100644
> --- a/lib/librte_eal/freebsd/eal.c
> +++ b/lib/librte_eal/freebsd/eal.c
> @@ -665,7 +665,8 @@ rte_eal_init(int argc, char **argv)
>  {
>         int i, fctret, ret;
>         pthread_t thread_id;
> -       static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0);
> +       static uint32_t run_once;
> +       uint32_t has_run = 0;
>         char cpuset[RTE_CPU_AFFINITY_STR_LEN];
>         char thread_name[RTE_MAX_THREAD_NAME_LEN];
>         const struct rte_config *config = rte_eal_get_configuration();
> @@ -679,7 +680,8 @@ rte_eal_init(int argc, char **argv)
>                 return -1;
>         }
>
> -       if (!rte_atomic32_test_and_set(&run_once)) {
> +       if (!__atomic_compare_exchange_n(&run_once, &has_run, 1, 0,
> +                                       __ATOMIC_RELAXED, __ATOMIC_RELAXED)) {
>                 rte_eal_init_alert("already called initialization.");
>                 rte_errno = EALREADY;
>                 return -1;
> @@ -705,7 +707,7 @@ rte_eal_init(int argc, char **argv)
>         if (fctret < 0) {
>                 rte_eal_init_alert("Invalid 'command line' arguments.");
>                 rte_errno = EINVAL;
> -               rte_atomic32_clear(&run_once);
> +               __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
>                 return -1;
>         }
>
> @@ -715,20 +717,20 @@ rte_eal_init(int argc, char **argv)
>         if (eal_plugins_init() < 0) {
>                 rte_eal_init_alert("Cannot init plugins");
>                 rte_errno = EINVAL;
> -               rte_atomic32_clear(&run_once);
> +               __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
>                 return -1;
>         }
>
>         if (eal_trace_init() < 0) {
>                 rte_eal_init_alert("Cannot init trace");
>                 rte_errno = EFAULT;
> -               rte_atomic32_clear(&run_once);
> +               __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
>                 return -1;
>         }
>
>         if (eal_option_device_parse()) {
>                 rte_errno = ENODEV;
> -               rte_atomic32_clear(&run_once);
> +               __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
>                 return -1;
>         }
>
> @@ -762,7 +764,7 @@ rte_eal_init(int argc, char **argv)
>         if (rte_bus_scan()) {
>                 rte_eal_init_alert("Cannot scan the buses for devices");
>                 rte_errno = ENODEV;
> -               rte_atomic32_clear(&run_once);
> +               __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
>                 return -1;
>         }
>
> @@ -790,7 +792,7 @@ rte_eal_init(int argc, char **argv)
>                 if (ret < 0) {
>                         rte_eal_init_alert("Cannot get hugepage information.");
>                         rte_errno = EACCES;
> -                       rte_atomic32_clear(&run_once);
> +                       __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
>                         return -1;
>                 }
>         }
> diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
> index 0960f01..82a73ed 100644
> --- a/lib/librte_eal/linux/eal.c
> +++ b/lib/librte_eal/linux/eal.c
> @@ -960,7 +960,8 @@ rte_eal_init(int argc, char **argv)
>  {
>         int i, fctret, ret;
>         pthread_t thread_id;
> -       static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0);
> +       static uint32_t run_once;
> +       uint32_t has_run = 0;
>         const char *p;
>         static char logid[PATH_MAX];
>         char cpuset[RTE_CPU_AFFINITY_STR_LEN];
> @@ -977,7 +978,8 @@ rte_eal_init(int argc, char **argv)
>                 return -1;
>         }
>
> -       if (!rte_atomic32_test_and_set(&run_once)) {
> +       if (!__atomic_compare_exchange_n(&run_once, &has_run, 1, 0,
> +                                       __ATOMIC_RELAXED, __ATOMIC_RELAXED)) {
>                 rte_eal_init_alert("already called initialization.");
>                 rte_errno = EALREADY;
>                 return -1;
> @@ -1005,14 +1007,14 @@ rte_eal_init(int argc, char **argv)
>         if (fctret < 0) {
>                 rte_eal_init_alert("Invalid 'command line' arguments.");
>                 rte_errno = EINVAL;
> -               rte_atomic32_clear(&run_once);
> +               __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
>                 return -1;
>         }
>
>         if (eal_plugins_init() < 0) {
>                 rte_eal_init_alert("Cannot init plugins");
>                 rte_errno = EINVAL;
> -               rte_atomic32_clear(&run_once);
> +               __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
>                 return -1;
>         }
>
> @@ -1024,7 +1026,7 @@ rte_eal_init(int argc, char **argv)
>
>         if (eal_option_device_parse()) {
>                 rte_errno = ENODEV;
> -               rte_atomic32_clear(&run_once);
> +               __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
>                 return -1;
>         }
>
> @@ -1064,7 +1066,7 @@ rte_eal_init(int argc, char **argv)
>         if (rte_bus_scan()) {
>                 rte_eal_init_alert("Cannot scan the buses for devices");
>                 rte_errno = ENODEV;
> -               rte_atomic32_clear(&run_once);
> +               __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
>                 return -1;
>         }
>
> @@ -1138,7 +1140,7 @@ rte_eal_init(int argc, char **argv)
>                 if (ret < 0) {
>                         rte_eal_init_alert("Cannot get hugepage information.");
>                         rte_errno = EACCES;
> -                       rte_atomic32_clear(&run_once);
> +                       __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
>                         return -1;
>                 }
>         }
> @@ -1162,7 +1164,7 @@ rte_eal_init(int argc, char **argv)
>         if (rte_eal_log_init(logid, internal_conf->syslog_facility) < 0) {
>                 rte_eal_init_alert("Cannot init logging.");
>                 rte_errno = ENOMEM;
> -               rte_atomic32_clear(&run_once);
> +               __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
>                 return -1;
>         }
>
> @@ -1170,7 +1172,7 @@ rte_eal_init(int argc, char **argv)
>         if (rte_eal_vfio_setup() < 0) {
>                 rte_eal_init_alert("Cannot init VFIO");
>                 rte_errno = EAGAIN;
> -               rte_atomic32_clear(&run_once);
> +               __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
>                 return -1;
>         }
>  #endif
> --
> 2.7.4
>

I see no reason to include rte_atomic.h in those files after this patch.
Did I miss something?


-- 
David Marchand


  reply	other threads:[~2020-09-23 13:07 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-11  3:29 [dpdk-dev] [PATCH 0/4] use C11 atomic builtins for libs Phil Yang
2020-09-11  3:29 ` [dpdk-dev] [PATCH 1/4] eal: use C11 atomic builtins for already initialized check Phil Yang
2020-09-11  3:29 ` [dpdk-dev] [PATCH 2/4] bbdev: use C11 atomic builtins for device processing counter Phil Yang
2020-09-11  3:29 ` [dpdk-dev] [PATCH 3/4] power: use C11 atomic builtins for power in use state update Phil Yang
2020-09-11  3:29 ` [dpdk-dev] [PATCH 4/4] ethdev: use C11 atomic builtins for link status update Phil Yang
2020-09-15 15:12 ` [dpdk-dev] [PATCH 0/4] use C11 atomic builtins for libs David Marchand
2020-09-16  7:32   ` Phil Yang
2020-09-16  8:23 ` [dpdk-dev] [PATCH v2 " Phil Yang
2020-09-16  8:23   ` [dpdk-dev] [PATCH v2 1/4] eal: use C11 atomic builtins for already initialized check Phil Yang
2020-09-23 13:06     ` David Marchand [this message]
2020-09-24  3:44       ` Phil Yang
2020-09-16  8:23   ` [dpdk-dev] [PATCH v2 2/4] bbdev: use C11 atomic builtins for device processing counter Phil Yang
2020-09-16  8:23   ` [dpdk-dev] [PATCH v2 3/4] power: use C11 atomic builtins for power in use state update Phil Yang
2020-09-16  8:23   ` [dpdk-dev] [PATCH v2 4/4] ethdev: use C11 atomic builtins for link status update Phil Yang
2020-09-17 16:08     ` Andrew Rybchenko
2020-09-23 13:18   ` [dpdk-dev] [PATCH v2 0/4] use C11 atomic builtins for libs David Marchand
2020-09-24  3:47     ` Phil Yang
2020-09-24  5:39   ` [dpdk-dev] [PATCH v3 " Phil Yang
2020-09-24  5:39     ` [dpdk-dev] [PATCH v3 1/4] eal: use C11 atomic builtins for already initialized check Phil Yang
2020-09-24  5:39     ` [dpdk-dev] [PATCH v3 2/4] bbdev: use C11 atomic builtins for device processing counter Phil Yang
2020-09-24 22:01       ` Chautru, Nicolas
2020-09-24 22:44         ` Honnappa Nagarahalli
2020-09-24 23:20           ` Chautru, Nicolas
2020-09-24  5:39     ` [dpdk-dev] [PATCH v3 3/4] power: use C11 atomic builtins for power in use state update Phil Yang
2020-09-24  8:34       ` David Hunt
2020-09-24  5:39     ` [dpdk-dev] [PATCH v3 4/4] ethdev: use C11 atomic builtins for link status update Phil Yang
2020-09-25 13:59     ` [dpdk-dev] [PATCH v3 0/4] use C11 atomic builtins for libs 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='CAJFAV8xJ6em=wonORV2zdDgrJSQ8XdcdBcyFZ-r0X-UkOf_4aA@mail.gmail.com' \
    --to=david.marchand@redhat.com \
    --cc=Honnappa.Nagarahalli@arm.com \
    --cc=Ruifeng.Wang@arm.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=nd@arm.com \
    --cc=phil.yang@arm.com \
    /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

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git