Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PM / Runtime: Respect autosuspend when idle triggers suspend

For devices which don't have a .runtime_idle() callback or if it
returns 0, rpm_idle() will end up in triggering a call to
rpm_suspend(), thus trying to carry out a runtime suspend directly
from runtime_idle().

In the above situation we want to respect devices which has enabled
autosuspend, we therfore append the flag sent to rpm_suspend with
RPM_AUTO.

Do note that drivers still needs to update the device last busy mark,
to control the delay for this circumstance.

Updated runtime PM documentation accordingly.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Acked-by: Kevin Hilman <khilman@linaro.org>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Ulf Hansson and committed by
Rafael J. Wysocki
d66e6db2 61e6cfa8

+11 -8
+8 -6
Documentation/power/runtime_pm.txt
··· 145 145 if the device can be suspended (i.e. if all of the conditions necessary for 146 146 suspending the device are satisfied) and to queue up a suspend request for the 147 147 device in that case. If there is no idle callback, or if the callback returns 148 - 0, then the PM core will attempt to carry out a runtime suspend of the device; 149 - in essence, it will call pm_runtime_suspend() directly. To prevent this (for 150 - example, if the callback routine has started a delayed suspend), the routine 151 - should return a non-zero value. Negative error return codes are ignored by the 152 - PM core. 148 + 0, then the PM core will attempt to carry out a runtime suspend of the device, 149 + also respecting devices configured for autosuspend. In essence this means a 150 + call to pm_runtime_autosuspend() (do note that drivers needs to update the 151 + device last busy mark, pm_runtime_mark_last_busy(), to control the delay under 152 + this circumstance). To prevent this (for example, if the callback routine has 153 + started a delayed suspend), the routine must return a non-zero value. Negative 154 + error return codes are ignored by the PM core. 153 155 154 156 The helper functions provided by the PM core, described in Section 4, guarantee 155 157 that the following constraints are met with respect to runtime PM callbacks for ··· 310 308 - execute the subsystem-level idle callback for the device; returns an 311 309 error code on failure, where -EINPROGRESS means that ->runtime_idle() is 312 310 already being executed; if there is no callback or the callback returns 0 313 - then run pm_runtime_suspend(dev) and return its result 311 + then run pm_runtime_autosuspend(dev) and return its result 314 312 315 313 int pm_runtime_suspend(struct device *dev); 316 314 - execute the subsystem-level suspend callback for the device; returns 0 on
+3 -2
drivers/base/power/runtime.c
··· 258 258 * Check if the device's runtime PM status allows it to be suspended. If 259 259 * another idle notification has been started earlier, return immediately. If 260 260 * the RPM_ASYNC flag is set then queue an idle-notification request; otherwise 261 - * run the ->runtime_idle() callback directly. 261 + * run the ->runtime_idle() callback directly. If the ->runtime_idle callback 262 + * doesn't exist or if it returns 0, call rpm_suspend with the RPM_AUTO flag. 262 263 * 263 264 * This function must be called under dev->power.lock with interrupts disabled. 264 265 */ ··· 332 331 333 332 out: 334 333 trace_rpm_return_int(dev, _THIS_IP_, retval); 335 - return retval ? retval : rpm_suspend(dev, rpmflags); 334 + return retval ? retval : rpm_suspend(dev, rpmflags | RPM_AUTO); 336 335 } 337 336 338 337 /**