linux/arch/riscv
Anton Blanchard 5d5fc33ce5
riscv: Improve exception and system call latency
Many CPUs implement return address branch prediction as a stack. The
RISCV architecture refers to this as a return address stack (RAS). If
this gets corrupted then the CPU will mispredict at least one but
potentally many function returns.

There are two issues with the current RISCV exception code:

- We are using the alternate link stack (x5/t0) for the indirect branch
  which makes the hardware think this is a function return. This will
  corrupt the RAS.

- We modify the return address of handle_exception to point to
  ret_from_exception. This will also corrupt the RAS.

Testing the null system call latency before and after the patch:

Visionfive2 (StarFive JH7110 / U74)
baseline: 189.87 ns
patched:  176.76 ns

Lichee pi 4a (T-Head TH1520 / C910)
baseline: 666.58 ns
patched:  636.90 ns

Just over 7% on the U74 and just over 4% on the C910.

Signed-off-by: Anton Blanchard <antonb@tenstorrent.com>
Signed-off-by: Cyril Bur <cyrilbur@tenstorrent.com>
Tested-by: Jisheng Zhang <jszhang@kernel.org>
Reviewed-by: Jisheng Zhang <jszhang@kernel.org>
Link: https://lore.kernel.org/r/20240607061335.2197383-1-cyrilbur@tenstorrent.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2024-07-26 05:50:45 -07:00
..
boot riscv: boot: remove duplicated targets line 2024-07-24 06:14:06 -07:00
configs RISC-V: run savedefconfig for defconfig 2024-07-22 10:57:47 -07:00
crypto crypto: riscv - add vector crypto accelerated AES-CBC-CTS 2024-03-20 08:56:11 -07:00
errata riscv: Extend cpufeature.c to detect vendor extensions 2024-07-22 15:36:54 -07:00
include Merge patch series "riscv: Separate vendor extensions from standard extensions" 2024-07-22 15:37:01 -07:00
kernel riscv: Improve exception and system call latency 2024-07-26 05:50:45 -07:00
kvm RISC-V Patches for the 6.11 Merge Window, Part 1 2024-07-20 09:11:27 -07:00
lib riscv: Optimize crc32 with Zbc extension 2024-07-10 13:19:50 -07:00
mm RISC-V Patches for the 6.11 Merge Window, Part 1 2024-07-20 09:11:27 -07:00
net RISC-V Patches for the 6.11 Merge Window, Part 1 2024-07-20 09:11:27 -07:00
purgatory Makefile: remove redundant tool coverage variables 2024-05-14 23:35:48 +09:00
tools
Kbuild RISC-V: hook new crypto subdir into build-system 2024-01-22 17:55:17 -08:00
Kconfig trace: riscv: Remove deprecated kprobe on ftrace support 2024-07-24 06:14:05 -07:00
Kconfig.debug riscv: Add tests for riscv module loading 2023-11-07 14:59:32 -08:00
Kconfig.errata riscv: thead: Rename T-Head PBMT to MAE 2024-04-25 10:22:33 -07:00
Kconfig.socs RISC-V: drop SOC_VIRT for ARCH_VIRT 2024-04-10 11:37:50 +01:00
Kconfig.vendor riscv: Extend cpufeature.c to detect vendor extensions 2024-07-22 15:36:54 -07:00
Makefile Merge patch series "riscv: Apply Zawrs when available" 2024-07-12 08:55:29 -07:00
Makefile.postlink kbuild: remove ARCH_POSTLINK from module builds 2023-10-28 21:10:08 +09:00