mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Robert Richter <robert.richter@amd.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: LKML <linux-kernel@vger.kernel.org>,
	oprofile-list <oprofile-list@lists.sourceforge.net>,
	Robert Richter <robert.richter@amd.com>
Subject: [PATCH 13/26] x86/oprofile: Implement multiplexing setup/shutdown functions
Date: Tue, 28 Jul 2009 19:07:13 +0200	[thread overview]
Message-ID: <1248800846-25422-14-git-send-email-robert.richter@amd.com> (raw)
In-Reply-To: <1248800846-25422-1-git-send-email-robert.richter@amd.com>

This patch implements nmi_setup_mux() and nmi_shutdown_mux() functions
to setup/shutdown multiplexing. Multiplexing code in nmi_int.c is now
much more separated.

Signed-off-by: Robert Richter <robert.richter@amd.com>
---
 arch/x86/oprofile/nmi_int.c |   76 ++++++++++++++++++++++--------------------
 1 files changed, 40 insertions(+), 36 deletions(-)

diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
index 02b57b8..674fa37 100644
--- a/arch/x86/oprofile/nmi_int.c
+++ b/arch/x86/oprofile/nmi_int.c
@@ -106,9 +106,35 @@ inline int op_x86_phys_to_virt(int phys)
 	return __get_cpu_var(switch_index) + phys;
 }
 
+static void nmi_shutdown_mux(void)
+{
+	int i;
+	for_each_possible_cpu(i) {
+		kfree(per_cpu(cpu_msrs, i).multiplex);
+		per_cpu(cpu_msrs, i).multiplex = NULL;
+		per_cpu(switch_index, i) = 0;
+	}
+}
+
+static int nmi_setup_mux(void)
+{
+	size_t multiplex_size =
+		sizeof(struct op_msr) * model->num_virt_counters;
+	int i;
+	for_each_possible_cpu(i) {
+		per_cpu(cpu_msrs, i).multiplex =
+			kmalloc(multiplex_size, GFP_KERNEL);
+		if (!per_cpu(cpu_msrs, i).multiplex)
+			return 0;
+	}
+	return 1;
+}
+
 #else
 
 inline int op_x86_phys_to_virt(int phys) { return phys; }
+static inline void nmi_shutdown_mux(void) { }
+static inline int nmi_setup_mux(void) { return 1; }
 
 #endif
 
@@ -120,51 +146,27 @@ static void free_msrs(void)
 		per_cpu(cpu_msrs, i).counters = NULL;
 		kfree(per_cpu(cpu_msrs, i).controls);
 		per_cpu(cpu_msrs, i).controls = NULL;
-
-#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
-		kfree(per_cpu(cpu_msrs, i).multiplex);
-		per_cpu(cpu_msrs, i).multiplex = NULL;
-#endif
 	}
 }
 
 static int allocate_msrs(void)
 {
-	int success = 1;
 	size_t controls_size = sizeof(struct op_msr) * model->num_controls;
 	size_t counters_size = sizeof(struct op_msr) * model->num_counters;
-#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
-	size_t multiplex_size = sizeof(struct op_msr) * model->num_virt_counters;
-#endif
 
 	int i;
 	for_each_possible_cpu(i) {
 		per_cpu(cpu_msrs, i).counters = kmalloc(counters_size,
-								GFP_KERNEL);
-		if (!per_cpu(cpu_msrs, i).counters) {
-			success = 0;
-			break;
-		}
+							GFP_KERNEL);
+		if (!per_cpu(cpu_msrs, i).counters)
+			return 0;
 		per_cpu(cpu_msrs, i).controls = kmalloc(controls_size,
-								GFP_KERNEL);
-		if (!per_cpu(cpu_msrs, i).controls) {
-			success = 0;
-			break;
-		}
-#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
-		per_cpu(cpu_msrs, i).multiplex =
-				kmalloc(multiplex_size, GFP_KERNEL);
-		if (!per_cpu(cpu_msrs, i).multiplex) {
-			success = 0;
-			break;
-		}
-#endif
+							GFP_KERNEL);
+		if (!per_cpu(cpu_msrs, i).controls)
+			return 0;
 	}
 
-	if (!success)
-		free_msrs();
-
-	return success;
+	return 1;
 }
 
 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
@@ -218,11 +220,15 @@ static int nmi_setup(void)
 	int cpu;
 
 	if (!allocate_msrs())
-		return -ENOMEM;
+		err = -ENOMEM;
+	else if (!nmi_setup_mux())
+		err = -ENOMEM;
+	else
+		err = register_die_notifier(&profile_exceptions_nb);
 
-	err = register_die_notifier(&profile_exceptions_nb);
 	if (err) {
 		free_msrs();
+		nmi_shutdown_mux();
 		return err;
 	}
 
@@ -314,9 +320,6 @@ static void nmi_cpu_shutdown(void *dummy)
 	apic_write(APIC_LVTPC, per_cpu(saved_lvtpc, cpu));
 	apic_write(APIC_LVTERR, v);
 	nmi_cpu_restore_registers(msrs);
-#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
-	per_cpu(switch_index, cpu) = 0;
-#endif
 }
 
 static void nmi_shutdown(void)
