LoongArch is a new architecture that is already supported by linux-6.1, gcc-12, and I want to add LoongArch spinlock support in s_lock.h.
From 68c252b4aab5d116b1bf791e16f072fb3ee0161f Mon Sep 17 00:00:00 2001 From: Zang Ruochen <zangruoc...@loongson.cn> Date: Thu, 1 Jun 2023 15:30:44 +0800 Subject: [PATCH] Add LoongArch spinlock support in s_lock.h.
--- src/include/storage/s_lock.h | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h index c9fa84cc43..bec55856af 100644 --- a/src/include/storage/s_lock.h +++ b/src/include/storage/s_lock.h @@ -529,6 +529,46 @@ do \ #endif /* __mips__ && !__sgi */ +/* LoongArch */ +#if defined(__loongarch__) +#define HAS_TEST_AND_SET + +typedef unsigned int slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int +tas(volatile slock_t *lock) +{ + register volatile slock_t *_l = lock; + register int _res; + register int _tmp; + + __asm__ __volatile__( + " ll.w %0, %2 \n" + " ori %1, %0, 1 \n" + " sc.w %1, %2 \n" + " xori %1, %1, 1 \n" + " or %0, %0, %1 \n" + " dbar 0 \n" +: "=&r" (_res), "=&r" (_tmp), "+ZC" (*_l) +: /* no inputs */ +: "memory"); + return _res; +} + +#define S_UNLOCK(lock) \ +do \ +{ \ + __asm__ __volatile__( \ + " dbar 0 \n" \ +: /* no outputs */ \ +: /* no inputs */ \ +: "memory"); \ + *((volatile slock_t *) (lock)) = 0; \ +} while (0) + +#endif /* LoongArch */ #if defined(__hppa) || defined(__hppa__) /* HP PA-RISC */ /* -- 2.20.1