Support SSTC while PM operations
Subsystems (3)
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
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
@@ -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
@@ -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
PATCH v4 2/2 clocksource/drivers/timer-riscv: Stop stimecmp when cpu hotplug
In reply to Nick HuStop 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
@@ -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
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.
Suggested-by Anup Patel <[email protected]>Signed-off-by Nick Hu <[email protected]>Reviewed-by Anup Patel <[email protected]>---
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
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