mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 0/2] Support SSTC while PM operations
@ 2024-10-28  3:39 Nick Hu
  2024-10-28  3:39 ` [PATCH v3 1/2] riscv: Add stimecmp save and restore Nick Hu
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Nick Hu @ 2024-10-28  3:39 UTC (permalink / raw)
  To: greentime.hu, zong.li, Rafael J. Wysocki, Pavel Machek,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Daniel Lezcano,
	Thomas Gleixner, Andrew Jones, Conor Dooley, Samuel Holland,
	Sunil V L, Nick Hu, linux-pm, linux-riscv, linux-kernel

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
Link: https://lore.kernel.org/lkml/20240926065422.226518-1-nick.hu@sifive.com/T/

changes in v2:
1. Add csr_read/write_hi_lo operations
2. Apply the suggestion from Anup.
Link: https://lore.kernel.org/lkml/20240829033904.477200-3-nick.hu@sifive.com/T/#u

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(+)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 1/2] riscv: Add stimecmp save and restore
  2024-10-28  3:39 [PATCH v3 0/2] Support SSTC while PM operations Nick Hu
@ 2024-10-28  3:39 ` Nick Hu
  2024-10-28  4:01   ` Anup Patel
  2024-10-28  3:39 ` [PATCH v3 2/2] clocksource/drivers/timer-riscv: Stop stimecmp when cpu hotplug Nick Hu
  2025-03-27  3:25 ` [PATCH v3 0/2] Support SSTC while PM operations patchwork-bot+linux-riscv
  2 siblings, 1 reply; 7+ messages in thread
From: Nick Hu @ 2024-10-28  3:39 UTC (permalink / raw)
  To: greentime.hu, zong.li, Rafael J. Wysocki, Pavel Machek,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Daniel Lezcano,
	Thomas Gleixner, Andrew Jones, Samuel Holland, Conor Dooley,
	Sunil V L, Nick Hu, linux-pm, linux-riscv, linux-kernel

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 <nick.hu@sifive.com>
---
 arch/riscv/include/asm/suspend.h |  4 ++++
 arch/riscv/kernel/suspend.c      | 14 ++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/arch/riscv/include/asm/suspend.h b/arch/riscv/include/asm/suspend.h
index 4ffb022b097f..dc5782b5fbad 100644
--- a/arch/riscv/include/asm/suspend.h
+++ b/arch/riscv/include/asm/suspend.h
@@ -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
 };
 
diff --git a/arch/riscv/kernel/suspend.c b/arch/riscv/kernel/suspend.c
index 9a8a0dc035b2..24b3f57d467f 100644
--- a/arch/riscv/kernel/suspend.c
+++ b/arch/riscv/kernel/suspend.c
@@ -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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 2/2] clocksource/drivers/timer-riscv: Stop stimecmp when cpu hotplug
  2024-10-28  3:39 [PATCH v3 0/2] Support SSTC while PM operations Nick Hu
  2024-10-28  3:39 ` [PATCH v3 1/2] riscv: Add stimecmp save and restore Nick Hu
@ 2024-10-28  3:39 ` Nick Hu
  2024-10-28  9:44   ` Daniel Lezcano
  2025-03-27  3:25 ` [PATCH v3 0/2] Support SSTC while PM operations patchwork-bot+linux-riscv
  2 siblings, 1 reply; 7+ messages in thread
From: Nick Hu @ 2024-10-28  3:39 UTC (permalink / raw)
  To: greentime.hu, zong.li, Rafael J. Wysocki, Pavel Machek,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Daniel Lezcano,
	Thomas Gleixner, Andrew Jones, Conor Dooley, Samuel Holland,
	Nick Hu, Sunil V L, linux-pm, linux-riscv, linux-kernel
  Cc: Anup Patel

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 <anup@brainfault.org>
Link: https://lore.kernel.org/lkml/20240829033904.477200-3-nick.hu@sifive.com/T/#u
Signed-off-by: Nick Hu <nick.hu@sifive.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
---
 drivers/clocksource/timer-riscv.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/clocksource/timer-riscv.c b/drivers/clocksource/timer-riscv.c
index 48ce50c5f5e6..166dee14e46b 100644
--- a/drivers/clocksource/timer-riscv.c
+++ b/drivers/clocksource/timer-riscv.c
@@ -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;
 }
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 1/2] riscv: Add stimecmp save and restore
  2024-10-28  3:39 ` [PATCH v3 1/2] riscv: Add stimecmp save and restore Nick Hu
@ 2024-10-28  4:01   ` Anup Patel
  0 siblings, 0 replies; 7+ messages in thread
From: Anup Patel @ 2024-10-28  4:01 UTC (permalink / raw)
  To: Nick Hu
  Cc: greentime.hu, zong.li, Rafael J. Wysocki, Pavel Machek,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Daniel Lezcano,
	Thomas Gleixner, Andrew Jones, Samuel Holland, Conor Dooley,
	Sunil V L, linux-pm, linux-riscv, linux-kernel

On Mon, Oct 28, 2024 at 9:09 AM Nick Hu <nick.hu@sifive.com> wrote:
>
> 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 <nick.hu@sifive.com>

LGTM.

Reviewed-by: Anup Patel <anup@brainfault.org>

Regards,
Anup

> ---
>  arch/riscv/include/asm/suspend.h |  4 ++++
>  arch/riscv/kernel/suspend.c      | 14 ++++++++++++++
>  2 files changed, 18 insertions(+)
>
> diff --git a/arch/riscv/include/asm/suspend.h b/arch/riscv/include/asm/suspend.h
> index 4ffb022b097f..dc5782b5fbad 100644
> --- a/arch/riscv/include/asm/suspend.h
> +++ b/arch/riscv/include/asm/suspend.h
> @@ -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
>  };
>
> diff --git a/arch/riscv/kernel/suspend.c b/arch/riscv/kernel/suspend.c
> index 9a8a0dc035b2..24b3f57d467f 100644
> --- a/arch/riscv/kernel/suspend.c
> +++ b/arch/riscv/kernel/suspend.c
> @@ -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
>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 2/2] clocksource/drivers/timer-riscv: Stop stimecmp when cpu hotplug
  2024-10-28  3:39 ` [PATCH v3 2/2] clocksource/drivers/timer-riscv: Stop stimecmp when cpu hotplug Nick Hu
