All of lore.kernel.org
 help / color / mirror / Atom feed
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 4/5] xen/arm64: use LSE in the bitops
Date: Tue,  1 Dec 2026 17:08:14 +0100	[thread overview]
Message-ID: <20261201160817.466800-5-luca@edera.dev> (raw)
In-Reply-To: <20261201160817.466800-1-luca@edera.dev>

As for the atomic_t operations, use ST{SET,CLR,EOR} and
LD{SET,CLR,EOR}AL when the CPU has LSE, with the same barriers; the
macros take the LSE operation as a new argument. The _timeout variants
now succeed on their first try.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Luca Di Maio <luca@edera.dev>
---
 xen/arch/arm/arm64/lib/bitops.c | 47 +++++++++++++++++++++++++++------
 1 file changed, 39 insertions(+), 8 deletions(-)

diff --git a/xen/arch/arm/arm64/lib/bitops.c b/xen/arch/arm/arm64/lib/bitops.c
index 275a780329..0153e4f68b 100644
--- a/xen/arch/arm/arm64/lib/bitops.c
+++ b/xen/arch/arm/arm64/lib/bitops.c
@@ -15,6 +15,7 @@
  */
 
 #include <xen/bitops.h>
+#include <asm/arm64/lse.h>
 #include <asm/system.h>
 
 /*
@@ -28,7 +29,7 @@
  * XXX: Rework the interface to use unsigned int.
  */
 
-#define bitop(name, instr)                                                  \
+#define bitop(name, instr, lse_op)                                          \
 static always_inline bool int_##name(int nr, volatile void *p, bool timeout,\
                                      unsigned int max_try)                  \
 {                                                                           \
@@ -37,6 +38,15 @@ static always_inline bool int_##name(int nr, volatile void *p, bool timeout,\
     const uint32_t mask = BITOP_MASK((unsigned int)nr);                     \
     unsigned long res, tmp;                                                 \
                                                                             \
+    if ( system_uses_lse_atomics() )                                        \
+    {                                                                       \
+        asm volatile ( __LSE_PREAMBLE                                       \
+                       "   st" #lse_op "   %w1, %0\n"                       \
+                       : "+Q" (*ptr)                                        \
+                       : "r" (mask) );                                      \
+        return true;                                                        \
+    }                                                                       \
+                                                                            \
     do                                                                      \
     {                                                                       \
         asm volatile ("// " __stringify(name) "\n"                          \
@@ -64,7 +74,7 @@ bool name##_timeout(int nr, volatile void *p, unsigned int max_try)         \
     return int_##name(nr, p, true, max_try);                                \
 }
 
-#define testop(name, instr)                                                 \
+#define testop(name, instr, lse_op)                                         \
 static always_inline bool int_##name(int nr, volatile void *p, int *oldbit, \
                                      bool timeout, unsigned int max_try)    \
 {                                                                           \
@@ -74,6 +84,18 @@ static always_inline bool int_##name(int nr, volatile void *p, int *oldbit, \
     const uint32_t mask = BITOP_MASK(bit);                                  \
     unsigned long res, tmp;                                                 \
                                                                             \
+    if ( system_uses_lse_atomics() )                                        \
+    {                                                                       \
+        asm volatile ( __LSE_PREAMBLE                                       \
+                       "   ld" #lse_op "al %w2, %w0, %1\n"                  \
+                       : "=&r" (tmp), "+Q" (*ptr)                           \
+                       : "r" (mask)                                         \
+                       : "memory" );                                        \
+        dmb(ish);                                                           \
+        *oldbit = (tmp >> bit) & 1;                                         \
+        return true;                                                        \
+    }                                                                       \
+                                                                            \
     do                                                                      \
     {                                                                       \
         asm volatile ("// " __stringify(name) "\n"                          \
@@ -112,19 +134,28 @@ bool name##_timeout(int nr, volatile void *p,                               \
     return int_##name(nr, p, oldbit, true, max_try);                        \
 }
 
-bitop(change_bit, eor)
-bitop(clear_bit, bic)
-bitop(set_bit, orr)
+bitop(change_bit, eor, eor)
+bitop(clear_bit, bic, clr)
+bitop(set_bit, orr, set)
 
-testop(test_and_change_bit, eor)
-testop(test_and_clear_bit, bic)
-testop(test_and_set_bit, orr)
+testop(test_and_change_bit, eor, eor)
+testop(test_and_clear_bit, bic, clr)
+testop(test_and_set_bit, orr, set)
 
 static always_inline bool int_clear_mask16(uint16_t mask, volatile uint16_t *p,
                                            bool timeout, unsigned int max_try)
 {
     unsigned long res, tmp;
 
+    if ( system_uses_lse_atomics() )
+    {
+        asm volatile ( __LSE_PREAMBLE
+                       "   stclrh  %w1, %0\n"
+                       : "+Q" (*p)
+                       : "r" (mask) );
+        return true;
+    }
+
     do
     {
         asm volatile ("//  int_clear_mask16\n"
-- 
2.47.3



  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 ` Luca Di Maio [this message]
2026-12-01 16:08 ` [PATCH v2 5/5] xen/arm64: use LSE for arch_fetch_and_add() Luca Di Maio

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-5-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.