Skip to content

Commit 92e0d14

Browse files
avpateldlezcano
authored andcommitted
clocksource/drivers/riscv_timer: Provide the sched_clock
Currently, we don't have a sched_clock registered for RISC-V systems. This means Linux time keeping will use jiffies (running at HZ) as the default sched_clock. To avoid this, we explicity provide sched_clock using RISC-V rdtime instruction (similar to riscv_timer clocksource). Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Palmer Dabbelt <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]>
1 parent 4f352d1 commit 92e0d14

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

drivers/clocksource/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ config ATCPIT100_TIMER
599599

600600
config RISCV_TIMER
601601
bool "Timer for the RISC-V platform"
602-
depends on RISCV
602+
depends on GENERIC_SCHED_CLOCK && RISCV
603603
default y
604604
select TIMER_PROBE
605605
select TIMER_OF

drivers/clocksource/riscv_timer.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/cpu.h>
99
#include <linux/delay.h>
1010
#include <linux/irq.h>
11+
#include <linux/sched_clock.h>
1112
#include <asm/smp.h>
1213
#include <asm/sbi.h>
1314

@@ -49,6 +50,11 @@ static unsigned long long riscv_clocksource_rdtime(struct clocksource *cs)
4950
return get_cycles64();
5051
}
5152

53+
static u64 riscv_sched_clock(void)
54+
{
55+
return get_cycles64();
56+
}
57+
5258
static DEFINE_PER_CPU(struct clocksource, riscv_clocksource) = {
5359
.name = "riscv_clocksource",
5460
.rating = 300,
@@ -97,6 +103,9 @@ static int __init riscv_timer_init_dt(struct device_node *n)
97103
cs = per_cpu_ptr(&riscv_clocksource, cpuid);
98104
clocksource_register_hz(cs, riscv_timebase);
99105

106+
sched_clock_register(riscv_sched_clock,
107+
BITS_PER_LONG, riscv_timebase);
108+
100109
error = cpuhp_setup_state(CPUHP_AP_RISCV_TIMER_STARTING,
101110
"clockevents/riscv/timer:starting",
102111
riscv_timer_starting_cpu, riscv_timer_dying_cpu);

0 commit comments

Comments
 (0)