From: Robert Richter <robert.richter@amd.com>
To: Don Zickus <dzickus@redhat.com>
Cc: "x86@kernel.org" <x86@kernel.org>,
Andi Kleen <andi@firstfloor.org>,
Peter Zijlstra <peterz@infradead.org>,
"ying.huang@intel.com" <ying.huang@intel.com>,
LKML <linux-kernel@vger.kernel.org>,
"paulmck@linux.vnet.ibm.com" <paulmck@linux.vnet.ibm.com>,
"avi@redhat.com" <avi@redhat.com>,
"jeremy@goop.org" <jeremy@goop.org>
Subject: Re: [V4][PATCH 4/6] x86, nmi: add in logic to handle multiple events and unknown NMIs
Date: Wed, 14 Sep 2011 18:26:53 +0200 [thread overview]
Message-ID: <20110914162653.GI6063@erda.amd.com> (raw)
In-Reply-To: <1315947509-6429-5-git-send-email-dzickus@redhat.com>
On 13.09.11 16:58:27, Don Zickus wrote:
> @@ -87,6 +87,16 @@ static int notrace __kprobes nmi_handle(unsigned int type, struct pt_regs *regs)
>
> handled += a->handler(type, regs);
>
> + /*
> + * Optimization: only loop once if this is not a
> + * back-to-back NMI. The idea is nothing is dropped
> + * on the first NMI, only on the second of a back-to-back
> + * NMI. No need to waste cycles going through all the
> + * handlers.
> + */
> + if (!b2b && handled)
> + break;
Don, if I am not missing something, this actually does not work
because perfctr NMIs do not re-trigger. Suppose a handler running
before perfctr. It sets 'handled' and the chain is stopped here. To
run through the perfctr handler the NMI must retrigger which it
doesn't.
I tested the above with enclosed patch.
The patch handles the nmi and then stops the chain. You see by the PMI
count that the perfctr nmi is not handled:
Patch applied:
# echo $(($(grep PMI /proc/interrupts | sed -e 's/.*: *//;s/ *Non.*//;s/ */ + /g')))
0
# echo $(($(grep NMI /proc/interrupts | sed -e 's/.*: *//;s/ *Non.*//;s/ */ + /g')))
0
# perf record -e cpu-cycles bash -c 'perl -e "while(1) {}" & sleep 5 ; kill $!'
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.011 MB perf.data (~472 samples) ]
# echo $(($(grep PMI /proc/interrupts | sed -e 's/.*: *//;s/ *Non.*//;s/ */ + /g')))
128
# echo $(($(grep NMI /proc/interrupts | sed -e 's/.*: *//;s/ *Non.*//;s/ */ + /g')))
1387
W/o the patch (tip/perf/core: 51887c8):
# echo $(($(grep NMI /proc/interrupts | sed -e 's/.*: *//;s/ *Non.*//;s/ */ + /g')))
0
# echo $(($(grep PMI /proc/interrupts | sed -e 's/.*: *//;s/ *Non.*//;s/ */ + /g')))
0
# perf record -e cpu-cycles bash -c 'perl -e "while(1) {}" & sleep 5 ; kill $!'
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.194 MB perf.data (~8455 samples) ]
# echo $(($(grep PMI /proc/interrupts | sed -e 's/.*: *//;s/ *Non.*//;s/ */ + /g')))
4918
# echo $(($(grep NMI /proc/interrupts | sed -e 's/.*: *//;s/ *Non.*//;s/ */ + /g')))
4918
So we may not jump out the while loop.
-Robert
> +
> a = next_a;
> }
> rcu_read_unlock();
>From b1d68bf037cfa78f073cf71c296057ff422294f2 Mon Sep 17 00:00:00 2001
From: Robert Richter <robert.richter@amd.com>
Date: Wed, 14 Sep 2011 11:44:49 +0200
Subject: [PATCH] perf_nmi_test
Signed-off-by: Robert Richter <robert.richter@amd.com>
---
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
next prev parent reply other threads:[~2011-09-14 16:27 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-13 20:58 [V4][PATCH 0/6] x86, nmi: new NMI handling routines Don Zickus
2011-09-13 20:58 ` [V4][PATCH 1/6] x86, nmi: split out nmi from traps.c Don Zickus
2011-09-13 20:58 ` [V4][PATCH 2/6] x86, nmi: create new NMI handler routines Don Zickus
2011-09-13 20:58 ` [V4][PATCH 3/6] x86, nmi: wire up NMI handlers to new routines Don Zickus
2011-09-13 22:49 ` Corey Minyard
2011-09-13 20:58 ` [V4][PATCH 4/6] x86, nmi: add in logic to handle multiple events and unknown NMIs Don Zickus
2011-09-14 7:08 ` Avi Kivity
2011-09-14 13:00 ` Don Zickus
2011-09-14 13:22 ` Avi Kivity
2011-09-14 15:03 ` Don Zickus
2011-09-14 12:56 ` Don Zickus
2011-09-14 20:20 ` Robert Richter
2011-09-14 16:26 ` Robert Richter [this message]
2011-09-14 17:58 ` Don Zickus
2011-09-14 20:16 ` Robert Richter
2011-09-14 20:44 ` Don Zickus
2011-09-15 16:55 ` Robert Richter
2011-09-13 20:58 ` [V4][PATCH 5/6] x86, nmi: track NMI usage stats Don Zickus
2011-09-13 20:58 ` [V4][PATCH 6/6] x86, nmi: print out NMI stats in /proc/interrupts Don Zickus
2011-09-15 14:47 ` Don Zickus
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=20110914162653.GI6063@erda.amd.com \
--to=robert.richter@amd.com \
--cc=andi@firstfloor.org \
--cc=avi@redhat.com \
--cc=dzickus@redhat.com \
--cc=jeremy@goop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=x86@kernel.org \
--cc=ying.huang@intel.com \
/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