Support SSTC while PM operations
Subsystems (3)
v3 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 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 · 1 line
2.34.1
PATCH v3 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.34.1
Re: [PATCH v3 1/2] riscv: Add stimecmp save and restore
Quoted 5 lines · Nick Hu
If the HW support the SSTC extension, we should save and restore the stimecmp register while cpu non retention suspend.
Signed-off-by Nick Hu <[email protected]>
LGTM.
Regards,
Anup
Quoted 56 lines
--- 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
-1@@ -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 } --2.34.1
PATCH v3 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
@@ -127,6 +127,12 @@ static int riscv_timer_starting_cpu(unsigned int cpu)static int riscv_timer_dying_cpu (unsigned int cpu) {disable_percpu_irq (riscv_clock_event_irq); +/* +* 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 (); +return 0 ; }
Signature · 1 line
2.34.1
Re: [PATCH v3 2/2] clocksource/drivers/timer-riscv: Stop stimecmp when cpu hotplug
Quoted 17 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]>--- drivers/clocksource/timer-riscv.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/clocksource/timer-riscv.c +0
-0@@ -127,6 +127,12 @@ static int riscv_timer_starting_cpu(unsigned int cpu)static int riscv_timer_dying_cpu (unsigned int cpu)
drivers/clocksource/timer-riscv.c static int riscv_timer_starting_cpu(unsigned int cpu) · line 137
Quoted 10 lines
drivers/clocksource/timer-riscv.c +6
-0{disable_percpu_irq (riscv_clock_event_irq); +/* +* 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 (); +return 0 ; }
Should it not be the opposite?
First stop the clock which clears the interrupt and then disable the irq?
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
Re: [PATCH v3 2/2] clocksource/drivers/timer-riscv: Stop stimecmp when cpu hotplug
Hi Daniel,
Quoted 32 lines · Daniel Lezcano
Quoted 17 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]>--- drivers/clocksource/timer-riscv.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/clocksource/timer-riscv.c +0
-0@@ -127,6 +127,12 @@ static int riscv_timer_starting_cpu(unsigned int cpu)static int riscv_timer_dying_cpu (unsigned int cpu)drivers/clocksource/timer-riscv.c static int riscv_timer_starting_cpu(unsigned int cpu) · line 137
Quoted 10 lines
drivers/clocksource/timer-riscv.c +6
-0{disable_percpu_irq (riscv_clock_event_irq); +/* +* 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 (); +return 0 ; }Should it not be the opposite?
Quoted 2 lines
First stop the clock which clears the interrupt and then disable the irq?
SIE.STIE = 0 ->
Mtimer interrupt comes -> trap to m-mode -> raise STIP -> stop the clock
Is the above case you are concerned about?
Quoted 10 lines
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCsFollow 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 Mon, 28 Oct 2024 11:39:24 +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 v3:
1. Update the commit description
2. Remove csr_read/write_hi_lo from the previous patch[...]
Here is the summary with links:
- [v3,1/2] riscv: Add stimecmp save and restore
https://git.kernel.org/riscv/c/ffef54ad4110
- [v3,2/2] clocksource/drivers/timer-riscv: Stop stimecmp when cpu hotplug (no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html