From: Luca Di Maio <luca@edera.dev>
To: xen-devel@lists.xenproject.org
Cc: Luca Di Maio <luca@edera.dev>,
Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien@xen.org>,
Bertrand Marquis <bertrand.marquis@arm.com>,
Michal Orzel <michal.orzel@amd.com>,
Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
Subject: [PATCH v2 5/5] xen/arm64: use LSE for arch_fetch_and_add()
Date: Tue, 1 Dec 2026 17:08:15 +0100 [thread overview]
Message-ID: <20261201160817.466800-6-luca@edera.dev> (raw)
In-Reply-To: <20261201160817.466800-1-luca@edera.dev>
The spinlock tickets come from __sync_fetch_and_add(), which the
compiler builds from an exclusive loop for Armv8.0. On arm64, use
LDADDAL when the CPU has LSE and the builtin otherwise; the builtin
macro is now arm32 only, as it would replace the arm64 function.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Luca Di Maio <luca@edera.dev>
---
xen/arch/arm/include/asm/arm64/system.h | 20 ++++++++++++++++++++
xen/arch/arm/include/asm/system.h | 2 ++
2 files changed, 22 insertions(+)
diff --git a/xen/arch/arm/include/asm/arm64/system.h b/xen/arch/arm/include/asm/arm64/system.h
index 2e2ee212a1..4cf3295b16 100644
--- a/xen/arch/arm/include/asm/arm64/system.h
+++ b/xen/arch/arm/include/asm/arm64/system.h
@@ -3,6 +3,7 @@
#define __ASM_ARM64_SYSTEM_H
#include <asm/arm64/cmpxchg.h>
+#include <asm/arm64/lse.h>
/* Uses uimm4 as a bitmask to select the clearing of one or more of
* the DAIF exception mask bits:
@@ -58,6 +59,25 @@ static inline int local_fiq_is_enabled(void)
return !(flags & PSR_FIQ_MASK);
}
+/* For Armv8.0 the compiler builds the builtin from an LL/SC loop. */
+static always_inline uint32_t arch_fetch_and_add(volatile uint32_t *ptr,
+ uint32_t v)
+{
+ if ( system_uses_lse_atomics() )
+ {
+ uint32_t old;
+
+ asm volatile ( __LSE_PREAMBLE
+ "ldaddal %w2, %w0, %1"
+ : "=&r" (old), "+Q" (*ptr)
+ : "r" (v)
+ : "memory" );
+ return old;
+ }
+
+ return __sync_fetch_and_add(ptr, v);
+}
+
#endif
/*
* Local variables:
diff --git a/xen/arch/arm/include/asm/system.h b/xen/arch/arm/include/asm/system.h
index 65d5c8e423..b988f79102 100644
--- a/xen/arch/arm/include/asm/system.h
+++ b/xen/arch/arm/include/asm/system.h
@@ -58,7 +58,9 @@ static inline int local_abort_is_enabled(void)
return !(flags & PSR_ABT_MASK);
}
+#ifdef CONFIG_ARM_32
#define arch_fetch_and_add(x, v) __sync_fetch_and_add(x, v)
+#endif
extern struct vcpu *__context_switch(struct vcpu *prev, struct vcpu *next);
--
2.47.3
prev parent reply other threads:[~2026-12-01 16:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 16:08 [PATCH v2 0/5] xen/arm64: use LSE atomics when the CPU has them Luca Di Maio
2026-12-01 16:08 ` [PATCH v2 1/5] xen/arm64: detect the LSE atomic instructions Luca Di Maio
2026-12-01 16:08 ` [PATCH v2 2/5] xen/arm64: use LSE in the atomic_t operations Luca Di Maio
2026-12-01 16:08 ` [PATCH v2 3/5] xen/arm64: use LSE in xchg() and cmpxchg() Luca Di Maio
2026-12-01 16:08 ` [PATCH v2 4/5] xen/arm64: use LSE in the bitops Luca Di Maio
2026-12-01 16:08 ` Luca Di Maio [this message]
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=20261201160817.466800-6-luca@edera.dev \
--to=luca@edera.dev \
--cc=Volodymyr_Babchuk@epam.com \
--cc=bertrand.marquis@arm.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/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.