All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: saeed bishara <saeed.bishara.os@gmail.com>
Cc: dev@dpdk.org, Hemant Agrawal <hemant.agrawal@nxp.com>,
	Sachin Saxena <sachin.saxena@nxp.com>
Subject: Re: [PATCH v5 11/24] drivers: replace rte_atomic16 with stdatomic
Date: Thu, 30 Jul 2026 20:24:46 -0700	[thread overview]
Message-ID: <20260730202446.46804175@phoenix.local> (raw)
In-Reply-To: <CAHfVqdVVG-W+PFZdimqwhrUrUZFSeCNodSu-VU7sscMpaiOVeA@mail.gmail.com>

On Mon, 22 Jun 2026 17:46:14 +0300
saeed bishara <saeed.bishara.os@gmail.com> wrote:

> On Sat, Jun 20, 2026 at 5:41 AM Stephen Hemminger
> <stephen@networkplumber.org> wrote:
> 
> > @@ -84,7 +84,7 @@ dpaa2_create_dpbp_device(int vdev_fd __rte_unused,
> >         }
> >
> >         dpbp_node->dpbp_id = dpbp_id;
> > -       rte_atomic16_init(&dpbp_node->in_use);
> > +       dpbp_node->in_use = 0;  
> The previous code implies an ordering barrier, so it guarantees that
> dpbp_node->dpbp_id is visible before in_use, while the new code
> doesn't. isn't the a problem?

That is incorrect assumption to make here.
Atomic init is not a barrier at all, it is just an assignment:

static inline void
rte_atomic16_init(rte_atomic16_t *v)
{
	v->cnt = 0;
}

