Skip to contentSkip to conversation

RISC-V Hardware Probing User Interface

PATCH In review Palmer Dabbelt 5 participants 15 messages Oct 13, 2022 – Jan 10, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover RISC-V Hardware Probing User Interface

These are very much up for discussion, as it's a pretty big new user interface and it's quite a bit different from how we've historically done things: this isn't just providing an ISA string to userspace, this has its own format for providing information to userspace.

There's been a bunch of off-list discussions about this, including at Plumbers. The original plan was to do something involving providing an ISA string to userspace, but ISA strings just aren't sufficient for a stable ABI any more: in order to parse an ISA string users need the version of the specifications that the string is written to, the version of each extension (sometimes at a finer granularity than the RISC-V releases/versions encode), and the expected use case for the ISA string (ie, is it a U-mode or M-mode string). That's a lot of complexity to try and keep ABI compatible and it's probably going to continue to grow, as even if there's no more complexity in the specifications we'll have to deal with the various ISA string parsing oddities that end up all over userspace.

Instead this patch set takes a very different approach and provides a se of key/value pairs that encode various bits about the system. The big advantage here is that we can clearly define what these mean so we can ensure ABI stability, but it also allows us to encode information that's unlikely to ever appear in an ISA string (see the misaligned access performance, for example). The resulting interface looks a lot like what arm64 and x86 do, and will hopefully fit well into something like ACPI in the future.

The actual user interface is a syscall. I'm not really sure that's the right way to go about this, but it makes for flexible prototying. Various other approaches have been talked about like making HWCAP2 a pointer, having a VDSO routine, or exposing this via sysfs. Those seem like generally reasonable approaches, but I've yet to figure out a way to get the general case working without a syscall as that's the only way I've come up with to deal with the heterogenous CPU case. Happy to hear if someone has a better idea, though, as I don't really want to add a syscall if we can avoid it.

I threw this together during the conferences so I would be surprised if it's not broken, but I figured it'd be best to just get something on the lists sooner rather that later. Happy to have someone go fix my code, but the new uABI is really going to be the tricky bit here. There's some test code included, but I haven't even booted a kernel with these patches so YMMV.

These are also up at kernel.org/palmer/linux/riscv-hwprobe-v1 in case that's easier for folks.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#1 lore raw

PATCH 1/5 RISC-V: Add a syscall for HW probing

We don't have enough space for these all in ELF_HWCAP{,2} and there's no system call that quite does this, so let's just provide an arch-specific one to probe for hardware capabilities. This currently just provides m{arch,imp,vendor}id, but with the key-value pairs we can pass more in the future.

---
I havn't run this yet.

---
 Documentation/riscv/hwprobe.rst       |  33 +++++++
 Documentation/riscv/index.rst         |   1 +
 arch/riscv/include/asm/cpufeature.h   |  21 +++++
 arch/riscv/include/asm/hwprobe.h      |  13 +++
 arch/riscv/include/asm/syscall.h      |   3 +
 arch/riscv/include/uapi/asm/hwprobe.h |  24 ++++++
 arch/riscv/include/uapi/asm/unistd.h  |   8 ++
 arch/riscv/kernel/cpu.c               |  45 +++++++++-
 arch/riscv/kernel/sys_riscv.c         | 118 +++++++++++++++++++++++++-
 9 files changed, 264 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/riscv/hwprobe.rst
 create mode 100644 arch/riscv/include/asm/cpufeature.h
 create mode 100644 arch/riscv/include/asm/hwprobe.h
 create mode 100644 arch/riscv/include/uapi/asm/hwprobe.h
Documentation/riscv/hwprobe.rst new file +33 -0
new file mode 100644
index 000000000000..be9ebe4af3dc
@@ -0,0 +1,33 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+RISC-V Hardware Probing Interface
+---------------------------------
+
+The RISC-V hardware probing interface is based around a single syscall, which
+is defined in <asm/hwprobe.h>::
+
+    struct riscv_hwprobe {
+        __u64 key, value;
+    };
+
+    long sys_riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count,
+                           size_t base_key, size_t cpu_count, cpu_set_t *cpus,
+                           unsigned long flags);
+
+The arguments are split into three groups: an array of key-value pairs, a CPU
+set, and some flags.  The key-value pairs are supplied with a count and an
+base, which is the first key that will be probed for.  The CPU set is defined
+by CPU_SET(3), the indicated features will be supported on all CPUs in the set.
+There are currently no flags, this value must be zero for future compatibility.
+
+On success the number of filled out pairs is returned, on failure a negative
+error code is returned.
+
+The following keys are defined:
+
+* :RISCV_HWPROBE_KEY_MVENDORID:: Contains the value of :mvendorid:, as per the
+  ISA specifications.
+* :RISCV_HWPROBE_KEY_MARCHID:: Contains the value of :marchid:, as per the ISA
+  specifications.
+* :RISCV_HWPROBE_KEY_MIMPLID:: Contains the value of :mimplid:, as per the ISA
+  specifications.
Documentation/riscv/index.rst +1 -0
index e23b876ad6eb..1c89bca55aec 100644
@@ -7,6 +7,7 @@ RISC-V architecture
 
     boot-image-header
     vm-layout
+    hwprobe
     patch-acceptance
 
     features
arch/riscv/include/asm/cpufeature.h new file +21 -0
new file mode 100644
index 000000000000..cbda062de9bd
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright 2022 Rivos, Inc
+ */
+
+#ifndef _ASM_CPUFEATURE_H
+#define _ASM_CPUFEATURE_H
+
+/*
+ * These are probed via a device_initcall(), via either the SBI or directly
+ * from the cooresponding CSRs.
+ */
+struct riscv_cpuinfo {
+        unsigned long mvendorid;
+        unsigned long marchid;
+        unsigned long mimpid;
+};
+
+DECLARE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo);
+
+#endif
arch/riscv/include/asm/hwprobe.h new file +13 -0
new file mode 100644
index 000000000000..08d1c3bdd78a
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Copyright 2022 Rivos, Inc
+ */
+
+#ifndef _ASM_HWPROBE_H
+#define _ASM_HWPROBE_H
+
+#include <uapi/asm/hwprobe.h>
+
+#define RISCV_HWPROBE_MAX_KEY 2
+
+#endif
arch/riscv/include/asm/syscall.h +3 -0
index 384a63b86420..78a6302ef711 100644
@@ -75,4 +75,7 @@ static inline int syscall_get_arch(struct task_struct *task)
 }
 
 asmlinkage long sys_riscv_flush_icache(uintptr_t, uintptr_t, uintptr_t);
+
+asmlinkage long sys_riscv_hwprobe(uintptr_t, uintptr_t, uintptr_t, uintptr_t,
+				  uintptr_t, uintptr_t);
 #endif	/* _ASM_RISCV_SYSCALL_H */
