Introduce CONFIG_SUSPEND for suspend-to-Ram and standby
[pv_ops_mirror.git] / include / linux / freezer.h
blobefded00ad08c5003bebd89964bb8b8619630a2c2
1 /* Freezer declarations */
3 #ifndef FREEZER_H_INCLUDED
4 #define FREEZER_H_INCLUDED
6 #include <linux/sched.h>
8 #ifdef CONFIG_PM_SLEEP
9 /*
10 * Check if a process has been frozen
12 static inline int frozen(struct task_struct *p)
14 return p->flags & PF_FROZEN;
18 * Check if there is a request to freeze a process
20 static inline int freezing(struct task_struct *p)
22 return test_tsk_thread_flag(p, TIF_FREEZE);
26 * Request that a process be frozen
28 static inline void set_freeze_flag(struct task_struct *p)
30 set_tsk_thread_flag(p, TIF_FREEZE);
34 * Sometimes we may need to cancel the previous 'freeze' request
36 static inline void clear_freeze_flag(struct task_struct *p)
38 clear_tsk_thread_flag(p, TIF_FREEZE);
42 * Wake up a frozen process
44 * task_lock() is taken to prevent the race with refrigerator() which may
45 * occur if the freezing of tasks fails. Namely, without the lock, if the
46 * freezing of tasks failed, thaw_tasks() might have run before a task in
47 * refrigerator() could call frozen_process(), in which case the task would be
48 * frozen and no one would thaw it.
50 static inline int thaw_process(struct task_struct *p)
52 task_lock(p);
53 if (frozen(p)) {
54 p->flags &= ~PF_FROZEN;
55 task_unlock(p);
56 wake_up_process(p);
57 return 1;
59 clear_freeze_flag(p);
60 task_unlock(p);
61 return 0;
64 extern void refrigerator(void);
65 extern int freeze_processes(void);
66 extern void thaw_processes(void);
68 static inline int try_to_freeze(void)
70 if (freezing(current)) {
71 refrigerator();
72 return 1;
73 } else
74 return 0;
78 * The PF_FREEZER_SKIP flag should be set by a vfork parent right before it
79 * calls wait_for_completion(&vfork) and reset right after it returns from this
80 * function. Next, the parent should call try_to_freeze() to freeze itself
81 * appropriately in case the child has exited before the freezing of tasks is
82 * complete. However, we don't want kernel threads to be frozen in unexpected
83 * places, so we allow them to block freeze_processes() instead or to set
84 * PF_NOFREEZE if needed and PF_FREEZER_SKIP is only set for userland vfork
85 * parents. Fortunately, in the ____call_usermodehelper() case the parent won't
86 * really block freeze_processes(), since ____call_usermodehelper() (the child)
87 * does a little before exec/exit and it can't be frozen before waking up the
88 * parent.
92 * If the current task is a user space one, tell the freezer not to count it as
93 * freezable.
95 static inline void freezer_do_not_count(void)
97 if (current->mm)
98 current->flags |= PF_FREEZER_SKIP;
102 * If the current task is a user space one, tell the freezer to count it as
103 * freezable again and try to freeze it.
105 static inline void freezer_count(void)
107 if (current->mm) {
108 current->flags &= ~PF_FREEZER_SKIP;
109 try_to_freeze();
114 * Check if the task should be counted as freezeable by the freezer
116 static inline int freezer_should_skip(struct task_struct *p)
118 return !!(p->flags & PF_FREEZER_SKIP);
122 * Tell the freezer that the current task should be frozen by it
124 static inline void set_freezable(void)
126 current->flags &= ~PF_NOFREEZE;
129 #else /* !CONFIG_PM_SLEEP */
130 static inline int frozen(struct task_struct *p) { return 0; }
131 static inline int freezing(struct task_struct *p) { return 0; }
132 static inline void set_freeze_flag(struct task_struct *p) {}
133 static inline void clear_freeze_flag(struct task_struct *p) {}
134 static inline int thaw_process(struct task_struct *p) { return 1; }
136 static inline void refrigerator(void) {}
137 static inline int freeze_processes(void) { BUG(); return 0; }
138 static inline void thaw_processes(void) {}
140 static inline int try_to_freeze(void) { return 0; }
142 static inline void freezer_do_not_count(void) {}
143 static inline void freezer_count(void) {}
144 static inline int freezer_should_skip(struct task_struct *p) { return 0; }
145 static inline void set_freezable(void) {}
146 #endif /* !CONFIG_PM_SLEEP */
148 #endif /* FREEZER_H_INCLUDED */