Skip to content

Commit fd4716a

Browse files
committed
Merge back earlier changes related to system suspend and hibernation
2 parents ec3cae6 + f747cde commit fd4716a

10 files changed

Lines changed: 222 additions & 61 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

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
/**
@@ -1401,7 +1444,7 @@ static int device_suspend_noirq(struct device *dev, pm_message_t state, bool asy
14011444
if (error || async_error)
14021445
return error;
14031446

1404-
dpm_async_suspend_parent(dev, async_suspend_noirq);
1447+
dpm_async_suspend_superior(dev, async_suspend_noirq);
14051448

14061449
return 0;
14071450
}
@@ -1597,7 +1640,7 @@ static int device_suspend_late(struct device *dev, pm_message_t state, bool asyn
15971640
if (error || async_error)
15981641
return error;
15991642

1600-
dpm_async_suspend_parent(dev, async_suspend_late);
1643+
dpm_async_suspend_superior(dev, async_suspend_late);
16011644

16021645
return 0;
16031646
}
@@ -1888,7 +1931,7 @@ static int device_suspend(struct device *dev, pm_message_t state, bool async)
18881931
if (error || async_error)
18891932
return error;
18901933

1891-
dpm_async_suspend_parent(dev, async_suspend);
1934+
dpm_async_suspend_superior(dev, async_suspend);
18921935

18931936
return 0;
18941937
}
@@ -2110,7 +2153,6 @@ int dpm_prepare(pm_message_t state)
21102153
int error = 0;
21112154

21122155
trace_suspend_resume(TPS("dpm_prepare"), state.event, true);
2113-
might_sleep();
21142156

21152157
/*
21162158
* Give a chance for the known devices to complete their probes, before

0 commit comments

Comments
 (0)