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

perf_counter: fix NMI race in task clock

We should not be updating ctx->time from NMI context, work around that.
Signed-off-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
LKML-Reference: <20090408130408.681326666@chello.nl>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 7333a800
...@@ -319,8 +319,6 @@ static void __perf_counter_disable(void *info) ...@@ -319,8 +319,6 @@ static void __perf_counter_disable(void *info)
spin_lock_irqsave(&ctx->lock, flags); spin_lock_irqsave(&ctx->lock, flags);
update_context_time(ctx);
/* /*
* If the counter is on, turn it off. * If the counter is on, turn it off.
* If it is in error state, leave it in error state. * If it is in error state, leave it in error state.
...@@ -2335,13 +2333,11 @@ static const struct hw_perf_counter_ops perf_ops_cpu_clock = { ...@@ -2335,13 +2333,11 @@ static const struct hw_perf_counter_ops perf_ops_cpu_clock = {
* Software counter: task time clock * Software counter: task time clock
*/ */
static void task_clock_perf_counter_update(struct perf_counter *counter) static void task_clock_perf_counter_update(struct perf_counter *counter, u64 now)
{ {
u64 prev, now; u64 prev;
s64 delta; s64 delta;
now = counter->ctx->time;
prev = atomic64_xchg(&counter->hw.prev_count, now); prev = atomic64_xchg(&counter->hw.prev_count, now);
delta = now - prev; delta = now - prev;
atomic64_add(delta, &counter->count); atomic64_add(delta, &counter->count);
...@@ -2369,13 +2365,24 @@ static int task_clock_perf_counter_enable(struct perf_counter *counter) ...@@ -2369,13 +2365,24 @@ static int task_clock_perf_counter_enable(struct perf_counter *counter)
static void task_clock_perf_counter_disable(struct perf_counter *counter) static void task_clock_perf_counter_disable(struct perf_counter *counter)
{ {
hrtimer_cancel(&counter->hw.hrtimer); hrtimer_cancel(&counter->hw.hrtimer);
task_clock_perf_counter_update(counter); task_clock_perf_counter_update(counter, counter->ctx->time);
} }
static void task_clock_perf_counter_read(struct perf_counter *counter) static void task_clock_perf_counter_read(struct perf_counter *counter)
{ {
u64 time;
if (!in_nmi()) {
update_context_time(counter->ctx); update_context_time(counter->ctx);
task_clock_perf_counter_update(counter); time = counter->ctx->time;
} else {
u64 now = perf_clock();
u64 delta = now - counter->ctx->timestamp;
time = counter->ctx->time + delta;
}
task_clock_perf_counter_update(counter, time);
} }
static const struct hw_perf_counter_ops perf_ops_task_clock = { static const struct hw_perf_counter_ops perf_ops_task_clock = {
......
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