arch/riscv/include/uapi/asm/hwprobe.h new file +24 -0
new file mode 100644
index 000000000000..88ef9e153637
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Copyright 2022 Rivos, Inc
+ */
+
+#ifndef _UAPI_ASM_HWPROBE_H
+#define _UAPI_ASM_HWPROBE_H
+
+#include <linux/types.h>
+
+/*
+ * Interface for probing hardware capabilities from userspace, see
+ * Documentation/riscv/hwprobe.rst for more information.
+ */
+struct riscv_hwprobe {
+    __u64 key, val;
+};
+
+#define RISCV_HWPROBE_KEY_MVENDORID	0
+#define RISCV_HWPROBE_KEY_MARCHID	1
+#define RISCV_HWPROBE_KEY_MIMPID	2
+/* Increase RISCV_HWPROBE_MAX_KEY when adding items. */
+
+#endif
arch/riscv/include/uapi/asm/unistd.h +8 -0
index 73d7cdd2ec49..37d47302322a 100644
@@ -43,3 +43,11 @@
 #define __NR_riscv_flush_icache (__NR_arch_specific_syscall + 15)
 #endif
 __SYSCALL(__NR_riscv_flush_icache, sys_riscv_flush_icache)
+
+/*
+ * Allows userspace to probe
+ */
+#ifndef __NR_riscv_hwprobe
+#define __NR_riscv_hwprobe (__NR_arch_specific_syscall + 14)
+#endif
+__SYSCALL(__NR_riscv_hwprobe, sys_riscv_hwprobe)
arch/riscv/kernel/cpu.c +44 -1

63 lines not on this page · raw message

arch/riscv/kernel/sys_riscv.c +117 -1

128 lines not on this page · raw message

Signature · 7 lines
2.38.0


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#3 lore raw

PATCH 2/5 RISC-V: hwprobe: Add support for RISCV_HWPROBE_BASE_BEHAVIOR_IMA

In reply to Palmer Dabbelt

We have an implicit set of base behaviors that userspace depends on, which are mostly defined in various ISA specifications.

---
 Documentation/riscv/hwprobe.rst       | 16 +++++++++++
 arch/riscv/include/asm/hwprobe.h      |  2 +-
 arch/riscv/include/uapi/asm/hwprobe.h |  7 +++++
 arch/riscv/kernel/sys_riscv.c         | 38 +++++++++++++++++++++++++++
 4 files changed, 62 insertions(+), 1 deletion(-)
Documentation/riscv/hwprobe.rst +16 -0
index be9ebe4af3dc..b182fcf4cd30 100644
@@ -31,3 +31,19 @@ The following keys are defined:
   specifications.
 * :RISCV_HWPROBE_KEY_MIMPLID:: Contains the value of :mimplid:, as per the ISA
   specifications.
