summaryrefslogtreecommitdiffstats
path: root/kernel/perf_counter.c
diff options
context:
space:
mode:
authorPeter Zijlstra2009-03-23 18:22:07 +0100
committerIngo Molnar2009-04-06 09:30:25 +0200
commit96f6d4444302bb2ea2cf409529eef816462f6ce0 (patch)
tree34ae6944b4a8e6db89c50dba5a3a8b9da3315122 /kernel/perf_counter.c
parentperf_counter: remove the event config bitfields (diff)
downloadkernel-qcow2-linux-96f6d4444302bb2ea2cf409529eef816462f6ce0.tar.gz
kernel-qcow2-linux-96f6d4444302bb2ea2cf409529eef816462f6ce0.tar.xz
kernel-qcow2-linux-96f6d4444302bb2ea2cf409529eef816462f6ce0.zip
perf_counter: avoid recursion
Tracepoint events like lock_acquire and software counters like pagefaults can recurse into the perf counter code again, avoid that. Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> Orig-LKML-Reference: <20090323172417.152096433@chello.nl> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/perf_counter.c')
-rw-r--r--kernel/perf_counter.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index ca14fc41ccdf..ce34bff07bda 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -23,6 +23,7 @@
#include <linux/mm.h>
#include <linux/vmstat.h>
#include <linux/rculist.h>
+#include <linux/hardirq.h>
#include <asm/irq_regs.h>
@@ -1532,10 +1533,31 @@ static void perf_swcounter_ctx_event(struct perf_counter_context *ctx,
rcu_read_unlock();
}
+static int *perf_swcounter_recursion_context(struct perf_cpu_context *cpuctx)
+{
+ if (in_nmi())
+ return &cpuctx->recursion[3];
+
+ if (in_irq())
+ return &cpuctx->recursion[2];
+
+ if (in_softirq())
+ return &cpuctx->recursion[1];
+
+ return &cpuctx->recursion[0];
+}
+
static void __perf_swcounter_event(enum perf_event_types type, u32 event,
u64 nr, int nmi, struct pt_regs *regs)
{
struct perf_cpu_context *cpuctx = &get_cpu_var(perf_cpu_context);
+ int *recursion = perf_swcounter_recursion_context(cpuctx);
+
+ if (*recursion)
+ goto out;
+
+ (*recursion)++;
+ barrier();
perf_swcounter_ctx_event(&cpuctx->ctx, type, event, nr, nmi, regs);
if (cpuctx->task_ctx) {
@@ -1543,6 +1565,10 @@ static void __perf_swcounter_event(enum perf_event_types type, u32 event,
nr, nmi, regs);
}
+ barrier();
+ (*recursion)--;
+
+out:
put_cpu_var(perf_cpu_context);
}