Skip to content

Commit

Permalink
perf: Fix running time accounting
Browse files Browse the repository at this point in the history
A recent fix to the shadow timestamp inadvertly broke the running time
accounting.

We must not update the running timestamp if we fail to schedule the
event, the event will not have ran. This can (and did) result in
negative total runtime because the stopped timestamp was before the
running timestamp (we 'started' but never stopped the event -- because
it never really started we didn't have to stop it either).

Reported-and-Tested-by: Vince Weaver <vincent.weaver@maine.edu>
Fixes: 72f669c ("perf: Update shadow timestamp before add event")
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: stable@vger.kernel.org # 4.1
Cc: Shaohua Li <shli@fb.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
  • Loading branch information
Peter Zijlstra authored and Thomas Gleixner committed Jul 27, 2015
1 parent cbfe8fa commit 00a2916
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kernel/events/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1868,8 +1868,6 @@ event_sched_in(struct perf_event *event,

perf_pmu_disable(event->pmu);

event->tstamp_running += tstamp - event->tstamp_stopped;

perf_set_shadow_time(event, ctx, tstamp);

perf_log_itrace_start(event);
Expand All @@ -1881,6 +1879,8 @@ event_sched_in(struct perf_event *event,
goto out;
}

event->tstamp_running += tstamp - event->tstamp_stopped;

if (!is_software_event(event))
cpuctx->active_oncpu++;
if (!ctx->nr_active++)
Expand Down

0 comments on commit 00a2916

Please sign in to comment.