Commit bcfc2602 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

perf_counter: Fix swcounter context invariance

perf_swcounter_is_counting() uses a lock, which means we cannot
use swcounters from NMI or when holding that particular lock,
this is unintended.

The below removes the lock, this opens up race window, but not
worse than the swcounters already experience due to RCU
traversal of the context in perf_swcounter_ctx_event().

This also fixes the hard lockups while opening a lockdep
tracepoint counter.
Signed-off-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: stephane eranian <eranian@googlemail.com>
Cc: Corey J Ashford <cjashfor@us.ibm.com>
LKML-Reference: <1250149915.10001.66.camel@twins>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 8fd101f2
...@@ -3444,40 +3444,32 @@ static void perf_swcounter_add(struct perf_counter *counter, u64 nr, ...@@ -3444,40 +3444,32 @@ static void perf_swcounter_add(struct perf_counter *counter, u64 nr,
static int perf_swcounter_is_counting(struct perf_counter *counter) static int perf_swcounter_is_counting(struct perf_counter *counter)
{ {
struct perf_counter_context *ctx; /*
unsigned long flags; * The counter is active, we're good!
int count; */
if (counter->state == PERF_COUNTER_STATE_ACTIVE) if (counter->state == PERF_COUNTER_STATE_ACTIVE)
return 1; return 1;
/*
* The counter is off/error, not counting.
*/
if (counter->state != PERF_COUNTER_STATE_INACTIVE) if (counter->state != PERF_COUNTER_STATE_INACTIVE)
return 0; return 0;
/* /*
* If the counter is inactive, it could be just because * The counter is inactive, if the context is active
* its task is scheduled out, or because it's in a group * we're part of a group that didn't make it on the 'pmu',
* which could not go on the PMU. We want to count in * not counting.
* the first case but not the second. If the context is
* currently active then an inactive software counter must
* be the second case. If it's not currently active then
* we need to know whether the counter was active when the
* context was last active, which we can determine by
* comparing counter->tstamp_stopped with ctx->time.
*
* We are within an RCU read-side critical section,
* which protects the existence of *ctx.
*/ */
ctx = counter->ctx; if (counter->ctx->is_active)
spin_lock_irqsave(&ctx->lock, flags); return 0;
count = 1;
/* Re-check state now we have the lock */ /*
if (counter->state < PERF_COUNTER_STATE_INACTIVE || * We're inactive and the context is too, this means the
counter->ctx->is_active || * task is scheduled out, we're counting events that happen
counter->tstamp_stopped < ctx->time) * to us, like migration events.
count = 0; */
spin_unlock_irqrestore(&ctx->lock, flags); return 1;
return count;
} }
static int perf_swcounter_match(struct perf_counter *counter, static int perf_swcounter_match(struct perf_counter *counter,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment