Skip to contentSkip to conversation

perf, x86: collection of pentium 4 fixes

PATCH In review Don Zickus 4 participants 24 messages Apr 21, 2011 – Apr 25, 2011 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Don Zickus

author
#0 lore raw

cover perf, x86: collection of pentium 4 fixes

This patch series has various clean ups for the P4 perf nmi layer. Some of the changes touch the other platforms but those should be minimally intrusive.

It would be nice to get these into 2.6.39 as two patches fix 'unknown' NMIs, which is listed as a regression from 2.6.38.

Cyrill Gorcunov (3):
perf, x86: P4 PMU -- Use perf_sample_data_init helper perf, x86: P4 PMU - Don't forget to clear cpuc->active_mask on
overflow
perf, x86: Add PERF_COUNT_HW_NMI_WATCHDOG event

Don Zickus (1):
perf, nmi: Move LVT un-masking into irq handlers

 arch/x86/kernel/cpu/perf_event.c       |    5 ++-
 arch/x86/kernel/cpu/perf_event_amd.c   |    1 +
 arch/x86/kernel/cpu/perf_event_intel.c |    4 +++
 arch/x86/kernel/cpu/perf_event_p4.c    |   34 +++++++++++++++++++++++++------
 arch/x86/kernel/cpu/perf_event_p6.c    |    1 +
 include/linux/perf_event.h             |    1 +
 kernel/watchdog.c                      |    2 +-
 7 files changed, 38 insertions(+), 10 deletions(-)
Signature · 1 line
1.7.4.2
author
#1 lore raw

PATCH 1/4 perf, x86: P4 PMU -- Use perf_sample_data_init helper

From: Cyrill Gorcunov <[email protected]>

Instead of opencoded assignments better to use
perf_sample_data_init helper.

---
 arch/x86/kernel/cpu/perf_event_p4.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/perf_event_p4.c +1 -2
index c2520e1..6f2bd89 100644
@@ -912,8 +912,7 @@ static int p4_pmu_handle_irq(struct pt_regs *regs)
 	int idx, handled = 0;
 	u64 val;
 
-	data.addr = 0;
-	data.raw = NULL;
+	perf_sample_data_init(&data, 0);
 
 	cpuc = &__get_cpu_var(cpu_hw_events);
 
Signature · 1 line
1.7.4.2
#2 lore raw

Re: [PATCH 1/4] perf, x86: P4 PMU -- Use perf_sample_data_init helper

Quoted 17 lines · Don Zickus

From: Cyrill Gorcunov <[email protected]>

Instead of opencoded assignments better to use
perf_sample_data_init helper.

---
 arch/x86/kernel/cpu/perf_event_p4.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/perf_event_p4.c +0 -0
index c2520e1..6f2bd89 100644

arch/x86/kernel/cpu/perf_event_p4.c static int p4_pmu_handle_irq(struct pt_regs *regs) · line 915

Quoted 6 lines
arch/x86/kernel/cpu/perf_event_p4.c +1 -2
@@ -912,8 +912,7 @@ static int p4_pmu_handle_irq(struct pt_regs *regs)
 	int idx, handled = 0;
 	u64 val;
 
-	data.addr = 0;
-	data.raw = NULL;
+	perf_sample_data_init(&data, 0);

This one sure can wait for v2.6.40, right?

Thanks,

Ingo

#3 lore raw

Re: [PATCH 1/4] perf, x86: P4 PMU -- Use perf_sample_data_init helper

yeah, it can wait

Quoted 33 lines · Ingo Molnar
Quoted 17 lines · Don Zickus

From: Cyrill Gorcunov <[email protected]>

Instead of opencoded assignments better to use
perf_sample_data_init helper.

---
 arch/x86/kernel/cpu/perf_event_p4.c |    3 +--

 1 files changed, 1 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/perf_event_p4.c +0 -0
index c2520e1..6f2bd89 100644

arch/x86/kernel/cpu/perf_event_p4.c static int p4_pmu_handle_irq(struct pt_regs *regs) · line 915

Quoted 6 lines
arch/x86/kernel/cpu/perf_event_p4.c +1 -2
@@ -912,8 +912,7 @@ static int p4_pmu_handle_irq(struct pt_regs *regs)
       int idx, handled = 0;
       u64 val;
 
-     data.addr = 0;
-     data.raw = NULL;
+     perf_sample_data_init(&data, 0);

This one sure can wait for v2.6.40, right?

Thanks,

       Ingo

#4 lore raw

[tip:perf/core] perf, x86: P4 PMU -- Use perf_sample_data_init helper

