[PATCH] perf_nmi_test

From: Robert Richter
Date: Wed Sep 14 2011 - 05:44:49 EST


Signed-off-by: Robert Richter <robert.richter@xxxxxxx>
---
arch/x86/kernel/cpu/perf_event.c | 45 ++++++++++++++++++++++++++++++++++++++
1 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index 594d425..2255221 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -31,6 +31,7 @@
#include <asm/compat.h>
#include <asm/smp.h>
#include <asm/alternative.h>
+#include <asm/hardirq.h>

#if 0
#undef wrmsrl
@@ -43,6 +44,8 @@ do { \
} while (0)
#endif

+#define irq_stats(x) (&per_cpu(irq_stat, x))
+
/*
* | NHM/WSM | SNB |
* register -------------------------------
@@ -1383,6 +1386,7 @@ perf_event_nmi_handler(struct notifier_block *self,
struct die_args *args = __args;
unsigned int this_nmi;
int handled;
+ int cpu;

if (!atomic_read(&active_events))
return NOTIFY_DONE;
@@ -1408,6 +1412,9 @@ perf_event_nmi_handler(struct notifier_block *self,
}

handled = x86_pmu.handle_irq(args->regs);
+ cpu = smp_processor_id();
+ trace_printk("perf: NMI: %d, PMI: %d, handled: %d\n", irq_stats(cpu)->__nmi_count,
+ irq_stats(cpu)->apic_perf_irqs, handled);
if (!handled)
return NOTIFY_DONE;

@@ -1961,3 +1968,41 @@ unsigned long perf_misc_flags(struct pt_regs *regs)

return misc;
}
+
+static DEFINE_PER_CPU(unsigned long, save_rip);
+
+static int __kprobes perf_test_nmi_handler(struct notifier_block *self,
+ unsigned long cmd, void *__args)
+{
+ struct die_args *args = __args;
+ bool b2b = false;
+ int cpu = smp_processor_id();
+
+ if (cmd != DIE_NMI)
+ return NOTIFY_DONE;
+
+ if (args->regs->ip == __this_cpu_read(save_rip))
+ b2b = true;
+
+ __this_cpu_write(save_rip, args->regs->ip);
+
+ trace_printk("skip: NMI: %d, PMI: %d, b2b: %d\n", irq_stats(cpu)->__nmi_count,
+ irq_stats(cpu)->apic_perf_irqs, b2b);
+
+ if (!b2b)
+ return NOTIFY_STOP;
+
+ return NOTIFY_DONE;
+}
+
+static __read_mostly struct notifier_block perf_test_nmi_notifier = {
+ .notifier_call = perf_test_nmi_handler,
+ .priority = NMI_LOCAL_HIGH_PRIOR,
+};
+
+static __init int perf_nmi_test_init(void)
+{
+ return register_die_notifier(&perf_test_nmi_notifier);
+}
+
+device_initcall(perf_nmi_test_init);
--
1.7.6.1



--
Advanced Micro Devices, Inc.
Operating System Research Center

--
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/