Skip to contentSkip to conversation

Misc RISC-V timer driver improvements

PATCH In review Anup Patel 3 participants 7 messages Jul 10, 2023 – Aug 16, 2023

Subsystems (2)
lore
Share & tools
lore

Anup Patel

author
#0 lore raw

cover Misc RISC-V timer driver improvements

This series does two improvements to the RISC-V timer driver:
1) Keep timer interrupt enable state in-sync with interrupt subsystem
2) Increase rating of clock event device when Sstc is available

These patches can also be found in the riscv_timer_imp_v1 branch at:
https://github.com/avpatel/linux.git

Anup Patel (2):
clocksource: timer-riscv: Don't enable/disable timer interrupt
clocksource: timer-riscv: Increase rating of clock_event_device for
Sstc

 drivers/clocksource/timer-riscv.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/2 clocksource: timer-riscv: Don't enable/disable timer interrupt

Currently, we enable/disable timer interrupt at runtime to start/stop timer events. This makes timer interrupt state go out-of-sync with the Linux interrupt subsystem.

To address the above issue, we can stop a per-HART timer interrupt by setting U64_MAX in timecmp CSR (or sbi_set_timer()) at the time of handling timer interrupt.

---
 drivers/clocksource/timer-riscv.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/clocksource/timer-riscv.c +13 -2
index da3071b387eb..f2ea2b3d2d43 100644
@@ -22,6 +22,7 @@
 #include <linux/io-64-nonatomic-lo-hi.h>
 #include <linux/interrupt.h>
 #include <linux/of_irq.h>
+#include <linux/limits.h>
 #include <clocksource/timer-riscv.h>
 #include <asm/smp.h>
 #include <asm/hwcap.h>
@@ -31,12 +32,22 @@
 static DEFINE_STATIC_KEY_FALSE(riscv_sstc_available);
 static bool riscv_timer_cannot_wake_cpu;
 
+static void riscv_clock_event_stop(void)
+{
+	if (static_branch_likely(&riscv_sstc_available)) {
+		csr_write(CSR_STIMECMP, ULONG_MAX);
+		if (IS_ENABLED(CONFIG_32BIT))
+			csr_write(CSR_STIMECMPH, ULONG_MAX);
+	} else {
+		sbi_set_timer(U64_MAX);
+	}
+}
+
 static int riscv_clock_next_event(unsigned long delta,
 		struct clock_event_device *ce)
 {
 	u64 next_tval = get_cycles64() + delta;
 
-	csr_set(CSR_IE, IE_TIE);
 	if (static_branch_likely(&riscv_sstc_available)) {
 #if defined(CONFIG_32BIT)
 		csr_write(CSR_STIMECMP, next_tval & 0xFFFFFFFF);
@@ -119,7 +130,7 @@ static irqreturn_t riscv_timer_interrupt(int irq, void *dev_id)
 {
 	struct clock_event_device *evdev = this_cpu_ptr(&riscv_clock_event);
 
-	csr_clear(CSR_IE, IE_TIE);
+	riscv_clock_event_stop();
 	evdev->event_handler(evdev);
 
 	return IRQ_HANDLED;
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 2/2 clocksource: timer-riscv: Increase rating of clock_event_device for Sstc

In reply to Anup Patel

When Sstc is available the RISC-V timer clock_event_device should be the preferred clock_event_device hence we increase clock_event_device rating for Sstc.

---
 drivers/clocksource/timer-riscv.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clocksource/timer-riscv.c +2 -0
index f2ea2b3d2d43..9c8f3e2decc2 100644
@@ -105,6 +105,8 @@ static int riscv_timer_starting_cpu(unsigned int cpu)
 	ce->irq = riscv_clock_event_irq;
 	if (riscv_timer_cannot_wake_cpu)
 		ce->features |= CLOCK_EVT_FEAT_C3STOP;
+	if (static_branch_likely(&riscv_sstc_available))
+		ce->rating = 450;
 	clockevents_config_and_register(ce, riscv_timebase, 100, 0x7fffffff);
 
 	enable_percpu_irq(riscv_clock_event_irq,
Signature · 1 line
2.34.1
Reviewed-by on the v1 series
#3 lore raw
In reply to Anup Patel
Quoted 6 lines · Anup Patel

This series does two improvements to the RISC-V timer driver:
1) Keep timer interrupt enable state in-sync with interrupt subsystem
2) Increase rating of clock event device when Sstc is available

These patches can also be found in the riscv_timer_imp_v1 branch at:
https://github.com/avpatel/linux.git

Other than wondering why you opted for 450 (curiosity really), this stuff looks fine to me.

Cheers,
Conor.

author
#4 lore raw
Quoted 11 lines · Conor Dooley
Quoted 6 lines · Anup Patel

This series does two improvements to the RISC-V timer driver:
1) Keep timer interrupt enable state in-sync with interrupt subsystem
2) Increase rating of clock event device when Sstc is available

These patches can also be found in the riscv_timer_imp_v1 branch at:
https://github.com/avpatel/linux.git

Other than wondering why you opted for 450 (curiosity really), this stuff looks fine to me.

It is the same as the rating for clock_event_device used by ARM arch timer. (Refer, __arch_timer_setup() in drivers/clocksource/arm_arch_timer.c)

Quoted 5 lines

Cheers,
Conor.

Regards,
Anup

#5 lore raw
Quoted 6 lines · Anup Patel
Quoted 2 lines · Conor Dooley

Other than wondering why you opted for 450 (curiosity really), this stuff looks fine to me.

It is the same as the rating for clock_event_device used by ARM arch timer.

That's what I figured, thanks!

maintainer Acked-by on the v1 series
#6 lore raw
In reply to Anup Patel
Quoted 7 lines · On Mon, 10 Jul 2023 06:19:00 PDT (-0700), [email protected] wrote:

This series does two improvements to the RISC-V timer driver:
1) Keep timer interrupt enable state in-sync with interrupt subsystem
2) Increase rating of clock event device when Sstc is available

These patches can also be found in the riscv_timer_imp_v1 branch at:
https://github.com/avpatel/linux.git

Quoted 7 lines

Anup Patel (2):
clocksource: timer-riscv: Don't enable/disable timer interrupt
clocksource: timer-riscv: Increase rating of clock_event_device for
Sstc

 drivers/clocksource/timer-riscv.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

in case the clock folks want to pick these up. Otherwise I'll look more closely and take them via the RISC-V tree. Thanks!

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