In reply to Don Zickus
Commit-ID:  103b3934817a7c42fba6e1ef76ecb390a2837d40
Gitweb:     http://git.kernel.org/tip/103b3934817a7c42fba6e1ef76ecb390a2837d40
Author:     Cyrill Gorcunov <[email protected]>
AuthorDate: Thu, 21 Apr 2011 11:03:20 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 22 Apr 2011 10:20:04 +0200

perf, x86: P4 PMU -- Use perf_sample_data_init helper

Instead of opencoded assignments better to use perf_sample_data_init helper.

---
 arch/x86/kernel/cpu/perf_event_p4.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/perf_event_p4.c +1 -2
index 8ff882f..ae31e96 100644
@@ -912,8 +912,7 @@ static int p4_pmu_handle_irq(struct pt_regs *regs)
 	int idx, handled = 0;
 	u64 val;
 
-	data.addr = 0;
-	data.raw = NULL;
+	perf_sample_data_init(&data, 0);
 
 	cpuc = &__get_cpu_var(cpu_hw_events);
 
author
#5 lore raw

PATCH 2/4 perf, x86: P4 PMU - Don't forget to clear cpuc->active_mask on overflow

In reply to Don Zickus

From: Cyrill Gorcunov <[email protected]>

It's not enough to simply disable event on overflow the cpuc->active_mask should be cleared as well otherwise counter may stall in "active" even in real being already disabled (which potentially may lead to the situation that user may not use this counter further).

Don pointed "I also noticed this patch fixed some unknown NMIs on a P4 when I stressed the box".

---
 arch/x86/kernel/cpu/perf_event_p4.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/perf_event_p4.c +1 -1
index 6f2bd89..56ba449 100644
@@ -946,7 +946,7 @@ static int p4_pmu_handle_irq(struct pt_regs *regs)
 		if (!x86_perf_event_set_period(event))
 			continue;
 		if (perf_event_overflow(event, 1, &data, regs))
