Discussion:
[PATCH 19/20] x86/oprofile/nmi: Convert to hotplug state machine
(too old to reply)
Sebastian Andrzej Siewior
2016-11-17 18:35:40 UTC
Permalink
Raw Message
Install the callbacks via the state machine and let the core invoke
the callbacks on the already online CPUs.

Cc: Robert Richter <***@kernel.org>
Cc: ***@kernel.org
Cc: oprofile-***@lists.sf.net
Signed-off-by: Sebastian Andrzej Siewior <***@linutronix.de>
---
arch/x86/oprofile/nmi_int.c | 61 +++++++++++++--------------------------------
1 file changed, 18 insertions(+), 43 deletions(-)

diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
index c39172cd6c87..47b4cbf8da68 100644
--- a/arch/x86/oprofile/nmi_int.c
+++ b/arch/x86/oprofile/nmi_int.c
@@ -339,10 +339,11 @@ static int allocate_msrs(void)
return 0;
}

-static void nmi_cpu_setup(void *dummy)
+static void nmi_cpu_setup(void)
{
int cpu = smp_processor_id();
struct op_msrs *msrs = &per_cpu(cpu_msrs, cpu);
+
nmi_cpu_save_registers(msrs);
raw_spin_lock(&oprofilefs_lock);
model->setup_ctrs(model, msrs);
@@ -369,7 +370,7 @@ static void nmi_cpu_restore_registers(struct op_msrs *msrs)
}
}

-static void nmi_cpu_shutdown(void *dummy)
+static void nmi_cpu_shutdown(void)
{
unsigned int v;
int cpu = smp_processor_id();
@@ -387,24 +388,26 @@ static void nmi_cpu_shutdown(void *dummy)
nmi_cpu_restore_registers(msrs);
}

-static void nmi_cpu_up(void)
+static int nmi_cpu_online(unsigned int cpu)
{
local_irq_disable();
if (nmi_enabled)
- nmi_cpu_setup(NULL);
+ nmi_cpu_setup();
if (ctr_running)
nmi_cpu_start(NULL);
local_irq_enable();
+ return 0;
}

-static void nmi_cpu_down(void)
+static int nmi_cpu_down_prep(unsigned int cpu)
{
local_irq_disable();
if (ctr_running)
nmi_cpu_stop(NULL);
if (nmi_enabled)
- nmi_cpu_shutdown(NULL);
+ nmi_cpu_shutdown();
local_irq_enable();
+ return 0;
}

static int nmi_create_files(struct dentry *root)
@@ -437,24 +440,7 @@ static int nmi_create_files(struct dentry *root)
return 0;
}

-static int oprofile_cpu_notifier(struct notifier_block *b, unsigned long action,
- void *data)
-{
- switch (action & ~CPU_TASKS_FROZEN) {
- case CPU_DOWN_FAILED:
- case CPU_ONLINE:
- nmi_cpu_up();
- break;
- case CPU_DOWN_PREPARE:
- nmi_cpu_down();
- break;
- }
- return NOTIFY_DONE;
-}
-
-static struct notifier_block oprofile_cpu_nb = {
- .notifier_call = oprofile_cpu_notifier
-};
+static enum cpuhp_state hp_online;