+* :RISCV_HWPROBE_KEY_BASE_BEHAVIOR:: A bitmask containing the base user-visible
+  behavior that this kernel supports.  The following base user ABIs are defined:
+    * :RISCV_HWPROBE_BASE_BEHAVIOR_IMA:: Support for rv32ima or rv64ima, as
+      defined by version 2.2 of the user ISA and version 1.10 of the privileged
+      ISA, with the following known exceptions (more exceptions may be added,
+      but only if it can be demonstrated that the user ABI is not broken):
+        * The :fence.i: instruction cannot be directly executed by userspace
+          programs (it may still be executed in userspace via a
+          kernel-controlled mechanism such as the vDSO).
+* :RISCV_HWPROBE_KEY_IMA_EXT_0:: A bitmask containing the extensions that are
+  compatible with the :RISCV_HWPROBE_BASE_BEHAVIOR_IMA: base system behavior.
+    * :RISCV_HWPROBE_IMA_FD:: The F and D extensions are supported, as defined
+      by commit cd20cee ("FMIN/FMAX now implement minimumNumber/maximumNumber,
+      not minNum/maxNum") of the RISC-V ISA manual.
+    * :RISCV_HWPROBE_IMA_C:: The C extension is supported, as defined by
+      version 2.2 of the RISC-V ISA manual.
arch/riscv/include/asm/hwprobe.h +1 -1
index 08d1c3bdd78a..7e52f1e1fe10 100644
@@ -8,6 +8,6 @@
 
 #include <uapi/asm/hwprobe.h>
 
-#define RISCV_HWPROBE_MAX_KEY 2
+#define RISCV_HWPROBE_MAX_KEY 4
 
 #endif
arch/riscv/include/uapi/asm/hwprobe.h +7 -0
index 88ef9e153637..07309376c6dc 100644
@@ -19,6 +19,13 @@ struct riscv_hwprobe {
 #define RISCV_HWPROBE_KEY_MVENDORID	0
 #define RISCV_HWPROBE_KEY_MARCHID	1
 #define RISCV_HWPROBE_KEY_MIMPID	2
+#define RISCV_HWPROBE_KEY_BASE_BEHAVIOR	3
+#define		RISCV_HWPROBE_BASE_BEHAVIOR_IMA	(1 << 0)
+#define RISCV_HWPROBE_KEY_IMA_EXT_0	4
+#define		RISCV_HWPROBE_IMA_FD		(1 << 0)
+#define		RISCV_HWPROBE_IMA_C		(1 << 1)
 /* Increase RISCV_HWPROBE_MAX_KEY when adding items. */
 
+
+
 #endif
arch/riscv/kernel/sys_riscv.c +38 -0
index 2b6cb82c3491..337e3f2a17c8 100644
@@ -9,6 +9,7 @@
 #include <asm/cacheflush.h>
 #include <asm/cpufeature.h>
 #include <asm/hwprobe.h>
+#include <asm/switch_to.h>
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
 #include <asm-generic/mman-common.h>
@@ -76,6 +77,11 @@ SYSCALL_DEFINE3(riscv_flush_icache, uintptr_t, start, uintptr_t, end,
 	return 0;
 }
 
+/*
+ * The hwprobe interface, for allowing userspace to probe to see which features
+ * are supported by the hardware.  See Documentation/riscv/hwprobe.rst for more
+ * details.
+ */
 static long set_hwprobe(struct riscv_hwprobe __user *pair, u64 key, u64 val)
 {
 	long ret;
@@ -158,6 +164,15 @@ long do_riscv_hwprobe(struct riscv_hwprobe __user *pairs, long pair_count,
 	if (!ret)
 		return -EFAULT;
 
+
+	/*
+	 * Userspace must provide at least one online CPU, without that there's
+	 * no way to define what is supported.
+	 */
+	cpumask_and(&cpus, &cpus, cpu_online_mask);
+	if (cpumask_empty(&cpus))
+		return -EINVAL;
+
 	out = 0;
 	k = key_offset;
 	while (out < pair_count && k < RISCV_HWPROBE_MAX_KEY) {
@@ -169,6 +184,29 @@ long do_riscv_hwprobe(struct riscv_hwprobe __user *pairs, long pair_count,
 		case RISCV_HWPROBE_KEY_MIMPID:
 			ret = hwprobe_mid(pairs + out, k, &cpus);
 			break;
+
+		/*
+		 * The kernel already assumes that the base single-letter ISA
+		 * extensions are supported on all harts, and only supports the
+		 * IMA base, so just cheat a bit here and tell that to
+		 * userspace.
+		 */
+		case RISCV_HWPROBE_KEY_BASE_BEHAVIOR:
+			ret = set_hwprobe(pairs + out, k,
+					  RISCV_HWPROBE_BASE_BEHAVIOR_IMA);
+			break;
+
+		case RISCV_HWPROBE_KEY_IMA_EXT_0:
+			{
+				u64 val = 0;
+
+				if (has_fpu())
+					val |= RISCV_HWPROBE_IMA_FD;
+				if (elf_hwcap & RISCV_ISA_EXT_c)
+					val |= RISCV_HWPROBE_IMA_C;
+				ret = set_hwprobe(pairs + out, k, val);
+			}
+			break;
 		}
 
 		if (ret < 0)
Signature · 7 lines
2.38.0


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#4 lore raw

PATCH 3/5 dt-bindings: Add RISC-V misaligned access performance

In reply to Palmer Dabbelt

This key allows device trees to specify the performance of misaligned accesses to main memory regions from each CPU in the system.

---
 Documentation/devicetree/bindings/riscv/cpus.yaml | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
Documentation/devicetree/bindings/riscv/cpus.yaml +15 -0
index 873dd12f6e89..832ae9101d05 100644
@@ -83,6 +83,21 @@ properties:
       - rv64imac
       - rv64imafdc
 
+  riscv,misaligned-access-performance:
+    description:
+      Identifies the performance of misaligned memory accesses to main memory
+      regions.  There are three flavors of unaligned access performance: "emulated"
+      means that misaligned accesses are emulated via software and thus
+      extremely slow, "slow" means that misaligned accesses are supported by
+      hardware but still slower that aligned accesses sequences, and "fast"
+      means that misaligned accesses are as fast or faster than the
+      cooresponding aligned accesses sequences.
+    $ref: "/schemas/types.yaml#/definitions/string"
+    enum:
+      - emulated
+      - slow
+      - fast
+
   # RISC-V requires 'timebase-frequency' in /cpus, so disallow it here
   timebase-frequency: false
 
Signature · 7 lines
2.38.0


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#5 lore raw

PATCH 4/5 RISC-V: hwprobe: Support probing of misaligned accesss performance

In reply to Palmer Dabbelt

This allows userspace to select various routines to use based on the performance of misaligned access on the target hardware.

---
 Documentation/riscv/hwprobe.rst       | 13 +++++++++++++
 arch/riscv/include/asm/cpufeature.h   |  2 ++
 arch/riscv/include/asm/hwprobe.h      |  2 +-
 arch/riscv/include/asm/smp.h          |  7 +++++++
 arch/riscv/include/uapi/asm/hwprobe.h |  7 +++++--
 arch/riscv/kernel/cpufeature.c        | 24 ++++++++++++++++++++++--
 arch/riscv/kernel/sys_riscv.c         | 22 ++++++++++++++++++++++
 7 files changed, 72 insertions(+), 5 deletions(-)
Documentation/riscv/hwprobe.rst +13 -0
index b182fcf4cd30..f8aa9137d8aa 100644
@@ -47,3 +47,16 @@ The following keys are defined:
       not minNum/maxNum") of the RISC-V ISA manual.
     * :RISCV_HWPROBE_IMA_C:: The C extension is supported, as defined by
       version 2.2 of the RISC-V ISA manual.
+* :RISCV_HWPROBE_KEY_PERF_0:: A bitmask that contains performance information
+  about the selected set of processors.
+    * :RISCV_HWPROBE_MISALIGNED_UNKNOWN:: The performance of misaligned
+      accesses is unknown.
+    * :RISCV_HWPROBE_MISALIGNED_EMULATED:: Misaligned accesses are emulated via
+      software, either in or below the kernel.  These accesses are always
+      extremely slow.
+    * :RISCV_HWPROBE_MISALIGNED_SLOW:: Misaligned accesses are supported in
+      hardware, but are slower than the cooresponding aligned accesses
+      sequences.
+    * :RISCV_HWPROBE_MISALIGNED_FAST:: Misaligned accesses are supported in
+      hardware and are faster than the cooresponding aligned accesses
+      sequences.
arch/riscv/include/asm/cpufeature.h +2 -0
index cbda062de9bd..54bdcf9a5049 100644
@@ -18,4 +18,6 @@ struct riscv_cpuinfo {
 
 DECLARE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo);
 
+DECLARE_PER_CPU(long, misaligned_access_speed);
+
 #endif
arch/riscv/include/asm/hwprobe.h +1 -1
index 7e52f1e1fe10..4e45e33015bc 100644
@@ -8,6 +8,6 @@
 
 #include <uapi/asm/hwprobe.h>
 
-#define RISCV_HWPROBE_MAX_KEY 4
+#define RISCV_HWPROBE_MAX_KEY 5
 
 #endif
arch/riscv/include/asm/smp.h +7 -0
index d3443be7eedc..5d98836cc446 100644
@@ -26,6 +26,13 @@ struct riscv_ipi_ops {
  */
 extern unsigned long __cpuid_to_hartid_map[NR_CPUS];
 #define cpuid_to_hartid_map(cpu)    __cpuid_to_hartid_map[cpu]
+static inline long hartid_to_cpuid_map(unsigned long hartid) {
+	long i;
+	for (i = 0; i < NR_CPUS; ++i)
+		if (cpuid_to_hartid_map(i) == hartid)
+			return i;
+	return -1;
+}
 
 /* print IPI stats */
 void show_ipi_stats(struct seq_file *p, int prec);
arch/riscv/include/uapi/asm/hwprobe.h +5 -2
index 07309376c6dc..e36b72f4e1af 100644
@@ -24,8 +24,11 @@ struct riscv_hwprobe {
 #define RISCV_HWPROBE_KEY_IMA_EXT_0	4
 #define		RISCV_HWPROBE_IMA_FD		(1 << 0)
 #define		RISCV_HWPROBE_IMA_C		(1 << 1)
+#define RISCV_HWPROBE_KEY_CPUPERF_0	5
+#define		RISCV_HWPROBE_MISALIGNED_UNKNOWN	(0 << 0)
+#define		RISCV_HWPROBE_MISALIGNED_EMULATED	(1 << 0)
+#define		RISCV_HWPROBE_MISALIGNED_SLOW		(2 << 0)
+#define		RISCV_HWPROBE_MISALIGNED_FAST		(3 << 0)
 /* Increase RISCV_HWPROBE_MAX_KEY when adding items. */
 
-
-
 #endif
arch/riscv/kernel/cpufeature.c +22 -2
index 553d755483ed..1599e40cd170 100644
@@ -15,6 +15,7 @@
 #include <asm/cacheflush.h>
 #include <asm/errata_list.h>
 #include <asm/hwcap.h>
+#include <asm/hwprobe.h>
 #include <asm/patch.h>
 #include <asm/pgtable.h>
 #include <asm/processor.h>
@@ -31,6 +32,9 @@ static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;
 __ro_after_init DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX);
 EXPORT_SYMBOL(riscv_isa_ext_keys);
 
+/* Performance information */
+DEFINE_PER_CPU(long, misaligned_access_speed);
+
 /**
  * riscv_isa_extension_base() - Get base extension word
  *
@@ -71,11 +75,11 @@ EXPORT_SYMBOL_GPL(__riscv_isa_extension_available);
 void __init riscv_fill_hwcap(void)
 {
 	struct device_node *node;
-	const char *isa;
+	const char *isa, *misaligned;
 	char print_str[NUM_ALPHA_EXTS + 1];
 	int i, j, rc;
 	static unsigned long isa2hwcap[256] = {0};
-	unsigned long hartid;
+	unsigned long hartid, cpu;
 
 	isa2hwcap['i'] = isa2hwcap['I'] = COMPAT_HWCAP_ISA_I;
 	isa2hwcap['m'] = isa2hwcap['M'] = COMPAT_HWCAP_ISA_M;
@@ -222,6 +226,22 @@ void __init riscv_fill_hwcap(void)
 			bitmap_copy(riscv_isa, this_isa, RISCV_ISA_EXT_MAX);
 		else
 			bitmap_and(riscv_isa, riscv_isa, this_isa, RISCV_ISA_EXT_MAX);
+
+		/*
+		 * Check for the performance of misaligned accesses.
+		 */
+		cpu = hartid_to_cpuid_map(hartid);
+		if (cpu < 0)
+			continue;
+
+		if (of_property_read_string(node, "riscv,misaligned-access-performance", &misaligned)) {
+			if (strcmp(misaligned, "emulated") == 0)
+				per_cpu(misaligned_access_speed, cpu) = RISCV_HWPROBE_MISALIGNED_EMULATED;
+			if (strcmp(misaligned, "slow") == 0)
+				per_cpu(misaligned_access_speed, cpu) = RISCV_HWPROBE_MISALIGNED_SLOW;
+			if (strcmp(misaligned, "fast") == 0)
+				per_cpu(misaligned_access_speed, cpu) = RISCV_HWPROBE_MISALIGNED_FAST;
+		}
 	}
 
 	/* We don't support systems with F but without D, so mask those out
arch/riscv/kernel/sys_riscv.c +22 -0
index 337e3f2a17c8..fc9e8cd1589b 100644
@@ -139,6 +139,24 @@ static long hwprobe_mid(struct riscv_hwprobe __user *pair, size_t key,
 	return set_hwprobe(pair, key, id);
 }
 
+static long hwprobe_misaligned(cpumask_t *cpus)
+{
+	long cpu, perf = -1;
+
+	for_each_cpu(cpu, cpus) {
+		long this_perf = per_cpu(misaligned_access_speed, cpu);
+		if (perf == -1)
+			perf = this_perf;
+
+		if (perf != this_perf)
+			perf = RISCV_HWPROBE_MISALIGNED_UNKNOWN;
+	}
+
+	if (perf == -1)
+		return RISCV_HWPROBE_MISALIGNED_UNKNOWN;
+	return perf;
+}
+
 static
 long do_riscv_hwprobe(struct riscv_hwprobe __user *pairs, long pair_count,
 		      long key_offset, long cpu_count,
@@ -207,6 +225,10 @@ long do_riscv_hwprobe(struct riscv_hwprobe __user *pairs, long pair_count,
 				ret = set_hwprobe(pairs + out, k, val);
 			}
 			break;
+
+		case RISCV_HWPROBE_KEY_CPUPERF_0:
+			set_hwprobe(pairs + out, k, hwprobe_misaligned(&cpus));
+			break;
 		}
 
 		if (ret < 0)
Signature · 7 lines
2.38.0


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#6 lore raw

Re: [PATCH v1 4/5] RISC-V: hwprobe: Support probing of misaligned accesss performance

Am Donnerstag, 13. Oktober 2022, 18:35:50 CET schrieb Palmer Dabbelt:

Quoted 4 lines

This allows userspace to select various routines to use based on the performance of misaligned access on the target hardware.

[...]

arch/riscv/include/asm/cpufeature.h struct riscv_cpuinfo { · line 21

Quoted 9 lines
arch/riscv/include/asm/cpufeature.h +1 -0
index cbda062de9bd..54bdcf9a5049 100644
@@ -18,4 +18,6 @@ struct riscv_cpuinfo {
 
 DECLARE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo);
 
+DECLARE_PER_CPU(long, misaligned_access_speed);

just my 2ct ... wouldn't it make sense to have struct riscv_cpuinfo as the central instance for all cpu-related stuff, so misaligned_access_speed could also be part of it?

Quoted 7 lines
arch/riscv/kernel/cpufeature.c +0 -0
index 553d755483ed..1599e40cd170 100644
@@ -222,6 +226,22 @@ void __init riscv_fill_hwcap(void)
 			bitmap_copy(riscv_isa, this_isa, RISCV_ISA_EXT_MAX);
 		else

arch/riscv/kernel/cpufeature.c void __init riscv_fill_hwcap(void) · line 237

Quoted 10 lines
arch/riscv/kernel/cpufeature.c +9 -0
 			bitmap_and(riscv_isa, riscv_isa, this_isa, RISCV_ISA_EXT_MAX);
+
+		/*
+		 * Check for the performance of misaligned accesses.
+		 */
+		cpu = hartid_to_cpuid_map(hartid);
+		if (cpu < 0)
+			continue;
+
+		if (of_property_read_string(node, "riscv,misaligned-access-performance", &misaligned)) {

I think this wants a "!" in front :-) .

of_property_read_string() returns 0 on success, so running this results in a nullptr right now.

arch/riscv/kernel/cpufeature.c void __init riscv_fill_hwcap(void) · line 247

Quoted 10 lines
arch/riscv/kernel/cpufeature.c +7 -0
+			if (strcmp(misaligned, "emulated") == 0)
+				per_cpu(misaligned_access_speed, cpu) = RISCV_HWPROBE_MISALIGNED_EMULATED;
+			if (strcmp(misaligned, "slow") == 0)
+				per_cpu(misaligned_access_speed, cpu) = RISCV_HWPROBE_MISALIGNED_SLOW;
+			if (strcmp(misaligned, "fast") == 0)
+				per_cpu(misaligned_access_speed, cpu) = RISCV_HWPROBE_MISALIGNED_FAST;
+		}
 	}
 
 	/* We don't support systems with F but without D, so mask those out

Heiko

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#7 lore raw

Re: [PATCH v1 4/5] RISC-V: hwprobe: Support probing of misaligned accesss performance

Quoted 14 lines · On Tue, 29 Nov 2022 13:09:49 PST (-0800), [email protected] wrote:

Am Donnerstag, 13. Oktober 2022, 18:35:50 CET schrieb Palmer Dabbelt:

Quoted 4 lines

This allows userspace to select various routines to use based on the performance of misaligned access on the target hardware.

[...]

Quoted 6 lines
arch/riscv/include/asm/cpufeature.h +0 -0
index cbda062de9bd..54bdcf9a5049 100644
@@ -18,4 +18,6 @@ struct riscv_cpuinfo {
 
Quoted 7 lines

arch/riscv/include/asm/cpufeature.h struct riscv_cpuinfo { · line 21

Quoted 3 lines
arch/riscv/include/asm/cpufeature.h +1 -0
 DECLARE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo);
 
+DECLARE_PER_CPU(long, misaligned_access_speed);

just my 2ct ... wouldn't it make sense to have struct riscv_cpuinfo as the central instance for all cpu-related stuff, so misaligned_access_speed could also be part of it?

I remember going through this one a few times and ending up here despite some cleaner-looking ways of doing it. That way does look cleaner, though, so I'll give it a shot and we'll see what happens...

Quoted 20 lines
Quoted 7 lines
arch/riscv/kernel/cpufeature.c +0 -0
index 553d755483ed..1599e40cd170 100644
@@ -222,6 +226,22 @@ void __init riscv_fill_hwcap(void)
 			bitmap_copy(riscv_isa, this_isa, RISCV_ISA_EXT_MAX);
 		else

arch/riscv/kernel/cpufeature.c void __init riscv_fill_hwcap(void) · line 237

Quoted 10 lines
arch/riscv/kernel/cpufeature.c +9 -0
 			bitmap_and(riscv_isa, riscv_isa, this_isa, RISCV_ISA_EXT_MAX);
+
+		/*
+		 * Check for the performance of misaligned accesses.
+		 */
+		cpu = hartid_to_cpuid_map(hartid);
+		if (cpu < 0)
+			continue;
+
+		if (of_property_read_string(node, "riscv,misaligned-access-performance", &misaligned)) {

I think this wants a "!" in front :-) .

Quoted 2 lines

of_property_read_string() returns 0 on success, so running this results in a nullptr right now.

Thanks. I'd not gotten around to actually running this so I bet it's broken in a bunch of ways. Did you try it out? I was really hoping to find some time to get at least the simple stuff in for this cycle, but too many things keep coming up.

Quoted 10 lines
Quoted 10 lines
arch/riscv/kernel/cpufeature.c +7 -0
+			if (strcmp(misaligned, "emulated") == 0)
+				per_cpu(misaligned_access_speed, cpu) = RISCV_HWPROBE_MISALIGNED_EMULATED;
+			if (strcmp(misaligned, "slow") == 0)
+				per_cpu(misaligned_access_speed, cpu) = RISCV_HWPROBE_MISALIGNED_SLOW;
+			if (strcmp(misaligned, "fast") == 0)
+				per_cpu(misaligned_access_speed, cpu) = RISCV_HWPROBE_MISALIGNED_FAST;
+		}
 	}
 
Quoted 4 lines

arch/riscv/kernel/cpufeature.c void __init riscv_fill_hwcap(void) · line 247

Quoted 1 line
arch/riscv/kernel/cpufeature.c +0 -0
 	/* We don't support systems with F but without D, so mask those out

Heiko

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#8 lore raw

Re: [PATCH v1 4/5] RISC-V: hwprobe: Support probing of misaligned accesss performance

Am Dienstag, 29. November 2022, 22:18:18 CET schrieb Palmer Dabbelt:

Quoted 47 lines · On Tue, 29 Nov 2022 13:09:49 PST (-0800), [email protected] wrote:
Quoted 14 lines

Am Donnerstag, 13. Oktober 2022, 18:35:50 CET schrieb Palmer Dabbelt:

Quoted 4 lines

This allows userspace to select various routines to use based on the performance of misaligned access on the target hardware.

[...]

Quoted 6 lines
arch/riscv/include/asm/cpufeature.h +0 -0
index cbda062de9bd..54bdcf9a5049 100644
@@ -18,4 +18,6 @@ struct riscv_cpuinfo {
 
Quoted 7 lines

arch/riscv/include/asm/cpufeature.h struct riscv_cpuinfo { · line 21

Quoted 3 lines
arch/riscv/include/asm/cpufeature.h +1 -0
 DECLARE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo);
 
+DECLARE_PER_CPU(long, misaligned_access_speed);

just my 2ct ... wouldn't it make sense to have struct riscv_cpuinfo as the central instance for all cpu-related stuff, so misaligned_access_speed could also be part of it?

I remember going through this one a few times and ending up here despite some cleaner-looking ways of doing it. That way does look cleaner, though, so I'll give it a shot and we'll see what happens...

Quoted 20 lines
Quoted 7 lines
arch/riscv/kernel/cpufeature.c +0 -0
index 553d755483ed..1599e40cd170 100644
@@ -222,6 +226,22 @@ void __init riscv_fill_hwcap(void)
 			bitmap_copy(riscv_isa, this_isa, RISCV_ISA_EXT_MAX);
 		else

arch/riscv/kernel/cpufeature.c void __init riscv_fill_hwcap(void) · line 237

Quoted 10 lines
arch/riscv/kernel/cpufeature.c +9 -0
 			bitmap_and(riscv_isa, riscv_isa, this_isa, RISCV_ISA_EXT_MAX);
+
+		/*
+		 * Check for the performance of misaligned accesses.
+		 */
+		cpu = hartid_to_cpuid_map(hartid);
+		if (cpu < 0)
+			continue;
+
+		if (of_property_read_string(node, "riscv,misaligned-access-performance", &misaligned)) {

I think this wants a "!" in front :-) .

Quoted 7 lines
Quoted 2 lines

of_property_read_string() returns 0 on success, so running this results in a nullptr right now.

Thanks. I'd not gotten around to actually running this so I bet it's broken in a bunch of ways. Did you try it out? I was really hoping to find some time to get at least the simple stuff in for this cycle, but too many things keep coming up.

I ran the code today, so bumped into the "!" issue. I'm not yet "using" it, but that will come in the next days.

And no worries about that time-thingy, your series already provides a nice pointer for the general direction to with things, so that is helpful in its own right.

I will simply report any brokeness I find when it happens ;-) .

Heiko

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#9 lore raw

Re: [PATCH v1 4/5] RISC-V: hwprobe: Support probing of misaligned accesss performance

Quoted 56 lines · On Tue, 29 Nov 2022 14:10:02 PST (-0800), [email protected] wrote:

Am Dienstag, 29. November 2022, 22:18:18 CET schrieb Palmer Dabbelt:

Quoted 47 lines · On Tue, 29 Nov 2022 13:09:49 PST (-0800), [email protected] wrote:
Quoted 14 lines

Am Donnerstag, 13. Oktober 2022, 18:35:50 CET schrieb Palmer Dabbelt:

Quoted 4 lines

This allows userspace to select various routines to use based on the performance of misaligned access on the target hardware.

[...]

Quoted 6 lines
arch/riscv/include/asm/cpufeature.h +0 -0
index cbda062de9bd..54bdcf9a5049 100644
@@ -18,4 +18,6 @@ struct riscv_cpuinfo {
 
Quoted 7 lines

arch/riscv/include/asm/cpufeature.h struct riscv_cpuinfo { · line 21

Quoted 3 lines
arch/riscv/include/asm/cpufeature.h +1 -0
 DECLARE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo);
 
+DECLARE_PER_CPU(long, misaligned_access_speed);

just my 2ct ... wouldn't it make sense to have struct riscv_cpuinfo as the central instance for all cpu-related stuff, so misaligned_access_speed could also be part of it?

I remember going through this one a few times and ending up here despite some cleaner-looking ways of doing it. That way does look cleaner, though, so I'll give it a shot and we'll see what happens...

Quoted 20 lines
Quoted 7 lines
arch/riscv/kernel/cpufeature.c +0 -0
index 553d755483ed..1599e40cd170 100644
@@ -222,6 +226,22 @@ void __init riscv_fill_hwcap(void)
 			bitmap_copy(riscv_isa, this_isa, RISCV_ISA_EXT_MAX);
 		else

arch/riscv/kernel/cpufeature.c void __init riscv_fill_hwcap(void) · line 237

Quoted 10 lines
arch/riscv/kernel/cpufeature.c +9 -0
 			bitmap_and(riscv_isa, riscv_isa, this_isa, RISCV_ISA_EXT_MAX);
+
+		/*
+		 * Check for the performance of misaligned accesses.
+		 */
+		cpu = hartid_to_cpuid_map(hartid);
+		if (cpu < 0)
+			continue;
+
+		if (of_property_read_string(node, "riscv,misaligned-access-performance", &misaligned)) {

I think this wants a "!" in front :-) .

Quoted 7 lines
Quoted 2 lines

of_property_read_string() returns 0 on success, so running this results in a nullptr right now.

Thanks. I'd not gotten around to actually running this so I bet it's broken in a bunch of ways. Did you try it out? I was really hoping to find some time to get at least the simple stuff in for this cycle, but too many things keep coming up.

Quoted 6 lines

I ran the code today, so bumped into the "!" issue. I'm not yet "using" it, but that will come in the next days.

And no worries about that time-thingy, your series already provides a nice pointer for the general direction to with things, so that is helpful in its own right.

I'm still worried about the release, as it's the last one before the glibc release and we'll need hooks there too.

Quoted 1 line

I will simply report any brokeness I find when it happens ;-) .

Awesome, thanks!

Quoted 3 lines

Heiko

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#10 lore raw

PATCH 5/5 selftests: Test the new RISC-V hwprobe interface

In reply to Palmer Dabbelt

This adds a test for the recently added RISC-V interface for probing hardware capabilities. It happens to be the first selftest we have for RISC-V, so I've added some infrastructure for those as well. The build stuff looks pretty straight-forward, but there's also a tiny C library to avoid coupling this to any userspace implementation.

---
I'm not actually sure this tiny C library is a good idea, but the toolchain I have locally doesn't have a functioning C library.

---
 tools/testing/selftests/Makefile              |   1 +
 tools/testing/selftests/riscv/Makefile        |  58 ++++++++++++++++++
 .../testing/selftests/riscv/hwprobe/Makefile  |  10 +++
 tools/testing/selftests/riscv/hwprobe/hwprobe | Bin 0 -> 75072 bytes
 .../testing/selftests/riscv/hwprobe/hwprobe.c |  49 +++++++++++++++
 .../selftests/riscv/hwprobe/sys_hwprobe.S     |  12 ++++
 tools/testing/selftests/riscv/libc.S          |  46 ++++++++++++++
 7 files changed, 176 insertions(+)
 create mode 100644 tools/testing/selftests/riscv/Makefile
 create mode 100644 tools/testing/selftests/riscv/hwprobe/Makefile
 create mode 100755 tools/testing/selftests/riscv/hwprobe/hwprobe
 create mode 100644 tools/testing/selftests/riscv/hwprobe/hwprobe.c
 create mode 100644 tools/testing/selftests/riscv/hwprobe/sys_hwprobe.S
 create mode 100644 tools/testing/selftests/riscv/libc.S
