diff options
Diffstat (limited to 'kernel/power')
-rw-r--r-- | kernel/power/block_io.c | 2 | ||||
-rw-r--r-- | kernel/power/hibernate.c | 27 | ||||
-rw-r--r-- | kernel/power/main.c | 55 | ||||
-rw-r--r-- | kernel/power/process.c | 21 | ||||
-rw-r--r-- | kernel/power/snapshot.c | 3 | ||||
-rw-r--r-- | kernel/power/suspend.c | 13 | ||||
-rw-r--r-- | kernel/power/swap.c | 12 |
7 files changed, 108 insertions, 25 deletions
diff --git a/kernel/power/block_io.c b/kernel/power/block_io.c index 97024fd40cd5..83bbc7c02df9 100644 --- a/kernel/power/block_io.c +++ b/kernel/power/block_io.c | |||
@@ -28,7 +28,7 @@ | |||
28 | static int submit(int rw, struct block_device *bdev, sector_t sector, | 28 | static int submit(int rw, struct block_device *bdev, sector_t sector, |
29 | struct page *page, struct bio **bio_chain) | 29 | struct page *page, struct bio **bio_chain) |
30 | { | 30 | { |
31 | const int bio_rw = rw | (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG); | 31 | const int bio_rw = rw | REQ_SYNC | REQ_UNPLUG; |
32 | struct bio *bio; | 32 | struct bio *bio; |
33 | 33 | ||
34 | bio = bio_alloc(__GFP_WAIT | __GFP_HIGH, 1); | 34 | bio = bio_alloc(__GFP_WAIT | __GFP_HIGH, 1); |
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index aa9e916da4d5..c77963938bca 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c | |||
@@ -3,7 +3,7 @@ | |||
3 | * | 3 | * |
4 | * Copyright (c) 2003 Patrick Mochel | 4 | * Copyright (c) 2003 Patrick Mochel |
5 | * Copyright (c) 2003 Open Source Development Lab | 5 | * Copyright (c) 2003 Open Source Development Lab |
6 | * Copyright (c) 2004 Pavel Machek <pavel@suse.cz> | 6 | * Copyright (c) 2004 Pavel Machek <pavel@ucw.cz> |
7 | * Copyright (c) 2009 Rafael J. Wysocki, Novell Inc. | 7 | * Copyright (c) 2009 Rafael J. Wysocki, Novell Inc. |
8 | * | 8 | * |
9 | * This file is released under the GPLv2. | 9 | * This file is released under the GPLv2. |
@@ -277,7 +277,7 @@ static int create_image(int platform_mode) | |||
277 | goto Enable_irqs; | 277 | goto Enable_irqs; |
278 | } | 278 | } |
279 | 279 | ||
280 | if (hibernation_test(TEST_CORE)) | 280 | if (hibernation_test(TEST_CORE) || !pm_check_wakeup_events()) |
281 | goto Power_up; | 281 | goto Power_up; |
282 | 282 | ||
283 | in_suspend = 1; | 283 | in_suspend = 1; |
@@ -288,8 +288,10 @@ static int create_image(int platform_mode) | |||
288 | error); | 288 | error); |
289 | /* Restore control flow magically appears here */ | 289 | /* Restore control flow magically appears here */ |
290 | restore_processor_state(); | 290 | restore_processor_state(); |
291 | if (!in_suspend) | 291 | if (!in_suspend) { |
292 | events_check_enabled = false; | ||
292 | platform_leave(platform_mode); | 293 | platform_leave(platform_mode); |
294 | } | ||
293 | 295 | ||
294 | Power_up: | 296 | Power_up: |
295 | sysdev_resume(); | 297 | sysdev_resume(); |
@@ -328,7 +330,7 @@ int hibernation_snapshot(int platform_mode) | |||
328 | 330 | ||
329 | error = platform_begin(platform_mode); | 331 | error = platform_begin(platform_mode); |
330 | if (error) | 332 | if (error) |
331 | return error; | 333 | goto Close; |
332 | 334 | ||
333 | /* Preallocate image memory before shutting down devices. */ | 335 | /* Preallocate image memory before shutting down devices. */ |
334 | error = hibernate_preallocate_memory(); | 336 | error = hibernate_preallocate_memory(); |
@@ -336,6 +338,7 @@ int hibernation_snapshot(int platform_mode) | |||
336 | goto Close; | 338 | goto Close; |
337 | 339 | ||
338 | suspend_console(); | 340 | suspend_console(); |
341 | hibernation_freeze_swap(); | ||
339 | saved_mask = clear_gfp_allowed_mask(GFP_IOFS); | 342 | saved_mask = clear_gfp_allowed_mask(GFP_IOFS); |
340 | error = dpm_suspend_start(PMSG_FREEZE); | 343 | error = dpm_suspend_start(PMSG_FREEZE); |
341 | if (error) | 344 | if (error) |
@@ -511,18 +514,24 @@ int hibernation_platform_enter(void) | |||
511 | 514 | ||
512 | local_irq_disable(); | 515 | local_irq_disable(); |
513 | sysdev_suspend(PMSG_HIBERNATE); | 516 | sysdev_suspend(PMSG_HIBERNATE); |
517 | if (!pm_check_wakeup_events()) { | ||
518 | error = -EAGAIN; | ||
519 | goto Power_up; | ||
520 | } | ||
521 | |||
514 | hibernation_ops->enter(); | 522 | hibernation_ops->enter(); |
515 | /* We should never get here */ | 523 | /* We should never get here */ |
516 | while (1); | 524 | while (1); |
517 | 525 | ||
518 | /* | 526 | Power_up: |
519 | * We don't need to reenable the nonboot CPUs or resume consoles, since | 527 | sysdev_resume(); |
520 | * the system is going to be halted anyway. | 528 | local_irq_enable(); |
521 | */ | 529 | enable_nonboot_cpus(); |
530 | |||
522 | Platform_finish: | 531 | Platform_finish: |
523 | hibernation_ops->finish(); | 532 | hibernation_ops->finish(); |
524 | 533 | ||
525 | dpm_suspend_noirq(PMSG_RESTORE); | 534 | dpm_resume_noirq(PMSG_RESTORE); |
526 | 535 | ||
527 | Resume_devices: | 536 | Resume_devices: |
528 | entering_platform_hibernation = false; | 537 | entering_platform_hibernation = false; |
diff --git a/kernel/power/main.c b/kernel/power/main.c index b58800b21fc0..62b0bc6e4983 100644 --- a/kernel/power/main.c +++ b/kernel/power/main.c | |||
@@ -204,6 +204,60 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, | |||
204 | 204 | ||
205 | power_attr(state); | 205 | power_attr(state); |
206 | 206 | ||
207 | #ifdef CONFIG_PM_SLEEP | ||
208 | /* | ||
209 | * The 'wakeup_count' attribute, along with the functions defined in | ||
210 | * drivers/base/power/wakeup.c, provides a means by which wakeup events can be | ||
211 | * handled in a non-racy way. | ||
212 | * | ||
213 | * If a wakeup event occurs when the system is in a sleep state, it simply is | ||
214 | * woken up. In turn, if an event that would wake the system up from a sleep | ||
215 | * state occurs when it is undergoing a transition to that sleep state, the | ||
216 | * transition should be aborted. Moreover, if such an event occurs when the | ||
217 | * system is in the working state, an attempt to start a transition to the | ||
218 | * given sleep state should fail during certain period after the detection of | ||
219 | * the event. Using the 'state' attribute alone is not sufficient to satisfy | ||
220 | * these requirements, because a wakeup event may occur exactly when 'state' | ||
221 | * is being written to and may be delivered to user space right before it is | ||
222 | * frozen, so the event will remain only partially processed until the system is | ||
223 | * woken up by another event. In particular, it won't cause the transition to | ||
224 | * a sleep state to be aborted. | ||
225 | * | ||
226 | * This difficulty may be overcome if user space uses 'wakeup_count' before | ||
227 | * writing to 'state'. It first should read from 'wakeup_count' and store | ||
228 | * the read value. Then, after carrying out its own preparations for the system | ||
229 | * transition to a sleep state, it should write the stored value to | ||
230 | * 'wakeup_count'. If that fails, at least one wakeup event has occured since | ||
231 | * 'wakeup_count' was read and 'state' should not be written to. Otherwise, it | ||
232 | * is allowed to write to 'state', but the transition will be aborted if there | ||
233 | * are any wakeup events detected after 'wakeup_count' was written to. | ||
234 | */ | ||
235 | |||
236 | static ssize_t wakeup_count_show(struct kobject *kobj, | ||
237 | struct kobj_attribute *attr, | ||
238 | char *buf) | ||
239 | { | ||
240 | unsigned long val; | ||
241 | |||
242 | return pm_get_wakeup_count(&val) ? sprintf(buf, "%lu\n", val) : -EINTR; | ||
243 | } | ||
244 | |||
245 | static ssize_t wakeup_count_store(struct kobject *kobj, | ||
246 | struct kobj_attribute *attr, | ||
247 | const char *buf, size_t n) | ||
248 | { | ||
249 | unsigned long val; | ||
250 | |||
251 | if (sscanf(buf, "%lu", &val) == 1) { | ||
252 | if (pm_save_wakeup_count(val)) | ||
253 | return n; | ||
254 | } | ||
255 | return -EINVAL; | ||
256 | } | ||
257 | |||
258 | power_attr(wakeup_count); | ||
259 | #endif /* CONFIG_PM_SLEEP */ | ||
260 | |||
207 | #ifdef CONFIG_PM_TRACE | 261 | #ifdef CONFIG_PM_TRACE |
208 | int pm_trace_enabled; | 262 | int pm_trace_enabled; |
209 | 263 | ||
@@ -236,6 +290,7 @@ static struct attribute * g[] = { | |||
236 | #endif | 290 | #endif |
237 | #ifdef CONFIG_PM_SLEEP | 291 | #ifdef CONFIG_PM_SLEEP |
238 | &pm_async_attr.attr, | 292 | &pm_async_attr.attr, |
293 | &wakeup_count_attr.attr, | ||
239 | #ifdef CONFIG_PM_DEBUG | 294 | #ifdef CONFIG_PM_DEBUG |
240 | &pm_test_attr.attr, | 295 | &pm_test_attr.attr, |
241 | #endif | 296 | #endif |
diff --git a/kernel/power/process.c b/kernel/power/process.c index 71ae29052ab6..028a99598f49 100644 --- a/kernel/power/process.c +++ b/kernel/power/process.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/syscalls.h> | 15 | #include <linux/syscalls.h> |
16 | #include <linux/freezer.h> | 16 | #include <linux/freezer.h> |
17 | #include <linux/delay.h> | 17 | #include <linux/delay.h> |
18 | #include <linux/workqueue.h> | ||
18 | 19 | ||
19 | /* | 20 | /* |
20 | * Timeout for stopping processes | 21 | * Timeout for stopping processes |
@@ -35,6 +36,7 @@ static int try_to_freeze_tasks(bool sig_only) | |||
35 | struct task_struct *g, *p; | 36 | struct task_struct *g, *p; |
36 | unsigned long end_time; | 37 | unsigned long end_time; |
37 | unsigned int todo; | 38 | unsigned int todo; |
39 | bool wq_busy = false; | ||
38 | struct timeval start, end; | 40 | struct timeval start, end; |
39 | u64 elapsed_csecs64; | 41 | u64 elapsed_csecs64; |
40 | unsigned int elapsed_csecs; | 42 | unsigned int elapsed_csecs; |
@@ -42,6 +44,10 @@ static int try_to_freeze_tasks(bool sig_only) | |||
42 | do_gettimeofday(&start); | 44 | do_gettimeofday(&start); |
43 | 45 | ||
44 | end_time = jiffies + TIMEOUT; | 46 | end_time = jiffies + TIMEOUT; |
47 | |||
48 | if (!sig_only) | ||
49 | freeze_workqueues_begin(); | ||
50 | |||
45 | while (true) { | 51 | while (true) { |
46 | todo = 0; | 52 | todo = 0; |
47 | read_lock(&tasklist_lock); | 53 | read_lock(&tasklist_lock); |
@@ -63,6 +69,12 @@ static int try_to_freeze_tasks(bool sig_only) | |||
63 | todo++; | 69 | todo++; |
64 | } while_each_thread(g, p); | 70 | } while_each_thread(g, p); |
65 | read_unlock(&tasklist_lock); | 71 | read_unlock(&tasklist_lock); |
72 | |||
73 | if (!sig_only) { | ||
74 | wq_busy = freeze_workqueues_busy(); | ||
75 | todo += wq_busy; | ||
76 | } | ||
77 | |||
66 | if (!todo || time_after(jiffies, end_time)) | 78 | if (!todo || time_after(jiffies, end_time)) |
67 | break; | 79 | break; |
68 | 80 | ||
@@ -86,8 +98,12 @@ static int try_to_freeze_tasks(bool sig_only) | |||
86 | */ | 98 | */ |
87 | printk("\n"); | 99 | printk("\n"); |
88 | printk(KERN_ERR "Freezing of tasks failed after %d.%02d seconds " | 100 | printk(KERN_ERR "Freezing of tasks failed after %d.%02d seconds " |
89 | "(%d tasks refusing to freeze):\n", | 101 | "(%d tasks refusing to freeze, wq_busy=%d):\n", |
90 | elapsed_csecs / 100, elapsed_csecs % 100, todo); | 102 | elapsed_csecs / 100, elapsed_csecs % 100, |
103 | todo - wq_busy, wq_busy); | ||
104 | |||
105 | thaw_workqueues(); | ||
106 | |||
91 | read_lock(&tasklist_lock); | 107 | read_lock(&tasklist_lock); |
92 | do_each_thread(g, p) { | 108 | do_each_thread(g, p) { |
93 | task_lock(p); | 109 | task_lock(p); |
@@ -157,6 +173,7 @@ void thaw_processes(void) | |||
157 | oom_killer_enable(); | 173 | oom_killer_enable(); |
158 | 174 | ||
159 | printk("Restarting tasks ... "); | 175 | printk("Restarting tasks ... "); |
176 | thaw_workqueues(); | ||
160 | thaw_tasks(true); | 177 | thaw_tasks(true); |
161 | thaw_tasks(false); | 178 | thaw_tasks(false); |
162 | schedule(); | 179 | schedule(); |
diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c index 25ce010e9f8b..5e7edfb05e66 100644 --- a/kernel/power/snapshot.c +++ b/kernel/power/snapshot.c | |||
@@ -3,7 +3,7 @@ | |||
3 | * | 3 | * |
4 | * This file provides system snapshot/restore functionality for swsusp. | 4 | * This file provides system snapshot/restore functionality for swsusp. |
5 | * | 5 | * |
6 | * Copyright (C) 1998-2005 Pavel Machek <pavel@suse.cz> | 6 | * Copyright (C) 1998-2005 Pavel Machek <pavel@ucw.cz> |
7 | * Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl> | 7 | * Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl> |
8 | * | 8 | * |
9 | * This file is released under the GPLv2. | 9 | * This file is released under the GPLv2. |
@@ -1086,6 +1086,7 @@ void swsusp_free(void) | |||
1086 | buffer = NULL; | 1086 | buffer = NULL; |
1087 | alloc_normal = 0; | 1087 | alloc_normal = 0; |
1088 | alloc_highmem = 0; | 1088 | alloc_highmem = 0; |
1089 | hibernation_thaw_swap(); | ||
1089 | } | 1090 | } |
1090 | 1091 | ||
1091 | /* Helper functions used for the shrinking of memory. */ | 1092 | /* Helper functions used for the shrinking of memory. */ |
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c index f37cb7dd4402..7335952ee473 100644 --- a/kernel/power/suspend.c +++ b/kernel/power/suspend.c | |||
@@ -136,19 +136,19 @@ static int suspend_enter(suspend_state_t state) | |||
136 | if (suspend_ops->prepare) { | 136 | if (suspend_ops->prepare) { |
137 | error = suspend_ops->prepare(); | 137 | error = suspend_ops->prepare(); |
138 | if (error) | 138 | if (error) |
139 | return error; | 139 | goto Platform_finish; |
140 | } | 140 | } |
141 | 141 | ||
142 | error = dpm_suspend_noirq(PMSG_SUSPEND); | 142 | error = dpm_suspend_noirq(PMSG_SUSPEND); |
143 | if (error) { | 143 | if (error) { |
144 | printk(KERN_ERR "PM: Some devices failed to power down\n"); | 144 | printk(KERN_ERR "PM: Some devices failed to power down\n"); |
145 | goto Platfrom_finish; | 145 | goto Platform_finish; |
146 | } | 146 | } |
147 | 147 | ||
148 | if (suspend_ops->prepare_late) { | 148 | if (suspend_ops->prepare_late) { |
149 | error = suspend_ops->prepare_late(); | 149 | error = suspend_ops->prepare_late(); |
150 | if (error) | 150 | if (error) |
151 | goto Power_up_devices; | 151 | goto Platform_wake; |
152 | } | 152 | } |
153 | 153 | ||
154 | if (suspend_test(TEST_PLATFORM)) | 154 | if (suspend_test(TEST_PLATFORM)) |
@@ -163,8 +163,10 @@ static int suspend_enter(suspend_state_t state) | |||
163 | 163 | ||
164 | error = sysdev_suspend(PMSG_SUSPEND); | 164 | error = sysdev_suspend(PMSG_SUSPEND); |
165 | if (!error) { | 165 | if (!error) { |
166 | if (!suspend_test(TEST_CORE)) | 166 | if (!suspend_test(TEST_CORE) && pm_check_wakeup_events()) { |
167 | error = suspend_ops->enter(state); | 167 | error = suspend_ops->enter(state); |
168 | events_check_enabled = false; | ||
169 | } | ||
168 | sysdev_resume(); | 170 | sysdev_resume(); |
169 | } | 171 | } |
170 | 172 | ||
@@ -178,10 +180,9 @@ static int suspend_enter(suspend_state_t state) | |||
178 | if (suspend_ops->wake) | 180 | if (suspend_ops->wake) |
179 | suspend_ops->wake(); | 181 | suspend_ops->wake(); |
180 | 182 | ||
181 | Power_up_devices: | ||
182 | dpm_resume_noirq(PMSG_RESUME); | 183 | dpm_resume_noirq(PMSG_RESUME); |
183 | 184 | ||
184 | Platfrom_finish: | 185 | Platform_finish: |
185 | if (suspend_ops->finish) | 186 | if (suspend_ops->finish) |
186 | suspend_ops->finish(); | 187 | suspend_ops->finish(); |
187 | 188 | ||
diff --git a/kernel/power/swap.c b/kernel/power/swap.c index b0bb21778391..5d0059eed3e4 100644 --- a/kernel/power/swap.c +++ b/kernel/power/swap.c | |||
@@ -4,7 +4,7 @@ | |||
4 | * This file provides functions for reading the suspend image from | 4 | * This file provides functions for reading the suspend image from |
5 | * and writing it to a swap partition. | 5 | * and writing it to a swap partition. |
6 | * | 6 | * |
7 | * Copyright (C) 1998,2001-2005 Pavel Machek <pavel@suse.cz> | 7 | * Copyright (C) 1998,2001-2005 Pavel Machek <pavel@ucw.cz> |
8 | * Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl> | 8 | * Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl> |
9 | * | 9 | * |
10 | * This file is released under the GPLv2. | 10 | * This file is released under the GPLv2. |
@@ -32,7 +32,7 @@ | |||
32 | /* | 32 | /* |
33 | * The swap map is a data structure used for keeping track of each page | 33 | * The swap map is a data structure used for keeping track of each page |
34 | * written to a swap partition. It consists of many swap_map_page | 34 | * written to a swap partition. It consists of many swap_map_page |
35 | * structures that contain each an array of MAP_PAGE_SIZE swap entries. | 35 | * structures that contain each an array of MAP_PAGE_ENTRIES swap entries. |
36 | * These structures are stored on the swap and linked together with the | 36 | * These structures are stored on the swap and linked together with the |
37 | * help of the .next_swap member. | 37 | * help of the .next_swap member. |
38 | * | 38 | * |
@@ -136,10 +136,10 @@ sector_t alloc_swapdev_block(int swap) | |||
136 | { | 136 | { |
137 | unsigned long offset; | 137 | unsigned long offset; |
138 | 138 | ||
139 | offset = swp_offset(get_swap_page_of_type(swap)); | 139 | offset = swp_offset(get_swap_for_hibernation(swap)); |
140 | if (offset) { | 140 | if (offset) { |
141 | if (swsusp_extents_insert(offset)) | 141 | if (swsusp_extents_insert(offset)) |
142 | swap_free(swp_entry(swap, offset)); | 142 | swap_free_for_hibernation(swp_entry(swap, offset)); |
143 | else | 143 | else |
144 | return swapdev_block(swap, offset); | 144 | return swapdev_block(swap, offset); |
145 | } | 145 | } |
@@ -148,7 +148,7 @@ sector_t alloc_swapdev_block(int swap) | |||
148 | 148 | ||
149 | /** | 149 | /** |
150 | * free_all_swap_pages - free swap pages allocated for saving image data. | 150 | * free_all_swap_pages - free swap pages allocated for saving image data. |
151 | * It also frees the extents used to register which swap entres had been | 151 | * It also frees the extents used to register which swap entries had been |
152 | * allocated. | 152 | * allocated. |
153 | */ | 153 | */ |
154 | 154 | ||
@@ -163,7 +163,7 @@ void free_all_swap_pages(int swap) | |||
163 | ext = container_of(node, struct swsusp_extent, node); | 163 | ext = container_of(node, struct swsusp_extent, node); |
164 | rb_erase(node, &swsusp_extents); | 164 | rb_erase(node, &swsusp_extents); |
165 | for (offset = ext->start; offset <= ext->end; offset++) | 165 | for (offset = ext->start; offset <= ext->end; offset++) |
166 | swap_free(swp_entry(swap, offset)); | 166 | swap_free_for_hibernation(swp_entry(swap, offset)); |
167 | 167 | ||
168 | kfree(ext); | 168 | kfree(ext); |
169 | } | 169 | } |