-			p4_pmu_disable_event(event);
+			x86_pmu_stop(event, 0);
 	}
 
 	if (handled) {
Signature · 1 line
1.7.4.2
#6 lore raw

[tip:perf/urgent] perf, x86: P4 PMU - Don't forget to clear cpuc->active_mask on overflow

Commit-ID:  1ea5a6afd95a4803900c97ed63a47a883ebe7b3e
Gitweb:     http://git.kernel.org/tip/1ea5a6afd95a4803900c97ed63a47a883ebe7b3e
Author:     Cyrill Gorcunov <[email protected]>
AuthorDate: Thu, 21 Apr 2011 11:03:21 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 22 Apr 2011 10:21:34 +0200

perf, x86: P4 PMU - Don't forget to clear cpuc->active_mask on overflow

It's not enough to simply disable event on overflow the cpuc->active_mask should be cleared as well otherwise counter may stall in "active" even in real being already disabled (which potentially may lead to the situation that user may not use this counter further).

Don pointed out that:

" I also noticed this patch fixed some unknown NMIs
on a P4 when I stressed the box".

---
 arch/x86/kernel/cpu/perf_event_p4.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/perf_event_p4.c +1 -1
index c2520e1..d1f77e2 100644
@@ -947,7 +947,7 @@ static int p4_pmu_handle_irq(struct pt_regs *regs)
 		if (!x86_perf_event_set_period(event))
 			continue;
 		if (perf_event_overflow(event, 1, &data, regs))
-			p4_pmu_disable_event(event);
+			x86_pmu_stop(event, 0);
 	}
 
 	if (handled) {
author
#7 lore raw

PATCH 3/4 perf, nmi: Move LVT un-masking into irq handlers

In reply to Don Zickus

It was noticed that P4 machines were generating double NMIs for each perf event. These extra NMIs lead to 'Dazed and confused' messages on the screen.

I tracked this down to a P4 quirk that said the overflow bit had to be cleared before re-enabling the apic LVT mask. My first attempt was to move the un-masking inside the perf nmi handler from before the chipset NMI handler to after.

This broke Nehalem boxes that seem to like the unmasking before the counters themselves are re-enabled.

In order to keep this change simple for 2.6.39, I decided to just simply move the apic LVT un-masking to the beginning of all the chipset NMI handlers, with the exeption of Pentium4's to fix the double NMI issue.

Later on we can move the un-masking to later in the handlers to save a number of 'extra' NMIs on those particular chipsets.

I tested this change on a P4 machine, an AMD machine, a Nehalem box, and a core2quad box. 'perf top' worked correctly along with various other small 'perf record' runs. Anything high stress breaks all the machines but that is a different problem.

Thanks to various people for testing different versions of this patch.

https://bugzilla.kernel.org/show_bug.cgi?id=33252

Reported-and-tested-by Shaun Ruffell <[email protected]>
CC Peter Zijlstra <[email protected]>
CC Robert Richter <[email protected]>
CC Maciej Rutecki <[email protected]>
CC George Spelvin <[email protected]>
CC Stephane Eranian <[email protected]>
---
 arch/x86/kernel/cpu/perf_event.c       |    5 +++--
 arch/x86/kernel/cpu/perf_event_intel.c |    3 +++
 arch/x86/kernel/cpu/perf_event_p4.c    |   14 ++++++++++----
 3 files changed, 16 insertions(+), 6 deletions(-)
arch/x86/kernel/cpu/perf_event.c +3 -2
index eed3673a..97c6c44 100644
@@ -1284,6 +1284,9 @@ static int x86_pmu_handle_irq(struct pt_regs *regs)
 
 	cpuc = &__get_cpu_var(cpu_hw_events);
 
+	/* chipsets have their own quirks when to unmask */
+	apic_write(APIC_LVTPC, APIC_DM_NMI);
+
 	for (idx = 0; idx < x86_pmu.num_counters; idx++) {
 		if (!test_bit(idx, cpuc->active_mask)) {
 			/*
@@ -1370,8 +1373,6 @@ perf_event_nmi_handler(struct notifier_block *self,
 		return NOTIFY_DONE;
 	}
 
-	apic_write(APIC_LVTPC, APIC_DM_NMI);
-
 	handled = x86_pmu.handle_irq(args->regs);
 	if (!handled)
 		return NOTIFY_DONE;
arch/x86/kernel/cpu/perf_event_intel.c +3 -0
index 8fc2b2c..d2326e1 100644
@@ -933,6 +933,9 @@ static int intel_pmu_handle_irq(struct pt_regs *regs)
 
 	cpuc = &__get_cpu_var(cpu_hw_events);
 
+	/* chipsets have their own quirks when to unmask */
+	apic_write(APIC_LVTPC, APIC_DM_NMI);
+
 	intel_pmu_disable_all();
 	handled = intel_pmu_drain_bts_buffer();
 	status = intel_pmu_get_status();
arch/x86/kernel/cpu/perf_event_p4.c +10 -4
index 56ba449..2d0ac91 100644
@@ -949,11 +949,17 @@ static int p4_pmu_handle_irq(struct pt_regs *regs)
 			x86_pmu_stop(event, 0);
 	}
 
-	if (handled) {
-		/* p4 quirk: unmask it again */
-		apic_write(APIC_LVTPC, apic_read(APIC_LVTPC) & ~APIC_LVT_MASKED);
+	if (handled)
 		inc_irq_stat(apic_perf_irqs);
-	}
+
+        /*
+	 * P4 quirks:
+	 * - An overflown perfctr will assert its interrupt
+	 *   until the OVF flag in its CCCR is cleared.
+	 * - LVTPC is masked on interrupt and must be
+	 *   unmasked by the LVTPC handler.
+	 */
+	apic_write(APIC_LVTPC, APIC_DM_NMI);
 
 	return handled;
 }
Signature · 1 line
1.7.4.2
#8 lore raw

Re: [PATCH 3/4] perf, nmi: Move LVT un-masking into irq handlers

arch/x86/kernel/cpu/perf_event.c static int x86_pmu_handle_irq(struct pt_regs *regs) · line 1289

Quoted 9 lines · Don Zickus
arch/x86/kernel/cpu/perf_event.c +3 -0
@@ -1284,6 +1284,9 @@ static int x86_pmu_handle_irq(struct pt_regs *regs)
 
 	cpuc = &__get_cpu_var(cpu_hw_events);
 
+	/* chipsets have their own quirks when to unmask */
+	apic_write(APIC_LVTPC, APIC_DM_NMI);
+

What sense does this comment make in this place?

Yes, chipsets have their own quirks - but the generic handler is not one of them. So a more appropriate comment would be to point out why we want to unmask there - before PMU handling or after it, etc.

Like the P4 quirk is documented a bit better:

arch/x86/kernel/cpu/perf_event.c static int x86_pmu_handle_irq(struct pt_regs *regs)

Quoted 8 lines
arch/x86/kernel/cpu/perf_event.c +8 -0
+        /*
+	 * P4 quirks:
+	 * - An overflown perfctr will assert its interrupt
+	 *   until the OVF flag in its CCCR is cleared.
+	 * - LVTPC is masked on interrupt and must be
+	 *   unmasked by the LVTPC handler.
+	 */
+	apic_write(APIC_LVTPC, APIC_DM_NMI);

(btw., there's whitespace damage above as well.)

Furthermore, the P4 comment should *explain* the quirk coherently, not just list random facts. What happens, why, where, and why do we unmask the LVTPC in that spot.

Thanks,

Ingo

author
#9 lore raw

Re: [PATCH 3/4] perf, nmi: Move LVT un-masking into irq handlers

Quoted 15 lines · Ingo Molnar

arch/x86/kernel/cpu/perf_event.c static int x86_pmu_handle_irq(struct pt_regs *regs) · line 1289

Quoted 9 lines · Don Zickus
arch/x86/kernel/cpu/perf_event.c +3 -0
@@ -1284,6 +1284,9 @@ static int x86_pmu_handle_irq(struct pt_regs *regs)
 
 	cpuc = &__get_cpu_var(cpu_hw_events);
 
+	/* chipsets have their own quirks when to unmask */
+	apic_write(APIC_LVTPC, APIC_DM_NMI);
+

What sense does this comment make in this place?

Quoted 3 lines

Yes, chipsets have their own quirks - but the generic handler is not one of them. So a more appropriate comment would be to point out why we want to unmask there - before PMU handling or after it, etc.

Yup. I rework that.

Quoted 14 lines

Like the P4 quirk is documented a bit better:

arch/x86/kernel/cpu/perf_event.c static int x86_pmu_handle_irq(struct pt_regs *regs)

Quoted 8 lines
arch/x86/kernel/cpu/perf_event.c +8 -0
+        /*
+	 * P4 quirks:
+	 * - An overflown perfctr will assert its interrupt
+	 *   until the OVF flag in its CCCR is cleared.
+	 * - LVTPC is masked on interrupt and must be
+	 *   unmasked by the LVTPC handler.
+	 */
+	apic_write(APIC_LVTPC, APIC_DM_NMI);

(btw., there's whitespace damage above as well.)

Quoted 3 lines

Furthermore, the P4 comment should *explain* the quirk coherently, not just list random facts. What happens, why, where, and why do we unmask the LVTPC in that spot.

Yeah, I copied that from the old watchdog code. I'll revise that too and repost.

Cheers,
Don

#10 lore raw

Re: [PATCH 3/4] perf, nmi: Move LVT un-masking into irq handlers

Quoted 16 lines · Don Zickus
Quoted 15 lines · Ingo Molnar

arch/x86/kernel/cpu/perf_event.c static int x86_pmu_handle_irq(struct pt_regs *regs) · line 1289

Quoted 9 lines · Don Zickus
arch/x86/kernel/cpu/perf_event.c +3 -0
@@ -1284,6 +1284,9 @@ static int x86_pmu_handle_irq(struct pt_regs *regs)
 
 	cpuc = &__get_cpu_var(cpu_hw_events);
 
+	/* chipsets have their own quirks when to unmask */
+	apic_write(APIC_LVTPC, APIC_DM_NMI);
+

What sense does this comment make in this place?

Quoted 5 lines
Quoted 3 lines

Yes, chipsets have their own quirks - but the generic handler is not one of them. So a more appropriate comment would be to point out why we want to unmask there - before PMU handling or after it, etc.

Yup. I rework that.

I suspect the comment from one of my draft version might fulfit, Don do you have it? /me looking in sent mbox

+ /*
+ * We have to unmask LVTPC *before* enabling counters,
+ * the key moment is that LVTPC is getting masked on
+ * PMI arrival and if PMU enabled before APIC unmasked
+ * a new oveflow signal may reach it but not propagated
+ * as NMI (due to transition timings) and LVTPC eventually
+ * stick masked forever dropping any further PMI signals.
+ */

it was for pmu-intel but i think same applies to general pmu handler.

Quoted 15 lines
Quoted 15 lines

Like the P4 quirk is documented a bit better:

arch/x86/kernel/cpu/perf_event.c static int x86_pmu_handle_irq(struct pt_regs *regs)

Quoted 8 lines
arch/x86/kernel/cpu/perf_event.c +8 -0
+        /*
+	 * P4 quirks:
+	 * - An overflown perfctr will assert its interrupt
+	 *   until the OVF flag in its CCCR is cleared.
+	 * - LVTPC is masked on interrupt and must be
+	 *   unmasked by the LVTPC handler.
+	 */
+	apic_write(APIC_LVTPC, APIC_DM_NMI);

(btw., there's whitespace damage above as well.)

Quoted 3 lines
Quoted 3 lines

Furthermore, the P4 comment should *explain* the quirk coherently, not just list random facts. What happens, why, where, and why do we unmask the LVTPC in that spot.

Ingo, actually I don't understand what else could be added here, should we post
the backtrace calls there? Or plain "we reach this point with OVF bit set" is enough?

Don't get me wrong please but the whole picture of what is happening can be seen only when
all caller sequence is taken into account and once (for some reason) the sequence get changed the "detailed" comment would simply mess the comment reader so I think the former comment is detailed enough and what is more important it's "general" enough so it doesn't depend on when code is called but points a reader on hw details and it's up to a reader to check "current" calling sequence because kernel code changes too damn fast ;)

Quoted 6 lines

Yeah, I copied that from the old watchdog code. I'll revise that too and repost.

Cheers,
Don

Signature · 1 line
    Cyrill

A message that is not in the archive (sent off-list or not yet received): [email protected]

#12 lore raw

Re: [PATCH 3/4] perf, nmi: Move LVT un-masking into irq handlers

Quoted 6 lines · lina

sorry,

How do I solve the problem of delivery failed?

Thanks,

Quoted 8 lines

Delivery to the following recipient failed permanently:

[email protected] <mailto:[email protected]>

Technical details of permanent failure:
Google tried to deliver your message, but it was rejected by the recipient domain. We recommend contacting the other email provider for further information about the cause of this error. The error that the other server returned was: 550 550 5.7.1 Content-Policy reject msg: The message contains HTML subpart, therefore we consider it SPAM or Outlook Virus. TEXT/PLAIN is accepted.! BF:<U 0.499653>; S1758441Ab1DYOLi (state 18).

It's written in the tech details of the failure

"Content-Policy reject msg: The message contains HTML subpart", so no HTML messages should be sent to LKML, plain text messaging only.

Signature · 1 line
    Cyrill
author
#13 lore raw

Re: [PATCH 3/4] perf, nmi: Move LVT un-masking into irq handlers

In reply to Cyrill Gorcunov
Quoted 8 lines · Cyrill Gorcunov

Don't get me wrong please but the whole picture of what is happening can be seen only when
all caller sequence is taken into account and once (for some reason) the sequence get changed the "detailed" comment would simply mess the comment reader so I think the former comment is detailed enough and what is more important it's "general" enough so it doesn't depend on when code is called but points a reader on hw details and it's up to a reader to check "current" calling sequence because kernel code changes too damn fast ;)

I think Ingo is looking for is something like

/*
* It has been observed that quirks in the P4 perf hw has forced the
* following sequence of events to happen in the order below *
* - clear the OVF bit (as it will continue to assert the NMI line)
* - unmask the apic LVTPC bit to allow NMIs from the PMU again
* - optionally re-enable the PMU to count events again
*
* Un-masking the apic prematurely (before clearing the OVF bit) has led
* to the creation of a second NMI event (which led to the unknown NMI
* warnings) due to the fact that the PMU will continue to generate an
* interrupt until its OVF bit is cleared.
*/

Something that specifically documents what we saw, why we saw it and what we are doing to avoid it.

Cheers,
Don

#14 lore raw

Re: [PATCH 3/4] perf, nmi: Move LVT un-masking into irq handlers

Quoted 26 lines · Don Zickus
Quoted 8 lines · Cyrill Gorcunov

Don't get me wrong please but the whole picture of what is happening can be seen only when
all caller sequence is taken into account and once (for some reason) the sequence get changed the "detailed" comment would simply mess the comment reader so I think the former comment is detailed enough and what is more important it's "general" enough so it doesn't depend on when code is called but points a reader on hw details and it's up to a reader to check "current" calling sequence because kernel code changes too damn fast ;)

I think Ingo is looking for is something like

/*
* It has been observed that quirks in the P4 perf hw has forced the
* following sequence of events to happen in the order below *
* - clear the OVF bit (as it will continue to assert the NMI line)
* - unmask the apic LVTPC bit to allow NMIs from the PMU again
* - optionally re-enable the PMU to count events again
*
* Un-masking the apic prematurely (before clearing the OVF bit) has led
* to the creation of a second NMI event (which led to the unknown NMI
* warnings) due to the fact that the PMU will continue to generate an
* interrupt until its OVF bit is cleared.
*/

Quoted 5 lines

Something that specifically documents what we saw, why we saw it and what we are doing to avoid it.

Cheers,
Don

Excellent, thanks a huge Don!

Signature · 1 line
    Cyrill
author
#15 lore raw

PATCH 4/4 perf, x86: Add PERF_COUNT_HW_NMI_WATCHDOG event

In reply to Don Zickus

From: Cyrill Gorcunov <[email protected]>

Due to restriction and specifics of Netburst PMU we need
a separated event for NMI watchdog. Note that on all other
than P4 PMU cpus this event is a simple alias for PERF_COUNT_HW_CPU_CYCLES.

This event is only used by x86 for now so no other archs involved.

---
 arch/x86/kernel/cpu/perf_event_amd.c   |    1 +
 arch/x86/kernel/cpu/perf_event_intel.c |    1 +
 arch/x86/kernel/cpu/perf_event_p4.c    |   15 +++++++++++++++
 arch/x86/kernel/cpu/perf_event_p6.c    |    1 +
 include/linux/perf_event.h             |    1 +
 kernel/watchdog.c                      |    2 +-
 6 files changed, 20 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/perf_event_amd.c +1 -0
index 461f62b..248d8d7 100644
@@ -102,6 +102,7 @@ static const u64 amd_perfmon_event_map[] =
   [PERF_COUNT_HW_CACHE_MISSES]		= 0x0081,
   [PERF_COUNT_HW_BRANCH_INSTRUCTIONS]	= 0x00c2,
   [PERF_COUNT_HW_BRANCH_MISSES]		= 0x00c3,
+  [PERF_COUNT_HW_NMI_WATCHDOG]		= 0x0076,
 };
 
 static u64 amd_pmu_event_map(int hw_event)
arch/x86/kernel/cpu/perf_event_intel.c +1 -0
index d2326e1..92351ec 100644
@@ -34,6 +34,7 @@ static const u64 intel_perfmon_event_map[] =
   [PERF_COUNT_HW_BRANCH_INSTRUCTIONS]	= 0x00c4,
   [PERF_COUNT_HW_BRANCH_MISSES]		= 0x00c5,
   [PERF_COUNT_HW_BUS_CYCLES]		= 0x013c,
+  [PERF_COUNT_HW_NMI_WATCHDOG]		= 0x003c,
 };
 
 static struct event_constraint intel_core_event_constraints[] =
arch/x86/kernel/cpu/perf_event_p4.c +15 -0
index 2d0ac91..9e13864 100644
@@ -557,6 +557,7 @@ static __initconst const u64 p4_hw_cache_event_ids
 };
 
 static u64 p4_general_events[PERF_COUNT_HW_MAX] = {
+
   /* non-halted CPU clocks */
   [PERF_COUNT_HW_CPU_CYCLES] =
 	p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_GLOBAL_POWER_EVENTS)		|
@@ -607,6 +608,20 @@ static u64 p4_general_events[PERF_COUNT_HW_MAX] = {
 		P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_DRV)		|
 		P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_OWN))	|
 	p4_config_pack_cccr(P4_CCCR_EDGE | P4_CCCR_COMPARE),
