2 * drivers/power/process.c - Functions for starting/stopping processes on
5 * Originally from swsusp.
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>
19 * Timeout for stopping processes
21 #define TIMEOUT (20 * HZ)
23 static inline int freezeable(struct task_struct
* p
)
26 (p
->flags
& PF_NOFREEZE
) ||
32 static int try_to_freeze_tasks(bool sig_only
)
34 struct task_struct
*g
, *p
;
35 unsigned long end_time
;
37 struct timeval start
, end
;
39 unsigned int elapsed_csecs
;
41 do_gettimeofday(&start
);
43 end_time
= jiffies
+ TIMEOUT
;
46 read_lock(&tasklist_lock
);
47 do_each_thread(g
, p
) {
48 if (frozen(p
) || !freezeable(p
))
51 if (!freeze_task(p
, sig_only
))
55 * Now that we've done set_freeze_flag, don't
56 * perturb a task in TASK_STOPPED or TASK_TRACED.
57 * It is "frozen enough". If the task does wake
58 * up, it will immediately call try_to_freeze.
60 if (!task_is_stopped_or_traced(p
) &&
61 !freezer_should_skip(p
))
63 } while_each_thread(g
, p
);
64 read_unlock(&tasklist_lock
);
65 yield(); /* Yield is okay here */
66 if (time_after(jiffies
, end_time
))
70 do_gettimeofday(&end
);
71 elapsed_csecs64
= timeval_to_ns(&end
) - timeval_to_ns(&start
);
72 do_div(elapsed_csecs64
, NSEC_PER_SEC
/ 100);
73 elapsed_csecs
= elapsed_csecs64
;
76 /* This does not unfreeze processes that are already frozen
77 * (we have slightly ugly calling convention in that respect,
78 * and caller must call thaw_processes() if something fails),
79 * but it cleans up leftover PF_FREEZE requests.
82 printk(KERN_ERR
"Freezing of tasks failed after %d.%02d seconds "
83 "(%d tasks refusing to freeze):\n",
84 elapsed_csecs
/ 100, elapsed_csecs
% 100, todo
);
86 read_lock(&tasklist_lock
);
87 do_each_thread(g
, p
) {
89 if (freezing(p
) && !freezer_should_skip(p
))
90 printk(KERN_ERR
" %s\n", p
->comm
);
93 } while_each_thread(g
, p
);
94 read_unlock(&tasklist_lock
);
96 printk("(elapsed %d.%02d seconds) ", elapsed_csecs
/ 100,
100 return todo
? -EBUSY
: 0;
104 * freeze_processes - tell processes to enter the refrigerator
106 int freeze_processes(void)
110 printk("Freezing user space processes ... ");
111 error
= try_to_freeze_tasks(true);
116 printk("Freezing remaining freezable tasks ... ");
117 error
= try_to_freeze_tasks(false);
122 oom_killer_disable();
130 static void thaw_tasks(bool nosig_only
)
132 struct task_struct
*g
, *p
;
134 read_lock(&tasklist_lock
);
135 do_each_thread(g
, p
) {
139 if (nosig_only
&& should_send_signal(p
))
142 if (cgroup_frozen(p
))
146 } while_each_thread(g
, p
);
147 read_unlock(&tasklist_lock
);
150 void thaw_processes(void)
154 printk("Restarting tasks ... ");