2 * drivers/power/process.c - Functions for starting/stopping processes on
5 * Originally from swsusp.
11 #include <linux/interrupt.h>
12 #include <linux/suspend.h>
13 #include <linux/module.h>
16 #define MDELAY(a) mdelay(a)
22 * Timeout for stopping processes
24 #define TIMEOUT (6 * HZ)
27 static inline int freezeable(struct task_struct * p)
30 (p->flags & PF_IOTHREAD) ||
31 (p->state == TASK_ZOMBIE) ||
32 (p->state == TASK_DEAD))
37 /* Refrigerator is place where frozen processes are stored :-). */
38 void refrigerator(unsigned long flag)
40 /* You need correct to work with real-time processes.
41 OTOH, this way one process may see (via /proc/) some other
42 process in stopped state (and thereby discovered we were
43 suspended. We probably do not care.
46 save = current->state;
47 current->state = TASK_STOPPED;
48 pr_debug("%s entered refrigerator\n", current->comm);
50 current->flags &= ~PF_FREEZE;
52 flush_signals(current); /* We have signaled a kernel thread, which isn't normal behaviour
53 and that may lead to 100%CPU sucking because those threads
54 just don't manage signals. */
55 current->flags |= PF_FROZEN;
56 while (current->flags & PF_FROZEN)
58 pr_debug("%s left refrigerator\n", current->comm);
59 current->state = save;
62 /* 0 = success, else # of processes that we failed to stop */
63 int freeze_processes(void)
66 unsigned long start_time;
67 struct task_struct *g, *p;
69 printk( "Stopping tasks: " );
73 read_lock(&tasklist_lock);
74 do_each_thread(g, p) {
78 if ((p->flags & PF_FROZEN) ||
79 (p->state == TASK_STOPPED))
82 /* FIXME: smp problem here: we may not access other process' flags
84 p->flags |= PF_FREEZE;
85 spin_lock_irqsave(&p->sighand->siglock, flags);
87 spin_unlock_irqrestore(&p->sighand->siglock, flags);
89 } while_each_thread(g, p);
90 read_unlock(&tasklist_lock);
91 yield(); /* Yield is okay here */
92 if (time_after(jiffies, start_time + TIMEOUT)) {
94 printk(KERN_ERR " stopping tasks failed (%d tasks remaining)\n", todo );
104 void thaw_processes(void)
106 struct task_struct *g, *p;
108 printk( "Restarting tasks..." );
109 read_lock(&tasklist_lock);
110 do_each_thread(g, p) {
113 if (p->flags & PF_FROZEN) {
114 p->flags &= ~PF_FROZEN;
117 printk(KERN_INFO " Strange, %s not stopped\n", p->comm );
119 } while_each_thread(g, p);
121 read_unlock(&tasklist_lock);
127 EXPORT_SYMBOL(refrigerator);