Skip to contentSkip to conversation

riscv: suspend: Add syscore ops for suspend

PATCH Superseded Nick Hu 2 participants 3 messages Aug 16, 2023 – Aug 17, 2023 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Nick Hu

author
#0 lore raw

PATCH 1/1 riscv: suspend: Add syscore ops for suspend

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.

---
 arch/riscv/kernel/suspend.c | 45 +++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
arch/riscv/kernel/suspend.c +45 -0
index 3c89b8ec69c4..ff69ff8a1974 100644
@@ -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);
Signature · 7 lines
2.34.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#1 lore raw
Quoted 8 lines · Nick Hu

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.

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.

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

author
#2 lore raw

Hi Conor

Quoted 7 lines · Conor Dooley
Quoted 5 lines · Nick Hu

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.

Quoted 7 lines
Quoted 3 lines

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.

Quoted 8 lines

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

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