|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH 2/5] xen/arm64: use LSE in the atomic_t operations
On a two-socket Graviton4 every pCPU of a socket spun in the exclusive
loop of atomic_add_return() on dom0's p2m rwlock, and dom0 hung at boot.
Use the LSE instruction for each operation when the CPU has it, with the
same barriers; CPUs without LSE keep the exclusive loops.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Luca Di Maio <luca@xxxxxxxxx>
---
xen/arch/arm/include/asm/arm64/atomic.h | 55 +++++++++++++++++++++++++
1 file changed, 55 insertions(+)
diff --git a/xen/arch/arm/include/asm/arm64/atomic.h
b/xen/arch/arm/include/asm/arm64/atomic.h
index 4460165295..a113401db6 100644
--- a/xen/arch/arm/include/asm/arm64/atomic.h
+++ b/xen/arch/arm/include/asm/arm64/atomic.h
@@ -22,6 +22,8 @@
#ifndef __ARCH_ARM_ARM64_ATOMIC
#define __ARCH_ARM_ARM64_ATOMIC
+#include <asm/arm64/lse.h>
+
/*
* AArch64 UP and SMP safe atomic ops. We use load exclusive and
* store exclusive to ensure that these are atomic. We may loop
@@ -32,6 +34,14 @@ static inline void atomic_add(int i, atomic_t *v)
unsigned long tmp;
int result;
+ if (system_uses_lse_atomics()) {
+ asm volatile(__LSE_PREAMBLE
+" stadd %w1, %0"
+ : "+Q" (v->counter)
+ : "r" (i));
+ return;
+ }
+
asm volatile("// atomic_add\n"
"1: ldxr %w0, %2\n"
" add %w0, %w0, %w3\n"
@@ -46,6 +56,16 @@ static inline int atomic_add_return(int i, atomic_t *v)
unsigned long tmp;
int result;
+ if (system_uses_lse_atomics()) {
+ asm volatile(__LSE_PREAMBLE
+" ldaddal %w2, %w0, %1"
+ : "=&r" (result), "+Q" (v->counter)
+ : "r" (i)
+ : "memory");
+ smp_mb();
+ return (int)((unsigned int)result + i);
+ }
+
asm volatile("// atomic_add_return\n"
"1: ldxr %w0, %2\n"
" add %w0, %w0, %w3\n"
@@ -64,6 +84,14 @@ static inline void atomic_sub(int i, atomic_t *v)
unsigned long tmp;
int result;
+ if (system_uses_lse_atomics()) {
+ asm volatile(__LSE_PREAMBLE
+" stadd %w1, %0"
+ : "+Q" (v->counter)
+ : "r" (-(unsigned int)i));
+ return;
+ }
+
asm volatile("// atomic_sub\n"
"1: ldxr %w0, %2\n"
" sub %w0, %w0, %w3\n"
@@ -78,6 +106,16 @@ static inline int atomic_sub_return(int i, atomic_t *v)
unsigned long tmp;
int result;
+ if (system_uses_lse_atomics()) {
+ asm volatile(__LSE_PREAMBLE
+" ldaddal %w2, %w0, %1"
+ : "=&r" (result), "+Q" (v->counter)
+ : "r" (-(unsigned int)i)
+ : "memory");
+ smp_mb();
+ return (int)((unsigned int)result - i);
+ }
+
asm volatile("// atomic_sub_return\n"
"1: ldxr %w0, %2\n"
" sub %w0, %w0, %w3\n"
@@ -96,6 +134,14 @@ static inline void atomic_and(int m, atomic_t *v)
unsigned long tmp;
int result;
+ if (system_uses_lse_atomics()) {
+ asm volatile(__LSE_PREAMBLE
+" stclr %w1, %0"
+ : "+Q" (v->counter)
+ : "r" (~m));
+ return;
+ }
+
asm volatile("// atomic_and\n"
"1: ldxr %w0, %2\n"
" and %w0, %w0, %w3\n"
@@ -112,6 +158,15 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int
new)
smp_mb();
+ if (system_uses_lse_atomics()) {
+ asm volatile(__LSE_PREAMBLE
+" cas %w0, %w2, %1"
+ : "+r" (old), "+Q" (v->counter)
+ : "r" (new));
+ smp_mb();
+ return old;
+ }
+
asm volatile("// atomic_cmpxchg\n"
"1: ldxr %w1, %2\n"
" cmp %w1, %w3\n"
--
2.47.3
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |