提交 03afed8b 编写于 作者: T Tejun Heo

freezer: clean up freeze_processes() failure path

freeze_processes() failure path is rather messy.  Freezing is canceled
for workqueues and tasks which aren't frozen yet but frozen tasks are
left alone and should be thawed by the caller and of course some
callers (xen and kexec) didn't do it.

This patch updates __thaw_task() to handle cancelation correctly and
makes freeze_processes() and freeze_kernel_threads() call
thaw_processes() on failure instead so that the system is fully thawed
on failure.  Unnecessary [suspend_]thaw_processes() calls are removed
from kernel/power/hibernate.c, suspend.c and user.c.

While at it, restructure error checking if clause in suspend_prepare()
to be less weird.

-v2: Srivatsa spotted missing removal of suspend_thaw_processes() in
     suspend_prepare() and error in commit message.  Updated.
Signed-off-by: NTejun Heo <tj@kernel.org>
Acked-by: NSrivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
上级 376fede8
...@@ -61,7 +61,6 @@ static inline bool try_to_freeze(void) ...@@ -61,7 +61,6 @@ static inline bool try_to_freeze(void)
} }
extern bool freeze_task(struct task_struct *p, bool sig_only); extern bool freeze_task(struct task_struct *p, bool sig_only);
extern void cancel_freezing(struct task_struct *p);
#ifdef CONFIG_CGROUP_FREEZER #ifdef CONFIG_CGROUP_FREEZER
extern int cgroup_freezing_or_frozen(struct task_struct *task); extern int cgroup_freezing_or_frozen(struct task_struct *task);
......
...@@ -129,21 +129,6 @@ bool freeze_task(struct task_struct *p, bool sig_only) ...@@ -129,21 +129,6 @@ bool freeze_task(struct task_struct *p, bool sig_only)
return ret; return ret;
} }
void cancel_freezing(struct task_struct *p)
{
unsigned long flags;
spin_lock_irqsave(&freezer_lock, flags);
if (freezing(p)) {
pr_debug(" clean up: %s\n", p->comm);
clear_freeze_flag(p);
spin_lock(&p->sighand->siglock);
recalc_sigpending_and_wake(p);
spin_unlock(&p->sighand->siglock);
}
spin_unlock_irqrestore(&freezer_lock, flags);
}
void __thaw_task(struct task_struct *p) void __thaw_task(struct task_struct *p)
{ {
unsigned long flags; unsigned long flags;
...@@ -153,10 +138,18 @@ void __thaw_task(struct task_struct *p) ...@@ -153,10 +138,18 @@ void __thaw_task(struct task_struct *p)
* be visible to @p as waking up implies wmb. Waking up inside * be visible to @p as waking up implies wmb. Waking up inside
* freezer_lock also prevents wakeups from leaking outside * freezer_lock also prevents wakeups from leaking outside
* refrigerator. * refrigerator.
*
* If !FROZEN, @p hasn't reached refrigerator, recalc sigpending to
* avoid leaving dangling TIF_SIGPENDING behind.
*/ */
spin_lock_irqsave(&freezer_lock, flags); spin_lock_irqsave(&freezer_lock, flags);
clear_freeze_flag(p); clear_freeze_flag(p);
if (frozen(p)) if (frozen(p)) {
wake_up_process(p); wake_up_process(p);
} else {
spin_lock(&p->sighand->siglock);
recalc_sigpending_and_wake(p);
spin_unlock(&p->sighand->siglock);
}
spin_unlock_irqrestore(&freezer_lock, flags); spin_unlock_irqrestore(&freezer_lock, flags);
} }
...@@ -607,17 +607,6 @@ static void power_down(void) ...@@ -607,17 +607,6 @@ static void power_down(void)
while(1); while(1);
} }
static int prepare_processes(void)
{
int error = 0;
if (freeze_processes()) {
error = -EBUSY;
thaw_processes();
}
return error;
}
/** /**
* hibernate - Carry out system hibernation, including saving the image. * hibernate - Carry out system hibernation, including saving the image.
*/ */
...@@ -650,7 +639,7 @@ int hibernate(void) ...@@ -650,7 +639,7 @@ int hibernate(void)
sys_sync(); sys_sync();
printk("done.\n"); printk("done.\n");
error = prepare_processes(); error = freeze_processes();
if (error) if (error)
goto Finish; goto Finish;
...@@ -811,7 +800,7 @@ static int software_resume(void) ...@@ -811,7 +800,7 @@ static int software_resume(void)
goto close_finish; goto close_finish;
pr_debug("PM: Preparing processes for restore.\n"); pr_debug("PM: Preparing processes for restore.\n");
error = prepare_processes(); error = freeze_processes();
if (error) { if (error) {
swsusp_close(FMODE_READ); swsusp_close(FMODE_READ);
goto Done; goto Done;
......
...@@ -91,11 +91,6 @@ static int try_to_freeze_tasks(bool sig_only) ...@@ -91,11 +91,6 @@ static int try_to_freeze_tasks(bool sig_only)
elapsed_csecs = elapsed_csecs64; elapsed_csecs = elapsed_csecs64;
if (todo) { if (todo) {
/* This does not unfreeze processes that are already frozen
* (we have slightly ugly calling convention in that respect,
* and caller must call thaw_processes() if something fails),
* but it cleans up leftover PF_FREEZE requests.
*/
printk("\n"); printk("\n");
printk(KERN_ERR "Freezing of tasks %s after %d.%02d seconds " printk(KERN_ERR "Freezing of tasks %s after %d.%02d seconds "
"(%d tasks refusing to freeze, wq_busy=%d):\n", "(%d tasks refusing to freeze, wq_busy=%d):\n",
...@@ -103,14 +98,11 @@ static int try_to_freeze_tasks(bool sig_only) ...@@ -103,14 +98,11 @@ static int try_to_freeze_tasks(bool sig_only)
elapsed_csecs / 100, elapsed_csecs % 100, elapsed_csecs / 100, elapsed_csecs % 100,
todo - wq_busy, wq_busy); todo - wq_busy, wq_busy);
thaw_workqueues();
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
do_each_thread(g, p) { do_each_thread(g, p) {
if (!wakeup && !freezer_should_skip(p) && if (!wakeup && !freezer_should_skip(p) &&
freezing(p) && !frozen(p)) freezing(p) && !frozen(p))
sched_show_task(p); sched_show_task(p);
cancel_freezing(p);
} while_each_thread(g, p); } while_each_thread(g, p);
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
} else { } else {
...@@ -123,6 +115,8 @@ static int try_to_freeze_tasks(bool sig_only) ...@@ -123,6 +115,8 @@ static int try_to_freeze_tasks(bool sig_only)
/** /**
* freeze_processes - Signal user space processes to enter the refrigerator. * freeze_processes - Signal user space processes to enter the refrigerator.
*
* On success, returns 0. On failure, -errno and system is fully thawed.
*/ */
int freeze_processes(void) int freeze_processes(void)
{ {
...@@ -137,11 +131,15 @@ int freeze_processes(void) ...@@ -137,11 +131,15 @@ int freeze_processes(void)
printk("\n"); printk("\n");
BUG_ON(in_atomic()); BUG_ON(in_atomic());
if (error)
thaw_processes();
return error; return error;
} }
/** /**
* freeze_kernel_threads - Make freezable kernel threads go to the refrigerator. * freeze_kernel_threads - Make freezable kernel threads go to the refrigerator.
*
* On success, returns 0. On failure, -errno and system is fully thawed.
*/ */
int freeze_kernel_threads(void) int freeze_kernel_threads(void)
{ {
...@@ -155,6 +153,8 @@ int freeze_kernel_threads(void) ...@@ -155,6 +153,8 @@ int freeze_kernel_threads(void)
printk("\n"); printk("\n");
BUG_ON(in_atomic()); BUG_ON(in_atomic());
if (error)
thaw_processes();
return error; return error;
} }
......
...@@ -106,13 +106,11 @@ static int suspend_prepare(void) ...@@ -106,13 +106,11 @@ static int suspend_prepare(void)
goto Finish; goto Finish;
error = suspend_freeze_processes(); error = suspend_freeze_processes();
if (error) { if (!error)
suspend_stats.failed_freeze++;
dpm_save_failed_step(SUSPEND_FREEZE);
} else
return 0; return 0;
suspend_thaw_processes(); suspend_stats.failed_freeze++;
dpm_save_failed_step(SUSPEND_FREEZE);
usermodehelper_enable(); usermodehelper_enable();
Finish: Finish:
pm_notifier_call_chain(PM_POST_SUSPEND); pm_notifier_call_chain(PM_POST_SUSPEND);
......
...@@ -257,10 +257,8 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd, ...@@ -257,10 +257,8 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
break; break;
error = freeze_processes(); error = freeze_processes();
if (error) { if (error)
thaw_processes();
usermodehelper_enable(); usermodehelper_enable();
}
if (!error) if (!error)
data->frozen = 1; data->frozen = 1;
break; break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册