@ 2024-10-28  9:44   ` Daniel Lezcano
  2024-10-29  7:52     ` Nick Hu
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Lezcano @ 2024-10-28  9:44 UTC (permalink / raw)
  To: Nick Hu, greentime.hu, zong.li, Rafael J. Wysocki, Pavel Machek,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Thomas Gleixner,
	Andrew Jones, Conor Dooley, Samuel Holland, Sunil V L, linux-pm,
	linux-riscv, linux-kernel
  Cc: Anup Patel

On 28/10/2024 04:39, Nick Hu wrote:
> 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 <anup@brainfault.org>
> Link: https://lore.kernel.org/lkml/20240829033904.477200-3-nick.hu@sifive.com/T/#u
> Signed-off-by: Nick Hu <nick.hu@sifive.com>
> Reviewed-by: Anup Patel <anup@brainfault.org>
> ---
>   drivers/clocksource/timer-riscv.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/clocksource/timer-riscv.c b/drivers/clocksource/timer-riscv.c
> index 48ce50c5f5e6..166dee14e46b 100644
> --- a/drivers/clocksource/timer-riscv.c
> +++ b/drivers/clocksource/timer-riscv.c
> @@ -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;
>   }

Should it not be the opposite?

First stop the clock which clears the interrupt and then disable the irq?





-- 
<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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 2/2] clocksource/drivers/timer-riscv: Stop stimecmp when cpu hotplug
  2024-10-28  9:44   ` Daniel Lezcano
@ 2024-10-29  7:52     ` Nick Hu
  0 siblings, 0 replies; 7+ messages in thread
From: Nick Hu @ 2024-10-29  7:52 UTC (permalink / raw)
  To: Daniel Lezcano
  Cc: greentime.hu, zong.li, Rafael J. Wysocki, Pavel Machek,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Thomas Gleixner,
	Andrew Jones, Conor Dooley, Samuel Holland, Sunil V L, linux-pm,
	linux-riscv, linux-kernel, Anup Patel

Hi Daniel,

On Mon, Oct 28, 2024 at 5:44 PM Daniel Lezcano
<daniel.lezcano@linaro.org> wrote:
>
> On 28/10/2024 04:39, Nick Hu wrote:
> > 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 <anup@brainfault.org>
> > Link: https://lore.kernel.org/lkml/20240829033904.477200-3-nick.hu@sifive.com/T/#u
> > Signed-off-by: Nick Hu <nick.hu@sifive.com>
> > Reviewed-by: Anup Patel <anup@brainfault.org>
> > ---
> >   drivers/clocksource/timer-riscv.c | 6 ++++++
> >   1 file changed, 6 insertions(+)
> >
> > diff --git a/drivers/clocksource/timer-riscv.c b/drivers/clocksource/timer-riscv.c
> > index 48ce50c5f5e6..166dee14e46b 100644
> > --- a/drivers/clocksource/timer-riscv.c
> > +++ b/drivers/clocksource/timer-riscv.c
> > @@ -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;
> >   }
>
> Should it not be the opposite?
>
> 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?

>
>
>
>
> --
> <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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 0/2] Support SSTC while PM operations
  2024-10-28  3:39 [PATCH v3 0/2] Support SSTC while PM operations Nick Hu
  2024-10-28  3:39 ` [PATCH v3 1/2] riscv: Add stimecmp save and restore Nick Hu
  2024-10-28  3:39 ` [PATCH v3 2/2] clocksource/drivers/timer-riscv: Stop stimecmp when cpu hotplug Nick Hu
@ 2025-03-27  3:25 ` patchwork-bot+linux-riscv
  2 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+linux-riscv @ 2025-03-27  3:25 UTC (permalink / raw)
  To: Nick Hu
  Cc: linux-riscv, greentime.hu, zong.li, rafael, pavel, paul.walmsley,
	palmer, aou, daniel.lezcano, tglx, ajones, conor.dooley,
	samuel.holland, sunilvl, linux-pm, linux-kernel

Hello:

This series was applied to riscv/linux.git (for-next)
by Alexandre Ghiti <alexghiti@rivosinc.com>:

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
> Link: https://lore.kernel.org/lkml/20240926065422.226518-1-nick.hu@sifive.com/T/
> 
> [...]

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-03-27  3:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-28  3:39 [PATCH v3 0/2] Support SSTC while PM operations Nick Hu
2024-10-28  3:39 ` [PATCH v3 1/2] riscv: Add stimecmp save and restore Nick Hu
2024-10-28  4:01   ` Anup Patel
2024-10-28  3:39 ` [PATCH v3 2/2] clocksource/drivers/timer-riscv: Stop stimecmp when cpu hotplug Nick Hu
2024-10-28  9:44   ` Daniel Lezcano
2024-10-29  7:52     ` Nick Hu
2025-03-27  3:25 ` [PATCH v3 0/2] Support SSTC while PM operations patchwork-bot+linux-riscv

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®