KEYS: Flag dead keys to induce EKEYREVOKED [try #6]
[linux-2.6/mini2440.git] / kernel / power / process.c
blobda2072d7381160493d540a51976f45a966b265fb
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/suspend.h>
13 #include <linux/module.h>
14 #include <linux/syscalls.h>
15 #include <linux/freezer.h>
17 /*
18 * Timeout for stopping processes
20 #define TIMEOUT (20 * HZ)
22 static inline int freezeable(struct task_struct * p)
24 if ((p == current) ||
25 (p->flags & PF_NOFREEZE) ||
26 (p->exit_state != 0))
27 return 0;
28 return 1;
31 static int try_to_freeze_tasks(bool sig_only)
33 struct task_struct *g, *p;
34 unsigned long end_time;
35 unsigned int todo;
36 struct timeval start, end;
37 u64 elapsed_csecs64;
38 unsigned int elapsed_csecs;
40 do_gettimeofday(&start);
42 end_time = jiffies + TIMEOUT;
43 do {
44 todo = 0;
45 read_lock(&tasklist_lock);
46 do_each_thread(g, p) {
47 if (frozen(p) || !freezeable(p))
48 continue;
50 if (!freeze_task(p, sig_only))
51 continue;
54 * Now that we've done set_freeze_flag, don't
55 * perturb a task in TASK_STOPPED or TASK_TRACED.
56 * It is "frozen enough". If the task does wake
57 * up, it will immediately call try_to_freeze.
59 if (!task_is_stopped_or_traced(p) &&
60 !freezer_should_skip(p))
61 todo++;
62 } while_each_thread(g, p);
63 read_unlock(&tasklist_lock);
64 yield(); /* Yield is okay here */
65 if (time_after(jiffies, end_time))
66 break;
67 } while (todo);
69 do_gettimeofday(&end);
70 elapsed_csecs64 = timeval_to_ns(&end) - timeval_to_ns(&start);
71 do_div(elapsed_csecs64, NSEC_PER_SEC / 100);
72 elapsed_csecs = elapsed_csecs64;
74 if (todo) {
75 /* This does not unfreeze processes that are already frozen
76 * (we have slightly ugly calling convention in that respect,
77 * and caller must call thaw_processes() if something fails),
78 * but it cleans up leftover PF_FREEZE requests.
80 printk("\n");
81 printk(KERN_ERR "Freezing of tasks failed after %d.%02d seconds "
82 "(%d tasks refusing to freeze):\n",
83 elapsed_csecs / 100, elapsed_csecs % 100, todo);
84 show_state();
85 read_lock(&tasklist_lock);
86 do_each_thread(g, p) {
87 task_lock(p);
88 if (freezing(p) && !freezer_should_skip(p))
89 printk(KERN_ERR " %s\n", p->comm);
90 cancel_freezing(p);
91 task_unlock(p);
92 } while_each_thread(g, p);
93 read_unlock(&tasklist_lock);
94 } else {
95 printk("(elapsed %d.%02d seconds) ", elapsed_csecs / 100,
96 elapsed_csecs % 100);
99 return todo ? -EBUSY : 0;
103 * freeze_processes - tell processes to enter the refrigerator
105 int freeze_processes(void)
107 int error;
109 printk("Freezing user space processes ... ");
110 error = try_to_freeze_tasks(true);
111 if (error)
112 goto Exit;
113 printk("done.\n");
115 printk("Freezing remaining freezable tasks ... ");
116 error = try_to_freeze_tasks(false);
117 if (error)
118 goto Exit;
119 printk("done.");
121 oom_killer_disable();
122 Exit:
123 BUG_ON(in_atomic());
124 printk("\n");
126 return error;
129 static void thaw_tasks(bool nosig_only)
131 struct task_struct *g, *p;
133 read_lock(&tasklist_lock);
134 do_each_thread(g, p) {
135 if (!freezeable(p))
136 continue;
138 if (nosig_only && should_send_signal(p))
139 continue;
141 if (cgroup_frozen(p))
142 continue;
144 thaw_process(p);
145 } while_each_thread(g, p);
146 read_unlock(&tasklist_lock);
149 void thaw_processes(void)
151 oom_killer_enable();
153 printk("Restarting tasks ... ");
154 thaw_tasks(true);
155 thaw_tasks(false);
156 schedule();
157 printk("done.\n");