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 * Timeout for stopping processes
19 #define TIMEOUT (6 * HZ)
22 static inline int freezeable(struct task_struct
* p
)
25 (p
->flags
& PF_NOFREEZE
) ||
26 (p
->exit_state
== EXIT_ZOMBIE
) ||
27 (p
->exit_state
== EXIT_DEAD
) ||
28 (p
->state
== TASK_STOPPED
) ||
29 (p
->state
== TASK_TRACED
))
34 /* Refrigerator is place where frozen processes are stored :-). */
35 void refrigerator(void)
37 /* Hmm, should we be allowed to suspend when there are realtime
40 save
= current
->state
;
41 pr_debug("%s entered refrigerator\n", current
->comm
);
44 frozen_process(current
);
45 spin_lock_irq(¤t
->sighand
->siglock
);
46 recalc_sigpending(); /* We sent fake signal, clean it up */
47 spin_unlock_irq(¤t
->sighand
->siglock
);
49 while (frozen(current
)) {
50 current
->state
= TASK_UNINTERRUPTIBLE
;
53 pr_debug("%s left refrigerator\n", current
->comm
);
54 current
->state
= save
;
57 /* 0 = success, else # of processes that we failed to stop */
58 int freeze_processes(void)
61 unsigned long start_time
;
62 struct task_struct
*g
, *p
;
65 printk( "Stopping tasks: " );
69 read_lock(&tasklist_lock
);
70 do_each_thread(g
, p
) {
77 spin_lock_irqsave(&p
->sighand
->siglock
, flags
);
79 spin_unlock_irqrestore(&p
->sighand
->siglock
, flags
);
81 } while_each_thread(g
, p
);
82 read_unlock(&tasklist_lock
);
83 yield(); /* Yield is okay here */
84 if (todo
&& time_after(jiffies
, start_time
+ TIMEOUT
)) {
86 printk(KERN_ERR
" stopping tasks failed (%d tasks remaining)\n", todo
);
91 /* This does not unfreeze processes that are already frozen
92 * (we have slightly ugly calling convention in that respect,
93 * and caller must call thaw_processes() if something fails),
94 * but it cleans up leftover PF_FREEZE requests.
97 read_lock(&tasklist_lock
);
100 pr_debug(" clean up: %s\n", p
->comm
);
101 p
->flags
&= ~PF_FREEZE
;
102 spin_lock_irqsave(&p
->sighand
->siglock
, flags
);
103 recalc_sigpending_tsk(p
);
104 spin_unlock_irqrestore(&p
->sighand
->siglock
, flags
);
106 while_each_thread(g
, p
);
107 read_unlock(&tasklist_lock
);
116 void thaw_processes(void)
118 struct task_struct
*g
, *p
;
120 printk( "Restarting tasks..." );
121 read_lock(&tasklist_lock
);
122 do_each_thread(g
, p
) {
125 if (!thaw_process(p
))
126 printk(KERN_INFO
" Strange, %s not stopped\n", p
->comm
);
127 } while_each_thread(g
, p
);
129 read_unlock(&tasklist_lock
);
134 EXPORT_SYMBOL(refrigerator
);