[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/5] xen/arm64: use LSE in xchg() and cmpxchg()



As for the atomic_t operations, use SWPAL and CAS when the CPU has LSE,
with the same barriers. A CAS cannot fail spuriously, so the _timeout
variants used by guest atomics succeed on their first try.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Luca Di Maio <luca@xxxxxxxxx>
---
 xen/arch/arm/include/asm/arm64/cmpxchg.h | 41 ++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/xen/arch/arm/include/asm/arm64/cmpxchg.h 
b/xen/arch/arm/include/asm/arm64/cmpxchg.h
index f160e8e7bc..442b6e1698 100644
--- a/xen/arch/arm/include/asm/arm64/cmpxchg.h
+++ b/xen/arch/arm/include/asm/arm64/cmpxchg.h
@@ -2,6 +2,7 @@
 #define __ASM_ARM64_CMPXCHG_H
 
 #include <xen/bug.h>
+#include <asm/arm64/lse.h>
 
 extern void __bad_xchg(volatile void *ptr, int size);
 
@@ -11,6 +12,14 @@ static inline unsigned long __xchg(unsigned long x, volatile 
void *ptr, int size
 
        switch (size) {
        case 1:
+               if (system_uses_lse_atomics()) {
+                       asm volatile(__LSE_PREAMBLE
+                       "       swpalb  %w2, %w0, %1"
+                               : "=&r" (ret), "+Q" (*(volatile u8 *)ptr)
+                               : "r" (x)
+                               : "memory");
+                       break;
+               }
                asm volatile("//        __xchg1\n"
                "1:     ldxrb   %w0, %2\n"
                "       stlxrb  %w1, %w3, %2\n"
@@ -20,6 +29,14 @@ static inline unsigned long __xchg(unsigned long x, volatile 
void *ptr, int size
                        : "memory");
                break;
        case 2:
+               if (system_uses_lse_atomics()) {
+                       asm volatile(__LSE_PREAMBLE
+                       "       swpalh  %w2, %w0, %1"
+                               : "=&r" (ret), "+Q" (*(volatile u16 *)ptr)
+                               : "r" (x)
+                               : "memory");
+                       break;
+               }
                asm volatile("//        __xchg2\n"
                "1:     ldxrh   %w0, %2\n"
                "       stlxrh  %w1, %w3, %2\n"
@@ -29,6 +46,14 @@ static inline unsigned long __xchg(unsigned long x, volatile 
void *ptr, int size
                        : "memory");
                break;
        case 4:
+               if (system_uses_lse_atomics()) {
+                       asm volatile(__LSE_PREAMBLE
+                       "       swpal   %w2, %w0, %1"
+                               : "=&r" (ret), "+Q" (*(volatile u32 *)ptr)
+                               : "r" (x)
+                               : "memory");
+                       break;
+               }
                asm volatile("//        __xchg4\n"
                "1:     ldxr    %w0, %2\n"
                "       stlxr   %w1, %w3, %2\n"
@@ -38,6 +63,14 @@ static inline unsigned long __xchg(unsigned long x, volatile 
void *ptr, int size
                        : "memory");
                break;
        case 8:
+               if (system_uses_lse_atomics()) {
+                       asm volatile(__LSE_PREAMBLE
+                       "       swpal   %2, %0, %1"
+                               : "=&r" (ret), "+Q" (*(volatile u64 *)ptr)
+                               : "r" (x)
+                               : "memory");
+                       break;
+               }
                asm volatile("//        __xchg8\n"
                "1:     ldxr    %0, %2\n"
                "       stlxr   %w1, %3, %2\n"
@@ -75,6 +108,14 @@ static inline bool __cmpxchg_case_##name(volatile void 
*ptr,                \
        unsigned long oldval;                                           \
        unsigned long res;                                              \
                                                                        \
+       if (system_uses_lse_atomics()) {                                \
+               asm volatile(__LSE_PREAMBLE                             \
+               "       cas" #sz "      %" #w "0, %" #w "2, %1"         \
+               : "+r" (*old), "+Q" (*(volatile unsigned long *)ptr)    \
+               : "r" (new));                                           \
+               return true;                                            \
+       }                                                               \
+                                                                       \
        do {                                                            \
                asm volatile("// __cmpxchg_case_" #name "\n"            \
                "       ldxr" #sz "     %" #w "1, %2\n"                 \
-- 
2.47.3




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.