Re: [PATCH v2] riscv: Add sysctl to control discard of vstate during syscall

From: Florian Weimer
Date: Sat Aug 09 2025 - 04:40:54 EST


* Drew Fustini:

> From: Drew Fustini <dfustini@xxxxxxxxxxxxxxx>
>
> Clobbering the vector registers can significantly increase system call
> latency for some implementations. To mitigate this performance impact, a
> sysctl knob is provided that controls whether the vector state is
> discarded in the syscall path:
>
> /proc/sys/abi/riscv_v_vstate_discard
>
> Valid values are:
>
> 0: Vector state is not always clobbered in all syscalls
> 1: Mandatory clobbering of vector state in all syscalls
>
> The initial state is controlled by CONFIG_RISCV_ISA_V_VSTATE_DISCARD.

Can this be put into the system call number instead, or make it specific
to some system calls in other ways?

I think C libraries can use this optimization for their system calls
(after adjusting the assembler clobbers) because the vector state is
caller-saved in the standard calling convention. But there is backwards
compatibility impact for turning this on for the entire process.

Thanks,
Florian