2 * drivers/power/process.c - Functions for starting/stopping processes on
5 * Originally from swsusp.
11 #include <linux/smp_lock.h>
12 #include <linux/interrupt.h>
13 #include <linux/suspend.h>
14 #include <linux/module.h>
17 #define MDELAY(a) mdelay(a)
23 * Timeout for stopping processes
25 #define TIMEOUT (6 * HZ)
28 static inline int freezeable(struct task_struct * p)
31 (p->flags & PF_NOFREEZE) ||
32 (p->state == TASK_ZOMBIE) ||
33 (p->state == TASK_DEAD) ||
34 (p->state == TASK_STOPPED))
39 /* Refrigerator is place where frozen processes are stored :-). */
40 void refrigerator(unsigned long flag)
42 /* Hmm, should we be allowed to suspend when there are realtime
45 save = current->state;
46 current->state = TASK_UNINTERRUPTIBLE;
47 pr_debug("%s entered refrigerator\n", current->comm);
49 current->flags &= ~PF_FREEZE;
51 spin_lock_irq(¤t->sighand->siglock);
52 recalc_sigpending(); /* We sent fake signal, clean it up */
53 spin_unlock_irq(¤t->sighand->siglock);
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);