nohz: Rename CONFIG_NO_HZ to CONFIG_NO_HZ_COMMON
[deliverable/linux.git] / include / linux / freezer.h
CommitLineData
7dfb7103
NC
1/* Freezer declarations */
2
83144186
RW
3#ifndef FREEZER_H_INCLUDED
4#define FREEZER_H_INCLUDED
5
6aa97070 6#include <linux/debug_locks.h>
5c543eff 7#include <linux/sched.h>
e42837bc 8#include <linux/wait.h>
a3201227 9#include <linux/atomic.h>
5c543eff 10
8174f150 11#ifdef CONFIG_FREEZER
a3201227
TH
12extern atomic_t system_freezing_cnt; /* nr of freezing conds in effect */
13extern bool pm_freezing; /* PM freezing in effect */
14extern bool pm_nosig_freezing; /* PM nosig freezing in effect */
15
957d1282
LF
16/*
17 * Timeout for stopping processes
18 */
19extern unsigned int freeze_timeout_msecs;
20
7dfb7103
NC
21/*
22 * Check if a process has been frozen
23 */
948246f7 24static inline bool frozen(struct task_struct *p)
7dfb7103
NC
25{
26 return p->flags & PF_FROZEN;
27}
28
a3201227 29extern bool freezing_slow_path(struct task_struct *p);
7dfb7103
NC
30
31/*
a3201227 32 * Check if there is a request to freeze a process
7dfb7103 33 */
a3201227 34static inline bool freezing(struct task_struct *p)
7dfb7103 35{
a3201227
TH
36 if (likely(!atomic_read(&system_freezing_cnt)))
37 return false;
38 return freezing_slow_path(p);
7dfb7103
NC
39}
40
dc52ddc0 41/* Takes and releases task alloc lock using task_lock() */
a5be2d0d 42extern void __thaw_task(struct task_struct *t);
7dfb7103 43
8a32c441 44extern bool __refrigerator(bool check_kthr_stop);
7dfb7103 45extern int freeze_processes(void);
2aede851 46extern int freeze_kernel_threads(void);
a9b6f562 47extern void thaw_processes(void);
181e9bde 48extern void thaw_kernel_threads(void);
7dfb7103 49
a0acae0e 50static inline bool try_to_freeze(void)
7dfb7103 51{
6aa97070
MSB
52 if (!(current->flags & PF_NOFREEZE))
53 debug_check_no_locks_held();
a0acae0e
TH
54 might_sleep();
55 if (likely(!freezing(current)))
56 return false;
8a32c441 57 return __refrigerator(false);
7dfb7103 58}
ff39593a 59
839e3407 60extern bool freeze_task(struct task_struct *p);
34b087e4 61extern bool set_freezable(void);
8174f150 62
dc52ddc0 63#ifdef CONFIG_CGROUP_FREEZER
22b4e111 64extern bool cgroup_freezing(struct task_struct *task);
dc52ddc0 65#else /* !CONFIG_CGROUP_FREEZER */
22b4e111 66static inline bool cgroup_freezing(struct task_struct *task)
5a7aadfe 67{
22b4e111 68 return false;
5a7aadfe 69}
dc52ddc0
MH
70#endif /* !CONFIG_CGROUP_FREEZER */
71
ba96a0c8
RW
72/*
73 * The PF_FREEZER_SKIP flag should be set by a vfork parent right before it
74 * calls wait_for_completion(&vfork) and reset right after it returns from this
75 * function. Next, the parent should call try_to_freeze() to freeze itself
76 * appropriately in case the child has exited before the freezing of tasks is
77 * complete. However, we don't want kernel threads to be frozen in unexpected
78 * places, so we allow them to block freeze_processes() instead or to set
467de1fc
SB
79 * PF_NOFREEZE if needed. Fortunately, in the ____call_usermodehelper() case the
80 * parent won't really block freeze_processes(), since ____call_usermodehelper()
81 * (the child) does a little before exec/exit and it can't be frozen before
82 * waking up the parent.
ba96a0c8
RW
83 */
84
467de1fc 85
dd67d32d
TH
86/**
87 * freezer_do_not_count - tell freezer to ignore %current
88 *
89 * Tell freezers to ignore the current task when determining whether the
90 * target frozen state is reached. IOW, the current task will be
91 * considered frozen enough by freezers.
92 *
93 * The caller shouldn't do anything which isn't allowed for a frozen task
94 * until freezer_cont() is called. Usually, freezer[_do_not]_count() pair
95 * wrap a scheduling operation and nothing much else.
96 */
ba96a0c8
RW
97static inline void freezer_do_not_count(void)
98{
467de1fc 99 current->flags |= PF_FREEZER_SKIP;
ba96a0c8
RW
100}
101
dd67d32d
TH
102/**
103 * freezer_count - tell freezer to stop ignoring %current
104 *
105 * Undo freezer_do_not_count(). It tells freezers that %current should be
106 * considered again and tries to freeze if freezing condition is already in
107 * effect.
ba96a0c8
RW
108 */
109static inline void freezer_count(void)
110{
467de1fc 111 current->flags &= ~PF_FREEZER_SKIP;
dd67d32d
TH
112 /*
113 * If freezing is in progress, the following paired with smp_mb()
114 * in freezer_should_skip() ensures that either we see %true
115 * freezing() or freezer_should_skip() sees !PF_FREEZER_SKIP.
116 */
117 smp_mb();
467de1fc 118 try_to_freeze();
ba96a0c8
RW
119}
120
dd67d32d
TH
121/**
122 * freezer_should_skip - whether to skip a task when determining frozen
123 * state is reached
124 * @p: task in quesion
125 *
126 * This function is used by freezers after establishing %true freezing() to
127 * test whether a task should be skipped when determining the target frozen
128 * state is reached. IOW, if this function returns %true, @p is considered
129 * frozen enough.
ba96a0c8 130 */
dd67d32d 131static inline bool freezer_should_skip(struct task_struct *p)
ba96a0c8 132{
dd67d32d
TH
133 /*
134 * The following smp_mb() paired with the one in freezer_count()
135 * ensures that either freezer_count() sees %true freezing() or we
136 * see cleared %PF_FREEZER_SKIP and return %false. This makes it
137 * impossible for a task to slip frozen state testing after
138 * clearing %PF_FREEZER_SKIP.
139 */
140 smp_mb();
141 return p->flags & PF_FREEZER_SKIP;
ba96a0c8 142}
ff39593a 143
d310310c 144/*
5d8f72b5
ON
145 * These macros are intended to be used whenever you want allow a sleeping
146 * task to be frozen. Note that neither return any clear indication of
147 * whether a freeze event happened while in this function.
d310310c
JL
148 */
149
150/* Like schedule(), but should not block the freezer. */
151#define freezable_schedule() \
152({ \
153 freezer_do_not_count(); \
154 schedule(); \
155 freezer_count(); \
156})
157
158/* Like schedule_timeout_killable(), but should not block the freezer. */
159#define freezable_schedule_timeout_killable(timeout) \
160({ \
b3b73ec0 161 long __retval; \
d310310c 162 freezer_do_not_count(); \
b3b73ec0 163 __retval = schedule_timeout_killable(timeout); \
d310310c 164 freezer_count(); \
b3b73ec0 165 __retval; \
d310310c
JL
166})
167
e42837bc 168/*
f06ac72e
JL
169 * Freezer-friendly wrappers around wait_event_interruptible(),
170 * wait_event_killable() and wait_event_interruptible_timeout(), originally
171 * defined in <linux/wait.h>
e42837bc
RW
172 */
173
f06ac72e
JL
174#define wait_event_freezekillable(wq, condition) \
175({ \
176 int __retval; \
6f35c4ab
ON
177 freezer_do_not_count(); \
178 __retval = wait_event_killable(wq, (condition)); \
179 freezer_count(); \
f06ac72e
JL
180 __retval; \
181})
182
e42837bc
RW
183#define wait_event_freezable(wq, condition) \
184({ \
185 int __retval; \
24b7ead3 186 for (;;) { \
e42837bc
RW
187 __retval = wait_event_interruptible(wq, \
188 (condition) || freezing(current)); \
24b7ead3 189 if (__retval || (condition)) \
e42837bc 190 break; \
24b7ead3
ON
191 try_to_freeze(); \
192 } \
e42837bc
RW
193 __retval; \
194})
195
e42837bc
RW
196#define wait_event_freezable_timeout(wq, condition, timeout) \
197({ \
198 long __retval = timeout; \
24b7ead3 199 for (;;) { \
e42837bc
RW
200 __retval = wait_event_interruptible_timeout(wq, \
201 (condition) || freezing(current), \
202 __retval); \
24b7ead3
ON
203 if (__retval <= 0 || (condition)) \
204 break; \
205 try_to_freeze(); \
206 } \
e42837bc
RW
207 __retval; \
208})
24b7ead3 209
8174f150 210#else /* !CONFIG_FREEZER */
948246f7 211static inline bool frozen(struct task_struct *p) { return false; }
a3201227 212static inline bool freezing(struct task_struct *p) { return false; }
62c9ea6b 213static inline void __thaw_task(struct task_struct *t) {}
7dfb7103 214
8a32c441 215static inline bool __refrigerator(bool check_kthr_stop) { return false; }
2aede851
RW
216static inline int freeze_processes(void) { return -ENOSYS; }
217static inline int freeze_kernel_threads(void) { return -ENOSYS; }
7dfb7103 218static inline void thaw_processes(void) {}
181e9bde 219static inline void thaw_kernel_threads(void) {}
7dfb7103 220
e5f57621 221static inline bool try_to_freeze_nowarn(void) { return false; }
a0acae0e 222static inline bool try_to_freeze(void) { return false; }
7dfb7103 223
ba96a0c8
RW
224static inline void freezer_do_not_count(void) {}
225static inline void freezer_count(void) {}
226static inline int freezer_should_skip(struct task_struct *p) { return 0; }
83144186 227static inline void set_freezable(void) {}
e42837bc 228
d310310c
JL
229#define freezable_schedule() schedule()
230
231#define freezable_schedule_timeout_killable(timeout) \
232 schedule_timeout_killable(timeout)
233
e42837bc
RW
234#define wait_event_freezable(wq, condition) \
235 wait_event_interruptible(wq, condition)
236
237#define wait_event_freezable_timeout(wq, condition, timeout) \
238 wait_event_interruptible_timeout(wq, condition, timeout)
239
e0c8ea1a
SF
240#define wait_event_freezekillable(wq, condition) \
241 wait_event_killable(wq, condition)
242
8174f150 243#endif /* !CONFIG_FREEZER */
83144186
RW
244
245#endif /* FREEZER_H_INCLUDED */
This page took 0.744163 seconds and 5 git commands to generate.