RFR: 8333245: RISC-V: UseRVV option can't be enabled after JDK-8316859

Fei Yang fyang at openjdk.org
Thu May 30 13:31:03 UTC 2024


On Thu, 30 May 2024 10:21:28 GMT, Robbin Ehn <rehn at openjdk.org> wrote:

> If you don't have RVV you are not guaranteed to have Zicsr, meaning the csrr read of vlenb may crash ? If you have csr, what will that return in this case? (no V but Zicsr)
> 
> You also need kernel support for RVV:
> 
> * You must turn on V from privilege mode, the kernel needs to do this.
> * If you are context switched in the middle of your vector code the kernel must saves all those V registers.
> 
> Only kernels with hw_probe that is reporting RVV is guaranteed todo this.
> 
> If this is a vanilla 6.1.15 you can't use V AFIAK. If there are out of tree patches on top of this to make V work, they need to add the hw_probe patches also.

That makes sense to me. I think you mean kernel versions >= 6.5 where process context switch and hwprobe support for RVV are both added at the same time [1].

[1] https://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux.git/commit/?h=for-next&id=d5e45e810e0e08114035d31d88049544c038e6fc

> So I would suggest something like:
> 
> * If UseRVV and hwcap V = true but no hwprobe.
> * Test if we can csrr in a safe fetch manor.
> * If we can, we try to read vector context status field, VS, to determine if it's on or off. (in a 'safe fetch' manor)
> * If that succeds, we store something in v0, change CPU using affinity mask, and verify that v0 contains that value after the change of CPU.
> * Now you just need to cross fingers that it is v1.0 :) (this will still fail on THEAD)
> 
> Or similar as we don't want the VM to crash just because an user added +UseRVV erroneously.
> 
> Note in 6.7 there is `prctl(PR_RISCV_V_SET_CONTROL, unsigned long arg)` to turn on/off V for a thread.

That sounds very tricky given that we have both rvv-0.7.1 and rvv-1.0 hardwares for now. I think it will be safer and simpler for us to rely on the availability of hwprobe syscall. But I guess will won't be a big issue when we do some simple performance evaluations like a simple JMH run, but yes, you have to change the code to force enable UseRVV when running on the older kernels.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/19472#issuecomment-2139557926


More information about the hotspot-dev mailing list