Skip to content

Commit 7a47497

Browse files
Merge patch series "RISC-V: hwprobe: Introduce which-cpus"
Andrew Jones <[email protected]> says: This series introduces a flag for the hwprobe syscall which effectively reverses its behavior from getting the values of keys for a set of cpus to getting the cpus for a set of key-value pairs. * b4-shazam-merge: RISC-V: selftests: Add which-cpus hwprobe test RISC-V: hwprobe: Introduce which-cpus flag RISC-V: Move the hwprobe syscall to its own file RISC-V: hwprobe: Clarify cpus size parameter Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
2 parents cbc9113 + ef7d6ab commit 7a47497

File tree

12 files changed

+693
-348
lines changed

12 files changed

+693
-348
lines changed

Documentation/arch/riscv/hwprobe.rst

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,34 @@ is defined in <asm/hwprobe.h>::
1212
};
1313

1414
long sys_riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count,
15-
size_t cpu_count, cpu_set_t *cpus,
15+
size_t cpusetsize, cpu_set_t *cpus,
1616
unsigned int flags);
1717

1818
The arguments are split into three groups: an array of key-value pairs, a CPU
1919
set, and some flags. The key-value pairs are supplied with a count. Userspace
2020
must prepopulate the key field for each element, and the kernel will fill in the
2121
value if the key is recognized. If a key is unknown to the kernel, its key field
2222
will be cleared to -1, and its value set to 0. The CPU set is defined by
23-
CPU_SET(3). For value-like keys (eg. vendor/arch/impl), the returned value will
24-
be only be valid if all CPUs in the given set have the same value. Otherwise -1
25-
will be returned. For boolean-like keys, the value returned will be a logical
26-
AND of the values for the specified CPUs. Usermode can supply NULL for cpus and
27-
0 for cpu_count as a shortcut for all online CPUs. There are currently no flags,
28-
this value must be zero for future compatibility.
23+
CPU_SET(3) with size ``cpusetsize`` bytes. For value-like keys (eg. vendor,
24+
arch, impl), the returned value will only be valid if all CPUs in the given set
25+
have the same value. Otherwise -1 will be returned. For boolean-like keys, the
26+
value returned will be a logical AND of the values for the specified CPUs.
27+
Usermode can supply NULL for ``cpus`` and 0 for ``cpusetsize`` as a shortcut for
28+
all online CPUs. The currently supported flags are:
29+
30+
* :c:macro:`RISCV_HWPROBE_WHICH_CPUS`: This flag basically reverses the behavior
31+
of sys_riscv_hwprobe(). Instead of populating the values of keys for a given
32+
set of CPUs, the values of each key are given and the set of CPUs is reduced
33+
by sys_riscv_hwprobe() to only those which match each of the key-value pairs.
34+
How matching is done depends on the key type. For value-like keys, matching
35+
means to be the exact same as the value. For boolean-like keys, matching
36+
means the result of a logical AND of the pair's value with the CPU's value is
37+
exactly the same as the pair's value. Additionally, when ``cpus`` is an empty
38+
set, then it is initialized to all online CPUs which fit within it, i.e. the
39+
CPU set returned is the reduction of all the online CPUs which can be
40+
represented with a CPU set of size ``cpusetsize``.
41+
42+
All other flags are reserved for future compatibility and must be zero.
2943

3044
On success 0 is returned, on failure a negative error code is returned.
3145

arch/riscv/include/asm/hwprobe.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,28 @@ static inline bool riscv_hwprobe_key_is_valid(__s64 key)
1515
return key >= 0 && key <= RISCV_HWPROBE_MAX_KEY;
1616
}
1717

18+
static inline bool hwprobe_key_is_bitmask(__s64 key)
19+
{
20+
switch (key) {
21+
case RISCV_HWPROBE_KEY_BASE_BEHAVIOR:
22+
case RISCV_HWPROBE_KEY_IMA_EXT_0:
23+
case RISCV_HWPROBE_KEY_CPUPERF_0:
24+
return true;
25+
}
26+
27+
return false;
28+
}
29+
30+
static inline bool riscv_hwprobe_pair_cmp(struct riscv_hwprobe *pair,
31+
struct riscv_hwprobe *other_pair)
32+
{
33+
if (pair->key != other_pair->key)
34+
return false;
35+
36+
if (hwprobe_key_is_bitmask(pair->key))
37+
return (pair->value & other_pair->value) == other_pair->value;
38+
39+
return pair->value == other_pair->value;
40+
}
41+
1842
#endif

arch/riscv/include/uapi/asm/hwprobe.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,7 @@ struct riscv_hwprobe {
6666
#define RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE 6
6767
/* Increase RISCV_HWPROBE_MAX_KEY when adding items. */
6868

69+
/* Flags */
70+
#define RISCV_HWPROBE_WHICH_CPUS (1 << 0)
71+
6972
#endif

arch/riscv/kernel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ obj-y += setup.o
5050
obj-y += signal.o
5151
obj-y += syscall_table.o
5252
obj-y += sys_riscv.o
53+
obj-y += sys_hwprobe.o
5354
obj-y += time.o
5455
obj-y += traps.o
5556
obj-y += riscv_ksyms.o

0 commit comments

Comments
 (0)