riscv: suspend: Add syscore ops for suspend
PATCH v2 1/1 riscv: suspend: Add syscore ops for 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 might lose the FPU and vector states when it goes to the non-retention system suspend state. Add syscore ops to save and restore the FPU and vector states of the current task to fix the issue above.
---
Changes in v2:
a) Add Co-developed-by and adjust the order of signed-off
b) Rephrase the commit message
arch/riscv/kernel/suspend.c | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
arch/riscv/kernel/suspend.c +45 -0
@@ -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 · 1 line
2.34.1
Quoted 6 lines · Nick Hu
If a task is the one who performs the suspend flow and it also do some floating or vector operations before the suspend, we might lose the FPU and vector states when it goes to the non-retention system suspend state. Add syscore ops to save and restore the FPU and vector states of the current task to fix the issue above.
This only applies to non-retentive system suspend so why do we need this before SBI system suspend is merged ?
Regards,
Anup
Quoted 78 lines
Co-developed-by Andy Chiu <[email protected]>Signed-off-by Andy Chiu <[email protected]>Signed-off-by Nick Hu <[email protected]>---
Changes in v2:
a) Add Co-developed-by and adjust the order of signed-off
b) Rephrase the commit messagearch/riscv/kernel/suspend.c | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)arch/riscv/kernel/suspend.c +45
-1@@ -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
Hi Anup
Quoted 9 lines · Anup Patel
Quoted 6 lines · Nick Hu
If a task is the one who performs the suspend flow and it also do some floating or vector operations before the suspend, we might lose the FPU and vector states when it goes to the non-retention system suspend state. Add syscore ops to save and restore the FPU and vector states of the current task to fix the issue above.
Quoted 7 lines
This only applies to non-retentive system suspend so why do we need this before SBI system suspend is merged ?
Regards,
Anup
How about hibernation?
Regards,
Nick
Quoted 70 lines
Quoted 70 lines
Co-developed-by Andy Chiu <[email protected]>Signed-off-by Andy Chiu <[email protected]>Signed-off-by Nick Hu <[email protected]>---
Changes in v2:
a) Add Co-developed-by and adjust the order of signed-off
b) Rephrase the commit messagearch/riscv/kernel/suspend.c | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)arch/riscv/kernel/suspend.c +40
-0@@ -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 )
Quoted 8 lines
Quoted 8 lines
arch/riscv/kernel/suspend.c +5
-1+{ +register_syscore_ops (&riscv_cpu_syscore_ops); +return 0 ; +} +arch_initcall (riscv_cpu_suspend_init); --2.34.1
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 14 lines · Nick Hu
Hi Anup
Quoted 9 lines · Anup Patel
Quoted 6 lines · Nick Hu
If a task is the one who performs the suspend flow and it also do some floating or vector operations before the suspend, we might lose the FPU and vector states when it goes to the non-retention system suspend state. Add syscore ops to save and restore the FPU and vector states of the current task to fix the issue above.
Quoted 8 lines
Quoted 7 lines
This only applies to non-retentive system suspend so why do we need this before SBI system suspend is merged ?
Regards,
AnupHow about hibernation?
If this is for hibernation then the commit description should say so.
Adding syscore_ops would mean these callbacks will be called for both suspend-to-ram and hibernate cases. Other architectures don't have this save/restore for suspend-to-ram because it is generally called from idle task.
Why not do the save/restore in save_processor_state() and restore_processor_state() just like arch/mips/power/cpu.c ?
Regards,
Anup
Quoted 81 lines
Regards,
NickQuoted 78 lines
Quoted 78 lines
Co-developed-by Andy Chiu <[email protected]>Signed-off-by Andy Chiu <[email protected]>Signed-off-by Nick Hu <[email protected]>---
Changes in v2:
a) Add Co-developed-by and adjust the order of signed-off
b) Rephrase the commit messagearch/riscv/kernel/suspend.c | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)arch/riscv/kernel/suspend.c +45
-1@@ -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
Hi Anup
Thanks for your feedbacks
Quoted 19 lines · Anup Patel
Quoted 17 lines · Nick Hu
Hi Anup
Quoted 12 lines · Anup Patel
Quoted 6 lines · Nick Hu
If a task is the one who performs the suspend flow and it also do some floating or vector operations before the suspend, we might lose the FPU and vector states when it goes to the non-retention system suspend state. Add syscore ops to save and restore the FPU and vector states of the current task to fix the issue above.
This only applies to non-retentive system suspend so why do we need this before SBI system suspend is merged ?
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Regards,
AnupHow about hibernation?
If this is for hibernation then the commit description should say so.
Actually this commit is for the suspend-to-ram. I ask about hibernation here because I think hibernation may also have the same issue too.
If hibernation doesn't need it, I can defer this patch until we have system suspend.
I send this patch because I believe we will support system suspend in the kernel soon or later and the hibernation might need it now.
Quoted 5 lines
Adding
syscore_opswould mean these callbacks will be called for both suspend-to-ram and hibernate cases. Other architectures don't have this save/restore for suspend-to-ram because it is generally called from idle task.
Do you think we don't have to consider the case in the patch?
Regards,
Nick
Quoted 88 lines
Why not do the save/restore in
save_processor_state()andrestore_processor_state()just likearch/mips/power/cpu.c?Regards,
AnupQuoted 81 lines
Regards,
NickQuoted 78 lines
Quoted 78 lines
Co-developed-by Andy Chiu <[email protected]>Signed-off-by Andy Chiu <[email protected]>Signed-off-by Nick Hu <[email protected]>---
Changes in v2:
a) Add Co-developed-by and adjust the order of signed-off
b) Rephrase the commit messagearch/riscv/kernel/suspend.c | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)arch/riscv/kernel/suspend.c +45
-1@@ -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
Quoted 32 lines · Nick Hu
Hi Anup
Thanks for your feedbacks
Quoted 19 lines · Anup Patel
Quoted 17 lines · Nick Hu
Hi Anup
Quoted 12 lines · Anup Patel
Quoted 6 lines · Nick Hu
If a task is the one who performs the suspend flow and it also do some floating or vector operations before the suspend, we might lose the FPU and vector states when it goes to the non-retention system suspend state. Add syscore ops to save and restore the FPU and vector states of the current task to fix the issue above.
This only applies to non-retentive system suspend so why do we need this before SBI system suspend is merged ?
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Regards,
AnupHow about hibernation?
If this is for hibernation then the commit description should say so.
Quoted 7 lines
Actually this commit is for the suspend-to-ram. I ask about hibernation here because I think hibernation may also have the same issue too.
If hibernation doesn't need it, I can defer this patch until we have system suspend.
I send this patch because I believe we will support system suspend in the kernel soon or later and the hibernation might need it now.
Okay, understood.
Quoted 7 lines
Quoted 6 lines
Adding
syscore_opswould mean these callbacks will be called for both suspend-to-ram and hibernate cases. Other architectures don't have this save/restore for suspend-to-ram because it is generally called from idle task.Do you think we don't have to consider the case in the patch?
I was comparing other architectures but I did not find any explicit saving of FP state for suspend-to-ram. Although, I did find explicit FP save for hibernate.
Functionally, it is fine to always save FP state for suspend-to-ram but I am wondering if this redundant work in suspend-to-ram path.
Regards,
Anup
Quoted 91 lines
Regards,
NickQuoted 88 lines
Why not do the save/restore in
save_processor_state()andrestore_processor_state()just likearch/mips/power/cpu.c?Regards,
AnupQuoted 81 lines
Regards,
NickQuoted 78 lines
Quoted 78 lines
Co-developed-by Andy Chiu <[email protected]>Signed-off-by Andy Chiu <[email protected]>Signed-off-by Nick Hu <[email protected]>---
Changes in v2:
a) Add Co-developed-by and adjust the order of signed-off
b) Rephrase the commit messagearch/riscv/kernel/suspend.c | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)arch/riscv/kernel/suspend.c +45
-1@@ -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
Hi Anup
Quoted 50 lines · Anup Patel
Quoted 32 lines · Nick Hu
Hi Anup
Thanks for your feedbacks
Quoted 19 lines · Anup Patel
Quoted 17 lines · Nick Hu
Hi Anup
Quoted 12 lines · Anup Patel
Quoted 6 lines · Nick Hu
If a task is the one who performs the suspend flow and it also do some floating or vector operations before the suspend, we might lose the FPU and vector states when it goes to the non-retention system suspend state. Add syscore ops to save and restore the FPU and vector states of the current task to fix the issue above.
This only applies to non-retentive system suspend so why do we need this before SBI system suspend is merged ?
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Regards,
AnupHow about hibernation?
If this is for hibernation then the commit description should say so.
Quoted 7 lines
Actually this commit is for the suspend-to-ram. I ask about hibernation here because I think hibernation may also have the same issue too.
If hibernation doesn't need it, I can defer this patch until we have system suspend.
I send this patch because I believe we will support system suspend in the kernel soon or later and the hibernation might need it now.Okay, understood.
Quoted 6 lines
Quoted 6 lines
Adding
syscore_opswould mean these callbacks will be called for both suspend-to-ram and hibernate cases. Other architectures don't have this save/restore for suspend-to-ram because it is generally called from idle task.
Quoted 9 lines
Quoted 1 line
Do you think we don't have to consider the case in the patch?
I was comparing other architectures but I did not find any explicit saving of FP state for suspend-to-ram. Although, I did find explicit FP save for hibernate.
Functionally, it is fine to always save FP state for suspend-to-ram but I am wondering if this redundant work in suspend-to-ram path.
Perhaps you are right. If no one would do the suspend-to-ram/hibernation during the FPU/VECTOR calculation in the same process, it may not be a practical case.
Regards,
Nick
Quoted 86 lines
Regards,
AnupQuoted 83 lines
Regards,
NickQuoted 80 lines
Why not do the save/restore in
save_processor_state()andrestore_processor_state()just likearch/mips/power/cpu.c?Regards,
AnupQuoted 73 lines
Regards,
NickQuoted 70 lines
Quoted 70 lines
Co-developed-by Andy Chiu <[email protected]>Signed-off-by Andy Chiu <[email protected]>Signed-off-by Nick Hu <[email protected]>---
Changes in v2:
a) Add Co-developed-by and adjust the order of signed-off
b) Rephrase the commit messagearch/riscv/kernel/suspend.c | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)arch/riscv/kernel/suspend.c +40
-0@@ -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 )
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
arch/riscv/kernel/suspend.c +5
-1+{ +register_syscore_ops (&riscv_cpu_syscore_ops); +return 0 ; +} +arch_initcall (riscv_cpu_suspend_init); --2.34.1
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Nick,
kernel test robot noticed the following build warnings:
[auto build test WARNING on linus/master]
[also build test WARNING on v6.5-rc7 next-20230822]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Nick-Hu/riscv-suspend-Add-syscore-ops-for-suspend/20230822-135024 base: linus/master patch link: https://lore.kernel.org/r/20230822054739.33552-1-nick.hu%40sifive.com patch subject: [PATCH v2] riscv: suspend: Add syscore ops for suspend config: riscv-randconfig-r121-20230822 (https://download.01.org/0day-ci/archive/20230823/[email protected]/config) compiler: riscv64-linux-gcc (GCC) 13.2.0 reproduce: (https://download.01.org/0day-ci/archive/20230823/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
arch/riscv/kernel/suspend.c: In function 'riscv_cpu_resume':
>> arch/riscv/kernel/suspend.c:114:25: warning: unused variable 'regs' [-Wunused-variable]
114 | struct pt_regs *regs = task_pt_regs(cur_task);
| ^~~~vim +/regs +114 arch/riscv/kernel/suspend.c
110
111 static void riscv_cpu_resume(void)
112 {
113 struct task_struct *cur_task = get_current();
> 114 struct pt_regs *regs = task_pt_regs(cur_task);
115
116 if (has_fpu())
117 fstate_restore(cur_task, regs);
118 if (has_vector())
119 riscv_v_vstate_restore(cur_task, regs);
120 }
121
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki