be2net: fix unconditionally returning IRQ_HANDLED in INTx
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / kernel / power / process.c
blobd5a258b60c6fd71aed065a0dd2ea5acadddc991f
1 /*
2 * drivers/power/process.c - Functions for starting/stopping processes on
3 * suspend transitions.
5 * Originally from swsusp.
6 */
9 #undef DEBUG
11 #include <linux/interrupt.h>
12 #include <linux/oom.h>
13 #include <linux/suspend.h>
14 #include <linux/module.h>
15 #include <linux/syscalls.h>
16 #include <linux/freezer.h>
17 #include <linux/delay.h>
18 #include <linux/workqueue.h>
19 #include <linux/kmod.h>
21 /*
22 * Timeout for stopping processes
24 #define TIMEOUT (20 * HZ)
26 static int try_to_freeze_tasks(bool user_only)
28 struct task_struct *g, *p;
29 unsigned long end_time;
30 unsigned int todo;
31 bool wq_busy = false;
32 struct timeval start, end;
33 u64 elapsed_csecs64;
34 unsigned int elapsed_csecs;
35 bool wakeup = false;
37 do_gettimeofday(&start);
39 end_time = jiffies + TIMEOUT;
41 if (!user_only)
42 freeze_workqueues_begin();
44 while (true) {
45 todo = 0;
46 read_lock(&tasklist_lock);
47 do_each_thread(g, p) {
48 if (p == current || !freeze_task(p))
49 continue;
51 if (!freezer_should_skip(p))
52 todo++;
53 } while_each_thread(g, p);
54 read_unlock(&tasklist_lock);
56 if (!user_only) {
57 wq_busy = freeze_workqueues_busy();
58 todo += wq_busy;
61 if (!todo || time_after(jiffies, end_time))
62 break;
64 if (pm_wakeup_pending()) {
65 wakeup = true;
66 break;
70 * We need to retry, but first give the freezing tasks some
71 * time to enter the refrigerator.
73 msleep(10);
76 do_gettimeofday(&end);
77 elapsed_csecs64 = timeval_to_ns(&end) - timeval_to_ns(&start);
78 do_div(elapsed_csecs64, NSEC_PER_SEC / 100);
79 elapsed_csecs = elapsed_csecs64;
81 if (todo) {
82 printk("\n");
83 printk(KERN_ERR "Freezing of tasks %s after %d.%02d seconds "
84 "(%d tasks refusing to freeze, wq_busy=%d):\n",
85 wakeup ? "aborted" : "failed",
86 elapsed_csecs / 100, elapsed_csecs % 100,
87 todo - wq_busy, wq_busy);
89 if (!wakeup) {
90 read_lock(&tasklist_lock);
91 do_each_thread(g, p) {
92 if (p != current && !freezer_should_skip(p)
93 && freezing(p) && !frozen(p))
94 sched_show_task(p);
95 } while_each_thread(g, p);
96 read_unlock(&tasklist_lock);
98 } else {
99 printk("(elapsed %d.%02d seconds) ", elapsed_csecs / 100,
100 elapsed_csecs % 100);
103 return todo ? -EBUSY : 0;
107 * freeze_processes - Signal user space processes to enter the refrigerator.
109 * On success, returns 0. On failure, -errno and system is fully thawed.
111 int freeze_processes(void)
113 int error;
115 error = __usermodehelper_disable(UMH_FREEZING);
116 if (error)
117 return error;
119 if (!pm_freezing)
120 atomic_inc(&system_freezing_cnt);
122 printk("Freezing user space processes ... ");
123 pm_freezing = true;
124 error = try_to_freeze_tasks(true);
125 if (!error) {
126 printk("done.");
127 __usermodehelper_set_disable_depth(UMH_DISABLED);
128 oom_killer_disable();
130 printk("\n");
131 BUG_ON(in_atomic());
133 if (error)
134 thaw_processes();
135 return error;
139 * freeze_kernel_threads - Make freezable kernel threads go to the refrigerator.
141 * On success, returns 0. On failure, -errno and only the kernel threads are
142 * thawed, so as to give a chance to the caller to do additional cleanups
143 * (if any) before thawing the userspace tasks. So, it is the responsibility
144 * of the caller to thaw the userspace tasks, when the time is right.
146 int freeze_kernel_threads(void)
148 int error;
150 printk("Freezing remaining freezable tasks ... ");
151 pm_nosig_freezing = true;
152 error = try_to_freeze_tasks(false);
153 if (!error)
154 printk("done.");
156 printk("\n");
157 BUG_ON(in_atomic());
159 if (error)
160 thaw_kernel_threads();
161 return error;
164 void thaw_processes(void)
166 struct task_struct *g, *p;
168 if (pm_freezing)
169 atomic_dec(&system_freezing_cnt);
170 pm_freezing = false;
171 pm_nosig_freezing = false;
173 oom_killer_enable();
175 printk("Restarting tasks ... ");
177 thaw_workqueues();
179 read_lock(&tasklist_lock);
180 do_each_thread(g, p) {
181 __thaw_task(p);
182 } while_each_thread(g, p);
183 read_unlock(&tasklist_lock);
185 usermodehelper_enable();
187 schedule();
188 printk("done.\n");
191 void thaw_kernel_threads(void)
193 struct task_struct *g, *p;
195 pm_nosig_freezing = false;
196 printk("Restarting kernel threads ... ");
198 thaw_workqueues();
200 read_lock(&tasklist_lock);
201 do_each_thread(g, p) {
202 if (p->flags & (PF_KTHREAD | PF_WQ_WORKER))
203 __thaw_task(p);
204 } while_each_thread(g, p);
205 read_unlock(&tasklist_lock);
207 schedule();
208 printk("done.\n");