tools/testing/selftests/Makefile +1 -0
index 10b34bb03bc1..9ff28a629f5b 100644
@@ -56,6 +56,7 @@ TARGETS += pstore
 TARGETS += ptrace
 TARGETS += openat2
 TARGETS += resctrl
+TARGETS += riscv
 TARGETS += rlimits
 TARGETS += rseq
 TARGETS += rtc
tools/testing/selftests/riscv/Makefile new file +58 -0

58 lines not on this page · raw message

tools/testing/selftests/riscv/hwprobe/Makefile new file +10 -0
new file mode 100644
index 000000000000..614501584803
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2021 ARM Limited
+# Originally tools/testing/arm64/abi/Makefile
+
+TEST_GEN_PROGS := hwprobe
+
+include ../../lib.mk
+
+$(OUTPUT)/hwprobe: hwprobe.c ../libc.S sys_hwprobe.S
+	$(CC) -o$@ $(CFLAGS) $(LDFLAGS) -nostdlib $^
tools/testing/selftests/riscv/hwprobe/hwprobe new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..6c37d3be12a9880d36a9d8fe9339be9e64c15efc
GIT binary patch
tools/testing/selftests/riscv/hwprobe/hwprobe.c new file +49 -0

49 lines not on this page · raw message

tools/testing/selftests/riscv/hwprobe/sys_hwprobe.S new file +12 -0
new file mode 100644
index 000000000000..42f93dad3a67
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2022 Rivos, Inc
+
+.text
+.global riscv_hwprobe
+riscv_hwprobe:
+	# Put __NR_riscv_hwprobe in the syscall number register, then just shim
+	# back the kernel's return.  This doesn't do any sort of errno
+	# handling, the caller can deal with it.
+	li a7, 258
+	ecall
+	ret
tools/testing/selftests/riscv/libc.S new file +46 -0

46 lines not on this page · raw message

Signature · 7 lines
2.38.0


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#11 lore raw
In reply to Palmer Dabbelt
Quoted 27 lines · Palmer Dabbelt

These are very much up for discussion, as it's a pretty big new user interface and it's quite a bit different from how we've historically done things: this isn't just providing an ISA string to userspace, this has its own format for providing information to userspace.

There's been a bunch of off-list discussions about this, including at Plumbers. The original plan was to do something involving providing an ISA string to userspace, but ISA strings just aren't sufficient for a stable ABI any more: in order to parse an ISA string users need the version of the specifications that the string is written to, the version of each extension (sometimes at a finer granularity than the RISC-V releases/versions encode), and the expected use case for the ISA string (ie, is it a U-mode or M-mode string). That's a lot of complexity to try and keep ABI compatible and it's probably going to continue to grow, as even if there's no more complexity in the specifications we'll have to deal with the various ISA string parsing oddities that end up all over userspace.

Instead this patch set takes a very different approach and provides a se of key/value pairs that encode various bits about the system. The big advantage here is that we can clearly define what these mean so we can ensure ABI stability, but it also allows us to encode information that's unlikely to ever appear in an ISA string (see the misaligned access performance, for example). The resulting interface looks a lot like what arm64 and x86 do, and will hopefully fit well into something like ACPI in the future.

Quoted 4 lines

The actual user interface is a syscall. I'm not really sure that's the right way to go about this, but it makes for flexible prototying. Various other approaches have been talked about like making HWCAP2 a pointer, having a VDSO routine, or exposing this via sysfs.

Hi Palmer,

To throw my two cents into the penny jar, I'd vote for sysfs. It handles the heterogeneous CPU case since cpu feature nodes can be hung off each cpu node. It also avoids yet another encoding. If we enumerate extensions and their properties then we need to maintain that enumeration in both the kernel space and userspace. If, OTOH, we use sysfs node names for the encoding, then, when we match the spec naming exactly, e.g.

.../features/zicbom
.../features/zihintpause
.../features/sscofpmf

userspace can look for features by name. Userspace libraries can even lead the kernel in development, since the encoding (the spec name) is already agreed.

Properties of extensions are just sub-nodes, some with standard names, like

.../features/zicbom/major
.../features/zicbom/minor

and others, which are cpu feature specific, like

.../features/zicbom/block_size

I used 'features' in the above examples for the node name, rather than 'isa', since not all features map to isa extensions, but it should be possible to fit non-isa features into the same framework.

Thanks,
drew

Quoted 19 lines

Those seem
like generally reasonable approaches, but I've yet to figure out a way to get the general case working without a syscall as that's the only way I've come up with to deal with the heterogenous CPU case. Happy to hear if someone has a better idea, though, as I don't really want to add a syscall if we can avoid it.

I threw this together during the conferences so I would be surprised if it's not broken, but I figured it'd be best to just get something on the lists sooner rather that later. Happy to have someone go fix my code, but the new uABI is really going to be the tricky bit here. There's some test code included, but I haven't even booted a kernel with these patches so YMMV.

These are also up at kernel.org/palmer/linux/riscv-hwprobe-v1 in case that's easier for folks.

Quoted 4 lines

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#12 lore raw

Hey!

Just bringing this up somewhere a bit more visible than the weekly pw sync-up yoke!
I just got my VisionFive2 today & I see Heiko has just posted another version of Zbb support series, right as I had started typing this in fact, so I'm curious where we stand. There's gonna be quite a few people with Zba/Zbb capable hardware soon by the looks of things, so it'd be nice to have something we can point people at that actually applies to recent kernels.

I know Palmer you said you'd do some work on it over Christmas, but since that didn't materialise - are you still planning on spinning up a v2?
Some thoughts on Drew's sysfs suggestion below would probably be useful if you aren't.

Thanks,
Conor.

Quoted 92 lines · Andrew Jones
Quoted 27 lines · Palmer Dabbelt

These are very much up for discussion, as it's a pretty big new user interface and it's quite a bit different from how we've historically done things: this isn't just providing an ISA string to userspace, this has its own format for providing information to userspace.

There's been a bunch of off-list discussions about this, including at Plumbers. The original plan was to do something involving providing an ISA string to userspace, but ISA strings just aren't sufficient for a stable ABI any more: in order to parse an ISA string users need the version of the specifications that the string is written to, the version of each extension (sometimes at a finer granularity than the RISC-V releases/versions encode), and the expected use case for the ISA string (ie, is it a U-mode or M-mode string). That's a lot of complexity to try and keep ABI compatible and it's probably going to continue to grow, as even if there's no more complexity in the specifications we'll have to deal with the various ISA string parsing oddities that end up all over userspace.

Instead this patch set takes a very different approach and provides a se of key/value pairs that encode various bits about the system. The big advantage here is that we can clearly define what these mean so we can ensure ABI stability, but it also allows us to encode information that's unlikely to ever appear in an ISA string (see the misaligned access performance, for example). The resulting interface looks a lot like what arm64 and x86 do, and will hopefully fit well into something like ACPI in the future.

Quoted 4 lines

The actual user interface is a syscall. I'm not really sure that's the right way to go about this, but it makes for flexible prototying. Various other approaches have been talked about like making HWCAP2 a pointer, having a VDSO routine, or exposing this via sysfs.

Hi Palmer,

To throw my two cents into the penny jar, I'd vote for sysfs. It handles the heterogeneous CPU case since cpu feature nodes can be hung off each cpu node. It also avoids yet another encoding. If we enumerate extensions and their properties then we need to maintain that enumeration in both the kernel space and userspace. If, OTOH, we use sysfs node names for the encoding, then, when we match the spec naming exactly, e.g.

.../features/zicbom
.../features/zihintpause
.../features/sscofpmf

userspace can look for features by name. Userspace libraries can even lead the kernel in development, since the encoding (the spec name) is already agreed.

Properties of extensions are just sub-nodes, some with standard names, like

.../features/zicbom/major
.../features/zicbom/minor

and others, which are cpu feature specific, like

.../features/zicbom/block_size

I used 'features' in the above examples for the node name, rather than 'isa', since not all features map to isa extensions, but it should be possible to fit non-isa features into the same framework.

Thanks,
drew

Quoted 19 lines

Those seem
like generally reasonable approaches, but I've yet to figure out a way to get the general case working without a syscall as that's the only way I've come up with to deal with the heterogenous CPU case. Happy to hear if someone has a better idea, though, as I don't really want to add a syscall if we can avoid it.

I threw this together during the conferences so I would be surprised if it's not broken, but I figured it'd be best to just get something on the lists sooner rather that later. Happy to have someone go fix my code, but the new uABI is really going to be the tricky bit here. There's some test code included, but I haven't even booted a kernel with these patches so YMMV.

These are also up at kernel.org/palmer/linux/riscv-hwprobe-v1 in case that's easier for folks.

Quoted 4 lines

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Quoted 4 lines

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#13 lore raw

Hey,

Am Montag, 9. Januar 2023, 19:47:17 CET schrieb Conor Dooley:

Quoted 11 lines

Hey!

Just bringing this up somewhere a bit more visible than the weekly pw sync-up yoke!
I just got my VisionFive2 today & I see Heiko has just posted another version of Zbb support series, right as I had started typing this in fact, so I'm curious where we stand. There's gonna be quite a few people with Zba/Zbb capable hardware soon by the looks of things, so it'd be nice to have something we can point people at that actually applies to recent kernels.

Quoted 5 lines

I know Palmer you said you'd do some work on it over Christmas, but since that didn't materialise - are you still planning on spinning up a v2?
Some thoughts on Drew's sysfs suggestion below would probably be useful if you aren't.

from my further optimization pov, I just rebased Palmer's v1 forward, as I essentially only want the has-fast-unaligned property from it ;-) .

The series I posted today is essentially the basics for "everyone with zbb" and I have a second part on top of that and Palmers hw-probing series that then does the further case.

I do hope to get that finalized tomorrow or wednesday.

Heiko

Quoted 93 lines · Andrew Jones
Quoted 92 lines · Palmer Dabbelt
Quoted 27 lines

These are very much up for discussion, as it's a pretty big new user interface and it's quite a bit different from how we've historically done things: this isn't just providing an ISA string to userspace, this has its own format for providing information to userspace.

There's been a bunch of off-list discussions about this, including at Plumbers. The original plan was to do something involving providing an ISA string to userspace, but ISA strings just aren't sufficient for a stable ABI any more: in order to parse an ISA string users need the version of the specifications that the string is written to, the version of each extension (sometimes at a finer granularity than the RISC-V releases/versions encode), and the expected use case for the ISA string (ie, is it a U-mode or M-mode string). That's a lot of complexity to try and keep ABI compatible and it's probably going to continue to grow, as even if there's no more complexity in the specifications we'll have to deal with the various ISA string parsing oddities that end up all over userspace.

