aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/power
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2014-06-03 17:10:23 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2014-06-03 17:10:23 -0400
commitee7f9d7c7c1d0fde6441be495f6f14eae43af2e0 (patch)
treee47d5f4ae1e8f939b0cde3548987d599181ce529 /kernel/power
parent97b80e685ffae9a6dc946ab08ed32f1eafda97d7 (diff)
parent057b0a7518e4b8fca26201715996d6d928a62300 (diff)
Merge branch 'pm-sleep'
* pm-sleep: PM / hibernate: fixed typo in comment PM / sleep: unregister wakeup source when disabling device wakeup PM / sleep: Introduce command line argument for sleep state enumeration PM / sleep: Use valid_state() for platform-dependent sleep states only PM / sleep: Add state field to pm_states[] entries PM / sleep: Update device PM documentation to cover direct_complete PM / sleep: Mechanism to avoid resuming runtime-suspended devices unnecessarily PM / hibernate: Fix memory corruption in resumedelay_setup() PM / hibernate: convert simple_strtoul to kstrtoul PM / hibernate: Documentation: Fix script for unswapping PM / hibernate: no kernel_power_off when pm_power_off NULL PM / hibernate: use unsigned local variables in swsusp_show_speed()
Diffstat (limited to 'kernel/power')
-rw-r--r--kernel/power/hibernate.c27
-rw-r--r--kernel/power/main.c33
-rw-r--r--kernel/power/power.h9
-rw-r--r--kernel/power/suspend.c94
-rw-r--r--kernel/power/suspend_test.c24
-rw-r--r--kernel/power/swap.c2
6 files changed, 114 insertions, 75 deletions
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index f4f2073711d3..df88d55dc436 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -35,7 +35,7 @@
35static int nocompress; 35static int nocompress;
36static int noresume; 36static int noresume;
37static int resume_wait; 37static int resume_wait;
38static int resume_delay; 38static unsigned int resume_delay;
39static char resume_file[256] = CONFIG_PM_STD_PARTITION; 39static char resume_file[256] = CONFIG_PM_STD_PARTITION;
40dev_t swsusp_resume_device; 40dev_t swsusp_resume_device;
41sector_t swsusp_resume_block; 41sector_t swsusp_resume_block;
@@ -228,19 +228,23 @@ static void platform_recover(int platform_mode)
228void swsusp_show_speed(struct timeval *start, struct timeval *stop, 228void swsusp_show_speed(struct timeval *start, struct timeval *stop,
229 unsigned nr_pages, char *msg) 229 unsigned nr_pages, char *msg)
230{ 230{
231 s64 elapsed_centisecs64; 231 u64 elapsed_centisecs64;
232 int centisecs; 232 unsigned int centisecs;
233 int k; 233 unsigned int k;
234 int kps; 234 unsigned int kps;
235 235
236 elapsed_centisecs64 = timeval_to_ns(stop) - timeval_to_ns(start); 236 elapsed_centisecs64 = timeval_to_ns(stop) - timeval_to_ns(start);
237 /*
238 * If "(s64)elapsed_centisecs64 < 0", it will print long elapsed time,
239 * it is obvious enough for what went wrong.
240 */
237 do_div(elapsed_centisecs64, NSEC_PER_SEC / 100); 241 do_div(elapsed_centisecs64, NSEC_PER_SEC / 100);
238 centisecs = elapsed_centisecs64; 242 centisecs = elapsed_centisecs64;
239 if (centisecs == 0) 243 if (centisecs == 0)
240 centisecs = 1; /* avoid div-by-zero */ 244 centisecs = 1; /* avoid div-by-zero */
241 k = nr_pages * (PAGE_SIZE / 1024); 245 k = nr_pages * (PAGE_SIZE / 1024);
242 kps = (k * 100) / centisecs; 246 kps = (k * 100) / centisecs;
243 printk(KERN_INFO "PM: %s %d kbytes in %d.%02d seconds (%d.%02d MB/s)\n", 247 printk(KERN_INFO "PM: %s %u kbytes in %u.%02u seconds (%u.%02u MB/s)\n",
244 msg, k, 248 msg, k,
245 centisecs / 100, centisecs % 100, 249 centisecs / 100, centisecs % 100,
246 kps / 1000, (kps % 1000) / 10); 250 kps / 1000, (kps % 1000) / 10);
@@ -595,7 +599,8 @@ static void power_down(void)
595 case HIBERNATION_PLATFORM: 599 case HIBERNATION_PLATFORM:
596 hibernation_platform_enter(); 600 hibernation_platform_enter();
597 case HIBERNATION_SHUTDOWN: 601 case HIBERNATION_SHUTDOWN:
598 kernel_power_off(); 602 if (pm_power_off)
603 kernel_power_off();
599 break; 604 break;
600#ifdef CONFIG_SUSPEND 605#ifdef CONFIG_SUSPEND
601 case HIBERNATION_SUSPEND: 606 case HIBERNATION_SUSPEND:
@@ -623,7 +628,8 @@ static void power_down(void)
623 * corruption after resume. 628 * corruption after resume.
624 */ 629 */
625 printk(KERN_CRIT "PM: Please power down manually\n"); 630 printk(KERN_CRIT "PM: Please power down manually\n");
626 while(1); 631 while (1)
632 cpu_relax();
627} 633}
628 634
629/** 635/**
@@ -1109,7 +1115,10 @@ static int __init resumewait_setup(char *str)
1109 1115
1110static int __init resumedelay_setup(char *str) 1116static int __init resumedelay_setup(char *str)
1111{ 1117{
1112 resume_delay = simple_strtoul(str, NULL, 0); 1118 int rc = kstrtouint(str, 0, &resume_delay);
1119
1120 if (rc)
1121 return rc;
1113 return 1; 1122 return 1;
1114} 1123}
1115 1124
diff --git a/kernel/power/main.c b/kernel/power/main.c
index 6271bc4073ef..573410d6647e 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -279,26 +279,26 @@ static inline void pm_print_times_init(void) {}
279struct kobject *power_kobj; 279struct kobject *power_kobj;
280 280
281/** 281/**
282 * state - control system power state. 282 * state - control system sleep states.
283 * 283 *
284 * show() returns what states are supported, which is hard-coded to 284 * show() returns available sleep state labels, which may be "mem", "standby",
285 * 'freeze' (Low-Power Idle), 'standby' (Power-On Suspend), 285 * "freeze" and "disk" (hibernation). See Documentation/power/states.txt for a
286 * 'mem' (Suspend-to-RAM), and 'disk' (Suspend-to-Disk). 286 * description of what they mean.
287 * 287 *
288 * store() accepts one of those strings, translates it into the 288 * store() accepts one of those strings, translates it into the proper
289 * proper enumerated value, and initiates a suspend transition. 289 * enumerated value, and initiates a suspend transition.
290 */ 290 */
291static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr, 291static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
292 char *buf) 292 char *buf)
293{ 293{
294 char *s = buf; 294 char *s = buf;
295#ifdef CONFIG_SUSPEND 295#ifdef CONFIG_SUSPEND
296 int i; 296 suspend_state_t i;
297
298 for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++)
299 if (pm_states[i].state)
300 s += sprintf(s,"%s ", pm_states[i].label);
297 301
298 for (i = 0; i < PM_SUSPEND_MAX; i++) {
299 if (pm_states[i] && valid_state(i))
300 s += sprintf(s,"%s ", pm_states[i]);
301 }
302#endif 302#endif
303#ifdef CONFIG_HIBERNATION 303#ifdef CONFIG_HIBERNATION
304 s += sprintf(s, "%s\n", "disk"); 304 s += sprintf(s, "%s\n", "disk");
@@ -314,7 +314,7 @@ static suspend_state_t decode_state(const char *buf, size_t n)
314{ 314{
315#ifdef CONFIG_SUSPEND 315#ifdef CONFIG_SUSPEND
316 suspend_state_t state = PM_SUSPEND_MIN; 316 suspend_state_t state = PM_SUSPEND_MIN;
317 const char * const *s; 317 struct pm_sleep_state *s;
318#endif 318#endif
319 char *p; 319 char *p;
320 int len; 320 int len;
@@ -328,8 +328,9 @@ static suspend_state_t decode_state(const char *buf, size_t n)
328 328
329#ifdef CONFIG_SUSPEND 329#ifdef CONFIG_SUSPEND
330 for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) 330 for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++)
331 if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) 331 if (s->state && len == strlen(s->label)
332 return state; 332 && !strncmp(buf, s->label, len))
333 return s->state;
333#endif 334#endif
334 335
335 return PM_SUSPEND_ON; 336 return PM_SUSPEND_ON;
@@ -447,8 +448,8 @@ static ssize_t autosleep_show(struct kobject *kobj,
447 448
448#ifdef CONFIG_SUSPEND 449#ifdef CONFIG_SUSPEND
449 if (state < PM_SUSPEND_MAX) 450 if (state < PM_SUSPEND_MAX)
450 return sprintf(buf, "%s\n", valid_state(state) ? 451 return sprintf(buf, "%s\n", pm_states[state].state ?
451 pm_states[state] : "error"); 452 pm_states[state].label : "error");
452#endif 453#endif
453#ifdef CONFIG_HIBERNATION 454#ifdef CONFIG_HIBERNATION
454 return sprintf(buf, "disk\n"); 455 return sprintf(buf, "disk\n");
diff --git a/kernel/power/power.h b/kernel/power/power.h
index 15f37ea08719..c60f13b5270a 100644
--- a/kernel/power/power.h
+++ b/kernel/power/power.h
@@ -178,17 +178,20 @@ extern void swsusp_show_speed(struct timeval *, struct timeval *,
178 unsigned int, char *); 178 unsigned int, char *);
179 179
180#ifdef CONFIG_SUSPEND 180#ifdef CONFIG_SUSPEND
181struct pm_sleep_state {
182 const char *label;
183 suspend_state_t state;
184};
185
181/* kernel/power/suspend.c */ 186/* kernel/power/suspend.c */
182extern const char *const pm_states[]; 187extern struct pm_sleep_state pm_states[];
183 188
184extern bool valid_state(suspend_state_t state);
185extern int suspend_devices_and_enter(suspend_state_t state); 189extern int suspend_devices_and_enter(suspend_state_t state);
186#else /* !CONFIG_SUSPEND */ 190#else /* !CONFIG_SUSPEND */
187static inline int suspend_devices_and_enter(suspend_state_t state) 191static inline int suspend_devices_and_enter(suspend_state_t state)
188{ 192{
189 return -ENOSYS; 193 return -ENOSYS;
190} 194}
191static inline bool valid_state(suspend_state_t state) { return false; }
192#endif /* !CONFIG_SUSPEND */ 195#endif /* !CONFIG_SUSPEND */
193 196
194#ifdef CONFIG_PM_TEST_SUSPEND 197#ifdef CONFIG_PM_TEST_SUSPEND
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index 155721f7f909..338a6f147974 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -31,10 +31,10 @@
31 31
32#include "power.h" 32#include "power.h"
33 33
34const char *const pm_states[PM_SUSPEND_MAX] = { 34struct pm_sleep_state pm_states[PM_SUSPEND_MAX] = {
35 [PM_SUSPEND_FREEZE] = "freeze", 35 [PM_SUSPEND_FREEZE] = { .label = "freeze", .state = PM_SUSPEND_FREEZE },
36 [PM_SUSPEND_STANDBY] = "standby", 36 [PM_SUSPEND_STANDBY] = { .label = "standby", },
37 [PM_SUSPEND_MEM] = "mem", 37 [PM_SUSPEND_MEM] = { .label = "mem", },
38}; 38};
39 39
40static const struct platform_suspend_ops *suspend_ops; 40static const struct platform_suspend_ops *suspend_ops;
@@ -68,42 +68,62 @@ void freeze_wake(void)
68} 68}
69EXPORT_SYMBOL_GPL(freeze_wake); 69EXPORT_SYMBOL_GPL(freeze_wake);
70 70
71static bool valid_state(suspend_state_t state)
72{
73 /*
74 * PM_SUSPEND_STANDBY and PM_SUSPEND_MEM states need low level
75 * support and need to be valid to the low level
76 * implementation, no valid callback implies that none are valid.
77 */
78 return suspend_ops && suspend_ops->valid && suspend_ops->valid(state);
79}
80
81/*
82 * If this is set, the "mem" label always corresponds to the deepest sleep state
83 * available, the "standby" label corresponds to the second deepest sleep state
84 * available (if any), and the "freeze" label corresponds to the remaining
85 * available sleep state (if there is one).
86 */
87static bool relative_states;
88
89static int __init sleep_states_setup(char *str)
90{
91 relative_states = !strncmp(str, "1", 1);
92 if (relative_states) {
93 pm_states[PM_SUSPEND_MEM].state = PM_SUSPEND_FREEZE;
94 pm_states[PM_SUSPEND_FREEZE].state = 0;
95 }
96 return 1;
97}
98
99__setup("relative_sleep_states=", sleep_states_setup);
100
71/** 101/**
72 * suspend_set_ops - Set the global suspend method table. 102 * suspend_set_ops - Set the global suspend method table.
73 * @ops: Suspend operations to use. 103 * @ops: Suspend operations to use.
74 */ 104 */
75void suspend_set_ops(const struct platform_suspend_ops *ops) 105void suspend_set_ops(const struct platform_suspend_ops *ops)
76{ 106{
107 suspend_state_t i;
108 int j = PM_SUSPEND_MAX - 1;
109
77 lock_system_sleep(); 110 lock_system_sleep();
111
78 suspend_ops = ops; 112 suspend_ops = ops;
113 for (i = PM_SUSPEND_MEM; i >= PM_SUSPEND_STANDBY; i--)
114 if (valid_state(i))
115 pm_states[j--].state = i;
116 else if (!relative_states)
117 pm_states[j--].state = 0;
118
119 pm_states[j--].state = PM_SUSPEND_FREEZE;
120 while (j >= PM_SUSPEND_MIN)
121 pm_states[j--].state = 0;
122
79 unlock_system_sleep(); 123 unlock_system_sleep();
80} 124}
81EXPORT_SYMBOL_GPL(suspend_set_ops); 125EXPORT_SYMBOL_GPL(suspend_set_ops);
82 126
83bool valid_state(suspend_state_t state)
84{
85 if (state == PM_SUSPEND_FREEZE) {
86#ifdef CONFIG_PM_DEBUG
87 if (pm_test_level != TEST_NONE &&
88 pm_test_level != TEST_FREEZER &&
89 pm_test_level != TEST_DEVICES &&
90 pm_test_level != TEST_PLATFORM) {
91 printk(KERN_WARNING "Unsupported pm_test mode for "
92 "freeze state, please choose "
93 "none/freezer/devices/platform.\n");
94 return false;
95 }
96#endif
97 return true;
98 }
99 /*
100 * PM_SUSPEND_STANDBY and PM_SUSPEND_MEMORY states need lowlevel
101 * support and need to be valid to the lowlevel
102 * implementation, no valid callback implies that none are valid.
103 */
104 return suspend_ops && suspend_ops->valid && suspend_ops->valid(state);
105}
106
107/** 127/**
108 * suspend_valid_only_mem - Generic memory-only valid callback. 128 * suspend_valid_only_mem - Generic memory-only valid callback.
109 * 129 *
@@ -330,9 +350,17 @@ static int enter_state(suspend_state_t state)
330{ 350{
331 int error; 351 int error;
332 352
333 if (!valid_state(state)) 353 if (state == PM_SUSPEND_FREEZE) {
334 return -ENODEV; 354#ifdef CONFIG_PM_DEBUG
335 355 if (pm_test_level != TEST_NONE && pm_test_level <= TEST_CPUS) {
356 pr_warning("PM: Unsupported test mode for freeze state,"
357 "please choose none/freezer/devices/platform.\n");
358 return -EAGAIN;
359 }
360#endif
361 } else if (!valid_state(state)) {
362 return -EINVAL;
363 }
336 if (!mutex_trylock(&pm_mutex)) 364 if (!mutex_trylock(&pm_mutex))
337 return -EBUSY; 365 return -EBUSY;
338 366
@@ -343,7 +371,7 @@ static int enter_state(suspend_state_t state)
343 sys_sync(); 371 sys_sync();
344 printk("done.\n"); 372 printk("done.\n");
345 373
346 pr_debug("PM: Preparing system for %s sleep\n", pm_states[state]); 374 pr_debug("PM: Preparing system for %s sleep\n", pm_states[state].label);
347 error = suspend_prepare(state); 375 error = suspend_prepare(state);
348 if (error) 376 if (error)
349 goto Unlock; 377 goto Unlock;
@@ -351,7 +379,7 @@ static int enter_state(suspend_state_t state)
351 if (suspend_test(TEST_FREEZER)) 379 if (suspend_test(TEST_FREEZER))
352 goto Finish; 380 goto Finish;
353 381
354 pr_debug("PM: Entering %s sleep\n", pm_states[state]); 382 pr_debug("PM: Entering %s sleep\n", pm_states[state].label);
355 pm_restrict_gfp_mask(); 383 pm_restrict_gfp_mask();
356 error = suspend_devices_and_enter(state); 384 error = suspend_devices_and_enter(state);
357 pm_restore_gfp_mask(); 385 pm_restore_gfp_mask();
diff --git a/kernel/power/suspend_test.c b/kernel/power/suspend_test.c
index 9b2a1d58558d..269b097e78ea 100644
--- a/kernel/power/suspend_test.c
+++ b/kernel/power/suspend_test.c
@@ -92,13 +92,13 @@ static void __init test_wakealarm(struct rtc_device *rtc, suspend_state_t state)
92 } 92 }
93 93
94 if (state == PM_SUSPEND_MEM) { 94 if (state == PM_SUSPEND_MEM) {
95 printk(info_test, pm_states[state]); 95 printk(info_test, pm_states[state].label);
96 status = pm_suspend(state); 96 status = pm_suspend(state);
97 if (status == -ENODEV) 97 if (status == -ENODEV)
98 state = PM_SUSPEND_STANDBY; 98 state = PM_SUSPEND_STANDBY;
99 } 99 }
100 if (state == PM_SUSPEND_STANDBY) { 100 if (state == PM_SUSPEND_STANDBY) {
101 printk(info_test, pm_states[state]); 101 printk(info_test, pm_states[state].label);
102 status = pm_suspend(state); 102 status = pm_suspend(state);
103 } 103 }
104 if (status < 0) 104 if (status < 0)
@@ -136,18 +136,16 @@ static char warn_bad_state[] __initdata =
136 136
137static int __init setup_test_suspend(char *value) 137static int __init setup_test_suspend(char *value)
138{ 138{
139 unsigned i; 139 suspend_state_t i;
140 140
141 /* "=mem" ==> "mem" */ 141 /* "=mem" ==> "mem" */
142 value++; 142 value++;
143 for (i = 0; i < PM_SUSPEND_MAX; i++) { 143 for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++)
144 if (!pm_states[i]) 144 if (!strcmp(pm_states[i].label, value)) {
145 continue; 145 test_state = pm_states[i].state;
146 if (strcmp(pm_states[i], value) != 0) 146 return 0;
147 continue; 147 }
148 test_state = (__force suspend_state_t) i; 148
149 return 0;
150 }
151 printk(warn_bad_state, value); 149 printk(warn_bad_state, value);
152 return 0; 150 return 0;
153} 151}
@@ -164,8 +162,8 @@ static int __init test_suspend(void)
164 /* PM is initialized by now; is that state testable? */ 162 /* PM is initialized by now; is that state testable? */
165 if (test_state == PM_SUSPEND_ON) 163 if (test_state == PM_SUSPEND_ON)
166 goto done; 164 goto done;
167 if (!valid_state(test_state)) { 165 if (!pm_states[test_state].state) {
168 printk(warn_bad_state, pm_states[test_state]); 166 printk(warn_bad_state, pm_states[test_state].label);
169 goto done; 167 goto done;
170 } 168 }
171 169
diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index 8c9a4819f798..aaa3261dea5d 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -567,7 +567,7 @@ static int lzo_compress_threadfn(void *data)
567 567
568/** 568/**
569 * save_image_lzo - Save the suspend image data compressed with LZO. 569 * save_image_lzo - Save the suspend image data compressed with LZO.
570 * @handle: Swap mam handle to use for saving the image. 570 * @handle: Swap map handle to use for saving the image.
571 * @snapshot: Image to read data from. 571 * @snapshot: Image to read data from.
572 * @nr_to_write: Number of pages to save. 572 * @nr_to_write: Number of pages to save.
573 */ 573 */