+
+  /* we use that named non-sleeping calls */
+  [PERF_COUNT_HW_NMI_WATCHDOG] =
+	p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_EXECUTION_EVENT)		|
+		P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS0)		|
+		P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS1)		|
+		P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS2)		|
+		P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS3)		|
+		P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS0)		|
+		P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS1)		|
+		P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS2)		|
+		P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS3))		|
+	p4_config_pack_cccr(P4_CCCR_THRESHOLD(15) | P4_CCCR_COMPLEMENT		|
+		P4_CCCR_COMPARE),
 };
 
 static struct p4_event_bind *p4_config_get_bind(u64 config)
arch/x86/kernel/cpu/perf_event_p6.c +1 -0
index 20c097e..3daeb18 100644
@@ -12,6 +12,7 @@ static const u64 p6_perfmon_event_map[] =
   [PERF_COUNT_HW_BRANCH_INSTRUCTIONS]	= 0x00c4,
   [PERF_COUNT_HW_BRANCH_MISSES]		= 0x00c5,
   [PERF_COUNT_HW_BUS_CYCLES]		= 0x0062,
+  [PERF_COUNT_HW_NMI_WATCHDOG]		= 0x0079,
 };
 
 static u64 p6_pmu_event_map(int hw_event)
include/linux/perf_event.h +1 -0
index 311b4dc..b67564d 100644
@@ -52,6 +52,7 @@ enum perf_hw_id {
 	PERF_COUNT_HW_BRANCH_INSTRUCTIONS	= 4,
 	PERF_COUNT_HW_BRANCH_MISSES		= 5,
 	PERF_COUNT_HW_BUS_CYCLES		= 6,
+	PERF_COUNT_HW_NMI_WATCHDOG		= 7,
 
 	PERF_COUNT_HW_MAX,			/* non-ABI */
 };
