Skip to content

Commit b6da6cb

Browse files
xhackerustcpalmer-dabbelt
authored andcommitted
riscv: introduce RISCV_EFFICIENT_UNALIGNED_ACCESS
Some riscv implementations such as T-HEAD's C906, C908, C910 and C920 support efficient unaligned access, for performance reason we want to enable HAVE_EFFICIENT_UNALIGNED_ACCESS on these platforms. To avoid performance regressions on other non efficient unaligned access platforms, HAVE_EFFICIENT_UNALIGNED_ACCESS can't be globally selected. To solve this problem, runtime code patching based on the detected speed is a good solution. But that's not easy, it involves lots of work to modify vairous subsystems such as net, mm, lib and so on. This can be done step by step. So let's take an easier solution: add support to efficient unaligned access and hide the support under NONPORTABLE. Now let's introduce RISCV_EFFICIENT_UNALIGNED_ACCESS which depends on NONPORTABLE, if users know during config time that the kernel will be only run on those efficient unaligned access hw platforms, they can enable it. Obviously, generic unified kernel Image shouldn't enable it. Signed-off-by: Jisheng Zhang <[email protected]> Reviewed-by: Charlie Jenkins <[email protected]> Reviewed-by: Eric Biggers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent b85ea95 commit b6da6cb

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

arch/riscv/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,19 @@ config RISCV_MISALIGNED
651651
load/store for both kernel and userspace. When disable, misaligned
652652
accesses will generate SIGBUS in userspace and panic in kernel.
653653

654+
config RISCV_EFFICIENT_UNALIGNED_ACCESS
655+
bool "Assume the CPU supports fast unaligned memory accesses"
656+
depends on NONPORTABLE
657+
select HAVE_EFFICIENT_UNALIGNED_ACCESS
658+
help
659+
Say Y here if you want the kernel to assume that the CPU supports
660+
efficient unaligned memory accesses. When enabled, this option
661+
improves the performance of the kernel on such CPUs. However, the
662+
kernel will run much more slowly, or will not be able to run at all,
663+
on CPUs that do not support efficient unaligned memory accesses.
664+
665+
If unsure what to do here, say N.
666+
654667
endmenu # "Platform type"
655668

656669
menu "Kernel features"

arch/riscv/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax)
108108
# unaligned accesses. While unaligned accesses are explicitly allowed in the
109109
# RISC-V ISA, they're emulated by machine mode traps on all extant
110110
# architectures. It's faster to have GCC emit only aligned accesses.
111+
ifneq ($(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS),y)
111112
KBUILD_CFLAGS += $(call cc-option,-mstrict-align)
113+
endif
112114

113115
ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
114116
prepare: stack_protector_prepare

0 commit comments

Comments
 (0)