Skip to content

Commit 7c1f7c2

Browse files
committed
Merge back earlier material related to system sleep
2 parents ebd6884 + 2096d42 commit 7c1f7c2

12 files changed

Lines changed: 227 additions & 68 deletions

File tree

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5000,6 +5000,18 @@
50005000
that number, otherwise (e.g., 'pmu_override=on'), MMCR1
50015001
remains 0.
50025002

5003+
pm_async= [PM]
5004+
Format: off
5005+
This parameter sets the initial value of the
5006+
/sys/power/pm_async sysfs knob at boot time.
5007+
If set to "off", disables asynchronous suspend and
5008+
resume of devices during system-wide power transitions.
5009+
This can be useful on platforms where device
5010+
dependencies are not well-defined, or for debugging
5011+
power management issues. Asynchronous operations are
5012+
enabled by default.
5013+
5014+
50035015
pm_debug_messages [SUSPEND,KNL]
50045016
Enable suspend/resume debug messages during boot up.
50055017

MAINTAINERS

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9787,7 +9787,7 @@ F: fs/freevxfs/
97879787

97889788
FREEZER
97899789
M: "Rafael J. Wysocki" <rafael@kernel.org>
9790-
M: Pavel Machek <pavel@kernel.org>
9790+
R: Pavel Machek <pavel@kernel.org>
97919791
L: linux-pm@vger.kernel.org
97929792
S: Supported
97939793
F: Documentation/power/freezing-of-tasks.rst
@@ -10663,7 +10663,7 @@ F: drivers/video/fbdev/hgafb.c
1066310663

1066410664
HIBERNATION (aka Software Suspend, aka swsusp)
1066510665
M: "Rafael J. Wysocki" <rafael@kernel.org>
10666-
M: Pavel Machek <pavel@kernel.org>
10666+
R: Pavel Machek <pavel@kernel.org>
1066710667
L: linux-pm@vger.kernel.org
1066810668
S: Supported
1066910669
B: https://bugzilla.kernel.org
@@ -23938,8 +23938,8 @@ F: drivers/sh/
2393823938

2393923939
SUSPEND TO RAM
2394023940
M: "Rafael J. Wysocki" <rafael@kernel.org>
23941-
M: Len Brown <len.brown@intel.com>
23942-
M: Pavel Machek <pavel@kernel.org>
23941+
R: Len Brown <lenb@kernel.org>
23942+
R: Pavel Machek <pavel@kernel.org>
2394323943
L: linux-pm@vger.kernel.org
2394423944
S: Supported
2394523945
B: https://bugzilla.kernel.org

drivers/acpi/device_pm.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,8 @@ int acpi_subsys_prepare(struct device *dev)
11191119
{
11201120
struct acpi_device *adev = ACPI_COMPANION(dev);
11211121

1122+
dev_pm_set_strict_midlayer(dev, true);
1123+
11221124
if (dev->driver && dev->driver->pm && dev->driver->pm->prepare) {
11231125
int ret = dev->driver->pm->prepare(dev);
11241126

@@ -1147,6 +1149,8 @@ void acpi_subsys_complete(struct device *dev)
11471149
*/
11481150
if (pm_runtime_suspended(dev) && pm_resume_via_firmware())
11491151
pm_request_resume(dev);
1152+
1153+
dev_pm_set_strict_midlayer(dev, false);
11501154
}
11511155
EXPORT_SYMBOL_GPL(acpi_subsys_complete);
11521156

drivers/base/power/main.c

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -647,14 +647,27 @@ static void dpm_async_resume_children(struct device *dev, async_func_t func)
647647
/*
648648
* Start processing "async" children of the device unless it's been
649649
* started already for them.
650-
*
651-
* This could have been done for the device's "async" consumers too, but
652-
* they either need to wait for their parents or the processing has
653-
* already started for them after their parents were processed.
654650
*/
655651
device_for_each_child(dev, func, dpm_async_with_cleanup);
656652
}
657653

654+
static void dpm_async_resume_subordinate(struct device *dev, async_func_t func)
655+
{
656+
struct device_link *link;
657+
int idx;
658+
659+
dpm_async_resume_children(dev, func);
660+
661+
idx = device_links_read_lock();
662+
663+
/* Start processing the device's "async" consumers. */
664+
list_for_each_entry_rcu(link, &dev->links.consumers, s_node)
665+
if (READ_ONCE(link->status) != DL_STATE_DORMANT)
666+
dpm_async_with_cleanup(link->consumer, func);
667+
668+
device_links_read_unlock(idx);
669+
}
670+
658671
static void dpm_clear_async_state(struct device *dev)
659672
{
660673
reinit_completion(&dev->power.completion);
@@ -663,7 +676,14 @@ static void dpm_clear_async_state(struct device *dev)
663676

664677
static bool dpm_root_device(struct device *dev)
665678
{
666-
return !dev->parent;
679+
lockdep_assert_held(&dpm_list_mtx);
680+
681+
/*
682+
* Since this function is required to run under dpm_list_mtx, the
683+
* list_empty() below will only return true if the device's list of
684+
* consumers is actually empty before calling it.
685+
*/
686+
return !dev->parent && list_empty(&dev->links.suppliers);
667687
}
668688

669689
static void async_resume_noirq(void *data, async_cookie_t cookie);
@@ -752,7 +772,7 @@ static void device_resume_noirq(struct device *dev, pm_message_t state, bool asy
752772
pm_dev_err(dev, state, async ? " async noirq" : " noirq", error);
753773
}
754774

755-
dpm_async_resume_children(dev, async_resume_noirq);
775+
dpm_async_resume_subordinate(dev, async_resume_noirq);
756776
}
757777

