[PATCH v2] PM / sleep: add configurable delay for pm_test

Zihuan Zhang posted 1 patch 7 months, 1 week ago
There is a newer version of this series
Documentation/admin-guide/kernel-parameters.txt | 7 +++++++
kernel/power/hibernate.c                        | 9 +++++++--
2 files changed, 14 insertions(+), 2 deletions(-)
[PATCH v2] PM / sleep: add configurable delay for pm_test
Posted by Zihuan Zhang 7 months, 1 week ago
This patch turns this 5 second delay into a configurable module
parameter, so users can determine how long to wait in this
pseudo-hibernate state before resuming the system.

The configurable delay parameter has been added to suspend and
synchronized to hibernation.

Example (wait 30 seconds);

  # echo 30 > /sys/module/hibernate/parameters/pm_test_delay
  # echo core > /sys/power/pm_test

Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn>
---
v2:
 - Fix typos.
---
 Documentation/admin-guide/kernel-parameters.txt | 7 +++++++
 kernel/power/hibernate.c                        | 9 +++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index d9fd26b95b34..1532c6fdc2d1 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -6998,6 +6998,13 @@
 			/sys/power/pm_test). Only available when CONFIG_PM_DEBUG
 			is set. Default value is 5.
 
+	hibernate.pm_test_delay=
+			[hibernate]
+			Sets the number of seconds to remain in a hibernation test
+			mode before resuming the system (see
+			/sys/power/pm_test). Only available when CONFIG_PM_DEBUG
+			is set. Default value is 5.
+
 	svm=		[PPC]
 			Format: { on | off | y | n | 1 | 0 }
 			This parameter controls use of the Protected
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 23c0f4e6cb2f..485133af884d 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -133,10 +133,15 @@ bool system_entering_hibernation(void)
 EXPORT_SYMBOL(system_entering_hibernation);
 
 #ifdef CONFIG_PM_DEBUG
+static unsigned int pm_test_delay = 5;
+module_param(pm_test_delay, uint, 0644);
+MODULE_PARM_DESC(pm_test_delay,
+		 "Number of seconds to wait before resuming from hibernation test");
 static void hibernation_debug_sleep(void)
 {
-	pr_info("debug: Waiting for 5 seconds.\n");
-	mdelay(5000);
+	pr_info("hibernation debug: Waiting for %d second(s).\n",
+		pm_test_delay);
+	mdelay(pm_test_delay * 1000);
 }
 
 static int hibernation_test(int level)
-- 
2.25.1
Re: [PATCH v2] PM / sleep: add configurable delay for pm_test
Posted by Randy Dunlap 7 months, 1 week ago
Hi--

On 5/6/25 8:44 PM, Zihuan Zhang wrote:
> This patch turns this 5 second delay into a configurable module
> parameter, so users can determine how long to wait in this
> pseudo-hibernate state before resuming the system.
> 
> The configurable delay parameter has been added to suspend and
> synchronized to hibernation.
> 
> Example (wait 30 seconds);
> 
>   # echo 30 > /sys/module/hibernate/parameters/pm_test_delay
>   # echo core > /sys/power/pm_test
> 
> Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn>
> ---
> v2:
>  - Fix typos.
> ---
>  Documentation/admin-guide/kernel-parameters.txt | 7 +++++++
>  kernel/power/hibernate.c                        | 9 +++++++--
>  2 files changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index d9fd26b95b34..1532c6fdc2d1 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -6998,6 +6998,13 @@
>  			/sys/power/pm_test). Only available when CONFIG_PM_DEBUG
>  			is set. Default value is 5.
>  

Please keep entries in kernel-parameters.txt in alphabetical order.

> +	hibernate.pm_test_delay=
> +			[hibernate]

	According to kernel-parameters.rst, that line above should be
			[HIBERNATION]

> +			Sets the number of seconds to remain in a hibernation test
> +			mode before resuming the system (see
> +			/sys/power/pm_test). Only available when CONFIG_PM_DEBUG
> +			is set. Default value is 5.
> +
>  	svm=		[PPC]
>  			Format: { on | off | y | n | 1 | 0 }
>  			This parameter controls use of the Protected
> diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
> index 23c0f4e6cb2f..485133af884d 100644
> --- a/kernel/power/hibernate.c
> +++ b/kernel/power/hibernate.c
> @@ -133,10 +133,15 @@ bool system_entering_hibernation(void)
>  EXPORT_SYMBOL(system_entering_hibernation);
>  
>  #ifdef CONFIG_PM_DEBUG
> +static unsigned int pm_test_delay = 5;
> +module_param(pm_test_delay, uint, 0644);
> +MODULE_PARM_DESC(pm_test_delay,
> +		 "Number of seconds to wait before resuming from hibernation test");
>  static void hibernation_debug_sleep(void)
>  {
> -	pr_info("debug: Waiting for 5 seconds.\n");
> -	mdelay(5000);
> +	pr_info("hibernation debug: Waiting for %d second(s).\n",
> +		pm_test_delay);
> +	mdelay(pm_test_delay * 1000);
>  }
>  
>  static int hibernation_test(int level)

-- 
~Randy