1 /* Freezer declarations */
3 #ifndef FREEZER_H_INCLUDED
4 #define FREEZER_H_INCLUDED
6 #include <linux/sched.h>
7 #include <linux/wait.h>
11 * Check if a process has been frozen
13 static inline int frozen(struct task_struct *p)
15 return p->flags & PF_FROZEN;
19 * Check if there is a request to freeze a process
21 static inline int freezing(struct task_struct *p)
23 return test_tsk_thread_flag(p, TIF_FREEZE);
27 * Request that a process be frozen
29 static inline void set_freeze_flag(struct task_struct *p)
31 set_tsk_thread_flag(p, TIF_FREEZE);
35 * Sometimes we may need to cancel the previous 'freeze' request
37 static inline void clear_freeze_flag(struct task_struct *p)
39 clear_tsk_thread_flag(p, TIF_FREEZE);
42 static inline bool should_send_signal(struct task_struct *p)
44 return !(p->flags & PF_FREEZER_NOSIG);
47 /* Takes and releases task alloc lock using task_lock() */
48 extern void __thaw_task(struct task_struct *t);
50 extern bool __refrigerator(bool check_kthr_stop);
51 extern int freeze_processes(void);
52 extern int freeze_kernel_threads(void);
53 extern void thaw_processes(void);
55 static inline bool try_to_freeze(void)
58 if (likely(!freezing(current)))
60 return __refrigerator(false);
63 extern bool freeze_task(struct task_struct *p, bool sig_only);
65 #ifdef CONFIG_CGROUP_FREEZER
66 extern bool cgroup_freezing(struct task_struct *task);
67 #else /* !CONFIG_CGROUP_FREEZER */
68 static inline bool cgroup_freezing(struct task_struct *task)
72 #endif /* !CONFIG_CGROUP_FREEZER */
75 * The PF_FREEZER_SKIP flag should be set by a vfork parent right before it
76 * calls wait_for_completion(&vfork) and reset right after it returns from this
77 * function. Next, the parent should call try_to_freeze() to freeze itself
78 * appropriately in case the child has exited before the freezing of tasks is
79 * complete. However, we don't want kernel threads to be frozen in unexpected
80 * places, so we allow them to block freeze_processes() instead or to set
81 * PF_NOFREEZE if needed and PF_FREEZER_SKIP is only set for userland vfork
82 * parents. Fortunately, in the ____call_usermodehelper() case the parent won't
83 * really block freeze_processes(), since ____call_usermodehelper() (the child)
84 * does a little before exec/exit and it can't be frozen before waking up the
89 * If the current task is a user space one, tell the freezer not to count it as
92 static inline void freezer_do_not_count(void)
95 current->flags |= PF_FREEZER_SKIP;
99 * If the current task is a user space one, tell the freezer to count it as
100 * freezable again and try to freeze it.
102 static inline void freezer_count(void)
105 current->flags &= ~PF_FREEZER_SKIP;
111 * Check if the task should be counted as freezable by the freezer
113 static inline int freezer_should_skip(struct task_struct *p)
115 return !!(p->flags & PF_FREEZER_SKIP);
119 * Tell the freezer that the current task should be frozen by it
121 static inline void set_freezable(void)
123 current->flags &= ~PF_NOFREEZE;
127 * Tell the freezer that the current task should be frozen by it and that it
128 * should send a fake signal to the task to freeze it.
130 static inline void set_freezable_with_signal(void)
132 current->flags &= ~(PF_NOFREEZE | PF_FREEZER_NOSIG);
136 * Freezer-friendly wrappers around wait_event_interruptible(),
137 * wait_event_killable() and wait_event_interruptible_timeout(), originally
138 * defined in <linux/wait.h>
141 #define wait_event_freezekillable(wq, condition) \
144 freezer_do_not_count(); \
145 __retval = wait_event_killable(wq, (condition)); \
150 #define wait_event_freezable(wq, condition) \
154 __retval = wait_event_interruptible(wq, \
155 (condition) || freezing(current)); \
156 if (__retval && !freezing(current)) \
158 else if (!(condition)) \
159 __retval = -ERESTARTSYS; \
160 } while (try_to_freeze()); \
165 #define wait_event_freezable_timeout(wq, condition, timeout) \
167 long __retval = timeout; \
169 __retval = wait_event_interruptible_timeout(wq, \
170 (condition) || freezing(current), \
172 } while (try_to_freeze()); \
175 #else /* !CONFIG_FREEZER */
176 static inline int frozen(struct task_struct *p) { return 0; }
177 static inline int freezing(struct task_struct *p) { return 0; }
178 static inline void set_freeze_flag(struct task_struct *p) {}
179 static inline void clear_freeze_flag(struct task_struct *p) {}
181 static inline bool __refrigerator(bool check_kthr_stop) { return false; }
182 static inline int freeze_processes(void) { return -ENOSYS; }
183 static inline int freeze_kernel_threads(void) { return -ENOSYS; }
184 static inline void thaw_processes(void) {}
186 static inline bool try_to_freeze(void) { return false; }
188 static inline void freezer_do_not_count(void) {}
189 static inline void freezer_count(void) {}
190 static inline int freezer_should_skip(struct task_struct *p) { return 0; }
191 static inline void set_freezable(void) {}
192 static inline void set_freezable_with_signal(void) {}
194 #define wait_event_freezable(wq, condition) \
195 wait_event_interruptible(wq, condition)
197 #define wait_event_freezable_timeout(wq, condition, timeout) \
198 wait_event_interruptible_timeout(wq, condition, timeout)
200 #define wait_event_freezekillable(wq, condition) \
201 wait_event_killable(wq, condition)
203 #endif /* !CONFIG_FREEZER */
205 #endif /* FREEZER_H_INCLUDED */