···50005000 that number, otherwise (e.g., 'pmu_override=on'), MMCR150015001 remains 0.5002500250035003+ pm_async= [PM]50045004+ Format: off50055005+ This parameter sets the initial value of the50065006+ /sys/power/pm_async sysfs knob at boot time.50075007+ If set to "off", disables asynchronous suspend and50085008+ resume of devices during system-wide power transitions.50095009+ This can be useful on platforms where device50105010+ dependencies are not well-defined, or for debugging50115011+ power management issues. Asynchronous operations are50125012+ enabled by default.50135013+50145014+50035015 pm_debug_messages [SUSPEND,KNL]50045016 Enable suspend/resume debug messages during boot up.50055017
+4-4
MAINTAINERS
···9787978797889788FREEZER97899789M: "Rafael J. Wysocki" <rafael@kernel.org>97909790-M: Pavel Machek <pavel@kernel.org>97909790+R: Pavel Machek <pavel@kernel.org>97919791L: linux-pm@vger.kernel.org97929792S: Supported97939793F: Documentation/power/freezing-of-tasks.rst···10663106631066410664HIBERNATION (aka Software Suspend, aka swsusp)1066510665M: "Rafael J. Wysocki" <rafael@kernel.org>1066610666-M: Pavel Machek <pavel@kernel.org>1066610666+R: Pavel Machek <pavel@kernel.org>1066710667L: linux-pm@vger.kernel.org1066810668S: Supported1066910669B: https://bugzilla.kernel.org···23938239382393923939SUSPEND TO RAM2394023940M: "Rafael J. Wysocki" <rafael@kernel.org>2394123941-M: Len Brown <len.brown@intel.com>2394223942-M: Pavel Machek <pavel@kernel.org>2394123941+R: Len Brown <lenb@kernel.org>2394223942+R: Pavel Machek <pavel@kernel.org>2394323943L: linux-pm@vger.kernel.org2394423944S: Supported2394523945B: https://bugzilla.kernel.org
+4
drivers/acpi/device_pm.c
···11191119{11201120 struct acpi_device *adev = ACPI_COMPANION(dev);1121112111221122+ dev_pm_set_strict_midlayer(dev, true);11231123+11221124 if (dev->driver && dev->driver->pm && dev->driver->pm->prepare) {11231125 int ret = dev->driver->pm->prepare(dev);11241126···11491147 */11501148 if (pm_runtime_suspended(dev) && pm_resume_via_firmware())11511149 pm_request_resume(dev);11501150+11511151+ dev_pm_set_strict_midlayer(dev, false);11521152}11531153EXPORT_SYMBOL_GPL(acpi_subsys_complete);11541154
+59-17
drivers/base/power/main.c
···647647 /*648648 * Start processing "async" children of the device unless it's been649649 * started already for them.650650- *651651- * This could have been done for the device's "async" consumers too, but652652- * they either need to wait for their parents or the processing has653653- * already started for them after their parents were processed.654650 */655651 device_for_each_child(dev, func, dpm_async_with_cleanup);652652+}653653+654654+static void dpm_async_resume_subordinate(struct device *dev, async_func_t func)655655+{656656+ struct device_link *link;657657+ int idx;658658+659659+ dpm_async_resume_children(dev, func);660660+661661+ idx = device_links_read_lock();662662+663663+ /* Start processing the device's "async" consumers. */664664+ list_for_each_entry_rcu(link, &dev->links.consumers, s_node)665665+ if (READ_ONCE(link->status) != DL_STATE_DORMANT)666666+ dpm_async_with_cleanup(link->consumer, func);667667+668668+ device_links_read_unlock(idx);656669}657670658671static void dpm_clear_async_state(struct device *dev)···676663677664static bool dpm_root_device(struct device *dev)678665{679679- return !dev->parent;666666+ lockdep_assert_held(&dpm_list_mtx);667667+668668+ /*669669+ * Since this function is required to run under dpm_list_mtx, the670670+ * list_empty() below will only return true if the device's list of671671+ * consumers is actually empty before calling it.672672+ */673673+ return !dev->parent && list_empty(&dev->links.suppliers);680674}681675682676static void async_resume_noirq(void *data, async_cookie_t cookie);···772752 pm_dev_err(dev, state, async ? " async noirq" : " noirq", error);773753 }774754775775- dpm_async_resume_children(dev, async_resume_noirq);755755+ dpm_async_resume_subordinate(dev, async_resume_noirq);776756}777757778758static void async_resume_noirq(void *data, async_cookie_t cookie)···915895 pm_dev_err(dev, state, async ? " async early" : " early", error);916896 }917897918918- dpm_async_resume_children(dev, async_resume_early);898898+ dpm_async_resume_subordinate(dev, async_resume_early);919899}920900921901static void async_resume_early(void *data, async_cookie_t cookie)···10911071 pm_dev_err(dev, state, async ? " async" : "", error);10921072 }1093107310941094- dpm_async_resume_children(dev, async_resume);10741074+ dpm_async_resume_subordinate(dev, async_resume);10951075}1096107610971077static void async_resume(void *data, async_cookie_t cookie)···11151095 ktime_t starttime = ktime_get();1116109611171097 trace_suspend_resume(TPS("dpm_resume"), state.event, true);11181118- might_sleep();1119109811201099 pm_transition = state;11211100 async_error = 0;···12171198 struct list_head list;1218119912191200 trace_suspend_resume(TPS("dpm_complete"), state.event, true);12201220- might_sleep();1221120112221202 INIT_LIST_HEAD(&list);12231203 mutex_lock(&dpm_list_mtx);···12761258 return false;12771259 }1278126012791279- return true;12611261+ /*12621262+ * Since this function is required to run under dpm_list_mtx, the12631263+ * list_empty() below will only return true if the device's list of12641264+ * consumers is actually empty before calling it.12651265+ */12661266+ return list_empty(&dev->links.consumers);12801267}1281126812821282-static void dpm_async_suspend_parent(struct device *dev, async_func_t func)12691269+static bool dpm_async_suspend_parent(struct device *dev, async_func_t func)12831270{12841271 guard(mutex)(&dpm_list_mtx);12851272···12961273 * deleted before it.12971274 */12981275 if (!device_pm_initialized(dev))12991299- return;12761276+ return false;1300127713011278 /* Start processing the device's parent if it is "async". */13021279 if (dev->parent)13031280 dpm_async_with_cleanup(dev->parent, func);12811281+12821282+ return true;12831283+}12841284+12851285+static void dpm_async_suspend_superior(struct device *dev, async_func_t func)12861286+{12871287+ struct device_link *link;12881288+ int idx;12891289+12901290+ if (!dpm_async_suspend_parent(dev, func))12911291+ return;12921292+12931293+ idx = device_links_read_lock();12941294+12951295+ /* Start processing the device's "async" suppliers. */12961296+ list_for_each_entry_rcu(link, &dev->links.suppliers, c_node)12971297+ if (READ_ONCE(link->status) != DL_STATE_DORMANT)12981298+ dpm_async_with_cleanup(link->supplier, func);12991299+13001300+ device_links_read_unlock(idx);13041301}1305130213061303static void dpm_async_suspend_complete_all(struct list_head *device_list)···14601417 if (error || async_error)14611418 return error;1462141914631463- dpm_async_suspend_parent(dev, async_suspend_noirq);14201420+ dpm_async_suspend_superior(dev, async_suspend_noirq);1464142114651422 return 0;14661423}···16571614 if (error || async_error)16581615 return error;1659161616601660- dpm_async_suspend_parent(dev, async_suspend_late);16171617+ dpm_async_suspend_superior(dev, async_suspend_late);1661161816621619 return 0;16631620}···19491906 if (error || async_error)19501907 return error;1951190819521952- dpm_async_suspend_parent(dev, async_suspend);19091909+ dpm_async_suspend_superior(dev, async_suspend);1953191019541911 return 0;19551912}···21722129 int error = 0;2173213021742131 trace_suspend_resume(TPS("dpm_prepare"), state.event, true);21752175- might_sleep();2176213221772133 /*21782134 * Give a chance for the known devices to complete their probes, before
+88-39
drivers/base/power/runtime.c
···19192020typedef int (*pm_callback_t)(struct device *);21212222+static inline pm_callback_t get_callback_ptr(const void *start, size_t offset)2323+{2424+ return *(pm_callback_t *)(start + offset);2525+}2626+2727+static pm_callback_t __rpm_get_driver_callback(struct device *dev,2828+ size_t cb_offset)2929+{3030+ if (dev->driver && dev->driver->pm)3131+ return get_callback_ptr(dev->driver->pm, cb_offset);3232+3333+ return NULL;3434+}3535+2236static pm_callback_t __rpm_get_callback(struct device *dev, size_t cb_offset)2337{2424- pm_callback_t cb;2538 const struct dev_pm_ops *ops;3939+ pm_callback_t cb = NULL;26402741 if (dev->pm_domain)2842 ops = &dev->pm_domain->ops;···5036 ops = NULL;51375238 if (ops)5353- cb = *(pm_callback_t *)((void *)ops + cb_offset);5454- else5555- cb = NULL;3939+ cb = get_callback_ptr(ops, cb_offset);56405757- if (!cb && dev->driver && dev->driver->pm)5858- cb = *(pm_callback_t *)((void *)dev->driver->pm + cb_offset);4141+ if (!cb)4242+ cb = __rpm_get_driver_callback(dev, cb_offset);59436044 return cb;6145}···18391827 dev->power.request_pending = false;18401828 dev->power.request = RPM_REQ_NONE;18411829 dev->power.deferred_resume = false;18421842- dev->power.needs_force_resume = 0;18301830+ dev->power.needs_force_resume = false;18431831 INIT_WORK(&dev->power.work, pm_runtime_work);1844183218451833 dev->power.timer_expires = 0;···18661854 pm_runtime_put(dev->parent);18671855 }18681856 }18571857+ /*18581858+ * Clear power.needs_force_resume in case it has been set by18591859+ * pm_runtime_force_suspend() invoked from a driver remove callback.18601860+ */18611861+ dev->power.needs_force_resume = false;18691862}1870186318711864/**···19581941 pm_request_idle(link->supplier);19591942}1960194319611961-bool pm_runtime_need_not_resume(struct device *dev)19441944+static pm_callback_t get_callback(struct device *dev, size_t cb_offset)19621945{19631963- return atomic_read(&dev->power.usage_count) <= 1 &&19641964- (atomic_read(&dev->power.child_count) == 0 ||19651965- dev->power.ignore_children);19461946+ /*19471947+ * Setting power.strict_midlayer means that the middle layer19481948+ * code does not want its runtime PM callbacks to be invoked via19491949+ * pm_runtime_force_suspend() and pm_runtime_force_resume(), so19501950+ * return a direct pointer to the driver callback in that case.19511951+ */19521952+ if (dev_pm_strict_midlayer_is_set(dev))19531953+ return __rpm_get_driver_callback(dev, cb_offset);19541954+19551955+ return __rpm_get_callback(dev, cb_offset);19661956}19571957+19581958+#define GET_CALLBACK(dev, callback) \19591959+ get_callback(dev, offsetof(struct dev_pm_ops, callback))1967196019681961/**19691962 * pm_runtime_force_suspend - Force a device into suspend state if needed.···19911964 * sure the device is put into low power state and it should only be used during19921965 * system-wide PM transitions to sleep states. It assumes that the analogous19931966 * pm_runtime_force_resume() will be used to resume the device.19941994- *19951995- * Do not use with DPM_FLAG_SMART_SUSPEND as this can lead to an inconsistent19961996- * state where this function has called the ->runtime_suspend callback but the19971997- * PM core marks the driver as runtime active.19981967 */19991968int pm_runtime_force_suspend(struct device *dev)20001969{···19981975 int ret;1999197620001977 pm_runtime_disable(dev);20012001- if (pm_runtime_status_suspended(dev))19781978+ if (pm_runtime_status_suspended(dev) || dev->power.needs_force_resume)20021979 return 0;2003198020042004- callback = RPM_GET_CALLBACK(dev, runtime_suspend);19811981+ callback = GET_CALLBACK(dev, runtime_suspend);2005198220061983 dev_pm_enable_wake_irq_check(dev, true);20071984 ret = callback ? callback(dev) : 0;···20131990 /*20141991 * If the device can stay in suspend after the system-wide transition20151992 * to the working state that will follow, drop the children counter of20162016- * its parent, but set its status to RPM_SUSPENDED anyway in case this20172017- * function will be called again for it in the meantime.19931993+ * its parent and the usage counters of its suppliers. Otherwise, set19941994+ * power.needs_force_resume to let pm_runtime_force_resume() know that19951995+ * the device needs to be taken care of and to prevent this function19961996+ * from handling the device again in case the device is passed to it19971997+ * once more subsequently.20181998 */20192019- if (pm_runtime_need_not_resume(dev)) {19991999+ if (pm_runtime_need_not_resume(dev))20202000 pm_runtime_set_suspended(dev);20212021- } else {20222022- __update_runtime_status(dev, RPM_SUSPENDED);20232023- dev->power.needs_force_resume = 1;20242024- }20012001+ else20022002+ dev->power.needs_force_resume = true;2025200320262004 return 0;20272005···20332009}20342010EXPORT_SYMBOL_GPL(pm_runtime_force_suspend);2035201120122012+#ifdef CONFIG_PM_SLEEP20132013+20362014/**20372015 * pm_runtime_force_resume - Force a device into resume state if needed.20382016 * @dev: Device to resume.20392017 *20402040- * Prior invoking this function we expect the user to have brought the device20412041- * into low power state by a call to pm_runtime_force_suspend(). Here we reverse20422042- * those actions and bring the device into full power, if it is expected to be20432043- * used on system resume. In the other case, we defer the resume to be managed20442044- * via runtime PM.20182018+ * This function expects that either pm_runtime_force_suspend() has put the20192019+ * device into a low-power state prior to calling it, or the device had been20202020+ * runtime-suspended before the preceding system-wide suspend transition and it20212021+ * was left in suspend during that transition.20452022 *20462046- * Typically this function may be invoked from a system resume callback.20232023+ * The actions carried out by pm_runtime_force_suspend(), or by a runtime20242024+ * suspend in general, are reversed and the device is brought back into full20252025+ * power if it is expected to be used on system resume, which is the case when20262026+ * its needs_force_resume flag is set or when its smart_suspend flag is set and20272027+ * its runtime PM status is "active".20282028+ *20292029+ * In other cases, the resume is deferred to be managed via runtime PM.20302030+ *20312031+ * Typically, this function may be invoked from a system resume callback.20472032 */20482033int pm_runtime_force_resume(struct device *dev)20492034{20502035 int (*callback)(struct device *);20512036 int ret = 0;2052203720532053- if (!dev->power.needs_force_resume)20382038+ if (!dev->power.needs_force_resume && (!dev_pm_smart_suspend(dev) ||20392039+ pm_runtime_status_suspended(dev)))20542040 goto out;2055204120562056- /*20572057- * The value of the parent's children counter is correct already, so20582058- * just update the status of the device.20592059- */20602060- __update_runtime_status(dev, RPM_ACTIVE);20612061-20622062- callback = RPM_GET_CALLBACK(dev, runtime_resume);20422042+ callback = GET_CALLBACK(dev, runtime_resume);2063204320642044 dev_pm_disable_wake_irq_check(dev, false);20652045 ret = callback ? callback(dev) : 0;···20742046 }2075204720762048 pm_runtime_mark_last_busy(dev);20492049+20772050out:20782078- dev->power.needs_force_resume = 0;20512051+ /*20522052+ * The smart_suspend flag can be cleared here because it is not going20532053+ * to be necessary until the next system-wide suspend transition that20542054+ * will update it again.20552055+ */20562056+ dev->power.smart_suspend = false;20572057+ /*20582058+ * Also clear needs_force_resume to make this function skip devices that20592059+ * have been seen by it once.20602060+ */20612061+ dev->power.needs_force_resume = false;20622062+20792063 pm_runtime_enable(dev);20802064 return ret;20812065}20822066EXPORT_SYMBOL_GPL(pm_runtime_force_resume);20672067+20682068+bool pm_runtime_need_not_resume(struct device *dev)20692069+{20702070+ return atomic_read(&dev->power.usage_count) <= 1 &&20712071+ (atomic_read(&dev->power.child_count) == 0 ||20722072+ dev->power.ignore_children);20732073+}20742074+20752075+#endif /* CONFIG_PM_SLEEP */
···879879#endif880880}881881882882+/*883883+ * dev_pm_set_strict_midlayer - Update the device's power.strict_midlayer flag884884+ * @dev: Target device.885885+ * @val: New flag value.886886+ *887887+ * When set, power.strict_midlayer means that the middle layer power management888888+ * code (typically, a bus type or a PM domain) does not expect its runtime PM889889+ * suspend callback to be invoked at all during system-wide PM transitions and890890+ * it does not expect its runtime PM resume callback to be invoked at any point891891+ * when runtime PM is disabled for the device during system-wide PM transitions.892892+ */893893+static inline void dev_pm_set_strict_midlayer(struct device *dev, bool val)894894+{895895+#ifdef CONFIG_PM_SLEEP896896+ dev->power.strict_midlayer = val;897897+#endif898898+}899899+900900+static inline bool dev_pm_strict_midlayer_is_set(struct device *dev)901901+{902902+#ifdef CONFIG_PM_SLEEP903903+ return dev->power.strict_midlayer;904904+#else905905+ return false;906906+#endif907907+}908908+882909static inline void device_lock(struct device *dev)883910{884911 mutex_lock(&dev->mutex);
+1
include/linux/pm.h
···683683 bool smart_suspend:1; /* Owned by the PM core */684684 bool must_resume:1; /* Owned by the PM core */685685 bool may_skip_resume:1; /* Set by subsystems */686686+ bool strict_midlayer:1;686687#else687688 bool should_wakeup:1;688689#endif
+12-4
include/linux/pm_runtime.h
···66666767extern int pm_generic_runtime_suspend(struct device *dev);6868extern int pm_generic_runtime_resume(struct device *dev);6969-extern bool pm_runtime_need_not_resume(struct device *dev);7069extern int pm_runtime_force_suspend(struct device *dev);7171-extern int pm_runtime_force_resume(struct device *dev);72707371extern int __pm_runtime_idle(struct device *dev, int rpmflags);7472extern int __pm_runtime_suspend(struct device *dev, int rpmflags);···255257256258static inline int pm_generic_runtime_suspend(struct device *dev) { return 0; }257259static inline int pm_generic_runtime_resume(struct device *dev) { return 0; }258258-static inline bool pm_runtime_need_not_resume(struct device *dev) {return true; }259260static inline int pm_runtime_force_suspend(struct device *dev) { return 0; }260260-static inline int pm_runtime_force_resume(struct device *dev) { return 0; }261261262262static inline int __pm_runtime_idle(struct device *dev, int rpmflags)263263{···325329static inline void pm_runtime_release_supplier(struct device_link *link) {}326330327331#endif /* !CONFIG_PM */332332+333333+#ifdef CONFIG_PM_SLEEP334334+335335+bool pm_runtime_need_not_resume(struct device *dev);336336+int pm_runtime_force_resume(struct device *dev);337337+338338+#else /* !CONFIG_PM_SLEEP */339339+340340+static inline bool pm_runtime_need_not_resume(struct device *dev) {return true; }341341+static inline int pm_runtime_force_resume(struct device *dev) { return -ENXIO; }342342+343343+#endif /* CONFIG_PM_SLEEP */328344329345/**330346 * pm_runtime_idle - Conditionally set up autosuspend of a device or suspend it.
+1-3
kernel/kexec_core.c
···10801080 console_suspend_all();10811081 error = dpm_suspend_start(PMSG_FREEZE);10821082 if (error)10831083- goto Resume_console;10831083+ goto Resume_devices;10841084 /*10851085 * dpm_suspend_end() must be called after dpm_suspend_start()10861086 * to complete the transition, like in the hibernation flows···11351135 dpm_resume_start(PMSG_RESTORE);11361136 Resume_devices:11371137 dpm_resume_end(PMSG_RESTORE);11381138- Resume_console:11391139- pm_restore_gfp_mask();11401138 console_resume_all();11411139 thaw_processes();11421140 Restore_console:
+6-1
kernel/power/console.c
···1616#define SUSPEND_CONSOLE (MAX_NR_CONSOLES-1)17171818static int orig_fgconsole, orig_kmsg;1919+static bool vt_switch_done;19202021static DEFINE_MUTEX(vt_switch_mutex);2122···137136 if (orig_fgconsole < 0)138137 return;139138139139+ vt_switch_done = true;140140+140141 orig_kmsg = vt_kmsg_redirect(SUSPEND_CONSOLE);141142 return;142143}143144144145void pm_restore_console(void)145146{146146- if (!pm_vt_switch())147147+ if (!pm_vt_switch() && !vt_switch_done)147148 return;148149149150 if (orig_fgconsole >= 0) {150151 vt_move_to_console(orig_fgconsole, 0);151152 vt_kmsg_redirect(orig_kmsg);152153 }154154+155155+ vt_switch_done = false;153156}
+9
kernel/power/main.c
···8899#include <linux/acpi.h>1010#include <linux/export.h>1111+#include <linux/init.h>1112#include <linux/kobject.h>1213#include <linux/string.h>1314#include <linux/pm-trace.h>···112111113112/* If set, devices may be suspended and resumed asynchronously. */114113int pm_async_enabled = 1;114114+115115+static int __init pm_async_setup(char *str)116116+{117117+ if (!strcmp(str, "off"))118118+ pm_async_enabled = 0;119119+ return 1;120120+}121121+__setup("pm_async=", pm_async_setup);115122116123static ssize_t pm_async_show(struct kobject *kobj, struct kobj_attribute *attr,117124 char *buf)