Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: x/sys: add riscv vector extension detection #62238

Open
mengzhuo opened this issue Aug 23, 2023 · 3 comments
Open

proposal: x/sys: add riscv vector extension detection #62238

mengzhuo opened this issue Aug 23, 2023 · 3 comments
Labels
arch-riscv Issues solely affecting the riscv64 architecture. Proposal
Milestone

Comments

@mengzhuo
Copy link
Contributor

Since Linux 6.5 will be released with riscv vector support, I proposal adding a vector feature detection for it.
Linux source code: https://github.com/torvalds/linux/blob/v6.5-rc7/arch/riscv/include/uapi/asm/hwcap.h

#define COMPAT_HWCAP_ISA_V	(1 << ('V' - 'A'))

The API change in x/sys is simple by adding:

var RISCV64 struct {
	HasV bool // Vector extension
}

Other Linux architecture had already supported aux reading, nothing changed in *_linux.

FreeBSD has not support riscv as Tier 1 platform, nothing changed in freebsd/riscv64.

p.s. In CL 508676, Mills wants a proposal for riscv64 vector extension detection.

Related #61416

@gopherbot gopherbot added this to the Proposal milestone Aug 23, 2023
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/508676 mentions this issue: cpu: add riscv vector extension detection

@bcmills bcmills added the arch-riscv Issues solely affecting the riscv64 architecture. label Aug 23, 2023
@bcmills
Copy link
Contributor

bcmills commented Aug 23, 2023

(attn @golang/riscv64)

@markdryan
Copy link
Contributor

We should also define what HasV actually means. Does it mean that Version 1.0 of the RISC-V Vector extension is supported or some earlier version? This is an issue as there are some boards on the market, e.g., Sipeed LicheePi that implement a draft version of the Vector specification (v0.7), and unfortunately, v0.7 and the ratified v1.0 are not binary compatible. Presumably we want HasV to be set to true only if the underlying CPU supports the ratified 1.0 version of the Vector specification or a backwardly compatible future version.

Assuming this is the case, there's another problem. It seems that the LicheePi has a custom kernel that reports support for the 'V' extension via hwcap, even though it only supports v0.7 of the standard. Any Go programs that were to use hwcap to detect the vector extension before executing V1.0 vector code would most likely crash on the LicheePi. This is not just a hypothetical concern. An issue was raised in OpenJDK this week reporting binary incompatibility vector related crashes on the LicheePi in the JVM. The solution adopted in the OpenJDK was to stop using hwcap to detect the Vector extension and to instead rely exclusively riscv_hwprobe, as proposed in #61416, to detect Vector . riscv_hwprobe does not have these issues as the extensions it reports are explicitly versioned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-riscv Issues solely affecting the riscv64 architecture. Proposal
Projects
Status: Incoming
Development

No branches or pull requests

4 participants