Skip to content

Commit 0e06b4a

Browse files
committed
PM: Add a switch for disabling/enabling asynchronous suspend/resume
Add sysfs attribute /sys/power/pm_async allowing the user space to disable/enable asynchronous suspend/resume of devices. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
1 parent 5af84b8 commit 0e06b4a

File tree

4 files changed

+50
-7
lines changed

4 files changed

+50
-7
lines changed

Documentation/ABI/testing/sysfs-power

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,16 @@ Description:
101101

102102
CAUTION: Using it will cause your machine's real-time (CMOS)
103103
clock to be set to a random invalid time after a resume.
104+
105+
What: /sys/power/pm_async
106+
Date: January 2009
107+
Contact: Rafael J. Wysocki <rjw@sisk.pl>
108+
Description:
109+
The /sys/power/pm_async file controls the switch allowing the
110+
user space to enable or disable asynchronous suspend and resume
111+
of devices. If enabled, this feature will cause some device
112+
drivers' suspend and resume callbacks to be executed in parallel
113+
with each other and with the main suspend thread. It is enabled
114+
if this file contains "1", which is the default. It may be
115+
disabled by writing "0" to this file, in which case all devices
116+
will be suspended and resumed synchronously.

drivers/base/power/main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ static void dpm_wait(struct device *dev, bool async)
201201
if (!dev)
202202
return;
203203

204-
if (async || dev->power.async_suspend)
204+
if (async || (pm_async_enabled && dev->power.async_suspend))
205205
wait_for_completion(&dev->power.completion);
206206
}
207207

@@ -563,7 +563,8 @@ static int device_resume(struct device *dev)
563563
{
564564
INIT_COMPLETION(dev->power.completion);
565565

566-
if (dev->power.async_suspend && !pm_trace_is_enabled()) {
566+
if (pm_async_enabled && dev->power.async_suspend
567+
&& !pm_trace_is_enabled()) {
567568
get_device(dev);
568569
async_schedule(async_resume, dev);
569570
return 0;
@@ -867,7 +868,7 @@ static int device_suspend(struct device *dev)
867868
{
868869
INIT_COMPLETION(dev->power.completion);
869870

870-
if (dev->power.async_suspend) {
871+
if (pm_async_enabled && dev->power.async_suspend) {
871872
get_device(dev);
872873
async_schedule(async_suspend, dev);
873874
return 0;

drivers/base/power/power.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ static inline void pm_runtime_remove(struct device *dev) {}
1212

1313
#ifdef CONFIG_PM_SLEEP
1414

15-
/*
16-
* main.c
17-
*/
15+
/* kernel/power/main.c */
16+
extern int pm_async_enabled;
1817

18+
/* drivers/base/power/main.c */
1919
extern struct list_head dpm_list; /* The active device list */
2020

2121
static inline struct device *to_device(struct list_head *entry)

kernel/power/main.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,32 @@ int pm_notifier_call_chain(unsigned long val)
4444
== NOTIFY_BAD) ? -EINVAL : 0;
4545
}
4646

47+
/* If set, devices may be suspended and resumed asynchronously. */
48+
int pm_async_enabled = 1;
49+
50+
static ssize_t pm_async_show(struct kobject *kobj, struct kobj_attribute *attr,
51+
char *buf)
52+
{
53+
return sprintf(buf, "%d\n", pm_async_enabled);
54+
}
55+
56+
static ssize_t pm_async_store(struct kobject *kobj, struct kobj_attribute *attr,
57+
const char *buf, size_t n)
58+
{
59+
unsigned long val;
60+
61+
if (strict_strtoul(buf, 10, &val))
62+
return -EINVAL;
63+
64+
if (val > 1)
65+
return -EINVAL;
66+
67+
pm_async_enabled = val;
68+
return n;
69+
}
70+
71+
power_attr(pm_async);
72+
4773
#ifdef CONFIG_PM_DEBUG
4874
int pm_test_level = TEST_NONE;
4975

@@ -208,8 +234,11 @@ static struct attribute * g[] = {
208234
#ifdef CONFIG_PM_TRACE
209235
&pm_trace_attr.attr,
210236
#endif
211-
#if defined(CONFIG_PM_SLEEP) && defined(CONFIG_PM_DEBUG)
237+
#ifdef CONFIG_PM_SLEEP
238+
&pm_async_attr.attr,
239+
#ifdef CONFIG_PM_DEBUG
212240
&pm_test_attr.attr,
241+
#endif
213242
#endif
214243
NULL,
215244
};

0 commit comments

Comments
 (0)