[PATCH] perf, x86: Fix spurious 'unknown NMI' messages on Pentium4 systems

From: Don Zickus
Date: Thu Apr 14 2011 - 10:48:48 EST

When using perf on a Pentium4 box, lots of unknown NMIs are
generated. This is the result of a P4 quirk that is subtle. The
P4 generates an NMI when the counter overflows and unlike other
models where the NMI is a one time event, the P4 continues to
assert its NMI until cleared by the OS.

As a side effect to this quirk, the NMI on the apic is masked
off to prevent a stream of NMIs until the overflow flag is
cleared. During the perf re-design, this subtle-ness was
overlooked and the apic was unmasked _before_ the overflow flag
was cleared. As a result, this generated an extra NMI on P4

The fix is trivial: wait until the NMI is properly handled
before un-masking the apic.

Tested-by: Shaun Ruffell <sruffell@xxxxxxxxxx>
Signed-off-by: Don Zickus <dzickus@xxxxxxxxxx>
Cc: Lin Ming <ming.m.lin@xxxxxxxxx>
Cc: Maciej Rutecki <maciej.rutecki@xxxxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Cc: Stephane Eranian <eranian@xxxxxxxxxx>
Cc: Robert Richter <robert.richter@xxxxxxx>
[ Added a comment into code itself as well. ]
Signed-off-by: Cyrill Gorcunov <gorcunov@xxxxxxxxxx>
Link: http://lkml.kernel.org/r/4DA70950.3060102@xxxxxxxxxx
Signed-off-by: Ingo Molnar <mingo@xxxxxxx>
arch/x86/kernel/cpu/perf_event.c | 9 ++++++++-
1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index eed3673a..d3a1902 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -1370,9 +1370,16 @@ perf_event_nmi_handler(struct notifier_block *self,

- apic_write(APIC_LVTPC, APIC_DM_NMI);

handled = x86_pmu.handle_irq(args->regs);
+ /*
+ * Note the unmasking of LVTPC entry must be
+ * done *after* counter oveflow flag is cleared
+ * otherwise it might lead to double NMIs generation.
+ */
+ apic_write(APIC_LVTPC, APIC_DM_NMI);
if (!handled)

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/