1
2
3#ifndef FREEZER_H_INCLUDED
4#define FREEZER_H_INCLUDED
5
6#include <linux/sched.h>
7#include <linux/wait.h>
8#include <linux/atomic.h>
9
10#ifdef CONFIG_FREEZER
11extern atomic_t system_freezing_cnt;
12extern bool pm_freezing;
13extern bool pm_nosig_freezing;
14
15
16
17
18static inline bool frozen(struct task_struct *p)
19{
20 return p->flags & PF_FROZEN;
21}
22
23extern bool freezing_slow_path(struct task_struct *p);
24
25
26
27
28static inline bool freezing(struct task_struct *p)
29{
30 if (likely(!atomic_read(&system_freezing_cnt)))
31 return false;
32 return freezing_slow_path(p);
33}
34
35
36extern void __thaw_task(struct task_struct *t);
37
38extern bool __refrigerator(bool check_kthr_stop);
39extern int freeze_processes(void);
40extern int freeze_kernel_threads(void);
41extern void thaw_processes(void);
42extern void thaw_kernel_threads(void);
43
44static inline bool try_to_freeze(void)
45{
46 might_sleep();
47 if (likely(!freezing(current)))
48 return false;
49 return __refrigerator(false);
50}
51
52extern bool freeze_task(struct task_struct *p);
53extern bool set_freezable(void);
54
55#ifdef CONFIG_CGROUP_FREEZER
56extern bool cgroup_freezing(struct task_struct *task);
57#else
58static inline bool cgroup_freezing(struct task_struct *task)
59{
60 return false;
61}
62#endif
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89static inline void freezer_do_not_count(void)
90{
91 current->flags |= PF_FREEZER_SKIP;
92}
93
94
95
96
97
98
99
100
101static inline void freezer_count(void)
102{
103 current->flags &= ~PF_FREEZER_SKIP;
104
105
106
107
108
109 smp_mb();
110 try_to_freeze();
111}
112
113
114
115
116
117
118
119
120
121
122
123static inline bool freezer_should_skip(struct task_struct *p)
124{
125
126
127
128
129
130
131
132 smp_mb();
133 return p->flags & PF_FREEZER_SKIP;
134}
135
136
137
138
139
140
141
142
143#define freezable_schedule() \
144({ \
145 freezer_do_not_count(); \
146 schedule(); \
147 freezer_count(); \
148})
149
150
151#define freezable_schedule_timeout_killable(timeout) \
152({ \
153 long __retval; \
154 freezer_do_not_count(); \
155 __retval = schedule_timeout_killable(timeout); \
156 freezer_count(); \
157 __retval; \
158})
159
160
161
162
163
164
165
166#define wait_event_freezekillable(wq, condition) \
167({ \
168 int __retval; \
169 freezer_do_not_count(); \
170 __retval = wait_event_killable(wq, (condition)); \
171 freezer_count(); \
172 __retval; \
173})
174
175#define wait_event_freezable(wq, condition) \
176({ \
177 int __retval; \
178 for (;;) { \
179 __retval = wait_event_interruptible(wq, \
180 (condition) || freezing(current)); \
181 if (__retval || (condition)) \
182 break; \
183 try_to_freeze(); \
184 } \
185 __retval; \
186})
187
188#define wait_event_freezable_timeout(wq, condition, timeout) \
189({ \
190 long __retval = timeout; \
191 for (;;) { \
192 __retval = wait_event_interruptible_timeout(wq, \
193 (condition) || freezing(current), \
194 __retval); \
195 if (__retval <= 0 || (condition)) \
196 break; \
197 try_to_freeze(); \
198 } \
199 __retval; \
200})
201
202#else
203static inline bool frozen(struct task_struct *p) { return false; }
204static inline bool freezing(struct task_struct *p) { return false; }
205static inline void __thaw_task(struct task_struct *t) {}
206
207static inline bool __refrigerator(bool check_kthr_stop) { return false; }
208static inline int freeze_processes(void) { return -ENOSYS; }
209static inline int freeze_kernel_threads(void) { return -ENOSYS; }
210static inline void thaw_processes(void) {}
211static inline void thaw_kernel_threads(void) {}
212
213static inline bool try_to_freeze_nowarn(void) { return false; }
214static inline bool try_to_freeze(void) { return false; }
215
216static inline void freezer_do_not_count(void) {}
217static inline void freezer_count(void) {}
218static inline int freezer_should_skip(struct task_struct *p) { return 0; }
219static inline void set_freezable(void) {}
220
221#define freezable_schedule() schedule()
222
223#define freezable_schedule_timeout_killable(timeout) \
224 schedule_timeout_killable(timeout)
225
226#define wait_event_freezable(wq, condition) \
227 wait_event_interruptible(wq, condition)
228
229#define wait_event_freezable_timeout(wq, condition, timeout) \
230 wait_event_interruptible_timeout(wq, condition, timeout)
231
232#define wait_event_freezekillable(wq, condition) \
233 wait_event_killable(wq, condition)
234
235#endif
236
237#endif
238