From: Palmer Dabbelt <palmer@rivosinc.com>
To: linux-riscv@lists.infradead.org, peterz@infradead.org
Cc: jonas@southpole.se, stefan.kristiansson@saunalahti.fi,
shorne@gmail.com, mingo@redhat.com, Will Deacon <will@kernel.org>,
longman@redhat.com, boqun.feng@gmail.com,
Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
aou@eecs.berkeley.edu, Arnd Bergmann <arnd@arndb.de>,
jszhang@kernel.org, wangkefeng.wang@huawei.com,
openrisc@lists.librecores.org, linux-kernel@vger.kernel.org,
linux-riscv@lists.infradead.org, linux-arch@vger.kernel.org,
Palmer Dabbelt <palmer@rivosinc.com>
Subject: [PATCH 4/5] RISC-V: Move to ticket-spinlocks
Date: Wed, 16 Mar 2022 16:25:59 -0700 [thread overview]
Message-ID: <20220316232600.20419-5-palmer@rivosinc.com> (raw)
In-Reply-To: <20220316232600.20419-1-palmer@rivosinc.com>
From: Palmer Dabbelt <palmer@rivosinc.com>
Our existing spinlocks aren't fair and replacing them has been on the
TODO list for a long time. This moves to the recently-introduced ticket
spinlocks, which are simple enough that they are likely to be correct
and fast on the vast majority of extant implementations.
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
---
arch/riscv/include/asm/Kbuild | 2 ++
arch/riscv/include/asm/spinlock.h | 41 +------------------------
arch/riscv/include/asm/spinlock_types.h | 6 +---
3 files changed, 4 insertions(+), 45 deletions(-)
diff --git a/arch/riscv/include/asm/Kbuild b/arch/riscv/include/asm/Kbuild
index 57b86fd9916c..42b1961af1a6 100644
--- a/arch/riscv/include/asm/Kbuild
+++ b/arch/riscv/include/asm/Kbuild
@@ -2,5 +2,7 @@
generic-y += early_ioremap.h
generic-y += flat.h
generic-y += kvm_para.h
+generic-y += ticket-lock.h
+generic-y += ticket-lock-types.h
generic-y += user.h
generic-y += vmlinux.lds.h
diff --git a/arch/riscv/include/asm/spinlock.h b/arch/riscv/include/asm/spinlock.h
index f4f7fa1b7ca8..38089cbdea92 100644
--- a/arch/riscv/include/asm/spinlock.h
+++ b/arch/riscv/include/asm/spinlock.h
@@ -10,46 +10,7 @@
#include <linux/kernel.h>
#include <asm/current.h>
#include <asm/fence.h>
-
-/*
- * Simple spin lock operations. These provide no fairness guarantees.
- */
-
-/* FIXME: Replace this with a ticket lock, like MIPS. */
-
-#define arch_spin_is_locked(x) (READ_ONCE((x)->lock) != 0)
-
-static inline void arch_spin_unlock(arch_spinlock_t *lock)
-{
- smp_store_release(&lock->lock, 0);
-}
-
-static inline int arch_spin_trylock(arch_spinlock_t *lock)
-{
- int tmp = 1, busy;
-
- __asm__ __volatile__ (
- " amoswap.w %0, %2, %1\n"
- RISCV_ACQUIRE_BARRIER
- : "=r" (busy), "+A" (lock->lock)
- : "r" (tmp)
- : "memory");
-
- return !busy;
-}
-
-static inline void arch_spin_lock(arch_spinlock_t *lock)
-{
- while (1) {
- if (arch_spin_is_locked(lock))
- continue;
-
- if (arch_spin_trylock(lock))
- break;
- }
-}
-
-/***********************************************************/
+#include <asm-generic/ticket-lock.h>
static inline void arch_read_lock(arch_rwlock_t *lock)
{
diff --git a/arch/riscv/include/asm/spinlock_types.h b/arch/riscv/include/asm/spinlock_types.h
index 5a35a49505da..431ee08e26c4 100644
--- a/arch/riscv/include/asm/spinlock_types.h
+++ b/arch/riscv/include/asm/spinlock_types.h
@@ -10,11 +10,7 @@
# error "please don't include this file directly"
#endif
-typedef struct {
- volatile unsigned int lock;
-} arch_spinlock_t;
-
-#define __ARCH_SPIN_LOCK_UNLOCKED { 0 }
+#include <asm-generic/ticket-lock-types.h>
typedef struct {
volatile unsigned int lock;
--
2.34.1
next prev parent reply other threads:[~2022-03-16 23:28 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-16 23:25 [PATCH 0/5] Generic Ticket Spinlocks Palmer Dabbelt
2022-03-16 23:25 ` [PATCH 1/5] asm-generic: qspinlock: Indicate the use of mixed-size atomics Palmer Dabbelt
2022-03-17 17:46 ` Waiman Long
2022-03-16 23:25 ` [PATCH 2/5] asm-generic: ticket-lock: New generic ticket-based spinlock Palmer Dabbelt
2022-03-17 9:46 ` Peter Zijlstra
2022-03-17 13:57 ` Boqun Feng
2022-03-17 15:03 ` Waiman Long
2022-03-17 15:34 ` Boqun Feng
2022-03-17 18:04 ` Waiman Long
2022-03-16 23:25 ` [PATCH 3/5] openrisc: Move to ticket-spinlock Palmer Dabbelt
2022-03-17 9:46 ` Peter Zijlstra
2022-03-21 21:29 ` Stafford Horne
2022-03-22 3:29 ` Guo Ren
2022-03-22 4:10 ` Stafford Horne
2022-03-22 6:45 ` Guo Ren
2022-03-16 23:25 ` Palmer Dabbelt [this message]
2022-03-16 23:26 ` [PATCH 5/5] RISC-V: Move to queued RW locks Palmer Dabbelt
2022-03-17 9:47 ` Peter Zijlstra
2022-03-17 9:16 ` [PATCH 0/5] Generic Ticket Spinlocks Arnd Bergmann
2022-03-17 11:09 ` Heiko Stübner
2022-03-18 7:24 ` Guo Ren
2022-03-18 8:40 ` Guo Ren
2022-03-22 18:18 ` Conor Dooley
2022-03-22 20:02 ` Palmer Dabbelt
2022-03-22 20:19 ` Conor Dooley
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=20220316232600.20419-5-palmer@rivosinc.com \
--to=palmer@rivosinc.com \
--cc=aou@eecs.berkeley.edu \
--cc=arnd@arndb.de \
--cc=boqun.feng@gmail.com \
--cc=jonas@southpole.se \
--cc=jszhang@kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=openrisc@lists.librecores.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=peterz@infradead.org \
--cc=shorne@gmail.com \
--cc=stefan.kristiansson@saunalahti.fi \
--cc=wangkefeng.wang@huawei.com \
--cc=will@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox