History

Merge branch 'pm-sleep'

* pm-sleep: PM / Freezer: Remove references to TIF_FREEZE in comments PM / Sleep: Add more wakeup source initialization routines PM / Hibernate: Enable usermodehelpers in hibernate() error path PM / Sleep: Make __pm_stay_awake() delete wakeup source timers PM / Sleep: Fix race conditions related to wakeup source timer function PM / Sleep: Fix possible infinite loop during wakeup source destruction PM / Hibernate: print physical addresses consistently with other parts of kernel PM: Add comment describing relationships between PM callbacks to pm.h PM / Sleep: Drop suspend_stats_update() PM / Sleep: Make enter_state() in kernel/power/suspend.c static PM / Sleep: Unify kerneldoc comments in kernel/power/suspend.c PM / Sleep: Remove unnecessary label from suspend_freeze_processes() PM / Sleep: Do not check wakeup too often in try_to_freeze_tasks() PM / Sleep: Initialize wakeup source locks in wakeup_source_add() PM / Hibernate: Refactor and simplify freezer_test_done PM / Hibernate: Thaw kernel threads in hibernation_snapshot() in error/test path PM / Freezer / Docs: Document the beauty of freeze/thaw semantics PM / Suspend: Avoid code duplication in suspend statistics update PM / Sleep: Introduce generic callbacks for new device PM phases PM / Sleep: Introduce "late suspend" and "early resume" of devices

Rafael J. Wysocki committed 14 years ago

Commit 643161a2 parents 743c5bc 37f08be20 files · +662 −259Browse files

Showing the changes to kernel (10 of 20 files). Show all

Unified · Split

10 files
  1. kernel/exit.c +1 −1
  2. kernel/freezer.c +3 −3
  3. kernel/kexec.c +4 −4
  4. kernel/power/hibernate.c +25 −22
  5. kernel/power/main.c +9 −11
  6. kernel/power/power.h +1 −6
  7. kernel/power/process.c +12 −12
  8. kernel/power/snapshot.c +4 −3
  9. kernel/power/suspend.c +42 −42
  10. kernel/power/user.c +3 −9