static int nmi_setup(void)
{
@@ -497,20 +483,17 @@ static int nmi_setup(void)
if (err)
goto fail;

- cpu_notifier_register_begin();
-
- /* Use get/put_online_cpus() to protect 'nmi_enabled' */
- get_online_cpus();
nmi_enabled = 1;
/* make nmi_enabled visible to the nmi handler: */
smp_mb();
- on_each_cpu(nmi_cpu_setup, NULL, 1);
- __register_cpu_notifier(&oprofile_cpu_nb);
- put_online_cpus();
-
- cpu_notifier_register_done();
-
+ err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/oprofile:online",
+ nmi_cpu_online, nmi_cpu_down_prep);
+ if (err < 0)
+ goto fail_nmi;
+ hp_online = err;
return 0;
+fail_nmi:
+ unregister_nmi_handler(NMI_LOCAL, "oprofile");
fail:
free_msrs();
return err;
@@ -520,17 +503,9 @@ static void nmi_shutdown(void)
{
struct op_msrs *msrs;

- cpu_notifier_register_begin();
-
- /* Use get/put_online_cpus() to protect 'nmi_enabled' & 'ctr_running' */
- get_online_cpus();
- on_each_cpu(nmi_cpu_shutdown, NULL, 1);
+ cpuhp_remove_state(hp_online);
nmi_enabled = 0;
ctr_running = 0;
- __unregister_cpu_notifier(&oprofile_cpu_nb);
- put_online_cpus();
-
- cpu_notifier_register_done();

/* make variables visible to the nmi handler: */
smp_mb();
--
2.10.2


------------------------------------------------------------------------------
Sebastian Andrzej Siewior
2016-11-17 18:35:39 UTC
Permalink
Raw Message
From: Anna-Maria Gleixner <anna-***@linutronix.de>

Since commit 1cf4f629d9d2 ("cpu/hotplug: Move online calls to
hotplugged cpu") the CPU_ONLINE and CPU_DOWN_PREPARE notifiers are
always run on the hot plugged CPU, and as of commit 3b9d6da67e11
("cpu/hotplug: Fix rollback during error-out in __cpu_disable()")
the CPU_DOWN_FAILED notifier also runs on the hot plugged CPU.
This patch converts the SMP functional calls into direct calls.

smp_call_function_single() executes the function with interrupts
disabled. This calling convention is preserved.

Cc: Robert Richter <***@kernel.org>
Cc: ***@kernel.org
Cc: oprofile-***@lists.sf.net
Signed-off-by: Anna-Maria Gleixner <anna-***@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <***@linutronix.de>
---
arch/x86/oprofile/nmi_int.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
index 28c04123b6dd..c39172cd6c87 100644
--- a/arch/x86/oprofile/nmi_int.c
+++ b/arch/x86/oprofile/nmi_int.c
@@ -387,20 +387,24 @@ static void nmi_cpu_shutdown(void *dummy)
nmi_cpu_restore_registers(msrs);
}

-static void nmi_cpu_up(void *dummy)
+static void nmi_cpu_up(void)
{
+ local_irq_disable();
if (nmi_enabled)
- nmi_cpu_setup(dummy);
+ nmi_cpu_setup(NULL);
if (ctr_running)
- nmi_cpu_start(dummy);
+ nmi_cpu_start(NULL);
+ local_irq_enable();
}

-static void nmi_cpu_down(void *dummy)
+static void nmi_cpu_down(void)
{
+ local_irq_disable();
if (ctr_running)
- nmi_cpu_stop(dummy);
+ nmi_cpu_stop(NULL);
if (nmi_enabled)
- nmi_cpu_shutdown(dummy);
+ nmi_cpu_shutdown(NULL);
+ local_irq_enable();
}

static int nmi_create_files(struct dentry *root)
@@ -436,15 +440,13 @@ static int nmi_create_files(struct dentry *root)
static int oprofile_cpu_notifier(struct notifier_block *b, unsigned long action,
void *data)
{
- int cpu = (unsigned long)data;
-
switch (action & ~CPU_TASKS_FROZEN) {
case CPU_DOWN_FAILED:
case CPU_ONLINE:
- smp_call_function_single(cpu, nmi_cpu_up, NULL, 0);
+ nmi_cpu_up();
break;
case CPU_DOWN_PREPARE:
- smp_call_function_single(cpu, nmi_cpu_down, NULL, 1);
+ nmi_cpu_down();
break;
}
return NOTIFY_DONE;
--
2.10.2


------------------------------------------------------------------------------
Loading...