-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In order to produce a generic kernel, a user can select CONFIG_COMBO_SPINLOCKS which will fallback at runtime to the ticket spinlock implementation if Zabha or Ziccrse are not present. Note that we can't use alternatives here because the discovery of extensions is done too late and we need to start with the qspinlock implementation because the ticket spinlock implementation would pollute the spinlock value, so let's use static keys. This is largely based on Guo's work and Leonardo reviews at [1]. Link: https://lore.kernel.org/linux-riscv/20231225125847.2778638-1-guoren@kernel.org/ [1] Signed-off-by: Guo Ren <guoren@kernel.org> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com> Reviewed-by: Andrea Parri <parri.andrea@gmail.com> Link: https://lore.kernel.org/r/20241103145153.105097-14-alexghiti@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
- Loading branch information
Alexandre Ghiti
authored and
Palmer Dabbelt
committed
Nov 11, 2024
1 parent
447b2af
commit ab83647
Showing
7 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
|
||
#ifndef __ASM_RISCV_SPINLOCK_H | ||
#define __ASM_RISCV_SPINLOCK_H | ||
|
||
#ifdef CONFIG_RISCV_COMBO_SPINLOCKS | ||
#define _Q_PENDING_LOOPS (1 << 9) | ||
|
||
#define __no_arch_spinlock_redefine | ||
#include <asm/ticket_spinlock.h> | ||
#include <asm/qspinlock.h> | ||
#include <asm/jump_label.h> | ||
|
||
/* | ||
* TODO: Use an alternative instead of a static key when we are able to parse | ||
* the extensions string earlier in the boot process. | ||
*/ | ||
DECLARE_STATIC_KEY_TRUE(qspinlock_key); | ||
|
||
#define SPINLOCK_BASE_DECLARE(op, type, type_lock) \ | ||
static __always_inline type arch_spin_##op(type_lock lock) \ | ||
{ \ | ||
if (static_branch_unlikely(&qspinlock_key)) \ | ||
return queued_spin_##op(lock); \ | ||
return ticket_spin_##op(lock); \ | ||
} | ||
|
||
SPINLOCK_BASE_DECLARE(lock, void, arch_spinlock_t *) | ||
SPINLOCK_BASE_DECLARE(unlock, void, arch_spinlock_t *) | ||
SPINLOCK_BASE_DECLARE(is_locked, int, arch_spinlock_t *) | ||
SPINLOCK_BASE_DECLARE(is_contended, int, arch_spinlock_t *) | ||
SPINLOCK_BASE_DECLARE(trylock, bool, arch_spinlock_t *) | ||
SPINLOCK_BASE_DECLARE(value_unlocked, int, arch_spinlock_t) | ||
|
||
#elif defined(CONFIG_RISCV_QUEUED_SPINLOCKS) | ||
|
||
#include <asm/qspinlock.h> | ||
|
||
#else | ||
|
||
#include <asm/ticket_spinlock.h> | ||
|
||
#endif | ||
|
||
#include <asm/qrwlock.h> | ||
|
||
#endif /* __ASM_RISCV_SPINLOCK_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters