Skip to contentSkip to conversation

clocksource: timer-riscv: Clear timer interrupt on timer initialization

PATCH Superseded Ley Foon Tan 2 participants 3 messages Jan 25, 2024

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clocksource: timer-riscv: Clear timer interrupt on timer initialization

In the RISC-V specification, the stimecmp register doesn't have a default value. To prevent the timer interrupt from being triggered during timer initialization, clear the timer interrupt by writing stimecmp with a maximum value.

---
 drivers/clocksource/timer-riscv.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/clocksource/timer-riscv.c +3 -0
index e66dcbd66566..a75a74647344 100644
@@ -172,6 +172,9 @@ static int __init riscv_timer_init_common(void)
 
 	sched_clock_register(riscv_sched_clock, 64, riscv_timebase);
 
+	/* Clear timer interrupt */
+	riscv_clock_event_stop();
+
 	error = request_percpu_irq(riscv_clock_event_irq,
 				    riscv_timer_interrupt,
 				    "riscv-timer", &riscv_clock_event);
Signature · 1 line
2.43.0
#1 lore raw
Quoted 16 lines · Ley Foon Tan

In the RISC-V specification, the stimecmp register doesn't have a default value. To prevent the timer interrupt from being triggered during timer initialization, clear the timer interrupt by writing stimecmp with a maximum value.

---
 drivers/clocksource/timer-riscv.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/clocksource/timer-riscv.c +0 -0
index e66dcbd66566..a75a74647344 100644

drivers/clocksource/timer-riscv.c static int __init riscv_timer_init_common(void) · line 177

Quoted 6 lines
drivers/clocksource/timer-riscv.c +3 -0
@@ -172,6 +172,9 @@ static int __init riscv_timer_init_common(void)
 
        sched_clock_register(riscv_sched_clock, 64, riscv_timebase);
 
+       /* Clear timer interrupt */
+       riscv_clock_event_stop();
+

The riscv_timer_init_common() is called only on boot HART.

I suggest doing riscv_clock_event_stop() in riscv_timer_starting_cpu() just before enable_percpu_irq().

I also suggest adding an appropriate Fixes tag in the commit description.

Regards,
Anup

Quoted 11 lines
drivers/clocksource/timer-riscv.c +0 -1
        error = request_percpu_irq(riscv_clock_event_irq,
                                    riscv_timer_interrupt,
                                    "riscv-timer", &riscv_clock_event);
--

2.43.0

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

#2 lore raw
Quoted 42 lines

-----Original Message-----
From: Anup Patel <[email protected]>
Sent: Friday, January 26, 2024 1:00 AM
To: Leyfoon Tan <[email protected]>
Cc: Daniel Lezcano <[email protected]>; Thomas Gleixner <[email protected]>; Palmer Dabbelt <[email protected]>; Paul Walmsley <[email protected]>; Albert Ou <[email protected]>; [email protected]; [email protected]; linux- [email protected]; Ley Foon Tan <[email protected]>
Subject: Re: [PATCH] clocksource: timer-riscv: Clear timer interrupt on timer initialization

Quoted 17 lines · Ley Foon Tan

In the RISC-V specification, the stimecmp register doesn't have a default value. To prevent the timer interrupt from being triggered during timer initialization, clear the timer interrupt by writing stimecmp with a maximum value.

---
 drivers/clocksource/timer-riscv.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/clocksource/timer-riscv.c +0 -0
index e66dcbd66566..a75a74647344 100644

drivers/clocksource/timer-riscv.c static int __init riscv_timer_init_common(void) · line 177

Quoted 6 lines
drivers/clocksource/timer-riscv.c +3 -0
@@ -172,6 +172,9 @@ static int __init riscv_timer_init_common(void)
 
        sched_clock_register(riscv_sched_clock, 64, riscv_timebase);
 
+       /* Clear timer interrupt */
+       riscv_clock_event_stop();
+

The riscv_timer_init_common() is called only on boot HART.

Quoted 8 lines

I suggest doing riscv_clock_event_stop() in riscv_timer_starting_cpu() just before enable_percpu_irq().

I also suggest adding an appropriate Fixes tag in the commit description.

Regards,
Anup

Okay, will change it.

Thanks.

Regards
Ley Foon