From: "Srivatsa S. Bhat" <srivatsa.bhat@linux.vnet.ibm.com>
To: "Américo Wang" <xiyou.wangcong@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
"Rafael J. Wysocki" <rjw@sisk.pl>,
pavel@ucw.cz, len.brown@intel.com, mingo@elte.hu,
akpm@linux-foundation.org, suresh.b.siddha@intel.com,
lucas.demarchi@profusion.mobi,
Linux PM mailing list <linux-pm@vger.kernel.org>,
rusty@rustcorp.com.au, vatsa@linux.vnet.ibm.com,
ashok.raj@intel.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] CPU hotplug, freezer: Fix bugs in CPU hotplug call path
Date: Sun, 09 Oct 2011 01:58:04 +0530 [thread overview]
Message-ID: <4E90B254.9010604@linux.vnet.ibm.com> (raw)
In-Reply-To: <CAM_iQpXDDeOzZ0L8MYFPhi_5rJJvinOD57nWWKfnCRxa_Jtx6Q@mail.gmail.com>
On 10/08/2011 06:22 PM, Américo Wang wrote:
> On Sat, Oct 8, 2011 at 4:56 AM, Srivatsa S. Bhat
> <srivatsa.bhat@linux.vnet.ibm.com> wrote:
>> diff --git a/include/linux/freezer.h b/include/linux/freezer.h
>> index 1effc8b..75c65d6 100644
>> --- a/include/linux/freezer.h
>> +++ b/include/linux/freezer.h
>> @@ -7,6 +7,9 @@
>> #include <linux/wait.h>
>>
>> #ifdef CONFIG_FREEZER
>> +
>> +extern struct mutex freezer_lock;
>> +
> [...]
>> static inline int try_to_freeze(void)
>> {
>> if (freezing(current)) {
>> diff --git a/kernel/cpu.c b/kernel/cpu.c
>> index 12b7458..b94c8f6 100644
>> --- a/kernel/cpu.c
>> +++ b/kernel/cpu.c
>> @@ -15,6 +15,7 @@
>> #include <linux/stop_machine.h>
>> #include <linux/mutex.h>
>> #include <linux/gfp.h>
>> +#include <linux/freezer.h>
>>
>> #ifdef CONFIG_SMP
>> /* Serializes the updates to cpu_online_mask, cpu_present_mask */
>> @@ -280,7 +281,9 @@ int __ref cpu_down(unsigned int cpu)
>> goto out;
>> }
>>
>> - err = _cpu_down(cpu, 0);
>> + mutex_lock(&freezer_lock);
>> + err = _cpu_down(cpu, tasks_are_frozen());
>> + mutex_unlock(&freezer_lock);
>>
>
> Can this even be compiled when CONFIG_FREEZER=n?
>
Oh! That's a mistake.. Thank you for pointing it out.
This one should fix it:
---
include/linux/freezer.h | 22 ++++++++++++++++++++++
kernel/cpu.c | 9 +++++++--
kernel/power/process.c | 27 ++++++++++++++++++++++++++-
3 files changed, 55 insertions(+), 3 deletions(-)
diff --git a/include/linux/freezer.h b/include/linux/freezer.h
index 1effc8b..3d80ddb 100644
--- a/include/linux/freezer.h
+++ b/include/linux/freezer.h
@@ -7,6 +7,19 @@
#include <linux/wait.h>
#ifdef CONFIG_FREEZER
+
+extern struct mutex freezer_lock;
+
+static inline void lock_freezer(void)
+{
+ mutex_lock(&freezer_lock);
+}
+
+static inline void unlock_freezer(void)
+{
+ mutex_unlock(&freezer_lock);
+}
+
/*
* Check if a process has been frozen
*/
@@ -51,6 +64,10 @@ extern void refrigerator(void);
extern int freeze_processes(void);
extern void thaw_processes(void);
+extern void set_tasks_frozen_flag(void);
+extern void clear_tasks_frozen_flag(void);
+extern int tasks_are_frozen(void);
+
static inline int try_to_freeze(void)
{
if (freezing(current)) {
@@ -164,6 +181,8 @@ static inline void set_freezable_with_signal(void)
__retval; \
})
#else /* !CONFIG_FREEZER */
+static inline void lock_freezer(void) {}
+static inline void unlock_freezer(void) {}
static inline int frozen(struct task_struct *p) { return 0; }
static inline int freezing(struct task_struct *p) { return 0; }
static inline void set_freeze_flag(struct task_struct *p) {}
@@ -173,6 +192,9 @@ static inline int thaw_process(struct task_struct *p) { return 1; }
static inline void refrigerator(void) {}
static inline int freeze_processes(void) { BUG(); return 0; }
static inline void thaw_processes(void) {}
+static inline void set_tasks_frozen_flag(void) {}
+static inline void clear_tasks_frozen_flag(void) {}
+static inline int tasks_are_frozen(void) { return 0; }
static inline int try_to_freeze(void) { return 0; }
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 12b7458..d81ceea 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -15,6 +15,7 @@
#include <linux/stop_machine.h>
#include <linux/mutex.h>
#include <linux/gfp.h>
+#include <linux/freezer.h>
#ifdef CONFIG_SMP
/* Serializes the updates to cpu_online_mask, cpu_present_mask */
@@ -280,7 +281,9 @@ int __ref cpu_down(unsigned int cpu)
goto out;
}
- err = _cpu_down(cpu, 0);
+ lock_freezer();
+ err = _cpu_down(cpu, tasks_are_frozen());
+ unlock_freezer();
out:
cpu_maps_update_done();
@@ -373,7 +376,9 @@ int __cpuinit cpu_up(unsigned int cpu)
goto out;
}
- err = _cpu_up(cpu, 0);
+ lock_freezer();
+ err = _cpu_up(cpu, tasks_are_frozen());
+ unlock_freezer();
out:
cpu_maps_update_done();
diff --git a/kernel/power/process.c b/kernel/power/process.c
index 0cf3a27..9da3369 100644
--- a/kernel/power/process.c
+++ b/kernel/power/process.c
@@ -17,11 +17,30 @@
#include <linux/delay.h>
#include <linux/workqueue.h>
-/*
+/*
* Timeout for stopping processes
*/
#define TIMEOUT (20 * HZ)
+DEFINE_MUTEX(freezer_lock);
+
+static int tasks_frozen;
+
+void set_tasks_frozen_flag(void)
+{
+ tasks_frozen = 1;
+}
+
+void clear_tasks_frozen_flag(void)
+{
+ tasks_frozen = 0;
+}
+
+int tasks_are_frozen(void)
+{
+ return tasks_frozen;
+}
+
static inline int freezable(struct task_struct * p)
{
if ((p == current) ||
@@ -141,6 +160,7 @@ int freeze_processes(void)
{
int error;
+ lock_freezer();
printk("Freezing user space processes ... ");
error = try_to_freeze_tasks(true);
if (error)
@@ -151,10 +171,12 @@ int freeze_processes(void)
error = try_to_freeze_tasks(false);
if (error)
goto Exit;
+ set_tasks_frozen_flag();
printk("done.");
oom_killer_disable();
Exit:
+ unlock_freezer();
BUG_ON(in_atomic());
printk("\n");
@@ -183,6 +205,7 @@ static void thaw_tasks(bool nosig_only)
void thaw_processes(void)
{
+ lock_freezer();
oom_killer_enable();
printk("Restarting tasks ... ");
@@ -190,6 +213,8 @@ void thaw_processes(void)
thaw_tasks(true);
thaw_tasks(false);
schedule();
+ clear_tasks_frozen_flag();
+ unlock_freezer();
printk("done.\n");
}
next prev parent reply other threads:[~2011-10-08 20:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-02 19:44 [PATCH] CPU hotplug, freezer: Fix bugs in CPU hotplug call path Srivatsa S. Bhat
2011-10-03 10:03 ` Peter Zijlstra
2011-10-04 13:19 ` Srivatsa S. Bhat
2011-10-04 13:28 ` [PATCH v2] " Srivatsa S. Bhat
2011-10-04 13:37 ` Peter Zijlstra
2011-10-07 20:56 ` Srivatsa S. Bhat
2011-10-08 12:52 ` Américo Wang
2011-10-08 20:28 ` Srivatsa S. Bhat [this message]
2011-10-10 10:48 ` Peter Zijlstra
2011-10-21 11:30 ` Srivatsa S. Bhat
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E90B254.9010604@linux.vnet.ibm.com \
--to=srivatsa.bhat@linux.vnet.ibm.com \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=ashok.raj@intel.com \
--cc=len.brown@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lucas.demarchi@profusion.mobi \
--cc=mingo@elte.hu \
--cc=pavel@ucw.cz \
--cc=rjw@sisk.pl \
--cc=rusty@rustcorp.com.au \
--cc=suresh.b.siddha@intel.com \
--cc=vatsa@linux.vnet.ibm.com \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).