linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] riscv: suspend: Add syscore ops for suspend
@ 2023-08-16  3:40 Nick Hu
  2023-08-16 12:33 ` Conor Dooley
  0 siblings, 1 reply; 3+ messages in thread
From: Nick Hu @ 2023-08-16  3:40 UTC (permalink / raw)
  To: nick.hu, paul.walmsley, palmer, aou, ajones, mason.huo,
	jeeheng.sia, conor.dooley, linux-riscv, linux-kernel
  Cc: Andy Chiu

Save and restore the FPU and vector states when system suspend. If a
task is the one who performs the suspend flow and it also do some
floating or vector operations before the suspend, we should save and
restore the FPU states and vector states for this task.

Signed-off-by: Nick Hu <nick.hu@sifive.com>
Signed-off-by: Andy Chiu <andy.chiu@sifive.com>
---
 arch/riscv/kernel/suspend.c | 45 +++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/arch/riscv/kernel/suspend.c b/arch/riscv/kernel/suspend.c
index 3c89b8ec69c4..ff69ff8a1974 100644
--- a/arch/riscv/kernel/suspend.c
+++ b/arch/riscv/kernel/suspend.c
@@ -4,9 +4,14 @@
  * Copyright (c) 2022 Ventana Micro Systems Inc.
  */
 
+#include <linux/cpu_pm.h>
 #include <linux/ftrace.h>
+#include <linux/thread_info.h>
+#include <linux/syscore_ops.h>
 #include <asm/csr.h>
 #include <asm/suspend.h>
+#include <asm/switch_to.h>
+#include <asm/vector.h>
 
 void suspend_save_csrs(struct suspend_context *context)
 {
@@ -85,3 +90,43 @@ int cpu_suspend(unsigned long arg,
 
 	return rc;
 }
+
+static int riscv_cpu_suspend(void)
+{
+	struct task_struct *cur_task = get_current();
+	struct pt_regs *regs = task_pt_regs(cur_task);
+
+	if (has_fpu()) {
+		if (unlikely(regs->status & SR_SD))
+			fstate_save(cur_task, regs);
+	}
+	if (has_vector()) {
+		if (unlikely(regs->status & SR_SD))
+			riscv_v_vstate_save(cur_task, regs);
+	}
+
+	return 0;
+}
+
+static void riscv_cpu_resume(void)
+{
+	struct task_struct *cur_task = get_current();
+	struct pt_regs *regs = task_pt_regs(cur_task);
+
+	if (has_fpu())
+		fstate_restore(cur_task, regs);
+	if (has_vector())
+		riscv_v_vstate_restore(cur_task, regs);
+}
+
+static struct syscore_ops riscv_cpu_syscore_ops = {
+	.suspend	= riscv_cpu_suspend,
+	.resume		= riscv_cpu_resume,
+};
+
+static int __init riscv_cpu_suspend_init(void)
+{
+	register_syscore_ops(&riscv_cpu_syscore_ops);
+	return 0;
+}
+arch_initcall(riscv_cpu_suspend_init);
-- 
2.34.1


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

* Re: [PATCH] riscv: suspend: Add syscore ops for suspend
  2023-08-16  3:40 [PATCH] riscv: suspend: Add syscore ops for suspend Nick Hu
@ 2023-08-16 12:33 ` Conor Dooley
  2023-08-17  7:15   ` Nick Hu
  0 siblings, 1 reply; 3+ messages in thread
From: Conor Dooley @ 2023-08-16 12:33 UTC (permalink / raw)
  To: Nick Hu
  Cc: paul.walmsley, palmer, aou, ajones, mason.huo, jeeheng.sia,
	linux-riscv, linux-kernel, Andy Chiu

[-- Attachment #1: Type: text/plain, Size: 799 bytes --]

On Wed, Aug 16, 2023 at 11:40:09AM +0800, Nick Hu wrote:
> Save and restore the FPU and vector states when system suspend. If a
> task is the one who performs the suspend flow and it also do some
> floating or vector operations before the suspend, we should save and
> restore the FPU states and vector states for this task.
> 
> Signed-off-by: Nick Hu <nick.hu@sifive.com>

> Signed-off-by: Andy Chiu <andy.chiu@sifive.com>

What was Andy's contribution to the patch?
Are you missing a co-developed-by tag?

Also, I'm a bit confused by the commit message due to a lack of
knowledge here - is this a fix or a new feature?
It reads as if things are not being saved/restored correctly, but
there's no "fix" related keywords in the commit message nor a Fixes:
tag.

Thanks,
Conor.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH] riscv: suspend: Add syscore ops for suspend
  2023-08-16 12:33 ` Conor Dooley
@ 2023-08-17  7:15   ` Nick Hu
  0 siblings, 0 replies; 3+ messages in thread
From: Nick Hu @ 2023-08-17  7:15 UTC (permalink / raw)
  To: Conor Dooley
  Cc: paul.walmsley, palmer, aou, ajones, mason.huo, jeeheng.sia,
	linux-riscv, linux-kernel, Andy Chiu

Hi Conor

On Wed, Aug 16, 2023 at 8:34 PM Conor Dooley <conor.dooley@microchip.com> wrote:
>
> On Wed, Aug 16, 2023 at 11:40:09AM +0800, Nick Hu wrote:
> > Save and restore the FPU and vector states when system suspend. If a
> > task is the one who performs the suspend flow and it also do some
> > floating or vector operations before the suspend, we should save and
> > restore the FPU states and vector states for this task.
> >
> > Signed-off-by: Nick Hu <nick.hu@sifive.com>
>
> > Signed-off-by: Andy Chiu <andy.chiu@sifive.com>
>
> What was Andy's contribution to the patch?
> Are you missing a co-developed-by tag?
>
He fixed something related to vector.
I'll add co-developed-by in the next version.

> Also, I'm a bit confused by the commit message due to a lack of
> knowledge here - is this a fix or a new feature?
> It reads as if things are not being saved/restored correctly, but
> there's no "fix" related keywords in the commit message nor a Fixes:
> tag.
>
> Thanks,
> Conor.
I'll rephrase the commit message.
Thanks for the feedback.

Thanks,
Nick

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

end of thread, other threads:[~2023-08-17  7:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-16  3:40 [PATCH] riscv: suspend: Add syscore ops for suspend Nick Hu
2023-08-16 12:33 ` Conor Dooley
2023-08-17  7:15   ` Nick Hu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).