kernel/exit.c+1−1
@@ -424,7 +424,7 @@ void daemonize(const char *name, ...) · 423 unmodified lines
424424 */
425425 exit_mm(current);
426426 /*
427− * We don't want to have TIF_FREEZE set if the system-wide hibernation
427+ * We don't want to get frozen, in case system-wide hibernation
428428 * or suspend transition begins right now.
429429 */
430430 current->flags |= (PF_NOFREEZE | PF_KTHREAD);
kernel/freezer.c+3−3
@@ -99,9 +99,9 @@ static void fake_signal_wake_up(struct task_struct *p) · 98 unmodified lines
9999 * freeze_task - send a freeze request to given task
100100 * @p: task to send the request to
101101 *
102− * If @p is freezing, the freeze request is sent by setting %TIF_FREEZE
103− * flag and either sending a fake signal to it or waking it up, depending
104− * on whether it has %PF_FREEZER_NOSIG set.
102+ * If @p is freezing, the freeze request is sent either by sending a fake
103+ * signal (if it's not a kernel thread) or waking it up (if it's a kernel
104+ * thread).
105105 *
106106 * RETURNS:
107107 * %false, if @p is not freezing or already frozen; %true, otherwise
kernel/kexec.c+4−4
@@ -1546,13 +1546,13 @@ int kernel_kexec(void) · 1545 unmodified lines
15461546 if (error)
15471547 goto Resume_console;
15481548 /* At this point, dpm_suspend_start() has been called,
1549− * but *not* dpm_suspend_noirq(). We *must* call
1550− * dpm_suspend_noirq() now. Otherwise, drivers for
1549+ * but *not* dpm_suspend_end(). We *must* call
1550+ * dpm_suspend_end() now. Otherwise, drivers for
15511551 * some devices (e.g. interrupt controllers) become
15521552 * desynchronized with the actual state of the
15531553 * hardware at resume time, and evil weirdness ensues.
15541554 */
1555− error = dpm_suspend_noirq(PMSG_FREEZE);
1555+ error = dpm_suspend_end(PMSG_FREEZE);
15561556 if (error)
15571557 goto Resume_devices;
15581558 error = disable_nonboot_cpus();
@@ -1579,7 +1579,7 @@ int kernel_kexec(void) · 20 unmodified lines
15791579 local_irq_enable();
15801580 Enable_cpus:
15811581 enable_nonboot_cpus();
1582− dpm_resume_noirq(PMSG_RESTORE);
1582+ dpm_resume_start(PMSG_RESTORE);
15831583 Resume_devices:
15841584 dpm_resume_end(PMSG_RESTORE);
15851585 Resume_console:
kernel/power/hibernate.c+25−22
@@ -245,8 +245,8 @@ void swsusp_show_speed(struct timeval *start, struct timeval *stop, · 244 unmodified lines
245245 * create_image - Create a hibernation image.
246246 * @platform_mode: Whether or not to use the platform driver.
247247 *
248− * Execute device drivers' .freeze_noirq() callbacks, create a hibernation image
249− * and execute the drivers' .thaw_noirq() callbacks.
248+ * Execute device drivers' "late" and "noirq" freeze callbacks, create a
249+ * hibernation image and run the drivers' "noirq" and "early" thaw callbacks.
250250 *
251251 * Control reappears in this routine after the subsequent restore.
252252 */
@@ -254,7 +254,7 @@ static int create_image(int platform_mode) · 1 unmodified line
254254 {
255255 int error;
256256
257− error = dpm_suspend_noirq(PMSG_FREEZE);
257+ error = dpm_suspend_end(PMSG_FREEZE);
258258 if (error) {
259259 printk(KERN_ERR "PM: Some devices failed to power down, "
260260 "aborting hibernation\n");
@@ -306,7 +306,7 @@ static int create_image(int platform_mode) · 45 unmodified lines
306306 Platform_finish:
307307 platform_finish(platform_mode);
308308
309− dpm_resume_noirq(in_suspend ?
309+ dpm_resume_start(in_suspend ?
310310 (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
311311
312312 return error;
@@ -343,13 +343,13 @@ int hibernation_snapshot(int platform_mode) · 30 unmodified lines
343343 * successful freezer test.
344344 */
345345 freezer_test_done = true;
346− goto Cleanup;
346+ goto Thaw;
347347 }
348348
349349 error = dpm_prepare(PMSG_FREEZE);
350350 if (error) {
351351 dpm_complete(PMSG_RECOVER);
352− goto Cleanup;
352+ goto Thaw;
353353 }
354354
355355 suspend_console();
@@ -385,6 +385,8 @@ int hibernation_snapshot(int platform_mode) · 29 unmodified lines
385385 platform_end(platform_mode);
386386 return error;
387387
388+ Thaw:
389+ thaw_kernel_threads();
388390 Cleanup:
389391 swsusp_free();
390392 goto Close;
@@ -394,16 +396,16 @@ int hibernation_snapshot(int platform_mode) · 3 unmodified lines
394396 * resume_target_kernel - Restore system state from a hibernation image.
395397 * @platform_mode: Whether or not to use the platform driver.
396398 *
397− * Execute device drivers' .freeze_noirq() callbacks, restore the contents of
398− * highmem that have not been restored yet from the image and run the low-level
399− * code that will restore the remaining contents of memory and switch to the
400− * just restored target kernel.
399+ * Execute device drivers' "noirq" and "late" freeze callbacks, restore the
400+ * contents of highmem that have not been restored yet from the image and run
401+ * the low-level code that will restore the remaining contents of memory and
402+ * switch to the just restored target kernel.
401403 */
402404 static int resume_target_kernel(bool platform_mode)
403405 {
404406 int error;
405407
406− error = dpm_suspend_noirq(PMSG_QUIESCE);
408+ error = dpm_suspend_end(PMSG_QUIESCE);
407409 if (error) {
408410 printk(KERN_ERR "PM: Some devices failed to power down, "
409411 "aborting resume\n");
@@ -460,7 +462,7 @@ static int resume_target_kernel(bool platform_mode) · 50 unmodified lines
460462 Cleanup:
461463 platform_restore_cleanup(platform_mode);
462464
463− dpm_resume_noirq(PMSG_RECOVER);
465+ dpm_resume_start(PMSG_RECOVER);
464466
465467 return error;
466468 }
@@ -518,7 +520,7 @@ int hibernation_platform_enter(void) · 51 unmodified lines
518520 goto Resume_devices;
519521 }
520522
521− error = dpm_suspend_noirq(PMSG_HIBERNATE);
523+ error = dpm_suspend_end(PMSG_HIBERNATE);
522524 if (error)
523525 goto Resume_devices;
524526
@@ -549,7 +551,7 @@ int hibernation_platform_enter(void) · 24 unmodified lines
549551 Platform_finish:
550552 hibernation_ops->finish();
551553
552− dpm_resume_noirq(PMSG_RESTORE);
554+ dpm_resume_start(PMSG_RESTORE);
553555
554556 Resume_devices:
555557 entering_platform_hibernation = false;
@@ -616,7 +618,7 @@ int hibernate(void) · 60 unmodified lines
616618 /* Allocate memory management structures */
617619 error = create_basic_memory_bitmaps();
618620 if (error)
619− goto Exit;
621+ goto Enable_umh;
620622
621623 printk(KERN_INFO "PM: Syncing filesystems ... ");
622624 sys_sync();
@@ -624,15 +626,11 @@ int hibernate(void) · 1 unmodified line
624626
625627 error = freeze_processes();
626628 if (error)
627− goto Finish;
629+ goto Free_bitmaps;
628630
629631 error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
630− if (error)
631− goto Thaw;
632− if (freezer_test_done) {
633− freezer_test_done = false;
632+ if (error || freezer_test_done)
634633 goto Thaw;
635− }
636634
637635 if (in_suspend) {
638636 unsigned int flags = 0;
@@ -657,8 +655,13 @@ int hibernate(void) · 18 unmodified lines
657655
658656 Thaw:
659657 thaw_processes();
660− Finish:
658+
659+ /* Don't bother checking whether freezer_test_done is true */
660+ freezer_test_done = false;
661+
662+ Free_bitmaps:
661663 free_basic_memory_bitmaps();
664+ Enable_umh:
662665 usermodehelper_enable();
663666 Exit:
664667 pm_notifier_call_chain(PM_POST_HIBERNATION);
kernel/power/main.c+9−11
@@ -165,16 +165,20 @@ static int suspend_stats_show(struct seq_file *s, void *unused) · 164 unmodified lines
165165 last_errno %= REC_FAILED_NUM;
166166 last_step = suspend_stats.last_failed_step + REC_FAILED_NUM - 1;
167167 last_step %= REC_FAILED_NUM;
168− seq_printf(s, "%s: %d\n%s: %d\n%s: %d\n%s: %d\n"
169− "%s: %d\n%s: %d\n%s: %d\n%s: %d\n",
168+ seq_printf(s, "%s: %d\n%s: %d\n%s: %d\n%s: %d\n%s: %d\n"
169+ "%s: %d\n%s: %d\n%s: %d\n%s: %d\n%s: %d\n",
170170 "success", suspend_stats.success,
171171 "fail", suspend_stats.fail,
172172 "failed_freeze", suspend_stats.failed_freeze,
173173 "failed_prepare", suspend_stats.failed_prepare,
174174 "failed_suspend", suspend_stats.failed_suspend,
175+ "failed_suspend_late",
176+ suspend_stats.failed_suspend_late,
175177 "failed_suspend_noirq",
176178 suspend_stats.failed_suspend_noirq,
177179 "failed_resume", suspend_stats.failed_resume,
180+ "failed_resume_early",
181+ suspend_stats.failed_resume_early,
178182 "failed_resume_noirq",
179183 suspend_stats.failed_resume_noirq);
180184 seq_printf(s, "failures:\n last_failed_dev:\t%-s\n",
@@ -287,16 +291,10 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, · 106 unmodified lines
287291
288292 #ifdef CONFIG_SUSPEND
289293 for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) {
290− if (*s && len == strlen(*s) && !strncmp(buf, *s, len))
294+ if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) {
295+ error = pm_suspend(state);
291296 break;
292− }
293− if (state < PM_SUSPEND_MAX && *s) {
294− error = enter_state(state);
295− if (error) {
296− suspend_stats.fail++;
297− dpm_save_failed_errno(error);
298− } else
299− suspend_stats.success++;
297+ }
300298 }
301299 #endif
302300
kernel/power/power.h+1−6
@@ -177,13 +177,11 @@ extern const char *const pm_states[]; · 176 unmodified lines
177177
178178 extern bool valid_state(suspend_state_t state);
179179 extern int suspend_devices_and_enter(suspend_state_t state);
180−extern int enter_state(suspend_state_t state);
181180 #else /* !CONFIG_SUSPEND */
182181 static inline int suspend_devices_and_enter(suspend_state_t state)
183182 {
184183 return -ENOSYS;
185184 }
186−static inline int enter_state(suspend_state_t state) { return -ENOSYS; }
187185 static inline bool valid_state(suspend_state_t state) { return false; }
188186 #endif /* !CONFIG_SUSPEND */
189187
@@ -234,16 +232,14 @@ static inline int suspend_freeze_processes(void) · 44 unmodified lines
234232 int error;
235233
236234 error = freeze_processes();
237−
238235 /*
239236 * freeze_processes() automatically thaws every task if freezing
240237 * fails. So we need not do anything extra upon error.
241238 */
242239 if (error)
243− goto Finish;
240+ return error;
244241
245242 error = freeze_kernel_threads();
246−
247243 /*
248244 * freeze_kernel_threads() thaws only kernel threads upon freezing
249245 * failure. So we have to thaw the userspace tasks ourselves.
@@ -251,7 +247,6 @@ static inline int suspend_freeze_processes(void) · 1 unmodified line
251247 if (error)
252248 thaw_processes();
253249
254− Finish:
255250 return error;
256251 }
257252
kernel/power/process.c+12−12
@@ -53,11 +53,9 @@ static int try_to_freeze_tasks(bool user_only) · 52 unmodified lines
5353 * It is "frozen enough". If the task does wake
5454 * up, it will immediately call try_to_freeze.
5555 *
56− * Because freeze_task() goes through p's
57− * scheduler lock after setting TIF_FREEZE, it's
58− * guaranteed that either we see TASK_RUNNING or
59− * try_to_stop() after schedule() in ptrace/signal
60− * stop sees TIF_FREEZE.
56+ * Because freeze_task() goes through p's scheduler lock, it's
57+ * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
58+ * transition can't race with task state testing here.
6159 */
6260 if (!task_is_stopped_or_traced(p) &&
6361 !freezer_should_skip(p))
@@ -98,13 +96,15 @@ static int try_to_freeze_tasks(bool user_only) · 34 unmodified lines
9896 elapsed_csecs / 100, elapsed_csecs % 100,
9997 todo - wq_busy, wq_busy);
10098
101− read_lock(&tasklist_lock);
102− do_each_thread(g, p) {
103− if (!wakeup && !freezer_should_skip(p) &&
104− p != current && freezing(p) && !frozen(p))
105− sched_show_task(p);
106− } while_each_thread(g, p);
107− read_unlock(&tasklist_lock);
99+ if (!wakeup) {
100+ read_lock(&tasklist_lock);
101+ do_each_thread(g, p) {
102+ if (p != current && !freezer_should_skip(p)
103+ && freezing(p) && !frozen(p))
104+ sched_show_task(p);
105+ } while_each_thread(g, p);
106+ read_unlock(&tasklist_lock);
107+ }
108108 } else {
109109 printk("(elapsed %d.%02d seconds) ", elapsed_csecs / 100,
110110 elapsed_csecs % 100);
kernel/power/snapshot.c+4−3
@@ -711,9 +711,10 @@ static void mark_nosave_pages(struct memory_bitmap *bm) · 710 unmodified lines
711711 list_for_each_entry(region, &nosave_regions, list) {
712712 unsigned long pfn;
713713
714− pr_debug("PM: Marking nosave pages: %016lx - %016lx\n",
715− region->start_pfn << PAGE_SHIFT,
716− region->end_pfn << PAGE_SHIFT);
714+ pr_debug("PM: Marking nosave pages: [mem %#010llx-%#010llx]\n",
715+ (unsigned long long) region->start_pfn << PAGE_SHIFT,
716+ ((unsigned long long) region->end_pfn << PAGE_SHIFT)
717+ - 1);
717718
718719 for (pfn = region->start_pfn; pfn < region->end_pfn; pfn++)
719720 if (pfn_valid(pfn)) {
kernel/power/suspend.c+42−42
@@ -37,8 +37,8 @@ const char *const pm_states[PM_SUSPEND_MAX] = { · 36 unmodified lines
3737 static const struct platform_suspend_ops *suspend_ops;
3838
3939 /**
40− * suspend_set_ops - Set the global suspend method table.
41− * @ops: Pointer to ops structure.
40+ * suspend_set_ops - Set the global suspend method table.
41+ * @ops: Suspend operations to use.
4242 */
4343 void suspend_set_ops(const struct platform_suspend_ops *ops)
4444 {
@@ -58,11 +58,11 @@ bool valid_state(suspend_state_t state) · 13 unmodified lines
5858 }
5959
6060 /**
61− * suspend_valid_only_mem - generic memory-only valid callback
61+ * suspend_valid_only_mem - Generic memory-only valid callback.
6262 *
63− * Platform drivers that implement mem suspend only and only need
64− * to check for that in their .valid callback can use this instead
65− * of rolling their own .valid callback.
63+ * Platform drivers that implement mem suspend only and only need to check for
64+ * that in their .valid() callback can use this instead of rolling their own
65+ * .valid() callback.
6666 */
6767 int suspend_valid_only_mem(suspend_state_t state)
6868 {
@@ -83,10 +83,11 @@ static int suspend_test(int level) · 14 unmodified lines
8383 }
8484
8585 /**
86− * suspend_prepare - Do prep work before entering low-power state.
86+ * suspend_prepare - Prepare for entering system sleep state.
8787 *
88− * This is common code that is called for each state that we're entering.
89− * Run suspend notifiers, allocate a console and stop all processes.
88+ * Common code run for every system sleep state that can be entered (except for
89+ * hibernation). Run suspend notifiers, allocate the "suspend" console and
90+ * freeze processes.
9091 */
9192 static int suspend_prepare(void)
9293 {
@@ -131,9 +132,9 @@ void __attribute__ ((weak)) arch_suspend_enable_irqs(void) · 38 unmodified lines
131132 }
132133
133134 /**
134− * suspend_enter - enter the desired system sleep state.
135− * @state: State to enter
136− * @wakeup: Returns information that suspend should not be entered again.
135+ * suspend_enter - Make the system enter the given sleep state.
136+ * @state: System sleep state to enter.
137+ * @wakeup: Returns information that the sleep state should not be re-entered.
137138 *
138139 * This function should be called after devices have been suspended.
139140 */
@@ -147,7 +148,7 @@ static int suspend_enter(suspend_state_t state, bool *wakeup) · 7 unmodified lines
147148 goto Platform_finish;
148149 }
149150
150− error = dpm_suspend_noirq(PMSG_SUSPEND);
151+ error = dpm_suspend_end(PMSG_SUSPEND);
151152 if (error) {
152153 printk(KERN_ERR "PM: Some devices failed to power down\n");
153154 goto Platform_finish;
@@ -189,7 +190,7 @@ static int suspend_enter(suspend_state_t state, bool *wakeup) · 35 unmodified lines
189190 if (suspend_ops->wake)
190191 suspend_ops->wake();
191192
192− dpm_resume_noirq(PMSG_RESUME);
193+ dpm_resume_start(PMSG_RESUME);
193194
194195 Platform_finish:
195196 if (suspend_ops->finish)
@@ -199,9 +200,8 @@ static int suspend_enter(suspend_state_t state, bool *wakeup) · 3 unmodified lines
199200 }
200201
201202 /**
202− * suspend_devices_and_enter - suspend devices and enter the desired system
203− * sleep state.
204− * @state: state to enter
203+ * suspend_devices_and_enter - Suspend devices and enter system sleep state.
204+ * @state: System sleep state to enter.
205205 */
206206 int suspend_devices_and_enter(suspend_state_t state)
207207 {
@@ -251,10 +251,10 @@ int suspend_devices_and_enter(suspend_state_t state) · 43 unmodified lines
251251 }
252252
253253 /**
254− * suspend_finish - Do final work before exiting suspend sequence.
254+ * suspend_finish - Clean up before finishing the suspend sequence.
255255 *
256− * Call platform code to clean up, restart processes, and free the
257− * console that we've allocated. This is not called for suspend-to-disk.
256+ * Call platform code to clean up, restart processes, and free the console that
257+ * we've allocated. This routine is not called for hibernation.
258258 */
259259 static void suspend_finish(void)
260260 {
@@ -265,16 +265,14 @@ static void suspend_finish(void) · 4 unmodified lines
265265 }
266266
267267 /**
268− * enter_state - Do common work of entering low-power state.
269− * @state: pm_state structure for state we're entering.
268+ * enter_state - Do common work needed to enter system sleep state.
269+ * @state: System sleep state to enter.
270270 *
271− * Make sure we're the only ones trying to enter a sleep state. Fail
272− * if someone has beat us to it, since we don't want anything weird to
273− * happen when we wake up.
274− * Then, do the setup for suspend, enter the state, and cleaup (after
275− * we've woken up).
271+ * Make sure that no one else is trying to put the system into a sleep state.
272+ * Fail if that's not the case. Otherwise, prepare for system suspend, make the
273+ * system enter the given sleep state and clean up after wakeup.
276274 */
277−int enter_state(suspend_state_t state)
275+static int enter_state(suspend_state_t state)
278276 {
279277 int error;
280278
@@ -310,24 +308,26 @@ int enter_state(suspend_state_t state) · 29 unmodified lines
310308 }
311309
312310 /**
313− * pm_suspend - Externally visible function for suspending system.
314− * @state: Enumerated value of state to enter.
311+ * pm_suspend - Externally visible function for suspending the system.
312+ * @state: System sleep state to enter.
315313 *
316− * Determine whether or not value is within range, get state
317− * structure, and enter (above).
314+ * Check if the value of @state represents one of the supported states,
315+ * execute enter_state() and update system suspend statistics.
318316 */
319317 int pm_suspend(suspend_state_t state)
320318 {
321− int ret;
322− if (state > PM_SUSPEND_ON && state < PM_SUSPEND_MAX) {
323− ret = enter_state(state);
324− if (ret) {
325− suspend_stats.fail++;
326− dpm_save_failed_errno(ret);
327− } else
328− suspend_stats.success++;
329− return ret;
319+ int error;
320+
321+ if (state <= PM_SUSPEND_ON || state >= PM_SUSPEND_MAX)
322+ return -EINVAL;
323+
324+ error = enter_state(state);
325+ if (error) {
326+ suspend_stats.fail++;
327+ dpm_save_failed_errno(error);
328+ } else {
329+ suspend_stats.success++;
330330 }
331− return -EINVAL;
331+ return error;
332332 }
333333 EXPORT_SYMBOL(pm_suspend);
kernel/power/user.c+3−9
@@ -249,16 +249,10 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd, · 248 unmodified lines
249249 }
250250 pm_restore_gfp_mask();
251251 error = hibernation_snapshot(data->platform_support);
252− if (error) {
253− thaw_kernel_threads();
254− } else {
252+ if (!error) {
255253 error = put_user(in_suspend, (int __user *)arg);
256− if (!error && !freezer_test_done)
257− data->ready = 1;
258− if (freezer_test_done) {
259− freezer_test_done = false;
260− thaw_kernel_threads();
261− }
254+ data->ready = !freezer_test_done && !error;
255+ freezer_test_done = false;
262256 }
263257 break;
264258

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t