* [PATCH] PM / sleep: Avoid excess pm_runtime_enable() calls in device_resume()
@ 2017-12-07 2:26 Rafael J. Wysocki
2017-12-07 19:44 ` Ulf Hansson
2017-12-08 20:25 ` Bjorn Helgaas
0 siblings, 2 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2017-12-07 2:26 UTC (permalink / raw)
To: Linux PM
Cc: Linux PCI, Linux ACPI, LKML, Bjorn Helgaas, Greg Kroah-Hartman,
Ulf Hansson, Mika Westerberg
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Middle-layer code doing suspend-time optimizations for devices with
the DPM_FLAG_SMART_SUSPEND flag set (currently, the PCI bus type and
the ACPI PM domain) needs to make the core skip ->thaw_early and
->thaw callbacks for those devices in some cases and it sets the
power.direct_complete flag for them for this purpose.
However, it turns out that setting power.direct_complete outside of
the PM core is a bad idea as it triggers an excessive invocation of
pm_runtime_enable() in device_resume().
For this reason, provide a helper to clear power.is_late_suspended
and power.is_suspended to be invoked by the middle-layer code in
question instead of setting power.direct_complete and make that code
call the new helper.
Fixes: c4b65157aeef (PCI / PM: Take SMART_SUSPEND driver flag into account)
Fixes: 05087360fd7a (ACPI / PM: Take SMART_SUSPEND driver flag into account)
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/device_pm.c | 2 +-
drivers/base/power/main.c | 15 +++++++++++++++
drivers/pci/pci-driver.c | 2 +-
include/linux/pm.h | 1 +
4 files changed, 18 insertions(+), 2 deletions(-)
Index: linux-pm/include/linux/pm.h
===================================================================
--- linux-pm.orig/include/linux/pm.h
+++ linux-pm/include/linux/pm.h
@@ -765,6 +765,7 @@ extern int pm_generic_poweroff_late(stru
extern int pm_generic_poweroff(struct device *dev);
extern void pm_generic_complete(struct device *dev);
+extern void dev_pm_skip_next_resume_phases(struct device *dev);
extern bool dev_pm_smart_suspend_and_suspended(struct device *dev);
#else /* !CONFIG_PM_SLEEP */
Index: linux-pm/drivers/base/power/main.c
===================================================================
--- linux-pm.orig/drivers/base/power/main.c
+++ linux-pm/drivers/base/power/main.c
@@ -526,6 +526,21 @@ static void dpm_watchdog_clear(struct dp
/*------------------------- Resume routines -------------------------*/
/**
+ * dev_pm_skip_next_resume_phases - Skip next system resume phases for device.
+ * @dev: Target device.
+ *
+ * Make the core skip the "early resume" and "resume" phases for @dev.
+ *
+ * This function can be called by middle-layer code during the "noirq" phase of
+ * system resume if necessary, but not by device drivers.
+ */
+void dev_pm_skip_next_resume_phases(struct device *dev)
+{
+ dev->power.is_late_suspended = false;
+ dev->power.is_suspended = false;
+}
+
+/**
* device_resume_noirq - Execute a "noirq resume" callback for given device.
* @dev: Device to handle.
* @state: PM transition of the system being carried out.
Index: linux-pm/drivers/pci/pci-driver.c
===================================================================
--- linux-pm.orig/drivers/pci/pci-driver.c
+++ linux-pm/drivers/pci/pci-driver.c
@@ -999,7 +999,7 @@ static int pci_pm_thaw_noirq(struct devi
* the subsequent "thaw" callbacks for the device.
*/
if (dev_pm_smart_suspend_and_suspended(dev)) {
- dev->power.direct_complete = true;
+ dev_pm_skip_next_resume_phases(dev);
return 0;
}
Index: linux-pm/drivers/acpi/device_pm.c
===================================================================
--- linux-pm.orig/drivers/acpi/device_pm.c
+++ linux-pm/drivers/acpi/device_pm.c
@@ -1138,7 +1138,7 @@ int acpi_subsys_thaw_noirq(struct device
* skip all of the subsequent "thaw" callbacks for the device.
*/
if (dev_pm_smart_suspend_and_suspended(dev)) {
- dev->power.direct_complete = true;
+ dev_pm_skip_next_resume_phases(dev);
return 0;
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] PM / sleep: Avoid excess pm_runtime_enable() calls in device_resume()
2017-12-07 2:26 [PATCH] PM / sleep: Avoid excess pm_runtime_enable() calls in device_resume() Rafael J. Wysocki
@ 2017-12-07 19:44 ` Ulf Hansson
2017-12-07 21:17 ` Rafael J. Wysocki
2017-12-08 20:25 ` Bjorn Helgaas
1 sibling, 1 reply; 5+ messages in thread
From: Ulf Hansson @ 2017-12-07 19:44 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: Linux PM, Linux PCI, Linux ACPI, LKML, Bjorn Helgaas,
Greg Kroah-Hartman, Mika Westerberg
On 7 December 2017 at 03:26, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Middle-layer code doing suspend-time optimizations for devices with
> the DPM_FLAG_SMART_SUSPEND flag set (currently, the PCI bus type and
> the ACPI PM domain) needs to make the core skip ->thaw_early and
> ->thaw callbacks for those devices in some cases and it sets the
> power.direct_complete flag for them for this purpose.
>
> However, it turns out that setting power.direct_complete outside of
> the PM core is a bad idea as it triggers an excessive invocation of
> pm_runtime_enable() in device_resume().
Do we need to clarify the comment about the flag in pm.h?
Or is "/* Owned by the PM core */" sufficient?
>
> For this reason, provide a helper to clear power.is_late_suspended
> and power.is_suspended to be invoked by the middle-layer code in
> question instead of setting power.direct_complete and make that code
> call the new helper.
>
> Fixes: c4b65157aeef (PCI / PM: Take SMART_SUSPEND driver flag into account)
> Fixes: 05087360fd7a (ACPI / PM: Take SMART_SUSPEND driver flag into account)
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro,org>
Kind regards
Uffe
> ---
> drivers/acpi/device_pm.c | 2 +-
> drivers/base/power/main.c | 15 +++++++++++++++
> drivers/pci/pci-driver.c | 2 +-
> include/linux/pm.h | 1 +
> 4 files changed, 18 insertions(+), 2 deletions(-)
>
> Index: linux-pm/include/linux/pm.h
> ===================================================================
> --- linux-pm.orig/include/linux/pm.h
> +++ linux-pm/include/linux/pm.h
> @@ -765,6 +765,7 @@ extern int pm_generic_poweroff_late(stru
> extern int pm_generic_poweroff(struct device *dev);
> extern void pm_generic_complete(struct device *dev);
>
> +extern void dev_pm_skip_next_resume_phases(struct device *dev);
> extern bool dev_pm_smart_suspend_and_suspended(struct device *dev);
>
> #else /* !CONFIG_PM_SLEEP */
> Index: linux-pm/drivers/base/power/main.c
> ===================================================================
> --- linux-pm.orig/drivers/base/power/main.c
> +++ linux-pm/drivers/base/power/main.c
> @@ -526,6 +526,21 @@ static void dpm_watchdog_clear(struct dp
> /*------------------------- Resume routines -------------------------*/
>
> /**
> + * dev_pm_skip_next_resume_phases - Skip next system resume phases for device.
> + * @dev: Target device.
> + *
> + * Make the core skip the "early resume" and "resume" phases for @dev.
> + *
> + * This function can be called by middle-layer code during the "noirq" phase of
> + * system resume if necessary, but not by device drivers.
> + */
> +void dev_pm_skip_next_resume_phases(struct device *dev)
> +{
> + dev->power.is_late_suspended = false;
> + dev->power.is_suspended = false;
> +}
> +
> +/**
> * device_resume_noirq - Execute a "noirq resume" callback for given device.
> * @dev: Device to handle.
> * @state: PM transition of the system being carried out.
> Index: linux-pm/drivers/pci/pci-driver.c
> ===================================================================
> --- linux-pm.orig/drivers/pci/pci-driver.c
> +++ linux-pm/drivers/pci/pci-driver.c
> @@ -999,7 +999,7 @@ static int pci_pm_thaw_noirq(struct devi
> * the subsequent "thaw" callbacks for the device.
> */
> if (dev_pm_smart_suspend_and_suspended(dev)) {
> - dev->power.direct_complete = true;
> + dev_pm_skip_next_resume_phases(dev);
> return 0;
> }
>
> Index: linux-pm/drivers/acpi/device_pm.c
> ===================================================================
> --- linux-pm.orig/drivers/acpi/device_pm.c
> +++ linux-pm/drivers/acpi/device_pm.c
> @@ -1138,7 +1138,7 @@ int acpi_subsys_thaw_noirq(struct device
> * skip all of the subsequent "thaw" callbacks for the device.
> */
> if (dev_pm_smart_suspend_and_suspended(dev)) {
> - dev->power.direct_complete = true;
> + dev_pm_skip_next_resume_phases(dev);
> return 0;
> }
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] PM / sleep: Avoid excess pm_runtime_enable() calls in device_resume()
2017-12-07 19:44 ` Ulf Hansson
@ 2017-12-07 21:17 ` Rafael J. Wysocki
0 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2017-12-07 21:17 UTC (permalink / raw)
To: Ulf Hansson
Cc: Rafael J. Wysocki, Linux PM, Linux PCI, Linux ACPI, LKML,
Bjorn Helgaas, Greg Kroah-Hartman, Mika Westerberg
On Thu, Dec 7, 2017 at 8:44 PM, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> On 7 December 2017 at 03:26, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
>> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>
>> Middle-layer code doing suspend-time optimizations for devices with
>> the DPM_FLAG_SMART_SUSPEND flag set (currently, the PCI bus type and
>> the ACPI PM domain) needs to make the core skip ->thaw_early and
>> ->thaw callbacks for those devices in some cases and it sets the
>> power.direct_complete flag for them for this purpose.
>>
>> However, it turns out that setting power.direct_complete outside of
>> the PM core is a bad idea as it triggers an excessive invocation of
>> pm_runtime_enable() in device_resume().
>
> Do we need to clarify the comment about the flag in pm.h?
>
> Or is "/* Owned by the PM core */" sufficient?
That should be sufficient (and I sort of tried to ignore it ...).
>>
>> For this reason, provide a helper to clear power.is_late_suspended
>> and power.is_suspended to be invoked by the middle-layer code in
>> question instead of setting power.direct_complete and make that code
>> call the new helper.
>>
>> Fixes: c4b65157aeef (PCI / PM: Take SMART_SUSPEND driver flag into account)
>> Fixes: 05087360fd7a (ACPI / PM: Take SMART_SUSPEND driver flag into account)
>> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Reviewed-by: Ulf Hansson <ulf.hansson@linaro,org>
Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] PM / sleep: Avoid excess pm_runtime_enable() calls in device_resume()
2017-12-07 2:26 [PATCH] PM / sleep: Avoid excess pm_runtime_enable() calls in device_resume() Rafael J. Wysocki
2017-12-07 19:44 ` Ulf Hansson
@ 2017-12-08 20:25 ` Bjorn Helgaas
2017-12-09 14:13 ` Rafael J. Wysocki
1 sibling, 1 reply; 5+ messages in thread
From: Bjorn Helgaas @ 2017-12-08 20:25 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: Linux PM, Linux PCI, Linux ACPI, LKML, Bjorn Helgaas,
Greg Kroah-Hartman, Ulf Hansson, Mika Westerberg
On Thu, Dec 07, 2017 at 03:26:14AM +0100, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Middle-layer code doing suspend-time optimizations for devices with
> the DPM_FLAG_SMART_SUSPEND flag set (currently, the PCI bus type and
> the ACPI PM domain) needs to make the core skip ->thaw_early and
> ->thaw callbacks for those devices in some cases and it sets the
> power.direct_complete flag for them for this purpose.
>
> However, it turns out that setting power.direct_complete outside of
> the PM core is a bad idea as it triggers an excessive invocation of
> pm_runtime_enable() in device_resume().
>
> For this reason, provide a helper to clear power.is_late_suspended
> and power.is_suspended to be invoked by the middle-layer code in
> question instead of setting power.direct_complete and make that code
> call the new helper.
>
> Fixes: c4b65157aeef (PCI / PM: Take SMART_SUSPEND driver flag into account)
> Fixes: 05087360fd7a (ACPI / PM: Take SMART_SUSPEND driver flag into account)
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
I don't pretend to understand this (and I don't need to, so don't
waste your time explaining), but I trust you :)
> ---
> drivers/acpi/device_pm.c | 2 +-
> drivers/base/power/main.c | 15 +++++++++++++++
> drivers/pci/pci-driver.c | 2 +-
> include/linux/pm.h | 1 +
> 4 files changed, 18 insertions(+), 2 deletions(-)
>
> Index: linux-pm/include/linux/pm.h
> ===================================================================
> --- linux-pm.orig/include/linux/pm.h
> +++ linux-pm/include/linux/pm.h
> @@ -765,6 +765,7 @@ extern int pm_generic_poweroff_late(stru
> extern int pm_generic_poweroff(struct device *dev);
> extern void pm_generic_complete(struct device *dev);
>
> +extern void dev_pm_skip_next_resume_phases(struct device *dev);
> extern bool dev_pm_smart_suspend_and_suspended(struct device *dev);
>
> #else /* !CONFIG_PM_SLEEP */
> Index: linux-pm/drivers/base/power/main.c
> ===================================================================
> --- linux-pm.orig/drivers/base/power/main.c
> +++ linux-pm/drivers/base/power/main.c
> @@ -526,6 +526,21 @@ static void dpm_watchdog_clear(struct dp
> /*------------------------- Resume routines -------------------------*/
>
> /**
> + * dev_pm_skip_next_resume_phases - Skip next system resume phases for device.
> + * @dev: Target device.
> + *
> + * Make the core skip the "early resume" and "resume" phases for @dev.
> + *
> + * This function can be called by middle-layer code during the "noirq" phase of
> + * system resume if necessary, but not by device drivers.
> + */
> +void dev_pm_skip_next_resume_phases(struct device *dev)
> +{
> + dev->power.is_late_suspended = false;
> + dev->power.is_suspended = false;
> +}
> +
> +/**
> * device_resume_noirq - Execute a "noirq resume" callback for given device.
> * @dev: Device to handle.
> * @state: PM transition of the system being carried out.
> Index: linux-pm/drivers/pci/pci-driver.c
> ===================================================================
> --- linux-pm.orig/drivers/pci/pci-driver.c
> +++ linux-pm/drivers/pci/pci-driver.c
> @@ -999,7 +999,7 @@ static int pci_pm_thaw_noirq(struct devi
> * the subsequent "thaw" callbacks for the device.
> */
> if (dev_pm_smart_suspend_and_suspended(dev)) {
> - dev->power.direct_complete = true;
> + dev_pm_skip_next_resume_phases(dev);
> return 0;
> }
>
> Index: linux-pm/drivers/acpi/device_pm.c
> ===================================================================
> --- linux-pm.orig/drivers/acpi/device_pm.c
> +++ linux-pm/drivers/acpi/device_pm.c
> @@ -1138,7 +1138,7 @@ int acpi_subsys_thaw_noirq(struct device
> * skip all of the subsequent "thaw" callbacks for the device.
> */
> if (dev_pm_smart_suspend_and_suspended(dev)) {
> - dev->power.direct_complete = true;
> + dev_pm_skip_next_resume_phases(dev);
> return 0;
> }
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] PM / sleep: Avoid excess pm_runtime_enable() calls in device_resume()
2017-12-08 20:25 ` Bjorn Helgaas
@ 2017-12-09 14:13 ` Rafael J. Wysocki
0 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2017-12-09 14:13 UTC (permalink / raw)
To: Bjorn Helgaas
Cc: Rafael J. Wysocki, Linux PM, Linux PCI, Linux ACPI, LKML,
Bjorn Helgaas, Greg Kroah-Hartman, Ulf Hansson, Mika Westerberg
On Fri, Dec 8, 2017 at 9:25 PM, Bjorn Helgaas <helgaas@kernel.org> wrote:
> On Thu, Dec 07, 2017 at 03:26:14AM +0100, Rafael J. Wysocki wrote:
>> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>
>> Middle-layer code doing suspend-time optimizations for devices with
>> the DPM_FLAG_SMART_SUSPEND flag set (currently, the PCI bus type and
>> the ACPI PM domain) needs to make the core skip ->thaw_early and
>> ->thaw callbacks for those devices in some cases and it sets the
>> power.direct_complete flag for them for this purpose.
>>
>> However, it turns out that setting power.direct_complete outside of
>> the PM core is a bad idea as it triggers an excessive invocation of
>> pm_runtime_enable() in device_resume().
>>
>> For this reason, provide a helper to clear power.is_late_suspended
>> and power.is_suspended to be invoked by the middle-layer code in
>> question instead of setting power.direct_complete and make that code
>> call the new helper.
>>
>> Fixes: c4b65157aeef (PCI / PM: Take SMART_SUSPEND driver flag into account)
>> Fixes: 05087360fd7a (ACPI / PM: Take SMART_SUSPEND driver flag into account)
>> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Acked-by: Bjorn Helgaas <bhelgaas@google.com>
>
> I don't pretend to understand this (and I don't need to, so don't
> waste your time explaining), but I trust you :)
Thank you! :-)
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-12-09 14:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-07 2:26 [PATCH] PM / sleep: Avoid excess pm_runtime_enable() calls in device_resume() Rafael J. Wysocki
2017-12-07 19:44 ` Ulf Hansson
2017-12-07 21:17 ` Rafael J. Wysocki
2017-12-08 20:25 ` Bjorn Helgaas
2017-12-09 14:13 ` Rafael J. Wysocki
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.