Skip to content

Commit 65a42d1

Browse files
ovidiusasrazvancrainea
authored andcommitted
core: implement FAST_LOCK for aarch64 (#3892)
(cherry picked from commit ecc8dbb)
1 parent 7193d4a commit 65a42d1

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

Makefile.defs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ arm_macros= __arm__ __thumb__
230230
arm6_macros= __ARM_ARCH_6__
231231
arm7_macros= __ARM_ARCH_7__ __ARM_ARCH_7A__
232232

233-
arm64_macros= __AARCH64EL__
233+
arm64_macros= __aarch64__ __AARCH64EL__ __AARCH64EB__
234234

235235
ppc_macros= __powerpc __powerpc__ __POWERPC__ __ppc__ _ARCH_PPC
236236
ppc64_macros= __ppc64__ _ARCH_PPC64
@@ -752,6 +752,10 @@ ifeq ($(ARCH), arm7)
752752
use_fast_lock=yes
753753
endif
754754

755+
ifeq ($(ARCH), aarch64)
756+
use_fast_lock=yes
757+
endif
758+
755759
ifeq ($(ARCH), ppc)
756760
use_fast_lock=yes
757761
endif

fastlock.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ inline static int tsl(volatile int* lock)
147147
#endif
148148
: "=&r" (val) : "r"(1), "r" (lock) : "cc", "memory"
149149
);
150+
#elif defined(__CPU_aarch64)
151+
#ifdef SPIN_OPTIMIZE
152+
if (__atomic_load_n(lock, __ATOMIC_RELAXED))
153+
return 1;
154+
#endif
155+
val = __atomic_exchange_n(lock, 1, __ATOMIC_ACQUIRE);
150156
#elif defined(__CPU_ppc) || defined(__CPU_ppc64)
151157
asm volatile(
152158
"1: lwarx %0, 0, %2\n\t"
@@ -300,6 +306,8 @@ inline static void release_lock(fl_lock_t* lock_struct)
300306
" str %1, [%2] \n\r"
301307
: "=m"(*lock) : "r"(0), "r"(lock) : "memory"
302308
);
309+
#elif defined(__CPU_aarch64)
310+
__atomic_store_n(lock, 0, __ATOMIC_RELEASE);
303311
#elif defined(__CPU_ppc) || defined(__CPU_ppc64)
304312
asm volatile(
305313
/* "sync\n\t" lwsync is faster and will work

futex_lock.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ inline static int _atomic_xchg(volatile int *lock, int newval)
159159
: "r"(newval), "r" (lock) : "memory"
160160
);
161161

162+
#elif defined(__CPU_aarch64)
163+
val = __atomic_exchange_n(lock, newval, __ATOMIC_ACQ_REL);
164+
162165
#elif defined(__CPU_ppc) || defined(__CPU_ppc64)
163166
asm volatile(
164167
"1: lwarx %0, 0, %2\n\t"

0 commit comments

Comments
 (0)