* [PATCH 0/3] arm64: use LSE atomics when available
@ 2026-11-30 16:33 Nick Hudson
2026-11-30 16:33 ` [PATCH 1/3] mailmap: add new contributor Nick Hudson
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Nick Hudson @ 2026-11-30 16:33 UTC (permalink / raw)
To: dev; +Cc: Nick Hudson
Two improvements for AArch64 atomics:
Patch 2 reworks the 128-bit compare-exchange in EAL. When the build
does not guarantee LSE (__ARM_FEATURE_ATOMICS / RTE_ARM_FEATURE_ATOMICS
not defined), use the compiler's AArch64 outlined atomic helpers
(__aarch64_cas16_*) so LSE vs LL/SC is selected at runtime from HWCAP,
instead of always falling back to the LL/SC loop. Builds that guarantee
LSE keep the inline CASP implementation; older toolchains without
outlined helpers keep the LL/SC fallback.
Patch 3 makes the BPF arm64 JIT query the ATOMICS CPU flag at runtime
when the build does not guarantee LSE, so JIT-generated code can use
stadd/swpal on capable hardware instead of being limited by build-time
flags.
Tested on an LSE-capable aarch64 VM (Ubuntu 26.04, GCC 15.2) with both
a -Dplatform=generic build (outlined helper path, verified calls to
__aarch64_cas16_* in disassembly) and a -Dplatform=n1sdp build (inline
casp/caspa/caspl/caspal). atomic_autotest, bpf_autotest and
bpf_atomic_imms_autotest pass on both.
Nick Hudson (3):
mailmap: add new contributor
eal: select 128-bit CAS by LSE support
bpf/arm64: detect atomics at build time or runtime
.mailmap | 1 +
lib/bpf/bpf_jit_arm64.c | 10 +++++-----
lib/eal/arm/include/rte_atomic_64.h | 29 +++++++++++++++++++++++++++++
3 files changed, 35 insertions(+), 5 deletions(-)
--
2.54.0 (Apple Git-157)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/3] mailmap: add new contributor
2026-11-30 16:33 [PATCH 0/3] arm64: use LSE atomics when available Nick Hudson
@ 2026-11-30 16:33 ` Nick Hudson
2026-11-30 16:33 ` [PATCH 2/3] eal: select 128-bit CAS by LSE support Nick Hudson
2026-11-30 16:33 ` [PATCH 3/3] bpf/arm64: detect atomics at build time or runtime Nick Hudson
2 siblings, 0 replies; 7+ messages in thread
From: Nick Hudson @ 2026-11-30 16:33 UTC (permalink / raw)
To: dev; +Cc: Nick Hudson, Thomas Monjalon
Add my name and email as a new DPDK contributor.
Signed-off-by: Nick Hudson <nhudson@akamai.com>
---
.mailmap | 1 +
1 file changed, 1 insertion(+)
diff --git a/.mailmap b/.mailmap
index a0096fb97a..245040ed6b 100644
--- a/.mailmap
+++ b/.mailmap
@@ -1226,6 +1226,7 @@ Niall Meade <niall.meade@intel.com>
Niall Power <niall.power@intel.com>
Nicholas Pratte <npratte@iol.unh.edu>
Nick Connolly <nick.connolly@arm.com> <nick.connolly@mayadata.io>
+Nick Hudson <nhudson@akamai.com>
Nick Nunley <nicholas.d.nunley@intel.com>
Niclas Storm <niclas.storm@ericsson.com>
Nicolas Chautru <nicolas.chautru@intel.com>
--
2.54.0 (Apple Git-157)
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] eal: select 128-bit CAS by LSE support
2026-11-30 16:33 [PATCH 0/3] arm64: use LSE atomics when available Nick Hudson
2026-11-30 16:33 ` [PATCH 1/3] mailmap: add new contributor Nick Hudson
@ 2026-11-30 16:33 ` Nick Hudson
2026-11-30 16:33 ` [PATCH 3/3] bpf/arm64: detect atomics at build time or runtime Nick Hudson
2 siblings, 0 replies; 7+ messages in thread
From: Nick Hudson @ 2026-11-30 16:33 UTC (permalink / raw)
To: dev; +Cc: Nick Hudson, Wathsala Vithanage
Use inline CASP instructions when __ARM_FEATURE_ATOMICS or
RTE_ARM_FEATURE_ATOMICS is defined. Otherwise, use AArch64 outlined
CAS helpers, which select LSE or LL/SC based on runtime HWCAP when
supported by the compiler. Retain the LL/SC fallback for older
toolchains without outlined helpers.
Signed-off-by: Nick Hudson <nhudson@akamai.com>
---
lib/eal/arm/include/rte_atomic_64.h | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/lib/eal/arm/include/rte_atomic_64.h b/lib/eal/arm/include/rte_atomic_64.h
index 604e777bcd..b976d8c23b 100644
--- a/lib/eal/arm/include/rte_atomic_64.h
+++ b/lib/eal/arm/include/rte_atomic_64.h
@@ -34,6 +34,18 @@ rte_atomic_thread_fence(rte_memory_order memorder)
/*------------------------ 128 bit atomic operations -------------------------*/
+#if defined(RTE_CC_CLANG) || (defined(RTE_CC_GCC) && GCC_VERSION >= 100100)
+#define __RTE_ARM64_HAS_OUTLINE_ATOMICS
+__extension__ extern __int128 __aarch64_cas16_relax(__int128, __int128,
+ __int128 *);
+__extension__ extern __int128 __aarch64_cas16_acq(__int128, __int128,
+ __int128 *);
+__extension__ extern __int128 __aarch64_cas16_rel(__int128, __int128,
+ __int128 *);
+__extension__ extern __int128 __aarch64_cas16_acq_rel(__int128, __int128,
+ __int128 *);
+#endif
+
#if defined(__ARM_FEATURE_ATOMICS) || defined(RTE_ARM_FEATURE_ATOMICS)
#if defined(RTE_CC_CLANG)
@@ -115,6 +127,21 @@ rte_atomic128_cmp_exchange(rte_int128_t *dst, rte_int128_t *exp,
else
__cas_128_acq_rel(dst, exp, desired);
old = *exp;
+#elif defined(__RTE_ARM64_HAS_OUTLINE_ATOMICS)
+ if (success == rte_memory_order_relaxed)
+ old.int128 = __aarch64_cas16_relax(expected.int128, desired.int128,
+ &dst->int128);
+ else if (success == rte_memory_order_acquire)
+ old.int128 = __aarch64_cas16_acq(expected.int128, desired.int128,
+ &dst->int128);
+ else if (success == rte_memory_order_release)
+ old.int128 = __aarch64_cas16_rel(expected.int128, desired.int128,
+ &dst->int128);
+ else
+ old.int128 = __aarch64_cas16_acq_rel(expected.int128, desired.int128,
+ &dst->int128);
+
+ *exp = old;
#else
#define __HAS_ACQ(mo) ((mo) != rte_memory_order_relaxed && (mo) != rte_memory_order_release)
#define __HAS_RLS(mo) ((mo) == rte_memory_order_release || (mo) == rte_memory_order_acq_rel || \
@@ -188,6 +215,8 @@ rte_atomic128_cmp_exchange(rte_int128_t *dst, rte_int128_t *exp,
return (old.int128 == expected.int128);
}
+#undef __RTE_ARM64_HAS_OUTLINE_ATOMICS
+
#ifdef __cplusplus
}
#endif
--
2.54.0 (Apple Git-157)
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3] bpf/arm64: detect atomics at build time or runtime
2026-11-30 16:33 [PATCH 0/3] arm64: use LSE atomics when available Nick Hudson
2026-11-30 16:33 ` [PATCH 1/3] mailmap: add new contributor Nick Hudson
2026-11-30 16:33 ` [PATCH 2/3] eal: select 128-bit CAS by LSE support Nick Hudson
@ 2026-11-30 16:33 ` Nick Hudson
2026-12-01 10:57 ` Konstantin Ananyev
2026-12-05 18:31 ` Marat Khalili
2 siblings, 2 replies; 7+ messages in thread
From: Nick Hudson @ 2026-11-30 16:33 UTC (permalink / raw)
To: dev; +Cc: Nick Hudson, Wathsala Vithanage, Konstantin Ananyev,
Marat Khalili
Use LSE instructions when __ARM_FEATURE_ATOMICS or
RTE_ARM_FEATURE_ATOMICS is defined. Otherwise, check runtime CPU flags
before selecting LSE instructions for JIT-generated code.
Signed-off-by: Nick Hudson <nhudson@akamai.com>
---
lib/bpf/bpf_jit_arm64.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/lib/bpf/bpf_jit_arm64.c b/lib/bpf/bpf_jit_arm64.c
index 4b897dccb8..8e17c21e8f 100644
--- a/lib/bpf/bpf_jit_arm64.c
+++ b/lib/bpf/bpf_jit_arm64.c
@@ -8,6 +8,7 @@
#include <rte_common.h>
#include <rte_byteorder.h>
+#include <rte_cpuflags.h>
#include <rte_debug.h>
#include "bpf_impl.h"
@@ -1031,15 +1032,14 @@ emit_stxr(struct a64_jit_ctx *ctx, bool is64, uint8_t rs, uint8_t rt,
emit_insn(ctx, insn, check_reg(rs) || check_reg(rt) || check_reg(rn));
}
-static int
+static bool
has_atomics(void)
{
- int rc = 0;
-
#if defined(__ARM_FEATURE_ATOMICS) || defined(RTE_ARM_FEATURE_ATOMICS)
- rc = 1;
+ return true;
+#else
+ return rte_cpu_get_flag_enabled(RTE_CPUFLAG_ATOMICS) == 1;
#endif
- return rc;
}
static void
--
2.54.0 (Apple Git-157)
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] bpf/arm64: detect atomics at build time or runtime
2026-11-30 16:33 ` [PATCH 3/3] bpf/arm64: detect atomics at build time or runtime Nick Hudson
@ 2026-12-01 10:57 ` Konstantin Ananyev
2026-12-01 13:11 ` Hudson, Nick
2026-12-05 18:31 ` Marat Khalili
1 sibling, 1 reply; 7+ messages in thread
From: Konstantin Ananyev @ 2026-12-01 10:57 UTC (permalink / raw)
To: Nick Hudson, dev; +Cc: Wathsala Vithanage, Konstantin Ananyev, Marat Khalili
> Use LSE instructions when __ARM_FEATURE_ATOMICS or
> RTE_ARM_FEATURE_ATOMICS is defined. Otherwise, check runtime CPU flags
> before selecting LSE instructions for JIT-generated code.
Just to understand: so we'll have all other dpdk binaries build without
RM_FEATURE_ATOMICS,
i.e. not allowed to use stadd/swapl instructions, but we still want to
generate bpf binary code
that would use these instructions, correct?
If so, I wonder do we really want it, and if yes, then what for?
>
> Signed-off-by: Nick Hudson <nhudson@akamai.com>
> ---
> lib/bpf/bpf_jit_arm64.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/lib/bpf/bpf_jit_arm64.c b/lib/bpf/bpf_jit_arm64.c
> index 4b897dccb8..8e17c21e8f 100644
> --- a/lib/bpf/bpf_jit_arm64.c
> +++ b/lib/bpf/bpf_jit_arm64.c
> @@ -8,6 +8,7 @@
>
> #include <rte_common.h>
> #include <rte_byteorder.h>
> +#include <rte_cpuflags.h>
> #include <rte_debug.h>
>
> #include "bpf_impl.h"
> @@ -1031,15 +1032,14 @@ emit_stxr(struct a64_jit_ctx *ctx, bool is64, uint8_t rs, uint8_t rt,
> emit_insn(ctx, insn, check_reg(rs) || check_reg(rt) || check_reg(rn));
> }
>
> -static int
> +static bool
> has_atomics(void)
> {
> - int rc = 0;
> -
> #if defined(__ARM_FEATURE_ATOMICS) || defined(RTE_ARM_FEATURE_ATOMICS)
> - rc = 1;
> + return true;
> +#else
> + return rte_cpu_get_flag_enabled(RTE_CPUFLAG_ATOMICS) == 1;
> #endif
> - return rc;
> }
>
> static void
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] bpf/arm64: detect atomics at build time or runtime
2026-12-01 10:57 ` Konstantin Ananyev
@ 2026-12-01 13:11 ` Hudson, Nick
0 siblings, 0 replies; 7+ messages in thread
From: Hudson, Nick @ 2026-12-01 13:11 UTC (permalink / raw)
To: Konstantin Ananyev
Cc: dev@dpdk.org, Wathsala Vithanage, Konstantin Ananyev,
Marat Khalili
[-- Attachment #1.1: Type: text/plain, Size: 1149 bytes --]
> On Dec 1, 2026, at 10:57 AM, Konstantin Ananyev <konstantin.v.ananyev@yandex.ru> wrote:
>
> Just to understand: so we'll have all other dpdk binaries build without RM_FEATURE_ATOMICS,
> i.e. not allowed to use stadd/swapl instructions, but we still want to generate bpf binary code
> that would use these instructions, correct?
A generic build already uses LSE atomics at runtime for all <128-bit
operations: the compiler builds the __atomic_* builtins with outlined
helpers (-moutline-atomics, default since GCC 10), which select LSE or
LL/SC based on HWCAP at startup. __ARM_FEATURE_ATOMICS is only defined
when the target guarantees LSE (armv8.1-a and later, or armv8-a+lse),
so an armv8-a generic build never sets it - runtime detection is the
only way such a build can use LSE.
This series just extends that to the two places that bypass the
compiler: the hand-written 128-bit CAS in EAL (patch 2) and the
JIT-generated atomics here, same as the Linux kernel arm64 eBPF JIT
does.
LL/SC loops have no forward-progress guarantee under contention,
which is one of the reasons -moutline-atomics became the default.
[-- Attachment #1.2: Type: text/html, Size: 4121 bytes --]
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 3212 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] bpf/arm64: detect atomics at build time or runtime
2026-11-30 16:33 ` [PATCH 3/3] bpf/arm64: detect atomics at build time or runtime Nick Hudson
2026-12-01 10:57 ` Konstantin Ananyev
@ 2026-12-05 18:31 ` Marat Khalili
1 sibling, 0 replies; 7+ messages in thread
From: Marat Khalili @ 2026-12-05 18:31 UTC (permalink / raw)
To: Nick Hudson; +Cc: Wathsala Vithanage, Konstantin Ananyev, dev
On 30/11/2026 16:33, Nick Hudson wrote:
> Use LSE instructions when __ARM_FEATURE_ATOMICS or
> RTE_ARM_FEATURE_ATOMICS is defined. Otherwise, check runtime CPU flags
> before selecting LSE instructions for JIT-generated code.
>
> Signed-off-by: Nick Hudson <nhudson@akamai.com>
Hi, thank you for working on this. I can ack the code, but not the
commit message or (missing) comments. The patch changes the current
behaviour in a meaningful but counterintuitive way. Understanding it
needs some analysis and may confuse some poor soul trying to figure out
in the middle of the night why DPDK executes atomic instructions in the
place it previously didn't.
Firstly, it would be nice if commit message clearly stated the change in
behaviour: generate JIT atomic instructions based on runtime
detection even if RTE_ARM_FEATURE_ATOMICS is disabled.
Secondly, it should explain the problem the patch is solving. Something
along the lines of target alone being insufficient to guarantee the
atomics availability for some values, LL/SC loops having
forward-progress issues under contention, behaviour commonality with the
rest of the platform (if it actually does the same already), yada yada.
Short comment inside has_atomics would help too, maybe (not sure) even a
release note. Searching mailing lists for answers should be the last
resort IMO.
I would also love to know how practically relevant having atomic eBPF
atomics in a armv8-a generic build is in 2027+, what prevents us from
just building for armv8.1-a. I'm not claiming it's not relevant, just
want to make sure it's not just a "nice to have" tweaking.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-12-05 18:31 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 16:33 [PATCH 0/3] arm64: use LSE atomics when available Nick Hudson
2026-11-30 16:33 ` [PATCH 1/3] mailmap: add new contributor Nick Hudson
2026-11-30 16:33 ` [PATCH 2/3] eal: select 128-bit CAS by LSE support Nick Hudson
2026-11-30 16:33 ` [PATCH 3/3] bpf/arm64: detect atomics at build time or runtime Nick Hudson
2026-12-01 10:57 ` Konstantin Ananyev
2026-12-01 13:11 ` Hudson, Nick
2026-12-05 18:31 ` Marat Khalili
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox