Skip to contentSkip to conversation

RISC-V: Provide the frequency of mtime via hwprobe

PATCH New Palmer Dabbelt 1 participant 1 message Nov 1, 2023

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

PATCH 1/1 RISC-V: Provide the frequency of mtime via hwprobe

A handful of user-visible behavior is based on the frequency of the machine-mode time.

---
"Stat_headcrabed" on IRC asked for this. I said it was easy and they should do it themselves, but they'd logged off by the time I got around to reading messages this morning. This is more of an example than anything, but I figured it'd be easier to just send it.

We likely need to think a bit about exactly how this is defined: there's more than just mtime now, and we've also got things like virtualization and perf. I'm not even sure it's sane to put this in hwprobe as opposed to providing it via some perf-related infrastructure...

It's the merge window so I'm not going to think about it, if someone wants to pick this up they're more than welcome to.

---
 Documentation/riscv/hwprobe.rst       | 2 ++
 arch/riscv/include/asm/hwprobe.h      | 2 +-
 arch/riscv/include/uapi/asm/hwprobe.h | 1 +
 arch/riscv/kernel/sys_riscv.c         | 5 +++++
 4 files changed, 9 insertions(+), 1 deletion(-)
Documentation/riscv/hwprobe.rst +2 -0
index a52996b22f75..3ec35c1f3819 100644
@@ -96,3 +96,5 @@ The following keys are defined:
 
   * :c:macro:`RISCV_HWPROBE_MISALIGNED_UNSUPPORTED`: Misaligned accesses are
     not supported at all and will generate a misaligned address fault.
+
+* :c:macro:`RISCV_HWPROBE_KEY_MTIME_FREQ`: Frequency (in Hz) of `mtime`.
arch/riscv/include/asm/hwprobe.h +1 -1
index 78936f4ff513..39df8604fea1 100644
@@ -8,6 +8,6 @@
 
 #include <uapi/asm/hwprobe.h>
 
-#define RISCV_HWPROBE_MAX_KEY 5
+#define RISCV_HWPROBE_MAX_KEY 6
 
 #endif
arch/riscv/include/uapi/asm/hwprobe.h +1 -0
index 006bfb48343d..2dc34d474724 100644
@@ -36,6 +36,7 @@ struct riscv_hwprobe {
 #define		RISCV_HWPROBE_MISALIGNED_FAST		(3 << 0)
 #define		RISCV_HWPROBE_MISALIGNED_UNSUPPORTED	(4 << 0)
 #define		RISCV_HWPROBE_MISALIGNED_MASK		(7 << 0)
+#define RISCV_HWPROBE_KEY_MTIME_FREQ	6
 /* Increase RISCV_HWPROBE_MAX_KEY when adding items. */
 
 #endif
arch/riscv/kernel/sys_riscv.c +5 -0
index 473159b5f303..facfa38f4c8a 100644
@@ -8,6 +8,7 @@
 #include <linux/syscalls.h>
 #include <asm/cacheflush.h>
 #include <asm/cpufeature.h>
+#include <asm/delay.h>
 #include <asm/hwprobe.h>
 #include <asm/sbi.h>
 #include <asm/vector.h>
@@ -215,6 +216,10 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair,
 		pair->value = hwprobe_misaligned(cpus);
 		break;
 
+	case RISCV_HWPROBE_KEY_MTIME_FREQ:
+		pair->value = riscv_timebase;
+		break;
+
 	/*
 	 * For forward compatibility, unknown keys don't fail the whole
 	 * call, but get their element key set to -1 and value set to 0
Signature · 7 lines
2.42.0


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