]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
RISC-V: Provide the frequency of time CSR via hwprobe
authorPalmer Dabbelt <palmer@rivosinc.com>
Tue, 2 Jul 2024 03:37:31 +0000 (11:37 +0800)
committerPalmer Dabbelt <palmer@rivosinc.com>
Fri, 26 Jul 2024 12:50:51 +0000 (05:50 -0700)
The RISC-V architecture makes a real time counter CSR (via RDTIME
instruction) available for applications in U-mode but there is no
architected mechanism for an application to discover the frequency
the counter is running at. Some applications (e.g., DPDK) use the
time counter for basic performance analysis as well as fine grained
time-keeping.

Add support to the hwprobe system call to export the time CSR
frequency to code running in U-mode.

Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
Reviewed-by: Evan Green <evan@rivosinc.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Acked-by: Punit Agrawal <punit.agrawal@bytedance.com>
Link: https://lore.kernel.org/r/20240702033731.71955-2-cuiyunhui@bytedance.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Documentation/arch/riscv/hwprobe.rst
arch/riscv/include/asm/hwprobe.h
arch/riscv/include/uapi/asm/hwprobe.h
arch/riscv/kernel/sys_hwprobe.c

index 02eb4d98b7deabd0b58f4a1dd6eab7af9ed87462..3db60a0911df651abcb4deeee58d686d2d9f6ea5 100644 (file)
@@ -264,3 +264,5 @@ The following keys are defined:
 
 * :c:macro:`RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS`: An unsigned long which
   represent the highest userspace virtual address usable.
+
+* :c:macro:`RISCV_HWPROBE_KEY_TIME_CSR_FREQ`: Frequency (in Hz) of `time CSR`.
index 150a9877b0af1f0bf79be13c697961ab7ce03d60..ef01c182af2b0507d53f0b774f6229d4ae6caacd 100644 (file)
@@ -8,7 +8,7 @@
 
 #include <uapi/asm/hwprobe.h>
 
-#define RISCV_HWPROBE_MAX_KEY 7
+#define RISCV_HWPROBE_MAX_KEY 8
 
 static inline bool riscv_hwprobe_key_is_valid(__s64 key)
 {
index 8b8f6ac0eae28686f1aec432a307869c641b9386..b706c8e47b027b1daa698928d96858622ea8a616 100644 (file)
@@ -81,6 +81,7 @@ struct riscv_hwprobe {
 #define                RISCV_HWPROBE_MISALIGNED_MASK           (7 << 0)
 #define RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE    6
 #define RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS 7
+#define RISCV_HWPROBE_KEY_TIME_CSR_FREQ        8
 /* Increase RISCV_HWPROBE_MAX_KEY when adding items. */
 
 /* Flags */
index 8a1c9ce170e85784c0e029e350ac13ff2387049f..8d1b5c35d2a7315b15d3355f29eb8c8a4e24e250 100644 (file)
@@ -9,6 +9,7 @@
 #include <asm/cpufeature.h>
 #include <asm/hwprobe.h>
 #include <asm/processor.h>
+#include <asm/delay.h>
 #include <asm/sbi.h>
 #include <asm/switch_to.h>
 #include <asm/uaccess.h>
@@ -236,6 +237,10 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair,
                pair->value = user_max_virt_addr();
                break;
 
+       case RISCV_HWPROBE_KEY_TIME_CSR_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