linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf_events: fix bug in AMD per-cpu initialization
@ 2010-03-17  8:40 Stephane Eranian
  2010-03-17 23:47 ` Peter Zijlstra
  0 siblings, 1 reply; 12+ messages in thread
From: Stephane Eranian @ 2010-03-17  8:40 UTC (permalink / raw)
  To: linux-kernel
  Cc: peterz, mingo, paulus, davem, fweisbec, robert.richter,
	perfmon2-devel, eranian, eranian

	On AMD processors, we need to allocate a data structure per Northbridge
	to handle certain events.

	On CPU initialization, we need to query the Northbridge id and check
	whether the structure is already allocated or not. We use the
	amd_get_nb_id() function to request the Northbridge identification.

	The recent cleanup of the CPU online/offline initialization introduced
	a bug. AMD cpu initialization is invoked on CPU_UP_PREPARE callback.
	This is before the CPU Northbridge id is calculated. Therefore no
	processor had a Northbridge structure allocated except the boot
	processor. That was causing bogus NB event scheduling.

	This patch uses the CPU_ONLINE callback to initialize the AMD
	Northbridge structure. This way amd_get_nb_id() returns valid
	information.

	The x86_cpu_up() callback was added. Could not call it cpu_online
	because of existing macro.

	Signed-off-by: Stephane Eranian <eranian@google.com>
	
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index 978d297..016c25a 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -213,6 +213,7 @@ struct x86_pmu {
 	void		(*quirks)(void);
 
 	void		(*cpu_prepare)(int cpu);
+	void		(*cpu_up)(int cpu);
 	void		(*cpu_starting)(int cpu);
 	void		(*cpu_dying)(int cpu);
 	void		(*cpu_dead)(int cpu);
@@ -1342,6 +1343,11 @@ x86_pmu_notifier(struct notifier_block *self, unsigned long action, void *hcpu)
 			x86_pmu.cpu_starting(cpu);
 		break;
 
+	case CPU_ONLINE:
+		if (x86_pmu.cpu_up)
+			x86_pmu.cpu_up(cpu);
+		break;
+
 	case CPU_DYING:
 		if (x86_pmu.cpu_dying)
 			x86_pmu.cpu_dying(cpu);
diff --git a/arch/x86/kernel/cpu/perf_event_amd.c b/arch/x86/kernel/cpu/perf_event_amd.c
index 358a8e3..584df49 100644
--- a/arch/x86/kernel/cpu/perf_event_amd.c
+++ b/arch/x86/kernel/cpu/perf_event_amd.c
@@ -346,6 +346,9 @@ static void amd_pmu_cpu_offline(int cpu)
 
 	cpuhw = &per_cpu(cpu_hw_events, cpu);
 
+	if (!cpuhw->amd_nb)
+		return;
+
 	raw_spin_lock(&amd_nb_lock);
 
 	if (--cpuhw->amd_nb->refcnt == 0)
@@ -379,7 +382,7 @@ static __initconst struct x86_pmu amd_pmu = {
 	.get_event_constraints	= amd_get_event_constraints,
 	.put_event_constraints	= amd_put_event_constraints,
 
-	.cpu_prepare		= amd_pmu_cpu_online,
+	.cpu_up			= amd_pmu_cpu_online,
 	.cpu_dead		= amd_pmu_cpu_offline,
 };
 

^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [PATCH] perf_events: fix bug in AMD per-cpu initialization
@ 2010-03-24 13:45 Stephane Eranian
  0 siblings, 0 replies; 12+ messages in thread
From: Stephane Eranian @ 2010-03-24 13:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: peterz, mingo, paulus, davem, fweisbec, robert.richter,
	perfmon2-devel, eranian, eranian, hpa, tglx, manfred

> Crap, you're right, either notify_cpu_starting() is done too early or
> smp_store_cpu_info() is done too late.
> 
> Since smp_store_cpu_info() relies on the result of calibrate_delay() we
> can't easily change that order, but since there really isn't any other
> CPU_STARTING user in tree (I appear to have created the first?!) we can
> easily move that notifier thing later.
> 
> (What's up with that IRQ-enable over calibrate_delay(), can't we simply
> enable the NMI watchdog later?)
> 
> So I guess something like the below should work:

The patch does work for me. I made two small modifications by
adding amd_has_nb() such that the correct checking is for on amd_nb.

	Signed-off-by: Stephane Eranian <eranian@google.com>

diff --git a/arch/x86/kernel/cpu/perf_event_amd.c b/arch/x86/kernel/cpu/perf_event_amd.c
index a61e54b..6204739 100644
--- a/arch/x86/kernel/cpu/perf_event_amd.c
+++ b/arch/x86/kernel/cpu/perf_event_amd.c
@@ -137,6 +137,13 @@ static inline int amd_is_nb_event(struct hw_perf_event *hwc)
 	return (hwc->config & 0xe0) == 0xe0;
 }
 
+static inline int amd_has_nb(struct cpu_hw_events *cpuc)
+{
+	struct amd_nb *nb = cpuc->amd_nb;
+
+	return nb && nb->nb_id != -1;
+}
+
 static void amd_put_event_constraints(struct cpu_hw_events *cpuc,
 				      struct perf_event *event)
 {
@@ -147,7 +154,7 @@ static void amd_put_event_constraints(struct cpu_hw_events *cpuc,
 	/*
 	 * only care about NB events
 	 */
-	if (!(nb && amd_is_nb_event(hwc)))
+	if (!(amd_has_nb(cpuc) && amd_is_nb_event(hwc)))
 		return;
 
 	/*
@@ -214,7 +221,7 @@ amd_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event)
 	/*
 	 * if not NB event or no NB, then no constraints
 	 */
-	if (!(nb && amd_is_nb_event(hwc)))
+	if (!(amd_has_nb(cpuc) && amd_is_nb_event(hwc)))
 		return &unconstrained;
 
 	/*

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2010-04-02 19:07 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-17  8:40 [PATCH] perf_events: fix bug in AMD per-cpu initialization Stephane Eranian
2010-03-17 23:47 ` Peter Zijlstra
2010-03-18  0:33   ` Stephane Eranian
2010-03-23 14:11     ` Peter Zijlstra
2010-03-23 14:55       ` Stephane Eranian
2010-03-23 15:07         ` Peter Zijlstra
2010-03-23 15:12           ` Stephane Eranian
2010-03-23 15:18             ` Peter Zijlstra
2010-03-23 22:41               ` Stephane Eranian
2010-04-02 19:06       ` [tip:perf/core] x86: Move notify_cpu_starting() callback to a later stage tip-bot for Peter Zijlstra
2010-04-02 19:07       ` [tip:perf/core] perf, x86: Fix AMD hotplug & constraint initialization tip-bot for Peter Zijlstra
  -- strict thread matches above, loose matches on Subject: below --
2010-03-24 13:45 [PATCH] perf_events: fix bug in AMD per-cpu initialization Stephane Eranian

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).