758778
static void async_resume_noirq(void *data, async_cookie_t cookie)
@@ -895,7 +915,7 @@ static void device_resume_early(struct device *dev, pm_message_t state, bool asy
895915
pm_dev_err(dev, state, async ? " async early" : " early", error);
896916
}
897917

898-
dpm_async_resume_children(dev, async_resume_early);
918+
dpm_async_resume_subordinate(dev, async_resume_early);
899919
}
900920

901921
static void async_resume_early(void *data, async_cookie_t cookie)
@@ -1071,7 +1091,7 @@ static void device_resume(struct device *dev, pm_message_t state, bool async)
10711091
pm_dev_err(dev, state, async ? " async" : "", error);
10721092
}
10731093

1074-
dpm_async_resume_children(dev, async_resume);
1094+
dpm_async_resume_subordinate(dev, async_resume);
10751095
}
10761096

10771097
static void async_resume(void *data, async_cookie_t cookie)
@@ -1095,7 +1115,6 @@ void dpm_resume(pm_message_t state)
10951115
ktime_t starttime = ktime_get();
10961116

10971117
trace_suspend_resume(TPS("dpm_resume"), state.event, true);
1098-
might_sleep();
10991118

11001119
pm_transition = state;
11011120
async_error = 0;
@@ -1198,7 +1217,6 @@ void dpm_complete(pm_message_t state)
11981217
struct list_head list;
11991218

12001219
trace_suspend_resume(TPS("dpm_complete"), state.event, true);
1201-
might_sleep();
12021220

12031221
INIT_LIST_HEAD(&list);
12041222
mutex_lock(&dpm_list_mtx);
@@ -1258,10 +1276,15 @@ static bool dpm_leaf_device(struct device *dev)
12581276
return false;
12591277
}
12601278

1261-
return true;
1279+
/*
1280+
* Since this function is required to run under dpm_list_mtx, the
1281+
* list_empty() below will only return true if the device's list of
1282+
* consumers is actually empty before calling it.
1283+
*/
1284+
return list_empty(&dev->links.consumers);
12621285
}
12631286

1264-
static void dpm_async_suspend_parent(struct device *dev, async_func_t func)
1287+
static bool dpm_async_suspend_parent(struct device *dev, async_func_t func)
12651288
{
12661289
guard(mutex)(&dpm_list_mtx);
12671290

@@ -1273,11 +1296,31 @@ static void dpm_async_suspend_parent(struct device *dev, async_func_t func)
12731296
* deleted before it.
12741297
*/
12751298
if (!device_pm_initialized(dev))
1276-
return;
1299+
return false;
12771300

12781301
/* Start processing the device's parent if it is "async". */
12791302
if (dev->parent)
12801303
dpm_async_with_cleanup(dev->parent, func);
1304+
1305+
return true;
1306+
}
1307+
1308+
static void dpm_async_suspend_superior(struct device *dev, async_func_t func)
1309+
{
1310+
struct device_link *link;
1311+
int idx;
1312+
1313+
if (!dpm_async_suspend_parent(dev, func))
1314+
return;
1315+
1316+
idx = device_links_read_lock();
1317+
1318+
/* Start processing the device's "async" suppliers. */
1319+
list_for_each_entry_rcu(link, &dev->links.suppliers, c_node)
1320+
if (READ_ONCE(link->status) != DL_STATE_DORMANT)
1321+
dpm_async_with_cleanup(link->supplier, func);
1322+
1323+
device_links_read_unlock(idx);
12811324
}
12821325

12831326
static void dpm_async_suspend_complete_all(struct list_head *device_list)
@@ -1417,7 +1460,7 @@ static int device_suspend_noirq(struct device *dev, pm_message_t state, bool asy
14171460
if (error || async_error)
14181461
return error;
14191462

1420-
dpm_async_suspend_parent(dev, async_suspend_noirq);
1463+
dpm_async_suspend_superior(dev, async_suspend_noirq);
14211464

14221465
return 0;
14231466
}
@@ -1614,7 +1657,7 @@ static int device_suspend_late(struct device *dev, pm_message_t state, bool asyn
16141657
if (error || async_error)
16151658
return error;
16161659

1617-
dpm_async_suspend_parent(dev, async_suspend_late);
1660+
dpm_async_suspend_superior(dev, async_suspend_late);
16181661

16191662
return 0;
16201663
}
@@ -1906,7 +1949,7 @@ static int device_suspend(struct device *dev, pm_message_t state, bool async)
19061949
if (error || async_error)
19071950
return error;
19081951

1909-
dpm_async_suspend_parent(dev, async_suspend);
1952+
dpm_async_suspend_superior(dev, async_suspend);
19101953

19111954
return 0;
19121955
}
@@ -2129,7 +2172,6 @@ int dpm_prepare(pm_message_t state)
21292172
int error = 0;
21302173

21312174
trace_suspend_resume(TPS("dpm_prepare"), state.event, true);
2132-
might_sleep();
21332175

21342176
/*
21352177
* Give a chance for the known devices to complete their probes, before

0 commit comments

Comments
 (0)