Skip to content

Commit 52420e4

Browse files
RISC-V: Provide the frequency of time CSR via hwprobe
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 <[email protected]> Reviewed-by: Evan Green <[email protected]> Reviewed-by: Anup Patel <[email protected]> Acked-by: Punit Agrawal <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 5c8405d commit 52420e4

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

Documentation/arch/riscv/hwprobe.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,5 @@ The following keys are defined:
264264

265265
* :c:macro:`RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS`: An unsigned long which
266266
represent the highest userspace virtual address usable.
267+
268+
* :c:macro:`RISCV_HWPROBE_KEY_TIME_CSR_FREQ`: Frequency (in Hz) of `time CSR`.

arch/riscv/include/asm/hwprobe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <uapi/asm/hwprobe.h>
1010

11-
#define RISCV_HWPROBE_MAX_KEY 7
11+
#define RISCV_HWPROBE_MAX_KEY 8
1212

1313
static inline bool riscv_hwprobe_key_is_valid(__s64 key)
1414
{

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ struct riscv_hwprobe {
8181
#define RISCV_HWPROBE_MISALIGNED_MASK (7 << 0)
8282
#define RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE 6
8383
#define RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS 7
84+
#define RISCV_HWPROBE_KEY_TIME_CSR_FREQ 8
8485
/* Increase RISCV_HWPROBE_MAX_KEY when adding items. */
8586

8687
/* Flags */

arch/riscv/kernel/sys_hwprobe.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <asm/cpufeature.h>
1010
#include <asm/hwprobe.h>
1111
#include <asm/processor.h>
12+
#include <asm/delay.h>
1213
#include <asm/sbi.h>
1314
#include <asm/switch_to.h>
1415
#include <asm/uaccess.h>
@@ -236,6 +237,10 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair,
236237
pair->value = user_max_virt_addr();
237238
break;
238239

240+
case RISCV_HWPROBE_KEY_TIME_CSR_FREQ:
241+
pair->value = riscv_timebase;
242+
break;
243+
239244
/*
240245
* For forward compatibility, unknown keys don't fail the whole
241246
* call, but get their element key set to -1 and value set to 0

0 commit comments

Comments
 (0)