From: Robert Richter <robert.richter@amd.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: Andi Kleen <andi@firstfloor.org>,
LKML <linux-kernel@vger.kernel.org>,
oprofile-list <oprofile-list@lists.sourceforge.net>,
Robert Richter <robert.richter@amd.com>
Subject: [PATCH 3/7] oprofile/x86: protect cpu hotplug sections
Date: Thu, 6 May 2010 15:26:10 +0200 [thread overview]
Message-ID: <1273152374-9392-4-git-send-email-robert.richter@amd.com> (raw)
In-Reply-To: <1273152374-9392-1-git-send-email-robert.richter@amd.com>
This patch reworks oprofile cpu hotplug code as follows:
Introduce ctr_running variable to check, if counters are running or
not. The state must be known for taking a cpu on or offline and when
switching counters during counter multiplexing.
Protect on_each_cpu() sections with get_online_cpus()/put_online_cpu()
functions. This is necessary if notifiers or states are
modified. Within these sections the cpu mask may not change.
Switch only between counters in nmi_cpu_switch(), if counters are
running. Otherwise the switch may restart a counter though they are
disabled.
Add nmi_cpu_setup() and nmi_cpu_shutdown() to cpu hotplug code. The
function must also be called to avoid uninitialzed counter usage.
Cc: Andi Kleen <andi@firstfloor.org>
Signed-off-by: Robert Richter <robert.richter@amd.com>
---
arch/x86/oprofile/nmi_int.c | 52 ++++++++++++++++++++++++++++++++++++++-----
1 files changed, 46 insertions(+), 6 deletions(-)
diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
index c5df8ee..b56601e 100644
--- a/arch/x86/oprofile/nmi_int.c
+++ b/arch/x86/oprofile/nmi_int.c
@@ -31,8 +31,9 @@ static struct op_x86_model_spec *model;
static DEFINE_PER_CPU(struct op_msrs, cpu_msrs);
static DEFINE_PER_CPU(unsigned long, saved_lvtpc);
-/* 0 == registered but off, 1 == registered and on */
-static int nmi_enabled = 0;
+/* must be protected with get_online_cpus()/put_online_cpus(): */
+static int nmi_enabled;
+static int ctr_running;
struct op_counter_config counter_config[OP_MAX_COUNTER];
@@ -103,7 +104,10 @@ static void nmi_cpu_start(void *dummy)
static int nmi_start(void)
{
+ get_online_cpus();
on_each_cpu(nmi_cpu_start, NULL, 1);
+ ctr_running = 1;
+ put_online_cpus();
return 0;
}
@@ -118,7 +122,10 @@ static void nmi_cpu_stop(void *dummy)
static void nmi_stop(void)
{
+ get_online_cpus();
on_each_cpu(nmi_cpu_stop, NULL, 1);
+ ctr_running = 0;
+ put_online_cpus();
}
#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
@@ -258,7 +265,10 @@ static int nmi_switch_event(void)
if (nmi_multiplex_on() < 0)
return -EINVAL; /* not necessary */
- on_each_cpu(nmi_cpu_switch, NULL, 1);
+ get_online_cpus();
+ if (ctr_running)
+ on_each_cpu(nmi_cpu_switch, NULL, 1);
+ put_online_cpus();
return 0;
}
@@ -386,8 +396,11 @@ static int nmi_setup(void)
if (err)
goto fail;
+ get_online_cpus();
on_each_cpu(nmi_cpu_setup, NULL, 1);
nmi_enabled = 1;
+ put_online_cpus();
+
return 0;
fail:
free_msrs();
@@ -433,8 +446,11 @@ static void nmi_shutdown(void)
{
struct op_msrs *msrs;
- nmi_enabled = 0;
+ get_online_cpus();
on_each_cpu(nmi_cpu_shutdown, NULL, 1);
+ nmi_enabled = 0;
+ ctr_running = 0;
+ put_online_cpus();
unregister_die_notifier(&profile_exceptions_nb);
msrs = &get_cpu_var(cpu_msrs);
model->shutdown(msrs);
@@ -442,6 +458,22 @@ static void nmi_shutdown(void)
put_cpu_var(cpu_msrs);
}
+static void nmi_cpu_up(void *dummy)
+{
+ if (nmi_enabled)
+ nmi_cpu_setup(dummy);
+ if (ctr_running)
+ nmi_cpu_start(dummy);
+}
+
+static void nmi_cpu_down(void *dummy)
+{
+ if (ctr_running)
+ nmi_cpu_stop(dummy);
+ if (nmi_enabled)
+ nmi_cpu_shutdown(dummy);
+}
+
static int nmi_create_files(struct super_block *sb, struct dentry *root)
{
unsigned int i;
@@ -478,10 +510,10 @@ static int oprofile_cpu_notifier(struct notifier_block *b, unsigned long action,
switch (action) {
case CPU_DOWN_FAILED:
case CPU_ONLINE:
- smp_call_function_single(cpu, nmi_cpu_start, NULL, 0);
+ smp_call_function_single(cpu, nmi_cpu_up, NULL, 0);
break;
case CPU_DOWN_PREPARE:
- smp_call_function_single(cpu, nmi_cpu_stop, NULL, 1);
+ smp_call_function_single(cpu, nmi_cpu_down, NULL, 1);
break;
}
return NOTIFY_DONE;
@@ -699,7 +731,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
return -ENODEV;
}
+ get_online_cpus();
register_cpu_notifier(&oprofile_cpu_nb);
+ nmi_enabled = 0;
+ ctr_running = 0;
+ put_online_cpus();
/* default values, can be overwritten by model */
ops->create_files = nmi_create_files;
@@ -729,7 +765,11 @@ void op_nmi_exit(void)
{
if (using_nmi) {
exit_sysfs();
+ get_online_cpus();
unregister_cpu_notifier(&oprofile_cpu_nb);
+ nmi_enabled = 0;
+ ctr_running = 0;
+ put_online_cpus();
}
if (model->exit)
model->exit();
--
1.7.0.3
next prev parent reply other threads:[~2010-05-06 15:24 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-06 13:26 [PATCH 0/7] oprofile/x86: fix cpu hotplug Robert Richter
2010-05-06 13:26 ` [PATCH 1/7] oprofile/x86: fix uninitialized counter usage during " Robert Richter
2010-05-06 13:26 ` [PATCH 2/7] oprofile/x86: remove CONFIG_SMP macros Robert Richter
2010-05-06 13:26 ` Robert Richter [this message]
2010-05-06 13:26 ` [PATCH 4/7] oprofile/x86: stop disabled counters in nmi handler Robert Richter
2010-05-06 13:26 ` [PATCH 5/7] oprofile/x86: reordering some functions Robert Richter
2010-05-06 13:26 ` [PATCH 6/7] oprofile/x86: notify cpus only when daemon is running Robert Richter
2010-05-06 13:26 ` [PATCH 7/7] oprofile/x86: make AMD IBS hotplug capable Robert Richter
2010-05-10 10:33 ` [GIT PULL] oprofile hotplug fixes for x86 Robert Richter
2010-05-10 11:14 ` Ingo Molnar
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=1273152374-9392-4-git-send-email-robert.richter@amd.com \
--to=robert.richter@amd.com \
--cc=andi@firstfloor.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=oprofile-list@lists.sourceforge.net \
/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
Powered by JetHome