Skip to contentSkip to conversation

PM: sleep: Allow disabling DPM watchdog by default

PATCH In review Tzung-Bi Shih 3 participants 6 messages May 28 – Jun 2

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM: sleep: Allow disabling DPM watchdog by default

Introduce the CONFIG_DPM_WATCHDOG_DEFAULT_ENABLED Kconfig option to allow the device suspend/resume watchdog (DPM watchdog) to be disabled by default at compile time.

Additionally, introduce the "dpm_watchdog_enabled" boot parameter to enable or disable the watchdog at boot time.

This provides flexibility for systems that want the watchdog code compiled in but inactive by default, allowing it to be enabled only when needed.

---
 .../admin-guide/kernel-parameters.txt         |  8 ++++++++
 drivers/base/power/main.c                     | 20 +++++++++++++++++++
 kernel/power/Kconfig                          |  9 +++++++++
 3 files changed, 37 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +8 -0
index 85936e48cf9a..3a919e660137 100644
@@ -1344,6 +1344,14 @@ Kernel parameters
 			it becomes active and is searched during signature
 			verification.
 
+	dpm_watchdog_enabled=
+			[KNL] Enable or disable the device suspend/resume
+			watchdog (DPM watchdog).
+			Format: {"0" | "1"}
+			0: disable
+			1: enable
+			Default value is set by CONFIG_DPM_WATCHDOG_DEFAULT_ENABLED.
+
 	driver_async_probe=  [KNL]
 			List of driver names to be probed asynchronously. *
 			matches with all driver names. If * is specified, the
drivers/base/power/main.c +20 -0
index e1b550664bab..4f92905f3edf 100644
@@ -527,6 +527,20 @@ module_param(dpm_watchdog_all_cpu_backtrace, bool, 0644);
 MODULE_PARM_DESC(dpm_watchdog_all_cpu_backtrace,
 		 "Backtrace all CPUs on DPM watchdog timeout");
 
