Skip to contentSkip to conversation

mfd: intel-lpss: Avoid resuming runtime-suspended lpss unnecessarily

PATCH Superseded Chen Yu 2 participants 3 messages Sep 28, 2016 – Sep 29, 2016

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Chen Yu

author
#0 lore raw

PATCH v2 1/1 mfd: intel-lpss: Avoid resuming runtime-suspended lpss unnecessarily

We have report that the intel_lpss_prepare() takes too much time during suspend, and this is because we first resume the devices from runtime suspend by resume_lpss_device(), to make sure they are in proper state before system suspend, which takes 100ms for each LPSS devices(PCI power state from D3_cold to D0). And since resume_lpss_device() resumes the devices synchronously, we might get huge latency if we have many LPSS devices.

So first try is to use pm_request_resume() instead, to make the runtime resume process asynchronously. Unfortunately the asynchronous runtime resume relies on pm_wq, which is freezed at early stage. So we choose another method, that is to avoid resuming runtime-suspended devices, if they are already runtime suspended. This is safe because for LPSS driver, the runtime suspend and system suspend are of the same hook - i.e., intel_lpss_suspend(). And moreover, this device is neither runtime wakeup source nor system wakeup source.

---
 drivers/mfd/intel-lpss.c | 9 +++++++++
 include/linux/pm.h       | 3 +++
 2 files changed, 12 insertions(+)
drivers/mfd/intel-lpss.c +9 -0
index 41b1138..2583db8 100644
@@ -485,6 +485,15 @@ static int resume_lpss_device(struct device *dev, void *data)
 int intel_lpss_prepare(struct device *dev)
 {
 	/*
+	 * This is safe because:
+	 * 1. The runtime suspend and system suspend
+	 * are of the same hook.
+	 * 2. This device is neither runtime wakeup source
+	 * nor system wakeup source.
+	 */
+	if (pm_runtime_status_suspended(dev))
+		return DPM_DIRECT_COMPLETE;
+	/*
 	 * Resume both child devices before entering system sleep. This
 	 * ensures that they are in proper state before they get suspended.
 	 */
include/linux/pm.h +3 -0
index 06eb353..5606ad9 100644
@@ -786,4 +786,7 @@ enum dpm_order {
 	DPM_ORDER_DEV_LAST,
 };
 
+/* The device is OK to remain runtime-suspended during suspend.*/
+#define DPM_DIRECT_COMPLETE 1
+
 #endif /* _LINUX_PM_H */
Signature · 1 line
2.7.4
#1 lore raw
Quoted 55 lines · Chen Yu

We have report that the intel_lpss_prepare() takes too much time during suspend, and this is because we first resume the devices from runtime suspend by resume_lpss_device(), to make sure they are in proper state before system suspend, which takes 100ms for each LPSS devices(PCI power state from D3_cold to D0). And since resume_lpss_device() resumes the devices synchronously, we might get huge latency if we have many LPSS devices.

So first try is to use pm_request_resume() instead, to make the runtime resume process asynchronously. Unfortunately the asynchronous runtime resume relies on pm_wq, which is freezed at early stage. So we choose another method, that is to avoid resuming runtime-suspended devices, if they are already runtime suspended. This is safe because for LPSS driver, the runtime suspend and system suspend are of the same hook - i.e., intel_lpss_suspend(). And moreover, this device is neither runtime wakeup source nor system wakeup source.

---
 drivers/mfd/intel-lpss.c | 9 +++++++++
 include/linux/pm.h       | 3 +++
 2 files changed, 12 insertions(+)
drivers/mfd/intel-lpss.c +9 -0
index 41b1138..2583db8 100644
@@ -485,6 +485,15 @@ static int resume_lpss_device(struct device *dev, void *data)
 int intel_lpss_prepare(struct device *dev)
 {
        /*
+        * This is safe because:
+        * 1. The runtime suspend and system suspend
+        * are of the same hook.
+        * 2. This device is neither runtime wakeup source
+        * nor system wakeup source.
+        */
+       if (pm_runtime_status_suspended(dev))
+               return DPM_DIRECT_COMPLETE;
+       /*
         * Resume both child devices before entering system sleep. This
         * ensures that they are in proper state before they get suspended.
         */
include/linux/pm.h +0 -0
index 06eb353..5606ad9 100644

include/linux/pm.h enum dpm_order { · line 789

Quoted 4 lines
include/linux/pm.h +1 -0
@@ -786,4 +786,7 @@ enum dpm_order {
        DPM_ORDER_DEV_LAST,
 };
 
+/* The device is OK to remain runtime-suspended during suspend.*/

/*
* Return this from system suspend/hibernation ->prepare() callback to
request the
* core to leave the device runtime-suspended during system suspend if possible. */

include/linux/pm.h enum dpm_order {

Quoted 4 lines
include/linux/pm.h +2 -1
+#define DPM_DIRECT_COMPLETE 1
+
 #endif /* _LINUX_PM_H */
--

But it is fine by me overall.

Thanks,
Rafael

author
#2 lore raw
Quoted 59 lines · Rafael J. Wysocki
Quoted 58 lines · Chen Yu

We have report that the intel_lpss_prepare() takes too much time during suspend, and this is because we first resume the devices from runtime suspend by resume_lpss_device(), to make sure they are in proper state before system suspend, which takes 100ms for each LPSS devices(PCI power state from D3_cold to D0). And since resume_lpss_device() resumes the devices synchronously, we might get huge latency if we have many LPSS devices.

So first try is to use pm_request_resume() instead, to make the runtime resume process asynchronously. Unfortunately the asynchronous runtime resume relies on pm_wq, which is freezed at early stage. So we choose another method, that is to avoid resuming runtime-suspended devices, if they are already runtime suspended. This is safe because for LPSS driver, the runtime suspend and system suspend are of the same hook - i.e., intel_lpss_suspend(). And moreover, this device is neither runtime wakeup source nor system wakeup source.

---
 drivers/mfd/intel-lpss.c | 9 +++++++++
 include/linux/pm.h       | 3 +++
 2 files changed, 12 insertions(+)
drivers/mfd/intel-lpss.c +9 -0
index 41b1138..2583db8 100644
@@ -485,6 +485,15 @@ static int resume_lpss_device(struct device *dev, void *data)
 int intel_lpss_prepare(struct device *dev)
 {
        /*
+        * This is safe because:
+        * 1. The runtime suspend and system suspend
+        * are of the same hook.
+        * 2. This device is neither runtime wakeup source
+        * nor system wakeup source.
+        */
+       if (pm_runtime_status_suspended(dev))
+               return DPM_DIRECT_COMPLETE;
+       /*
         * Resume both child devices before entering system sleep. This
         * ensures that they are in proper state before they get suspended.
         */
include/linux/pm.h +0 -0
index 06eb353..5606ad9 100644
@@ -786,4 +786,7 @@ enum dpm_order {
        DPM_ORDER_DEV_LAST,
 };
 
Quoted 8 lines

include/linux/pm.h enum dpm_order { · line 789

Quoted 1 line
include/linux/pm.h +1 -0
+/* The device is OK to remain runtime-suspended during suspend.*/

/*
* Return this from system suspend/hibernation ->prepare() callback to
request the
* core to leave the device runtime-suspended during system suspend if possible. */

I've taken this comment in a new version, thanks!

Quoted 9 lines

include/linux/pm.h enum dpm_order {

Quoted 4 lines
include/linux/pm.h +2 -1
+#define DPM_DIRECT_COMPLETE 1
+
 #endif /* _LINUX_PM_H */
--

But it is fine by me overall.

Thanks,
Rafael