kernel/watchdog.c +1 -1
index 14733d4..3b6e0af 100644
@@ -191,7 +191,7 @@ static int is_softlockup(unsigned long touch_ts)
 #ifdef CONFIG_HARDLOCKUP_DETECTOR
 static struct perf_event_attr wd_hw_attr = {
 	.type		= PERF_TYPE_HARDWARE,
-	.config		= PERF_COUNT_HW_CPU_CYCLES,
+	.config		= PERF_COUNT_HW_NMI_WATCHDOG,
 	.size		= sizeof(struct perf_event_attr),
 	.pinned		= 1,
 	.disabled	= 1,
Signature · 1 line
1.7.4.2
#16 lore raw

Re: [PATCH 4/4] perf, x86: Add PERF_COUNT_HW_NMI_WATCHDOG event

Quoted 7 lines · Don Zickus

From: Cyrill Gorcunov <[email protected]>

Due to restriction and specifics of Netburst PMU we need
a separated event for NMI watchdog. Note that on all other
than P4 PMU cpus this event is a simple alias for PERF_COUNT_HW_CPU_CYCLES.

This event is only used by x86 for now so no other archs involved.

hm, there's no explanation exactly why this is needed and what the alternatives are.

This sentence:

Quoted 1 line

+ /* we use that named non-sleeping calls */

does not parse for me.

Thanks,

Ingo

#17 lore raw

Re: [PATCH 4/4] perf, x86: Add PERF_COUNT_HW_NMI_WATCHDOG event

P4 cant move events between counters in compare with architectural event so when nmi-watchdog is used perf top is blocked because it needs same counters but the counters already borrowed for watchdog. as result we need a different event and counters for watchdog.

Ingo, nonsleeping cycles is from intel sdm, so when someone start reading this code in future will find this term in sdm fast. or i could put the reference from sdm itself here, hm?

Quoted 24 lines · Ingo Molnar
Quoted 7 lines · Don Zickus

From: Cyrill Gorcunov <[email protected]>

Due to restriction and specifics of Netburst PMU we need
a separated event for NMI watchdog. Note that on all other
than P4 PMU cpus this event is a simple alias for PERF_COUNT_HW_CPU_CYCLES.

This event is only used by x86 for now so no other archs involved.

hm, there's no explanation exactly why this is needed and what the alternatives are.

This sentence:

Quoted 1 line

+  /* we use that named non-sleeping calls */

does not parse for me.

Thanks,

       Ingo

#18 lore raw

Re: [PATCH 4/4] perf, x86: Add PERF_COUNT_HW_NMI_WATCHDOG event

Quoted 2 lines · Cyrill Gorcunov

we need a different event and counters for watchdog.

Does it count the same thing though? If so we could look at having alternative encodings support (we might need something like that for offcore too).

#19 lore raw

Re: [PATCH 4/4] perf, x86: Add PERF_COUNT_HW_NMI_WATCHDOG event

Quoted 7 lines · Peter Zijlstra
Quoted 2 lines · Cyrill Gorcunov

we need a different event and counters for watchdog.

Does it count the same thing though? If so we could look at having alternative encodings support (we might need something like that for offcore too).

Yes, they count the same thing (well some tech details are different but not much).By using different counters we are allowed to run them simultaneously which makes perf top works again.

Could you elaborate what you have in mind with "alternative encodings" here?

#20 lore raw

Re: [PATCH 4/4] perf, x86: Add PERF_COUNT_HW_NMI_WATCHDOG event

Quoted 9 lines · Cyrill Gorcunov
Quoted 7 lines · Peter Zijlstra
Quoted 2 lines · Cyrill Gorcunov

we need a different event and counters for watchdog.

Does it count the same thing though? If so we could look at having alternative encodings support (we might need something like that for offcore too).

Quoted 6 lines

Yes, they count the same thing (well some tech details are different but not much).By using different counters we are allowed to run them simultaneously which makes perf top works again.

Could you elaborate what you have in mind with "alternative encodings" here?

Right, so the idea is that one event (concept) has two (or more) representations in the config space. And when scheduling the events we find we have a conflict, we simply try the alternative encoding(s).

For example, with the offcore bits, we have two events: r1b7 and r1bb that both have an extra MSR to fill (01A6 and 01A7 resp). Now if you were to write the same value to these MSRs these events would count the exact same thing.

So eg. for counting remote dram hits, you can use: r1b7:20ff or r1bb:20ff, both count the same. So if we want to support a generic event that counts remote dram hits we must pick one. Now if that one is taken for measuring some L3 event, we'll have a conflict and not schedule the thing, even though the other counter might be available.

POWER has something similar and has already implemented this alternative encoding scheme.

#21 lore raw

Re: [PATCH 4/4] perf, x86: Add PERF_COUNT_HW_NMI_WATCHDOG event

Thanks! Looks interesting. Need to think if duch scheme is possible for p4 case.

Quoted 38 lines · Peter Zijlstra
Quoted 9 lines · Cyrill Gorcunov
Quoted 7 lines · Peter Zijlstra
Quoted 2 lines · Cyrill Gorcunov

we need a different event and counters for watchdog.

Does it count the same thing though? If so we could look at having alternative encodings support (we might need something like that for offcore too).

Quoted 6 lines

Yes, they count the same thing (well some tech details are different but not much).By using different counters we are allowed to run them simultaneously which makes perf top works again.

Could you elaborate what you have in mind with "alternative encodings" here?

Right, so the idea is that one event (concept) has two (or more) representations in the config space. And when scheduling the events we find we have a conflict, we simply try the alternative encoding(s).

For example, with the offcore bits, we have two events: r1b7 and r1bb that both have an extra MSR to fill (01A6 and 01A7 resp). Now if you were to write the same value to these MSRs these events would count the exact same thing.

So eg. for counting remote dram hits, you can use: r1b7:20ff or r1bb:20ff, both count the same. So if we want to support a generic event that counts remote dram hits we must pick one. Now if that one is taken for measuring some L3 event, we'll have a conflict and not schedule the thing, even though the other counter might be available.

POWER has something similar and has already implemented this alternative encoding scheme.

#22 lore raw

Re: [PATCH 4/4] perf, x86: Add PERF_COUNT_HW_NMI_WATCHDOG event

In reply to Peter Zijlstra

On 04/22/2011 01:45 PM, Peter Zijlstra wrote:
...

Quoted 5 lines

Right, so the idea is that one event (concept) has two (or more) representations in the config space. And when scheduling the events we find we have a conflict, we simply try the alternative encoding(s).

...

Yeah, Peter, I think it's quite possible to use alternative encoding for p4 as well,
not sure tho if some "generalized" approach for all perf would be applied to p4 but we can make event "aliases" being per-pmu eventually.

So Ingo, drop this patch then ;)