@@ -326,6 +329,7 @@ static void nmi_shutdown(void)
 	nmi_enabled = 0;
 	on_each_cpu(nmi_cpu_shutdown, NULL, 1);
 	unregister_die_notifier(&profile_exceptions_nb);
+	nmi_shutdown_mux();
 	msrs = &get_cpu_var(cpu_msrs);
 	model->shutdown(msrs);
 	free_msrs();
-- 
1.6.3.3



  parent reply	other threads:[~2009-07-28 17:20 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-28 17:07 [PATCH 0/26] oprofile: Performance counter multiplexing Robert Richter
2009-07-28 17:07 ` [PATCH 01/26] x86/oprofile: Rework and simplify nmi_cpu_setup() Robert Richter
2009-07-28 17:07 ` [PATCH 02/26] x86/oprofile: Whitespaces changes only Robert Richter
2009-07-28 17:07 ` [PATCH 03/26] oprofile: Implement performance counter multiplexing Robert Richter
2009-07-28 17:07 ` [PATCH 04/26] x86/oprofile: Fix usage of NUM_CONTROLS/NUM_COUNTERS macros Robert Richter
2009-07-28 17:07 ` [PATCH 05/26] x86/oprofile: Use per_cpu() instead of __get_cpu_var() Robert Richter
2009-07-28 17:07 ` [PATCH 06/26] x86/oprofile: Fix initialization of switch_index Robert Richter
2009-07-28 17:07 ` [PATCH 07/26] oprofile: oprofile_set_timeout(), return with error for invalid args Robert Richter
2009-07-28 17:07 ` [PATCH 08/26] oprofile: Rename variable timeout_jiffies and move to oprofile_files.c Robert Richter
2009-07-28 17:07 ` [PATCH 09/26] oprofile: Remove oprofile_multiplexing_init() Robert Richter
2009-07-28 17:07 ` [PATCH 10/26] oprofile: Grouping multiplexing code in oprof.c Robert Richter
2009-07-28 17:07 ` [PATCH 11/26] oprofile: Introduce op_x86_phys_to_virt() Robert Richter
2009-07-28 17:07 ` [PATCH 12/26] oprofile: Grouping multiplexing code in op_model_amd.c Robert Richter
2009-07-28 17:07 ` Robert Richter [this message]
2009-07-28 17:07 ` [PATCH 14/26] x86/oprofile: Moving nmi_setup_cpu_mux() in nmi_int.c Robert Richter
2009-07-28 17:07 ` [PATCH 15/26] x86/oprofile: Moving nmi_cpu_save/restore_mpx_registers() " Robert Richter
2009-07-28 17:07 ` [PATCH 16/26] x86/oprofile: Moving nmi_cpu_switch() " Robert Richter
2009-07-28 17:07 ` [PATCH 17/26] x86/oprofile: Remove const qualifier from struct op_x86_model_spec Robert Richter
2009-07-28 17:07 ` [PATCH 18/26] x86/oprofile: Remove unused num_virt_controls " Robert Richter
2009-07-28 17:07 ` [PATCH 19/26] x86/oprofile: Modify initialization of num_virt_counters Robert Richter
2009-07-28 17:07 ` [PATCH 20/26] x86/oprofile: Add function has_mux() to check multiplexing support Robert Richter
2009-07-28 17:07 ` [PATCH 21/26] x86/oprofile: Enable multiplexing only if the model supports it Robert Richter
2009-07-28 17:07 ` [PATCH 22/26] x86/oprofile: Implement mux_clone() Robert Richter
2009-07-28 17:07 ` [PATCH 23/26] oprofile: Adding switch counter to oprofile statistic variables Robert Richter
2009-07-28 17:07 ` [PATCH 24/26] x86/oprofile: Implement op_x86_virt_to_phys() Robert Richter
2009-07-28 17:07 ` [PATCH 25/26] x86/oprofile: Add counter reservation check for virtual counters Robert Richter
2009-07-28 17:07 ` [PATCH 26/26] x86/oprofile: Small coding style fixes Robert Richter
2009-07-28 18:45 ` [PATCH 0/26] oprofile: Performance counter multiplexing Andi Kleen
2009-07-28 22:18   ` Suthikulpanit, Suravee
2009-08-03 11:22 ` Ingo Molnar
2009-08-03 14:25   ` Arjan van de Ven
2009-08-04 20:11     ` Ingo Molnar
2009-08-05 12:35       ` Robert Richter
2009-08-06  7:31         ` Pekka Enberg
2009-08-06 10:51           ` Ingo Molnar
2009-08-13 16:13             ` Robert Richter
     [not found]           ` <20090806105134.GD11236__37984.4768475325$1249556453$gmane$org@elte.hu>
2010-02-26 14:51             ` Andi Kleen
2010-03-05 16:46               ` Robert Richter
2010-03-05 17:01                 ` Steven Rostedt
2010-03-08  3:51                 ` Andi Kleen
2009-08-03 16:30   ` Robert Richter
2009-08-04 17:05     ` 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=1248800846-25422-14-git-send-email-robert.richter@amd.com \
    --to=robert.richter@amd.com \
    --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