* [PATCH v6 0/8] riscv: optimize mode switch latency for Vector
@ 2026-09-18 21:51 Andy Chiu
2026-10-06 9:40 ` patchwork-bot+linux-riscv
2026-10-06 10:01 ` Paul Walmsley
0 siblings, 2 replies; 3+ messages in thread
From: Andy Chiu @ 2026-09-18 21:51 UTC (permalink / raw)
To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, linux-riscv
Cc: andybnac, Andy Chiu, dfustini, greentime.hu, linux-kernel, olof
This series provide several optimizations targeting system call latency
regarding vector context management. Before the series, the kernel
handled user's vector context in an conservative way, where registers
were null out and VS is tracked as DIRTY. This introduce excess context
saving and restoring when there is a context swicth. Also, the kernel
turned off Vector at the exception entry, making all in-kernel vector
usecase take the serialization cost, which includes context switch and
user copies. The cost is not easy to hide as vector code are usually sit
right after enabling V.
Since vector register are set to a known state at syscall exit, the
series set VS to INIT at syscall entry and null out the vector register
at the exit, skipping unnecessary saves and restores. The series also
introduce riscv_novstateopt, when unset, enables vector in the kernel
mode, and do not perform register nulling on the syscall fast path,
where there is no context switch or kernel-mode vector during the
syscall.
With the whole series, nginx request throughput vs base on a four-core
Ascalon-S, by served page size (* = statistically distinct):
86B 1KB 2KB 4KB 8KB 16KB 32KB
v5 +0.79%* +1.36%* +2.33%* +2.02%* +0.14% +0.93% +2.42%*
v6 +0.33%* -0.23% +2.88%* +2.19%* +1.02% +1.14% +1.40%*
This series depends on [1], which is now queued in the KVM RISC-V tree
[2]. For those who prefer git, the series is also available at [3].
Patch summary:
- New patches: 2
- Modified patches: 7, 8
- Unchanged patches: 1, 3, 4, 5, 6
Changelog v6:
- Refactor the context switch of preemptible kernel-mode vector (2)
- Address checkpatch warnings by reformatting patch 7
- Drive the optimization with an alternative instead of
CONFIG_RISCV_VSTATE_OPT, enable it by default (8)
- Link to v5: https://lore.kernel.org/all/20260810172255.1532787-1-tchiu@tenstorrent.com/
Changelog v5:
- Rebase on top of the kvm fix
- Do not read sstatus in vector context swicth (1)
- Add a test for vectorized user copy (2)
- Enable vector in the kernel-mode and skip nulling at syscall fast
path, gurad the optimization in a new config (7)
- Link to v4: https://patchwork.kernel.org/project/linux-riscv/cover/20260528190927.886558-1-tchiu@tenstorrent.com/
Changelog v4:
- Fix a build warning (1)
- Prevent setting INIT when it is already and provide performance
meassurements (2)
- Address comments from sashiko (4)
- Link to v3: https://lore.kernel.org/all/20260521162521.188629-1-tchiu@tenstorrent.com/
Changelog v3:
- Refactor function names. (1, 2)
- Merge daichengrong's patch, with a fix and optimzation. (2)
- Fix ptrace GETREGSET failure. (3)
- Strengthen ptrace SETREGSET semantics and add a test to cover it. (3,
4)
- Fix a potential ABI break in signal and add a test to prevent future
breaks. (3, 4)
- Link to v2: https://lore.kernel.org/linux-riscv/20260402043414.2421916-1-andybnac@gmail.com/
Changelog v2: rebase on top of for-next
[1] [PATCH v5 0/3] RISC-V: KVM: fix vcpu vector context handling
https://lore.kernel.org/all/20260803215250.824417-1-tchiu@tenstorrent.com/
[2] https://github.com/kvm-riscv/linux/tree/riscv_kvm_next
[3] https://github.com/tchiu-TT/linux/commits/vctxopt/v6/
Andy Chiu (7):
riscv: do not read csr in vector context switch
riscv: vector: refactor context switch for kernel-mode vector
selftest: riscv: test vectorized user copy
riscv: vector: refactor vector context operations
riscv: vector: adjust ptrace and signal behavior for INITIAL state
selftests: riscv: Extend vector tests for sigreturn and ptrace
riscv: vector: optimize vstate operations
daichengrong (1):
riscv: clarify vector state semantics on syscall and context switch
.../admin-guide/kernel-parameters.txt | 13 ++
arch/riscv/include/asm/alternative-macros.h | 6 +
arch/riscv/include/asm/alternative.h | 3 -
arch/riscv/include/asm/cpufeature-macros.h | 12 +-
arch/riscv/include/asm/kvm_vcpu_vector.h | 8 +-
arch/riscv/include/asm/vector.h | 78 ++++---
arch/riscv/kernel/cpufeature.c | 19 ++
arch/riscv/kernel/entry.S | 15 +-
arch/riscv/kernel/kernel_mode_vector.c | 13 +-
arch/riscv/kernel/process.c | 3 +
arch/riscv/kernel/ptrace.c | 13 +-
arch/riscv/kernel/signal.c | 11 +-
arch/riscv/kernel/vector.c | 56 ++++-
arch/riscv/kvm/vcpu.c | 2 +-
arch/riscv/kvm/vcpu_vector.c | 6 +-
.../selftests/riscv/sigreturn/sigreturn.c | 69 ++++++
tools/testing/selftests/riscv/vector/Makefile | 6 +-
.../selftests/riscv/vector/v_uaccess_stress.c | 221 ++++++++++++++++++
.../selftests/riscv/vector/vstate_ptrace.c | 111 ++++++++-
19 files changed, 598 insertions(+), 67 deletions(-)
create mode 100644 tools/testing/selftests/riscv/vector/v_uaccess_stress.c
base-commit: c93809c637bd1fb1e0d0f0168b53cfe1c4767d21
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v6 0/8] riscv: optimize mode switch latency for Vector
2026-09-18 21:51 [PATCH v6 0/8] riscv: optimize mode switch latency for Vector Andy Chiu
@ 2026-10-06 9:40 ` patchwork-bot+linux-riscv
2026-10-06 10:01 ` Paul Walmsley
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+linux-riscv @ 2026-10-06 9:40 UTC (permalink / raw)
To: Andy Chiu
Cc: linux-riscv, pjw, palmer, aou, alex, andybnac, dfustini,
greentime.hu, linux-kernel, olof
Hello:
This series was applied to riscv/linux.git (for-next)
by Paul Walmsley <pjw@kernel.org>:
On Fri, 18 Sep 2026 16:51:14 -0500 you wrote:
> This series provide several optimizations targeting system call latency
> regarding vector context management. Before the series, the kernel
> handled user's vector context in an conservative way, where registers
> were null out and VS is tracked as DIRTY. This introduce excess context
> saving and restoring when there is a context swicth. Also, the kernel
> turned off Vector at the exception entry, making all in-kernel vector
> usecase take the serialization cost, which includes context switch and
> user copies. The cost is not easy to hide as vector code are usually sit
> right after enabling V.
>
> [...]
Here is the summary with links:
- [v6,1/8] riscv: do not read csr in vector context switch
https://git.kernel.org/riscv/c/5fd018c630e2
- [v6,2/8] riscv: vector: refactor context switch for kernel-mode vector
https://git.kernel.org/riscv/c/4740b934ebe7
- [v6,3/8] selftest: riscv: test vectorized user copy
https://git.kernel.org/riscv/c/52318cf0fa6e
- [v6,4/8] riscv: vector: refactor vector context operations
https://git.kernel.org/riscv/c/1a5c75ee3d09
- [v6,5/8] riscv: clarify vector state semantics on syscall and context switch
https://git.kernel.org/riscv/c/cc12e55016ba
- [v6,6/8] riscv: vector: adjust ptrace and signal behavior for INITIAL state
https://git.kernel.org/riscv/c/0d4b43a7734d
- [v6,7/8] selftests: riscv: Extend vector tests for sigreturn and ptrace
https://git.kernel.org/riscv/c/6740ec489dd7
- [v6,8/8] riscv: vector: optimize vstate operations
(no matching commit)
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v6 0/8] riscv: optimize mode switch latency for Vector
2026-09-18 21:51 [PATCH v6 0/8] riscv: optimize mode switch latency for Vector Andy Chiu
2026-10-06 9:40 ` patchwork-bot+linux-riscv
@ 2026-10-06 10:01 ` Paul Walmsley
1 sibling, 0 replies; 3+ messages in thread
From: Paul Walmsley @ 2026-10-06 10:01 UTC (permalink / raw)
To: Andy Chiu
Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
linux-riscv, andybnac, dfustini, greentime.hu, linux-kernel,
olof
On Fri, 18 Sep 2026, Andy Chiu wrote:
> This series provide several optimizations targeting system call latency
> regarding vector context management. Before the series, the kernel
> handled user's vector context in an conservative way, where registers
> were null out and VS is tracked as DIRTY. This introduce excess context
> saving and restoring when there is a context swicth. Also, the kernel
> turned off Vector at the exception entry, making all in-kernel vector
> usecase take the serialization cost, which includes context switch and
> user copies. The cost is not easy to hide as vector code are usually sit
> right after enabling V.
>
> Since vector register are set to a known state at syscall exit, the
> series set VS to INIT at syscall entry and null out the vector register
> at the exit, skipping unnecessary saves and restores. The series also
> introduce riscv_novstateopt, when unset, enables vector in the kernel
> mode, and do not perform register nulling on the syscall fast path,
> where there is no context switch or kernel-mode vector during the
> syscall.
>
> With the whole series, nginx request throughput vs base on a four-core
> Ascalon-S, by served page size (* = statistically distinct):
>
> 86B 1KB 2KB 4KB 8KB 16KB 32KB
> v5 +0.79%* +1.36%* +2.33%* +2.02%* +0.14% +0.93% +2.42%*
> v6 +0.33%* -0.23% +2.88%* +2.19%* +1.02% +1.14% +1.40%*
>
> This series depends on [1], which is now queued in the KVM RISC-V tree
> [2]. For those who prefer git, the series is also available at [3].
Thanks. Given the KVM fixes dependency, it's probably best to wait to
merge most of these until v7.5. But I think it's OK to pick up 1, 2, and
3? Will queue those for v7.4.
- Paul
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-06 10:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-18 21:51 [PATCH v6 0/8] riscv: optimize mode switch latency for Vector Andy Chiu
2026-10-06 9:40 ` patchwork-bot+linux-riscv
2026-10-06 10:01 ` Paul Walmsley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®