diff options
author | Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com> | 2012-02-03 16:22:41 -0500 |
---|---|---|
committer | Rafael J. Wysocki <rjw@sisk.pl> | 2012-02-04 16:23:05 -0500 |
commit | 379e0be812ab8a2a351e784b0c987788f5123090 (patch) | |
tree | 70f1e7ac57e198d0a94a89a65933da9a2ca35ccc /kernel | |
parent | fe9161db2e6053da21e4649d77bbefaf3030b11d (diff) |
PM / Freezer: Thaw only kernel threads if freezing of kernel threads fails
If freezing of kernel threads fails, we are expected to automatically
thaw tasks in the error recovery path. However, at times, we encounter
situations in which we would like the automatic error recovery path
to thaw only the kernel threads, because we want to be able to do
some more cleanup before we thaw userspace. Something like:
error = freeze_kernel_threads();
if (error) {
/* Do some cleanup */
/* Only then thaw userspace tasks*/
thaw_processes();
}
An example of such a situation is where we freeze/thaw filesystems
during suspend/hibernation. There, if freezing of kernel threads
fails, we would like to thaw the frozen filesystems before thawing
the userspace tasks.
So, modify freeze_kernel_threads() to thaw only kernel threads in
case of freezing failure. And change suspend_freeze_processes()
accordingly. (At the same time, let us also get rid of the rather
cryptic usage of the conditional operator (:?) in that function.)
[rjw: In fact, this patch fixes a regression introduced during the
3.3 merge window, because without it thaw_processes() may be called
before swsusp_free() in some situations and that may lead to massive
memory allocation failures.]
Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Acked-by: Tejun Heo <tj@kernel.org>
Acked-by: Nigel Cunningham <nigel@tuxonice.net>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/power/power.h | 24 | ||||
-rw-r--r-- | kernel/power/process.c | 7 |
2 files changed, 27 insertions, 4 deletions
diff --git a/kernel/power/power.h b/kernel/power/power.h index 0c4defe6d3b8..21724eee5206 100644 --- a/kernel/power/power.h +++ b/kernel/power/power.h | |||
@@ -231,8 +231,28 @@ extern int pm_test_level; | |||
231 | #ifdef CONFIG_SUSPEND_FREEZER | 231 | #ifdef CONFIG_SUSPEND_FREEZER |
232 | static inline int suspend_freeze_processes(void) | 232 | static inline int suspend_freeze_processes(void) |
233 | { | 233 | { |
234 | int error = freeze_processes(); | 234 | int error; |
235 | return error ? : freeze_kernel_threads(); | 235 | |
236 | error = freeze_processes(); | ||
237 | |||
238 | /* | ||
239 | * freeze_processes() automatically thaws every task if freezing | ||
240 | * fails. So we need not do anything extra upon error. | ||
241 | */ | ||
242 | if (error) | ||
243 | goto Finish; | ||
244 | |||
245 | error = freeze_kernel_threads(); | ||
246 | |||
247 | /* | ||
248 | * freeze_kernel_threads() thaws only kernel threads upon freezing | ||
249 | * failure. So we have to thaw the userspace tasks ourselves. | ||
250 | */ | ||
251 | if (error) | ||
252 | thaw_processes(); | ||
253 | |||
254 | Finish: | ||
255 | return error; | ||
236 | } | 256 | } |
237 | 257 | ||
238 | static inline void suspend_thaw_processes(void) | 258 | static inline void suspend_thaw_processes(void) |
diff --git a/kernel/power/process.c b/kernel/power/process.c index eeca00311f39..7e426459e60a 100644 --- a/kernel/power/process.c +++ b/kernel/power/process.c | |||
@@ -143,7 +143,10 @@ int freeze_processes(void) | |||
143 | /** | 143 | /** |
144 | * freeze_kernel_threads - Make freezable kernel threads go to the refrigerator. | 144 | * freeze_kernel_threads - Make freezable kernel threads go to the refrigerator. |
145 | * | 145 | * |
146 | * On success, returns 0. On failure, -errno and system is fully thawed. | 146 | * On success, returns 0. On failure, -errno and only the kernel threads are |
147 | * thawed, so as to give a chance to the caller to do additional cleanups | ||
148 | * (if any) before thawing the userspace tasks. So, it is the responsibility | ||
149 | * of the caller to thaw the userspace tasks, when the time is right. | ||
147 | */ | 150 | */ |
148 | int freeze_kernel_threads(void) | 151 | int freeze_kernel_threads(void) |
149 | { | 152 | { |
@@ -159,7 +162,7 @@ int freeze_kernel_threads(void) | |||
159 | BUG_ON(in_atomic()); | 162 | BUG_ON(in_atomic()); |
160 | 163 | ||
161 | if (error) | 164 | if (error) |
162 | thaw_processes(); | 165 | thaw_kernel_threads(); |
163 | return error; | 166 | return error; |
164 | } | 167 | } |
165 | 168 | ||