0001
0002
0003
0004 #ifndef FREEZER_H_INCLUDED
0005 #define FREEZER_H_INCLUDED
0006
0007 #include <linux/debug_locks.h>
0008 #include <linux/sched.h>
0009 #include <linux/wait.h>
0010 #include <linux/atomic.h>
0011
0012 #ifdef CONFIG_FREEZER
0013 extern atomic_t system_freezing_cnt;
0014 extern bool pm_freezing;
0015 extern bool pm_nosig_freezing;
0016
0017
0018
0019
0020 extern unsigned int freeze_timeout_msecs;
0021
0022
0023
0024
0025 static inline bool frozen(struct task_struct *p)
0026 {
0027 return p->flags & PF_FROZEN;
0028 }
0029
0030 extern bool freezing_slow_path(struct task_struct *p);
0031
0032
0033
0034
0035 static inline bool freezing(struct task_struct *p)
0036 {
0037 if (likely(!atomic_read(&system_freezing_cnt)))
0038 return false;
0039 return freezing_slow_path(p);
0040 }
0041
0042
0043 extern void __thaw_task(struct task_struct *t);
0044
0045 extern bool __refrigerator(bool check_kthr_stop);
0046 extern int freeze_processes(void);
0047 extern int freeze_kernel_threads(void);
0048 extern void thaw_processes(void);
0049 extern void thaw_kernel_threads(void);
0050
0051
0052
0053
0054
0055 static inline bool try_to_freeze_unsafe(void)
0056 {
0057 might_sleep();
0058 if (likely(!freezing(current)))
0059 return false;
0060 return __refrigerator(false);
0061 }
0062
0063 static inline bool try_to_freeze(void)
0064 {
0065 if (!(current->flags & PF_NOFREEZE))
0066 debug_check_no_locks_held();
0067 return try_to_freeze_unsafe();
0068 }
0069
0070 extern bool freeze_task(struct task_struct *p);
0071 extern bool set_freezable(void);
0072
0073 #ifdef CONFIG_CGROUP_FREEZER
0074 extern bool cgroup_freezing(struct task_struct *task);
0075 #else
0076 static inline bool cgroup_freezing(struct task_struct *task)
0077 {
0078 return false;
0079 }
0080 #endif
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107 static inline void freezer_do_not_count(void)
0108 {
0109 current->flags |= PF_FREEZER_SKIP;
0110 }
0111
0112
0113
0114
0115
0116
0117
0118
0119 static inline void freezer_count(void)
0120 {
0121 current->flags &= ~PF_FREEZER_SKIP;
0122
0123
0124
0125
0126
0127 smp_mb();
0128 try_to_freeze();
0129 }
0130
0131
0132 static inline void freezer_count_unsafe(void)
0133 {
0134 current->flags &= ~PF_FREEZER_SKIP;
0135 smp_mb();
0136 try_to_freeze_unsafe();
0137 }
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149 static inline bool freezer_should_skip(struct task_struct *p)
0150 {
0151
0152
0153
0154
0155
0156
0157
0158 smp_mb();
0159 return p->flags & PF_FREEZER_SKIP;
0160 }
0161
0162
0163
0164
0165
0166
0167
0168
0169 static inline void freezable_schedule(void)
0170 {
0171 freezer_do_not_count();
0172 schedule();
0173 freezer_count();
0174 }
0175
0176
0177 static inline void freezable_schedule_unsafe(void)
0178 {
0179 freezer_do_not_count();
0180 schedule();
0181 freezer_count_unsafe();
0182 }
0183
0184
0185
0186
0187
0188 static inline long freezable_schedule_timeout(long timeout)
0189 {
0190 long __retval;
0191 freezer_do_not_count();
0192 __retval = schedule_timeout(timeout);
0193 freezer_count();
0194 return __retval;
0195 }
0196
0197
0198
0199
0200
0201 static inline long freezable_schedule_timeout_interruptible(long timeout)
0202 {
0203 long __retval;
0204 freezer_do_not_count();
0205 __retval = schedule_timeout_interruptible(timeout);
0206 freezer_count();
0207 return __retval;
0208 }
0209
0210
0211 static inline long freezable_schedule_timeout_interruptible_unsafe(long timeout)
0212 {
0213 long __retval;
0214
0215 freezer_do_not_count();
0216 __retval = schedule_timeout_interruptible(timeout);
0217 freezer_count_unsafe();
0218 return __retval;
0219 }
0220
0221
0222 static inline long freezable_schedule_timeout_killable(long timeout)
0223 {
0224 long __retval;
0225 freezer_do_not_count();
0226 __retval = schedule_timeout_killable(timeout);
0227 freezer_count();
0228 return __retval;
0229 }
0230
0231
0232 static inline long freezable_schedule_timeout_killable_unsafe(long timeout)
0233 {
0234 long __retval;
0235 freezer_do_not_count();
0236 __retval = schedule_timeout_killable(timeout);
0237 freezer_count_unsafe();
0238 return __retval;
0239 }
0240
0241
0242
0243
0244
0245 static inline int freezable_schedule_hrtimeout_range(ktime_t *expires,
0246 u64 delta, const enum hrtimer_mode mode)
0247 {
0248 int __retval;
0249 freezer_do_not_count();
0250 __retval = schedule_hrtimeout_range(expires, delta, mode);
0251 freezer_count();
0252 return __retval;
0253 }
0254
0255
0256
0257
0258
0259
0260
0261
0262 #define wait_event_freezekillable_unsafe(wq, condition) \
0263 ({ \
0264 int __retval; \
0265 freezer_do_not_count(); \
0266 __retval = wait_event_killable(wq, (condition)); \
0267 freezer_count_unsafe(); \
0268 __retval; \
0269 })
0270
0271 #else
0272 static inline bool frozen(struct task_struct *p) { return false; }
0273 static inline bool freezing(struct task_struct *p) { return false; }
0274 static inline void __thaw_task(struct task_struct *t) {}
0275
0276 static inline bool __refrigerator(bool check_kthr_stop) { return false; }
0277 static inline int freeze_processes(void) { return -ENOSYS; }
0278 static inline int freeze_kernel_threads(void) { return -ENOSYS; }
0279 static inline void thaw_processes(void) {}
0280 static inline void thaw_kernel_threads(void) {}
0281
0282 static inline bool try_to_freeze(void) { return false; }
0283
0284 static inline void freezer_do_not_count(void) {}
0285 static inline void freezer_count(void) {}
0286 static inline int freezer_should_skip(struct task_struct *p) { return 0; }
0287 static inline void set_freezable(void) {}
0288
0289 #define freezable_schedule() schedule()
0290
0291 #define freezable_schedule_unsafe() schedule()
0292
0293 #define freezable_schedule_timeout(timeout) schedule_timeout(timeout)
0294
0295 #define freezable_schedule_timeout_interruptible(timeout) \
0296 schedule_timeout_interruptible(timeout)
0297
0298 #define freezable_schedule_timeout_interruptible_unsafe(timeout) \
0299 schedule_timeout_interruptible(timeout)
0300
0301 #define freezable_schedule_timeout_killable(timeout) \
0302 schedule_timeout_killable(timeout)
0303
0304 #define freezable_schedule_timeout_killable_unsafe(timeout) \
0305 schedule_timeout_killable(timeout)
0306
0307 #define freezable_schedule_hrtimeout_range(expires, delta, mode) \
0308 schedule_hrtimeout_range(expires, delta, mode)
0309
0310 #define wait_event_freezekillable_unsafe(wq, condition) \
0311 wait_event_killable(wq, condition)
0312
0313 #endif
0314
0315 #endif