> >
> >         TAILQ_INSERT_TAIL(&dpbp_dev_list, dpbp_node, next);
> >
> > @@ -103,7 +103,10 @@ struct dpaa2_dpbp_dev *dpaa2_alloc_dpbp_dev(void)
> >
> >         /* Get DPBP dev handle from list using index */
> >         TAILQ_FOREACH(dpbp_dev, &dpbp_dev_list, next) {
> > -               if (dpbp_dev && rte_atomic16_test_and_set(&dpbp_dev->in_use))
> > +               uint16_t expected = 0;
> > +               if (rte_atomic_compare_exchange_strong_explicit(
> > +                           &dpbp_dev->in_use, &expected, 1,
> > +                           rte_memory_order_acquire, rte_memory_order_relaxed))  
> 
> aren't rte_atomic_flag_test_and_set_explicit/rte_atomic_flag_clear_explicit
> a better candidates instead of
> rte_atomic_compare_exchange_strong_explicit/rte_atomic_store_explicit

Atomic flags are not used in DPDK for a number of reasons.
 - limited operations only test and set, no load
 - lots of variation in between stdatomic and compilers
 - no improvement in code generation

Instead DPDK has chosen to just use RTE_ATOMIC(bool)



More wordy AI response:

On Mon, 22 Jun 2026 17:46:14 +0300
saeed bishara <saeed.bishara.os@gmail.com> wrote:

> > -       rte_atomic16_init(&dpbp_node->in_use);
> > +       dpbp_node->in_use = 0;
> The previous code implies an ordering barrier, so it guarantees that
> dpbp_node->dpbp_id is visible before in_use, while the new code
> doesn't. isn't the a problem?

rte_atomic16_init() is a plain store:

	static inline void
	rte_atomic16_init(rte_atomic16_t *v)
	{
		v->cnt = 0;
	}

Same for rte_atomic16_clear(). Only test_and_set() and dec() implied a
barrier, via __sync_*. So no ordering is dropped.

Neither version has a barrier between these stores and
TAILQ_INSERT_TAIL(), and the list is not atomic either, so a reader
concurrent with device creation would be unsafe regardless. Devices are
created during bus probe.

The point does apply in reverse though: with the field declared
RTE_ATOMIC(uint16_t), a plain assignment is a seq_cst store when built
with enable_stdatomic=true, and a plain store otherwise. v7 uses
rte_atomic_store_explicit(..., rte_memory_order_relaxed) so both builds
behave the same.

> aren't rte_atomic_flag_test_and_set_explicit/rte_atomic_flag_clear_explicit
> a better candidates instead of
> rte_atomic_compare_exchange_strong_explicit/rte_atomic_store_explicit ?

Semantically yes, but there is no portable type for the struct member.
In rte_stdatomic.h those map to C11 atomic_flag with enable_stdatomic=true
and to __atomic_test_and_set()/__atomic_clear() (bool or char) otherwise.
atomic_flag also has no load operation and no initializer other than
ATOMIC_FLAG_INIT. That is why rte_atomic_flag_* has no users in the tree.

If an rte_atomic_flag type covering both backends is added, these sites
are good candidates to convert.

  reply	other threads:[~2026-07-31  3:24 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <https://inbox.dpdk.org/dev/20260521042043.1590536-1-stephen@networkplumber.org>
2026-06-20  2:28 ` [PATCH v5 00/24] deprecate rte_atomic functions Stephen Hemminger
2026-06-20  2:28   ` [PATCH v5 01/24] bpf: use C11 atomics in BPF_ST_ATOMIC_REG Stephen Hemminger
2026-06-20  2:28   ` [PATCH v5 02/24] net/bonding: use stdatomic Stephen Hemminger
2026-06-20  2:28   ` [PATCH v5 03/24] net/nbl: remove unused rte_atomic16 field Stephen Hemminger
2026-06-20  2:28   ` [PATCH v5 04/24] net/ena: replace use of rte_atomicNN Stephen Hemminger
2026-06-22  8:46     ` saeed bishara
2026-06-20  2:28   ` [PATCH v5 05/24] net/failsafe: convert to stdatomic Stephen Hemminger
2026-06-20  2:28   ` [PATCH v5 06/24] net/enic: do not use deprecated rte_atomic64 Stephen Hemminger
2026-06-20  2:28   ` [PATCH v5 07/24] net/pfe: use ethdev linkstatus helpers Stephen Hemminger
2026-06-20  2:28   ` [PATCH v5 08/24] net/sfc: replace rte_atomic with stdatomic Stephen Hemminger
2026-06-20  2:28   ` [PATCH v5 09/24] crypto/ccp: replace use of rte_atomic64 " Stephen Hemminger
2026-06-20  2:28   ` [PATCH v5 10/24] bus/dpaa: replace rte_atomic16 " Stephen Hemminger
2026-06-20  2:28   ` [PATCH v5 11/24] drivers: " Stephen Hemminger
2026-06-22 14:46     ` saeed bishara
2026-07-31  3:24       ` Stephen Hemminger [this message]
2026-06-20  2:28   ` [PATCH v5 12/24] net/netvsc: replace rte_atomic32 " Stephen Hemminger
2026-06-22 20:43     ` [EXTERNAL] " Long Li
2026-06-20  2:28   ` [PATCH v5 13/24] event/sw: convert from rte_atomic32 to stdatomic Stephen Hemminger
2026-06-20  2:28   ` [PATCH v5 14/24] bus/vmbus: convert from rte_atomic " Stephen Hemminger
2026-06-22 20:57     ` [EXTERNAL] " Long Li
2026-06-20  2:28   ` [PATCH v5 15/24] common/dpaax: use stdatomic instead of rte_atomic Stephen Hemminger
2026-06-20  2:28   ` [PATCH v5 16/24] net/bnx2x: convert from rte_atomic32 to stdatomic Stephen Hemminger
2026-06-20  2:28   ` [PATCH v5 17/24] bus/fslmc: replace rte_atomic32 with stdatomic Stephen Hemminger
2026-06-20  2:28   ` [PATCH v5 18/24] drivers/event: replace rte_atomic32 in selftests Stephen Hemminger
2026-06-20  2:28   ` [PATCH v5 19/24] net/hinic: replace rte_atomic32 with stdatomic Stephen Hemminger
2026-06-20  2:28   ` [PATCH v5 20/24] net/txgbe: " Stephen Hemminger
2026-06-20  2:28   ` [PATCH v5 21/24] net/vhost: use stdatomic instead of rte_atomic32 Stephen Hemminger
2026-06-20  2:28   ` [PATCH v5 22/24] vdpa/ifc: replace rte_atomic32 with stdatomic Stephen Hemminger
2026-06-20  2:28   ` [PATCH v5 23/24] test/atomic: suppress deprecation warnings for legacy APIs Stephen Hemminger
2026-06-20  2:28   ` [PATCH v5 24/24] eal: deprecate rte_atomicNN functions Stephen Hemminger
2026-06-21  4:27   ` [PATCH v5 00/24] deprecate rte_atomic functions Hemant Agrawal

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=20260730202446.46804175@phoenix.local \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=hemant.agrawal@nxp.com \
    --cc=sachin.saxena@nxp.com \
    --cc=saeed.bishara.os@gmail.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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.