Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 147280
b: refs/heads/master
c: 96f6d44
h: refs/heads/master
v: v3
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Apr 6, 2009
1 parent 9af708b commit a3c1f94
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: f4a2deb4860497f4332cf6a1acddab3dd628ddf0
refs/heads/master: 96f6d4444302bb2ea2cf409529eef816462f6ce0
7 changes: 7 additions & 0 deletions trunk/include/linux/perf_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ struct perf_cpu_context {
int active_oncpu;
int max_pertask;
int exclusive;

/*
* Recursion avoidance:
*
* task, softirq, irq, nmi context
*/
int recursion[4];
};

/*
Expand Down
26 changes: 26 additions & 0 deletions trunk/kernel/perf_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -1532,17 +1533,42 @@ 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) {
perf_swcounter_ctx_event(cpuctx->task_ctx, type, event,
nr, nmi, regs);
}

barrier();
(*recursion)--;

out:
put_cpu_var(perf_cpu_context);
}

Expand Down

0 comments on commit a3c1f94

Please sign in to comment.