diff options
author | Tejun Heo <tj@kernel.org> | 2011-11-21 15:32:25 -0500 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2011-11-21 15:32:25 -0500 |
commit | a3201227f803ad7fd43180c5195dbe5a2bf998aa (patch) | |
tree | 1845ba06346f8a8772fe1c90f8960bd1a430d05c /include | |
parent | 22b4e111fa01a1147aa562ceaf18a752a928ef4e (diff) |
freezer: make freezing() test freeze conditions in effect instead of TIF_FREEZE
Using TIF_FREEZE for freezing worked when there was only single
freezing condition (the PM one); however, now there is also the
cgroup_freezer and single bit flag is getting clumsy.
thaw_processes() is already testing whether cgroup freezing in in
effect to avoid thawing tasks which were frozen by both PM and cgroup
freezers.
This is racy (nothing prevents race against cgroup freezing) and
fragile. A much simpler way is to test actual freeze conditions from
freezing() - ie. directly test whether PM or cgroup freezing is in
effect.
This patch adds variables to indicate whether and what type of
freezing conditions are in effect and reimplements freezing() such
that it directly tests whether any of the two freezing conditions is
active and the task should freeze. On fast path, freezing() is still
very cheap - it only tests system_freezing_cnt.
This makes the clumsy dancing aroung TIF_FREEZE unnecessary and
freeze/thaw operations more usual - updating state variables for the
new state and nudging target tasks so that they notice the new state
and comply. As long as the nudging happens after state update, it's
race-free.
* This allows use of freezing() in freeze_task(). Replace the open
coded tests with freezing().
* p != current test is added to warning printing conditions in
try_to_freeze_tasks() failure path. This is necessary as freezing()
is now true for the task which initiated freezing too.
-v2: Oleg pointed out that re-freezing FROZEN cgroup could increment
system_freezing_cnt. Fixed.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Paul Menage <paul@paulmenage.org> (for the cgroup portions)
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/freezer.h | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/include/linux/freezer.h b/include/linux/freezer.h index b2b4abc5a739..8e29f2b7ce11 100644 --- a/include/linux/freezer.h +++ b/include/linux/freezer.h | |||
@@ -5,8 +5,13 @@ | |||
5 | 5 | ||
6 | #include <linux/sched.h> | 6 | #include <linux/sched.h> |
7 | #include <linux/wait.h> | 7 | #include <linux/wait.h> |
8 | #include <linux/atomic.h> | ||
8 | 9 | ||
9 | #ifdef CONFIG_FREEZER | 10 | #ifdef CONFIG_FREEZER |
11 | extern atomic_t system_freezing_cnt; /* nr of freezing conds in effect */ | ||
12 | extern bool pm_freezing; /* PM freezing in effect */ | ||
13 | extern bool pm_nosig_freezing; /* PM nosig freezing in effect */ | ||
14 | |||
10 | /* | 15 | /* |
11 | * Check if a process has been frozen | 16 | * Check if a process has been frozen |
12 | */ | 17 | */ |
@@ -15,28 +20,16 @@ static inline int frozen(struct task_struct *p) | |||
15 | return p->flags & PF_FROZEN; | 20 | return p->flags & PF_FROZEN; |
16 | } | 21 | } |
17 | 22 | ||
18 | /* | 23 | extern bool freezing_slow_path(struct task_struct *p); |
19 | * Check if there is a request to freeze a process | ||
20 | */ | ||
21 | static inline int freezing(struct task_struct *p) | ||
22 | { | ||
23 | return test_tsk_thread_flag(p, TIF_FREEZE); | ||
24 | } | ||
25 | 24 | ||
26 | /* | 25 | /* |
27 | * Request that a process be frozen | 26 | * Check if there is a request to freeze a process |
28 | */ | ||
29 | static inline void set_freeze_flag(struct task_struct *p) | ||
30 | { | ||
31 | set_tsk_thread_flag(p, TIF_FREEZE); | ||
32 | } | ||
33 | |||
34 | /* | ||
35 | * Sometimes we may need to cancel the previous 'freeze' request | ||
36 | */ | 27 | */ |
37 | static inline void clear_freeze_flag(struct task_struct *p) | 28 | static inline bool freezing(struct task_struct *p) |
38 | { | 29 | { |
39 | clear_tsk_thread_flag(p, TIF_FREEZE); | 30 | if (likely(!atomic_read(&system_freezing_cnt))) |
31 | return false; | ||
32 | return freezing_slow_path(p); | ||
40 | } | 33 | } |
41 | 34 | ||
42 | static inline bool should_send_signal(struct task_struct *p) | 35 | static inline bool should_send_signal(struct task_struct *p) |
@@ -174,9 +167,7 @@ static inline void set_freezable_with_signal(void) | |||
174 | }) | 167 | }) |
175 | #else /* !CONFIG_FREEZER */ | 168 | #else /* !CONFIG_FREEZER */ |
176 | static inline int frozen(struct task_struct *p) { return 0; } | 169 | static inline int frozen(struct task_struct *p) { return 0; } |
177 | static inline int freezing(struct task_struct *p) { return 0; } | 170 | static inline bool freezing(struct task_struct *p) { return false; } |
178 | static inline void set_freeze_flag(struct task_struct *p) {} | ||
179 | static inline void clear_freeze_flag(struct task_struct *p) {} | ||
180 | 171 | ||
181 | static inline bool __refrigerator(bool check_kthr_stop) { return false; } | 172 | static inline bool __refrigerator(bool check_kthr_stop) { return false; } |
182 | static inline int freeze_processes(void) { return -ENOSYS; } | 173 | static inline int freeze_processes(void) { return -ENOSYS; } |