Instead this patch set takes a very different approach and provides a se of key/value pairs that encode various bits about the system. The big advantage here is that we can clearly define what these mean so we can ensure ABI stability, but it also allows us to encode information that's unlikely to ever appear in an ISA string (see the misaligned access performance, for example). The resulting interface looks a lot like what arm64 and x86 do, and will hopefully fit well into something like ACPI in the future.

Quoted 4 lines

The actual user interface is a syscall. I'm not really sure that's the right way to go about this, but it makes for flexible prototying. Various other approaches have been talked about like making HWCAP2 a pointer, having a VDSO routine, or exposing this via sysfs.

Hi Palmer,

To throw my two cents into the penny jar, I'd vote for sysfs. It handles the heterogeneous CPU case since cpu feature nodes can be hung off each cpu node. It also avoids yet another encoding. If we enumerate extensions and their properties then we need to maintain that enumeration in both the kernel space and userspace. If, OTOH, we use sysfs node names for the encoding, then, when we match the spec naming exactly, e.g.

.../features/zicbom
.../features/zihintpause
.../features/sscofpmf

userspace can look for features by name. Userspace libraries can even lead the kernel in development, since the encoding (the spec name) is already agreed.

Properties of extensions are just sub-nodes, some with standard names, like

.../features/zicbom/major
.../features/zicbom/minor

and others, which are cpu feature specific, like

.../features/zicbom/block_size

I used 'features' in the above examples for the node name, rather than 'isa', since not all features map to isa extensions, but it should be possible to fit non-isa features into the same framework.

Thanks,
drew

Quoted 23 lines

Those seem
like generally reasonable approaches, but I've yet to figure out a way to get the general case working without a syscall as that's the only way I've come up with to deal with the heterogenous CPU case. Happy to hear if someone has a better idea, though, as I don't really want to add a syscall if we can avoid it.

I threw this together during the conferences so I would be surprised if it's not broken, but I figured it'd be best to just get something on the lists sooner rather that later. Happy to have someone go fix my code, but the new uABI is really going to be the tricky bit here. There's some test code included, but I haven't even booted a kernel with these patches so YMMV.

These are also up at kernel.org/palmer/linux/riscv-hwprobe-v1 in case that's easier for folks.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Quoted 5 lines
Quoted 4 lines

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#14 lore raw

Hey Heiko,
I thought I replied yesterday but obviously not!

Quoted 14 lines · Heiko Stübner

Hey,

Am Montag, 9. Januar 2023, 19:47:17 CET schrieb Conor Dooley:

Quoted 11 lines

Hey!

Just bringing this up somewhere a bit more visible than the weekly pw sync-up yoke!
I just got my VisionFive2 today & I see Heiko has just posted another version of Zbb support series, right as I had started typing this in fact, so I'm curious where we stand. There's gonna be quite a few people with Zba/Zbb capable hardware soon by the looks of things, so it'd be nice to have something we can point people at that actually applies to recent kernels.

Quoted 8 lines
Quoted 5 lines

I know Palmer you said you'd do some work on it over Christmas, but since that didn't materialise - are you still planning on spinning up a v2?
Some thoughts on Drew's sysfs suggestion below would probably be useful if you aren't.

from my further optimization pov, I just rebased Palmer's v1 forward, as I essentially only want the has-fast-unaligned property from it ;-) .

IIRC the v1 didn't build? Did you manage to get it built & test it at all?

Quoted 5 lines

The series I posted today is essentially the basics for "everyone with zbb" and I have a second part on top of that and Palmers hw-probing series that then does the further case.

I do hope to get that finalized tomorrow or wednesday.

I was going to ask what the "second part" was, but I figure if that's your timeline for it, I'll probably see the answer to that question soon enough :)

Thanks,
Conor.

Quoted 93 lines
Quoted 93 lines · Andrew Jones
Quoted 92 lines · Palmer Dabbelt
Quoted 27 lines

These are very much up for discussion, as it's a pretty big new user interface and it's quite a bit different from how we've historically done things: this isn't just providing an ISA string to userspace, this has its own format for providing information to userspace.

There's been a bunch of off-list discussions about this, including at Plumbers. The original plan was to do something involving providing an ISA string to userspace, but ISA strings just aren't sufficient for a stable ABI any more: in order to parse an ISA string users need the version of the specifications that the string is written to, the version of each extension (sometimes at a finer granularity than the RISC-V releases/versions encode), and the expected use case for the ISA string (ie, is it a U-mode or M-mode string). That's a lot of complexity to try and keep ABI compatible and it's probably going to continue to grow, as even if there's no more complexity in the specifications we'll have to deal with the various ISA string parsing oddities that end up all over userspace.

Instead this patch set takes a very different approach and provides a se of key/value pairs that encode various bits about the system. The big advantage here is that we can clearly define what these mean so we can ensure ABI stability, but it also allows us to encode information that's unlikely to ever appear in an ISA string (see the misaligned access performance, for example). The resulting interface looks a lot like what arm64 and x86 do, and will hopefully fit well into something like ACPI in the future.

Quoted 4 lines

The actual user interface is a syscall. I'm not really sure that's the right way to go about this, but it makes for flexible prototying. Various other approaches have been talked about like making HWCAP2 a pointer, having a VDSO routine, or exposing this via sysfs.

Hi Palmer,

To throw my two cents into the penny jar, I'd vote for sysfs. It handles the heterogeneous CPU case since cpu feature nodes can be hung off each cpu node. It also avoids yet another encoding. If we enumerate extensions and their properties then we need to maintain that enumeration in both the kernel space and userspace. If, OTOH, we use sysfs node names for the encoding, then, when we match the spec naming exactly, e.g.

.../features/zicbom
.../features/zihintpause
.../features/sscofpmf

userspace can look for features by name. Userspace libraries can even lead the kernel in development, since the encoding (the spec name) is already agreed.

Properties of extensions are just sub-nodes, some with standard names, like

.../features/zicbom/major
.../features/zicbom/minor

and others, which are cpu feature specific, like

.../features/zicbom/block_size

I used 'features' in the above examples for the node name, rather than 'isa', since not all features map to isa extensions, but it should be possible to fit non-isa features into the same framework.

Thanks,
drew

Quoted 23 lines

Those seem
like generally reasonable approaches, but I've yet to figure out a way to get the general case working without a syscall as that's the only way I've come up with to deal with the heterogenous CPU case. Happy to hear if someone has a better idea, though, as I don't really want to add a syscall if we can avoid it.

I threw this together during the conferences so I would be surprised if it's not broken, but I figured it'd be best to just get something on the lists sooner rather that later. Happy to have someone go fix my code, but the new uABI is really going to be the tricky bit here. There's some test code included, but I haven't even booted a kernel with these patches so YMMV.

These are also up at kernel.org/palmer/linux/riscv-hwprobe-v1 in case that's easier for folks.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Quoted 9 lines
Quoted 5 lines
Quoted 4 lines

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv