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

perf: Provide better condition for event rotation

Try to avoid useless rotation and PMU disables.

[ Could be improved by keeping a nr_runnable count to better account
  for the < PERF_STAT_INACTIVE counters ]
Signed-off-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: paulus@samba.org
Cc: eranian@google.com
Cc: robert.richter@amd.com
Cc: fweisbec@gmail.com
LKML-Reference: <new-submission>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent f3d46b2e
...@@ -1524,12 +1524,15 @@ static void perf_ctx_adjust_freq(struct perf_event_context *ctx) ...@@ -1524,12 +1524,15 @@ static void perf_ctx_adjust_freq(struct perf_event_context *ctx)
*/ */
if (interrupts == MAX_INTERRUPTS) { if (interrupts == MAX_INTERRUPTS) {
perf_log_throttle(event, 1); perf_log_throttle(event, 1);
perf_disable();
event->pmu->unthrottle(event); event->pmu->unthrottle(event);
perf_enable();
} }
if (!event->attr.freq || !event->attr.sample_freq) if (!event->attr.freq || !event->attr.sample_freq)
continue; continue;
perf_disable();
event->pmu->read(event); event->pmu->read(event);
now = atomic64_read(&event->count); now = atomic64_read(&event->count);
delta = now - hwc->freq_count_stamp; delta = now - hwc->freq_count_stamp;
...@@ -1537,6 +1540,7 @@ static void perf_ctx_adjust_freq(struct perf_event_context *ctx) ...@@ -1537,6 +1540,7 @@ static void perf_ctx_adjust_freq(struct perf_event_context *ctx)
if (delta > 0) if (delta > 0)
perf_adjust_period(event, TICK_NSEC, delta); perf_adjust_period(event, TICK_NSEC, delta);
perf_enable();
} }
raw_spin_unlock(&ctx->lock); raw_spin_unlock(&ctx->lock);
} }
...@@ -1546,9 +1550,6 @@ static void perf_ctx_adjust_freq(struct perf_event_context *ctx) ...@@ -1546,9 +1550,6 @@ static void perf_ctx_adjust_freq(struct perf_event_context *ctx)
*/ */
static void rotate_ctx(struct perf_event_context *ctx) static void rotate_ctx(struct perf_event_context *ctx)
{ {
if (!ctx->nr_events)
return;
raw_spin_lock(&ctx->lock); raw_spin_lock(&ctx->lock);
/* Rotate the first entry last of non-pinned groups */ /* Rotate the first entry last of non-pinned groups */
...@@ -1561,19 +1562,28 @@ void perf_event_task_tick(struct task_struct *curr) ...@@ -1561,19 +1562,28 @@ void perf_event_task_tick(struct task_struct *curr)
{ {
struct perf_cpu_context *cpuctx; struct perf_cpu_context *cpuctx;
struct perf_event_context *ctx; struct perf_event_context *ctx;
int rotate = 0;
if (!atomic_read(&nr_events)) if (!atomic_read(&nr_events))
return; return;
cpuctx = &__get_cpu_var(perf_cpu_context); cpuctx = &__get_cpu_var(perf_cpu_context);
ctx = curr->perf_event_ctxp; if (cpuctx->ctx.nr_events &&
cpuctx->ctx.nr_events != cpuctx->ctx.nr_active)
rotate = 1;
perf_disable(); ctx = curr->perf_event_ctxp;
if (ctx && ctx->nr_events && ctx->nr_events != ctx->nr_active)
rotate = 1;
perf_ctx_adjust_freq(&cpuctx->ctx); perf_ctx_adjust_freq(&cpuctx->ctx);
if (ctx) if (ctx)
perf_ctx_adjust_freq(ctx); perf_ctx_adjust_freq(ctx);
if (!rotate)
return;
perf_disable();
cpu_ctx_sched_out(cpuctx, EVENT_FLEXIBLE); cpu_ctx_sched_out(cpuctx, EVENT_FLEXIBLE);
if (ctx) if (ctx)
task_ctx_sched_out(ctx, EVENT_FLEXIBLE); task_ctx_sched_out(ctx, EVENT_FLEXIBLE);
...@@ -1585,7 +1595,6 @@ void perf_event_task_tick(struct task_struct *curr) ...@@ -1585,7 +1595,6 @@ void perf_event_task_tick(struct task_struct *curr)
cpu_ctx_sched_in(cpuctx, EVENT_FLEXIBLE); cpu_ctx_sched_in(cpuctx, EVENT_FLEXIBLE);
if (ctx) if (ctx)
task_ctx_sched_in(curr, EVENT_FLEXIBLE); task_ctx_sched_in(curr, EVENT_FLEXIBLE);
perf_enable(); perf_enable();
} }
......
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