From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755039AbcKUPzM (ORCPT ); Mon, 21 Nov 2016 10:55:12 -0500 Received: from terminus.zytor.com ([198.137.202.10]:40682 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754183AbcKUPzK (ORCPT ); Mon, 21 Nov 2016 10:55:10 -0500 Date: Mon, 21 Nov 2016 07:55:03 -0800 From: tip-bot for Sebastian Andrzej Siewior Message-ID: Cc: hpa@zytor.com, tglx@linutronix.de, rric@kernel.org, bigeasy@linutronix.de, mingo@kernel.org, linux-kernel@vger.kernel.org Reply-To: mingo@kernel.org, linux-kernel@vger.kernel.org, bigeasy@linutronix.de, rric@kernel.org, tglx@linutronix.de, hpa@zytor.com In-Reply-To: <20161117183541.8588-20-bigeasy@linutronix.de> References: <20161117183541.8588-20-bigeasy@linutronix.de> To: linux-tip-commits@vger.kernel.org Subject: [tip:smp/hotplug] x86/oprofile/nmi: Convert to hotplug state machine Git-Commit-ID: cff817393431c3cc6fc3eaaeb8511ee0d16116aa X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: cff817393431c3cc6fc3eaaeb8511ee0d16116aa Gitweb: http://git.kernel.org/tip/cff817393431c3cc6fc3eaaeb8511ee0d16116aa Author: Sebastian Andrzej Siewior AuthorDate: Thu, 17 Nov 2016 19:35:40 +0100 Committer: Thomas Gleixner CommitDate: Mon, 21 Nov 2016 16:37:09 +0100 x86/oprofile/nmi: Convert to hotplug state machine Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs. Signed-off-by: Sebastian Andrzej Siewior Cc: Robert Richter Cc: oprofile-list@lists.sf.net Cc: rt@linuxtronix.de Link: http://lkml.kernel.org/r/20161117183541.8588-20-bigeasy@linutronix.de Signed-off-by: Thomas Gleixner --- 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 c39172c..ffdbc48 100644 --- a/arch/x86/oprofile/nmi_int.c +++ b/arch/x86/oprofile/nmi_int.c @@ -339,10 +339,11 @@ fail: 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 cpuhp_nmi_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; + cpuhp_nmi_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(cpuhp_nmi_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();