Signature · 1 line
    Cyrill
author
#23 lore raw

Re: [PATCH 4/4] perf, x86: Add PERF_COUNT_HW_NMI_WATCHDOG event

Quoted 7 lines · Cyrill Gorcunov

On 04/22/2011 01:45 PM, Peter Zijlstra wrote:
...

Quoted 5 lines

Right, so the idea is that one event (concept) has two (or more) representations in the config space. And when scheduling the events we find we have a conflict, we simply try the alternative encoding(s).

Quoted 7 lines

...

Yeah, Peter, I think it's quite possible to use alternative encoding for p4 as well,
not sure tho if some "generalized" approach for all perf would be applied to p4 but we can make event "aliases" being per-pmu eventually.

So Ingo, drop this patch then ;)

Eek, when can you have an alternate patch for this Cyril? I just want to make sure this can still eventually find its way into 2.6.40.

Cheers,
Don

#24 lore raw

Re: [PATCH 4/4] perf, x86: Add PERF_COUNT_HW_NMI_WATCHDOG event

Quoted 14 lines · Don Zickus
Quoted 13 lines · Cyrill Gorcunov

On 04/22/2011 01:45 PM, Peter Zijlstra wrote:
...

Quoted 5 lines

Right, so the idea is that one event (concept) has two (or more) representations in the config space. And when scheduling the events we find we have a conflict, we simply try the alternative encoding(s).

...

Yeah, Peter, I think it's quite possible to use alternative encoding for p4 as well,
not sure tho if some "generalized" approach for all perf would be applied to p4 but we can make event "aliases" being per-pmu eventually.

Quoted 7 lines
Quoted 1 line

So Ingo, drop this patch then ;)

Eek, when can you have an alternate patch for this Cyril? I just want to make sure this can still eventually find its way into 2.6.40.

Cheers,
Don

I need kinda aliases for events (or alternative scheme as PeterZ mentions),
Don I'll try to make something tomorrow, ok? With aliases we would not need to even modify sources outside of p4 pmu which is good i think. I've some spare bits in low hw:config bits so this aliases could go there as a start.

Signature · 1 line
    Cyrill