Skip to contentSkip to conversation

Support SSTC while PM operations

PATCH Applied Nick Hu 3 participants 5 messages Feb 19, 2025 – Mar 27, 2025

Subsystems (3)
lore
Share & tools
lore

Nick Hu

author
#0 lore raw

v4 cover Support SSTC while PM operations

When the cpu is going to be hotplug, stop the stimecmp to prevent pending interrupt.
When the cpu is going to be suspended, save the stimecmp before entering the suspend state and restore it in the resume path.

changes in v4:
1. Apply the suggestion from Daniel to stop the clock before disabling the irq.

changes in v3:
1. Update the commit description
2. Remove csr_read/write_hi_lo from the previous patch

changes in v2:
1. Add csr_read/write_hi_lo operations
2. Apply the suggestion from Anup.

Nick Hu (2):
riscv: Add stimecmp save and restore clocksource/drivers/timer-riscv: Stop stimecmp when cpu hotplug

 arch/riscv/include/asm/suspend.h  |  4 ++++
 arch/riscv/kernel/suspend.c       | 14 ++++++++++++++
 drivers/clocksource/timer-riscv.c |  6 ++++++
 3 files changed, 24 insertions(+)
Signature · 7 lines
2.17.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
author
#1 lore raw

PATCH v4 1/2 riscv: Add stimecmp save and restore

If the HW support the SSTC extension, we should save and restore the stimecmp register while cpu non retention suspend.

---
 arch/riscv/include/asm/suspend.h |  4 ++++
 arch/riscv/kernel/suspend.c      | 14 ++++++++++++++
 2 files changed, 18 insertions(+)
arch/riscv/include/asm/suspend.h +4 -0
index 4ffb022b097f..dc5782b5fbad 100644
@@ -18,6 +18,10 @@ struct suspend_context {
 	unsigned long ie;
 #ifdef CONFIG_MMU
 	unsigned long satp;
+	unsigned long stimecmp;
+#if __riscv_xlen < 64
+	unsigned long stimecmph;
+#endif
 #endif
 };
 
arch/riscv/kernel/suspend.c +14 -0
index 9a8a0dc035b2..24b3f57d467f 100644
@@ -30,6 +30,13 @@ void suspend_save_csrs(struct suspend_context *context)
 	 */
 
 #ifdef CONFIG_MMU
+	if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SSTC)) {
+		context->stimecmp = csr_read(CSR_STIMECMP);
+#if __riscv_xlen < 64
+		context->stimecmph = csr_read(CSR_STIMECMPH);
+#endif
+	}
+
 	context->satp = csr_read(CSR_SATP);
 #endif
 }
@@ -43,6 +50,13 @@ void suspend_restore_csrs(struct suspend_context *context)
 	csr_write(CSR_IE, context->ie);
 
 #ifdef CONFIG_MMU
+	if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SSTC)) {
+		csr_write(CSR_STIMECMP, context->stimecmp);
+#if __riscv_xlen < 64
+		csr_write(CSR_STIMECMPH, context->stimecmph);
+#endif
+	}
+
 	csr_write(CSR_SATP, context->satp);
 #endif
 }
Signature · 1 line
2.17.1
author
#2 lore raw

PATCH v4 2/2 clocksource/drivers/timer-riscv: Stop stimecmp when cpu hotplug

In reply to Nick Hu

Stop the timer when the cpu is going to be offline otherwise the timer interrupt may be pending while performing power-down.

---
 drivers/clocksource/timer-riscv.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/clocksource/timer-riscv.c +6 -0
index 48ce50c5f5e6..4d7cf338824a 100644
@@ -126,7 +126,13 @@ static int riscv_timer_starting_cpu(unsigned int cpu)
 
 static int riscv_timer_dying_cpu(unsigned int cpu)
 {
+	/*
+	 * Stop the timer when the cpu is going to be offline otherwise
+	 * the timer interrupt may be pending while performing power-down.
+	 */
+	riscv_clock_event_stop();
 	disable_percpu_irq(riscv_clock_event_irq);
+
 	return 0;
 }
 
Signature · 1 line
2.17.1
Acked-by on v4 2/2
#3 lore raw

Re: [PATCH v4 2/2] clocksource/drivers/timer-riscv: Stop stimecmp when cpu hotplug

Quoted 8 lines · Nick Hu

Stop the timer when the cpu is going to be offline otherwise the timer interrupt may be pending while performing power-down.

---

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#4 lore raw
In reply to Nick Hu
This series was applied to riscv/linux.git (for-next) by Alexandre Ghiti <[email protected]>:

Hello:

This series was applied to riscv/linux.git (for-next) by Alexandre Ghiti <[email protected]>:

Quoted 11 lines · On Wed, 19 Feb 2025 19:41:33 +0800 you wrote:

When the cpu is going to be hotplug, stop the stimecmp to prevent pending interrupt.
When the cpu is going to be suspended, save the stimecmp before entering the suspend state and restore it in the resume path.

changes in v4:
1. Apply the suggestion from Daniel to stop the clock before disabling the irq.

[...]

Here is the summary with links:
- [v4,1/2] riscv: Add stimecmp save and restore

    https://git.kernel.org/riscv/c/ffef54ad4110
  - [v4,2/2] clocksource/drivers/timer-riscv: Stop stimecmp when cpu hotplug
    https://git.kernel.org/riscv/c/70c93b026ed0

You are awesome, thank you!

Signature · 9 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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