Skip to content

Commit

Permalink
[RISCV] Bump hwprobe support to Linux 6.11 (#108578)
Browse files Browse the repository at this point in the history
This patch is the follow-up of
#94352 with some updates:
1. Add support for more extensions for `zve*`, `zimop`, `zc*`, `zcmop`
and `zawrs`.
2. Use `RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF` to check whether the
processor supports fast misaligned scalar memory access.
#108551 reminds me that the
patch
https://lore.kernel.org/all/[email protected]/T/
has been merged. Address comment
#94352 (comment).

References:
1. constants:
https://github.com/torvalds/linux/blame/v6.11-rc7/arch/riscv/include/uapi/asm/hwprobe.h
2. https://docs.kernel.org/arch/riscv/hwprobe.html
3. Related commits:
1. `zve*` support:
torvalds/linux@de8f828
2. `zimop` support:
torvalds/linux@36f8960
3. `zc*` support:
torvalds/linux@0ad70db
4. `zcmop` support:
torvalds/linux@fc078ea
5. `zawrs` support:
torvalds/linux@244c18f
6. scalar misaligned perf:
torvalds/linux@c42e2f0
and
torvalds/linux@1f52888
  • Loading branch information
dtcxzyw authored Oct 5, 2024
1 parent e6549b8 commit bf895c7
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions llvm/lib/TargetParser/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1998,7 +1998,8 @@ struct RISCVHwProbe {
};
const StringMap<bool> sys::getHostCPUFeatures() {
RISCVHwProbe Query[]{{/*RISCV_HWPROBE_KEY_BASE_BEHAVIOR=*/3, 0},
{/*RISCV_HWPROBE_KEY_IMA_EXT_0=*/4, 0}};
{/*RISCV_HWPROBE_KEY_IMA_EXT_0=*/4, 0},
{/*RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF=*/9, 0}};
int Ret = syscall(/*__NR_riscv_hwprobe=*/258, /*pairs=*/Query,
/*pair_count=*/std::size(Query), /*cpu_count=*/0,
/*cpus=*/0, /*flags=*/0);
Expand Down Expand Up @@ -2054,9 +2055,26 @@ const StringMap<bool> sys::getHostCPUFeatures() {
Features["zicond"] = ExtMask & (1ULL << 35); // RISCV_HWPROBE_EXT_ZICOND
Features["zihintpause"] =
ExtMask & (1ULL << 36); // RISCV_HWPROBE_EXT_ZIHINTPAUSE

// TODO: set unaligned-scalar-mem if RISCV_HWPROBE_KEY_MISALIGNED_PERF returns
// RISCV_HWPROBE_MISALIGNED_FAST.
Features["zve32x"] = ExtMask & (1ULL << 37); // RISCV_HWPROBE_EXT_ZVE32X
Features["zve32f"] = ExtMask & (1ULL << 38); // RISCV_HWPROBE_EXT_ZVE32F
Features["zve64x"] = ExtMask & (1ULL << 39); // RISCV_HWPROBE_EXT_ZVE64X
Features["zve64f"] = ExtMask & (1ULL << 40); // RISCV_HWPROBE_EXT_ZVE64F
Features["zve64d"] = ExtMask & (1ULL << 41); // RISCV_HWPROBE_EXT_ZVE64D
Features["zimop"] = ExtMask & (1ULL << 42); // RISCV_HWPROBE_EXT_ZIMOP
Features["zca"] = ExtMask & (1ULL << 43); // RISCV_HWPROBE_EXT_ZCA
Features["zcb"] = ExtMask & (1ULL << 44); // RISCV_HWPROBE_EXT_ZCB
Features["zcd"] = ExtMask & (1ULL << 45); // RISCV_HWPROBE_EXT_ZCD
Features["zcf"] = ExtMask & (1ULL << 46); // RISCV_HWPROBE_EXT_ZCF
Features["zcmop"] = ExtMask & (1ULL << 47); // RISCV_HWPROBE_EXT_ZCMOP
Features["zawrs"] = ExtMask & (1ULL << 48); // RISCV_HWPROBE_EXT_ZAWRS

// Check whether the processor supports fast misaligned scalar memory access.
// NOTE: RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF is only available on
// Linux 6.11 or later. If it is not recognized, the key field will be cleared
// to -1.
if (Query[2].Key != -1 &&
Query[2].Value == /*RISCV_HWPROBE_MISALIGNED_SCALAR_FAST=*/3)
Features["unaligned-scalar-mem"] = true;

return Features;
}
Expand Down

0 comments on commit bf895c7

Please sign in to comment.