+#ifdef CONFIG_DPM_WATCHDOG_DEFAULT_ENABLED
+static unsigned int __read_mostly dpm_watchdog_enabled = 1;
+#else
+static unsigned int __read_mostly dpm_watchdog_enabled;
+#endif
+
+static int __init dpm_watchdog_setup(char *str)
+{
+	if (kstrtouint(str, 0, &dpm_watchdog_enabled) == 0)
+		return 1;
+	return 0;
+}
+__setup("dpm_watchdog_enabled=", dpm_watchdog_setup);
+
 /**
  * dpm_watchdog_handler - Driver suspend / resume watchdog handler.
  * @t: The timer that PM watchdog depends on.
@@ -570,6 +584,9 @@ static void dpm_watchdog_set(struct dpm_watchdog *wd, struct device *dev)
 {
 	struct timer_list *timer = &wd->timer;
 
+	if (!dpm_watchdog_enabled)
+		return;
+
 	wd->dev = dev;
 	wd->tsk = current;
 	wd->fatal = CONFIG_DPM_WATCHDOG_TIMEOUT == CONFIG_DPM_WATCHDOG_WARNING_TIMEOUT;
@@ -588,6 +605,9 @@ static void dpm_watchdog_clear(struct dpm_watchdog *wd)
 {
 	struct timer_list *timer = &wd->timer;
 
+	if (!dpm_watchdog_enabled)
+		return;
+
 	timer_delete_sync(timer);
 	timer_destroy_on_stack(timer);
 }
kernel/power/Kconfig +9 -0
index 05337f437cca..d4cecdb8575e 100644
@@ -267,6 +267,15 @@ config DPM_WATCHDOG
 	  captured in pstore device for inspection in subsequent
 	  boot session.
 
+config DPM_WATCHDOG_DEFAULT_ENABLED
+	bool "Enable DPM watchdog by default"
+	depends on DPM_WATCHDOG
+	default y
+	help
+	  If you say Y here, the DPM watchdog will be enabled by default.
+	  If you say N, it will be compiled in but disabled, requiring a
+	  boot parameter to activate.
+
 config DPM_WATCHDOG_TIMEOUT
 	int "Watchdog timeout to panic in seconds"
 	range 1 120
Signature · 1 line
2.54.0.929.g9b7fa37559-goog
#1 lore raw
Quoted 49 lines · Tzung-Bi Shih

Introduce the CONFIG_DPM_WATCHDOG_DEFAULT_ENABLED Kconfig option to allow the device suspend/resume watchdog (DPM watchdog) to be disabled by default at compile time.

Additionally, introduce the "dpm_watchdog_enabled" boot parameter to enable or disable the watchdog at boot time.

This provides flexibility for systems that want the watchdog code compiled in but inactive by default, allowing it to be enabled only when needed.

---
 .../admin-guide/kernel-parameters.txt         |  8 ++++++++
 drivers/base/power/main.c                     | 20 +++++++++++++++++++
 kernel/power/Kconfig                          |  9 +++++++++
 3 files changed, 37 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +8 -0
index 85936e48cf9a..3a919e660137 100644
@@ -1344,6 +1344,14 @@ Kernel parameters
                        it becomes active and is searched during signature
                        verification.
 
+       dpm_watchdog_enabled=
+                       [KNL] Enable or disable the device suspend/resume
+                       watchdog (DPM watchdog).
+                       Format: {"0" | "1"}
+                       0: disable
+                       1: enable
+                       Default value is set by CONFIG_DPM_WATCHDOG_DEFAULT_ENABLED.
+
        driver_async_probe=  [KNL]
                        List of driver names to be probed asynchronously. *
                        matches with all driver names. If * is specified, the
drivers/base/power/main.c +3 -0
index e1b550664bab..4f92905f3edf 100644
@@ -527,6 +527,20 @@ module_param(dpm_watchdog_all_cpu_backtrace, bool, 0644);
 MODULE_PARM_DESC(dpm_watchdog_all_cpu_backtrace,
                 "Backtrace all CPUs on DPM watchdog timeout");
 
+#ifdef CONFIG_DPM_WATCHDOG_DEFAULT_ENABLED
+static unsigned int __read_mostly dpm_watchdog_enabled = 1;
+#else

drivers/base/power/main.c module_param(dpm_watchdog_all_cpu_backtrace, bool, 0644); · line 542

Quoted 10 lines
drivers/base/power/main.c +10 -0
+static unsigned int __read_mostly dpm_watchdog_enabled;
+#endif
+
+static int __init dpm_watchdog_setup(char *str)
+{
+       if (kstrtouint(str, 0, &dpm_watchdog_enabled) == 0)
+               return 1;
+       return 0;
+}
+__setup("dpm_watchdog_enabled=", dpm_watchdog_setup);

You might as well use a module parameter to allow this to be set or clear at run time. Is there a particular reason why you only want it to be enabled or disabled via the kernel command line?

Quoted 47 lines
drivers/base/power/main.c +7 -0
+
 /**
  * dpm_watchdog_handler - Driver suspend / resume watchdog handler.
  * @t: The timer that PM watchdog depends on.
@@ -570,6 +584,9 @@ static void dpm_watchdog_set(struct dpm_watchdog *wd, struct device *dev)
 {
        struct timer_list *timer = &wd->timer;
 
+       if (!dpm_watchdog_enabled)
+               return;
+
        wd->dev = dev;
        wd->tsk = current;
        wd->fatal = CONFIG_DPM_WATCHDOG_TIMEOUT == CONFIG_DPM_WATCHDOG_WARNING_TIMEOUT;
@@ -588,6 +605,9 @@ static void dpm_watchdog_clear(struct dpm_watchdog *wd)
 {
        struct timer_list *timer = &wd->timer;
 
+       if (!dpm_watchdog_enabled)
+               return;
+
        timer_delete_sync(timer);
        timer_destroy_on_stack(timer);
 }
kernel/power/Kconfig +9 -1
index 05337f437cca..d4cecdb8575e 100644
@@ -267,6 +267,15 @@ config DPM_WATCHDOG
          captured in pstore device for inspection in subsequent
          boot session.
 
+config DPM_WATCHDOG_DEFAULT_ENABLED
+       bool "Enable DPM watchdog by default"
+       depends on DPM_WATCHDOG
+       default y
+       help
+         If you say Y here, the DPM watchdog will be enabled by default.
+         If you say N, it will be compiled in but disabled, requiring a
+         boot parameter to activate.
+
 config DPM_WATCHDOG_TIMEOUT
        int "Watchdog timeout to panic in seconds"
        range 1 120
--

2.54.0.929.g9b7fa37559-goog

#2 lore raw
Quoted 18 lines · Rafael J. Wysocki
Quoted 17 lines · Tzung-Bi Shih
drivers/base/power/main.c +9 -0
index e1b550664bab..4f92905f3edf 100644
@@ -527,6 +527,20 @@ module_param(dpm_watchdog_all_cpu_backtrace, bool, 0644);
 MODULE_PARM_DESC(dpm_watchdog_all_cpu_backtrace,
                 "Backtrace all CPUs on DPM watchdog timeout");
 
+#ifdef CONFIG_DPM_WATCHDOG_DEFAULT_ENABLED
+static unsigned int __read_mostly dpm_watchdog_enabled = 1;
+#else
+static unsigned int __read_mostly dpm_watchdog_enabled;
+#endif
+
+static int __init dpm_watchdog_setup(char *str)
+{
+       if (kstrtouint(str, 0, &dpm_watchdog_enabled) == 0)
Quoted 8 lines

drivers/base/power/main.c module_param(dpm_watchdog_all_cpu_backtrace, bool, 0644); · line 542

Quoted 4 lines
drivers/base/power/main.c +4 -0
+               return 1;
+       return 0;
+}
+__setup("dpm_watchdog_enabled=", dpm_watchdog_setup);

You might as well use a module parameter to allow this to be set or clear at run time. Is there a particular reason why you only want it to be enabled or disabled via the kernel command line?

Thanks for the suggestion. Mainly because in our use cases, we only need to set it once at boot time.

Also, I was wondering if we need to consider potential races if the flag can be set at runtime. E.g.:
1) The flag is set.
2) dpm_watchdog_set() is called and the timer is started.
3) The flag is then unset.
4) The subsequent dpm_watchdog_clear() isn't stop the timer.

Given this, would you still suggest providing the module parameter for completeness?

Quoted 25 lines
Quoted 25 lines
drivers/base/power/main.c +7 -0
+
 /**
  * dpm_watchdog_handler - Driver suspend / resume watchdog handler.
  * @t: The timer that PM watchdog depends on.
@@ -570,6 +584,9 @@ static void dpm_watchdog_set(struct dpm_watchdog *wd, struct device *dev)
 {
        struct timer_list *timer = &wd->timer;
 
+       if (!dpm_watchdog_enabled)
+               return;
+
        wd->dev = dev;
        wd->tsk = current;
        wd->fatal = CONFIG_DPM_WATCHDOG_TIMEOUT == CONFIG_DPM_WATCHDOG_WARNING_TIMEOUT;
@@ -588,6 +605,9 @@ static void dpm_watchdog_clear(struct dpm_watchdog *wd)
 {
        struct timer_list *timer = &wd->timer;
 
+       if (!dpm_watchdog_enabled)
+               return;
+
        timer_delete_sync(timer);
        timer_destroy_on_stack(timer);
 }
#3 lore raw
Quoted 39 lines · Tzung-Bi Shih
Quoted 18 lines · Rafael J. Wysocki
Quoted 17 lines · Tzung-Bi Shih
drivers/base/power/main.c +9 -0
index e1b550664bab..4f92905f3edf 100644
@@ -527,6 +527,20 @@ module_param(dpm_watchdog_all_cpu_backtrace, bool, 0644);
 MODULE_PARM_DESC(dpm_watchdog_all_cpu_backtrace,
                 "Backtrace all CPUs on DPM watchdog timeout");
 
+#ifdef CONFIG_DPM_WATCHDOG_DEFAULT_ENABLED
+static unsigned int __read_mostly dpm_watchdog_enabled = 1;
+#else
+static unsigned int __read_mostly dpm_watchdog_enabled;
+#endif
+
+static int __init dpm_watchdog_setup(char *str)
+{
+       if (kstrtouint(str, 0, &dpm_watchdog_enabled) == 0)
Quoted 8 lines

drivers/base/power/main.c module_param(dpm_watchdog_all_cpu_backtrace, bool, 0644); · line 542

Quoted 4 lines
drivers/base/power/main.c +4 -0
+               return 1;
+       return 0;
+}
+__setup("dpm_watchdog_enabled=", dpm_watchdog_setup);

You might as well use a module parameter to allow this to be set or clear at run time. Is there a particular reason why you only want it to be enabled or disabled via the kernel command line?

Thanks for the suggestion. Mainly because in our use cases, we only need to set it once at boot time.

Also, I was wondering if we need to consider potential races if the flag can be set at runtime. E.g.:
1) The flag is set.
2) dpm_watchdog_set() is called and the timer is started.
3) The flag is then unset.
4) The subsequent dpm_watchdog_clear() isn't stop the timer.

Quoted 2 lines

Given this, would you still suggest providing the module parameter for completeness?

Would that lead to anything bad, though? If I'm remembering correctly, would that mean that any already ongoing PM operations would still be subject to the timer, but not any new ones.

My suggestion would also be to actually make the timeout and warning timeout configurable at runtime.

Best,
Tomasz

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
drivers/base/power/main.c +7 -0
+
 /**
  * dpm_watchdog_handler - Driver suspend / resume watchdog handler.
  * @t: The timer that PM watchdog depends on.
@@ -570,6 +584,9 @@ static void dpm_watchdog_set(struct dpm_watchdog *wd, struct device *dev)
 {
        struct timer_list *timer = &wd->timer;
 
+       if (!dpm_watchdog_enabled)
+               return;
+
        wd->dev = dev;
        wd->tsk = current;
        wd->fatal = CONFIG_DPM_WATCHDOG_TIMEOUT == CONFIG_DPM_WATCHDOG_WARNING_TIMEOUT;
@@ -588,6 +605,9 @@ static void dpm_watchdog_clear(struct dpm_watchdog *wd)
 {
        struct timer_list *timer = &wd->timer;
 
+       if (!dpm_watchdog_enabled)
+               return;
+
        timer_delete_sync(timer);
        timer_destroy_on_stack(timer);
 }
#4 lore raw
Quoted 40 lines · Tomasz Figa
Quoted 39 lines · Tzung-Bi Shih
Quoted 18 lines · Rafael J. Wysocki
Quoted 17 lines · Tzung-Bi Shih
drivers/base/power/main.c +9 -0
index e1b550664bab..4f92905f3edf 100644
@@ -527,6 +527,20 @@ module_param(dpm_watchdog_all_cpu_backtrace, bool, 0644);
 MODULE_PARM_DESC(dpm_watchdog_all_cpu_backtrace,
                 "Backtrace all CPUs on DPM watchdog timeout");
 
+#ifdef CONFIG_DPM_WATCHDOG_DEFAULT_ENABLED
+static unsigned int __read_mostly dpm_watchdog_enabled = 1;
+#else
+static unsigned int __read_mostly dpm_watchdog_enabled;
+#endif
+
+static int __init dpm_watchdog_setup(char *str)
+{
+       if (kstrtouint(str, 0, &dpm_watchdog_enabled) == 0)
Quoted 8 lines

drivers/base/power/main.c module_param(dpm_watchdog_all_cpu_backtrace, bool, 0644); · line 542

Quoted 4 lines
drivers/base/power/main.c +4 -0
+               return 1;
+       return 0;
+}
+__setup("dpm_watchdog_enabled=", dpm_watchdog_setup);

You might as well use a module parameter to allow this to be set or clear at run time. Is there a particular reason why you only want it to be enabled or disabled via the kernel command line?

Thanks for the suggestion. Mainly because in our use cases, we only need to set it once at boot time.

Also, I was wondering if we need to consider potential races if the flag can be set at runtime. E.g.:
1) The flag is set.
2) dpm_watchdog_set() is called and the timer is started.
3) The flag is then unset.
4) The subsequent dpm_watchdog_clear() isn't stop the timer.

Quoted 6 lines
Quoted 2 lines

Given this, would you still suggest providing the module parameter for completeness?

Would that lead to anything bad, though? If I'm remembering correctly, would that mean that any already ongoing PM operations would still be subject to the timer, but not any new ones.

I was overthinking the race. All userspace programs should be frozen when the DPM watchdog is active. The race I was concerned about isn't possible.

Would you still suggest providing the module parameter for completeness?

Quoted 3 lines

My suggestion would also be to actually make the timeout and warning timeout configurable at runtime.

I'm working on that and I think that should be in a separate patch.

#5 lore raw
Quoted 45 lines · Tzung-Bi Shih
Quoted 43 lines · Tomasz Figa
Quoted 41 lines · Tzung-Bi Shih
Quoted 18 lines · Rafael J. Wysocki
Quoted 17 lines · Tzung-Bi Shih
drivers/base/power/main.c +9 -0
index e1b550664bab..4f92905f3edf 100644
@@ -527,6 +527,20 @@ module_param(dpm_watchdog_all_cpu_backtrace, bool, 0644);
 MODULE_PARM_DESC(dpm_watchdog_all_cpu_backtrace,
                 "Backtrace all CPUs on DPM watchdog timeout");
 
+#ifdef CONFIG_DPM_WATCHDOG_DEFAULT_ENABLED
+static unsigned int __read_mostly dpm_watchdog_enabled = 1;
+#else
+static unsigned int __read_mostly dpm_watchdog_enabled;
+#endif
+
+static int __init dpm_watchdog_setup(char *str)
+{
+       if (kstrtouint(str, 0, &dpm_watchdog_enabled) == 0)
Quoted 8 lines

drivers/base/power/main.c module_param(dpm_watchdog_all_cpu_backtrace, bool, 0644); · line 542

Quoted 4 lines
drivers/base/power/main.c +4 -0
+               return 1;
+       return 0;
+}
+__setup("dpm_watchdog_enabled=", dpm_watchdog_setup);

You might as well use a module parameter to allow this to be set or clear at run time. Is there a particular reason why you only want it to be enabled or disabled via the kernel command line?

Thanks for the suggestion. Mainly because in our use cases, we only need to set it once at boot time.

Also, I was wondering if we need to consider potential races if the flag can be set at runtime. E.g.:
1) The flag is set.
2) dpm_watchdog_set() is called and the timer is started.
3) The flag is then unset.
4) The subsequent dpm_watchdog_clear() isn't stop the timer.

Given this, would you still suggest providing the module parameter for completeness?

Quoted 6 lines
Quoted 3 lines

Would that lead to anything bad, though? If I'm remembering correctly, would that mean that any already ongoing PM operations would still be subject to the timer, but not any new ones.

I was overthinking the race. All userspace programs should be frozen when the DPM watchdog is active. The race I was concerned about isn't possible.

Right. Somehow I was convinced that the DPM watchdog is also used for runtime PM, but after checking the code it doesn't look like so.

Quoted 2 lines

Would you still suggest providing the module parameter for completeness?

I'd also vote for a module parameter. Being able to toggle this at runtime would be useful for troubleshooting problems without needing to change the command line arguments (which isn't trivial on some systems).

Quoted 6 lines
Quoted 4 lines

My suggestion would also be to actually make the timeout and warning timeout configurable at runtime.

I'm working on that and I think that should be in a separate patch.

Great, thanks. I'll leave the splitting and other logistics to the maintainers.

Best,
Tomasz