History

perf: Fix running time accounting

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).

Peter Zijlstra committed 11 years ago

Commit 00a29161 parent cbfe8fa1 file · +2 −2Browse files

Showing the changes to kernel (1 of 1 file). Show all

Unified · Split

kernel/events/core.c+2−2
@@ -1868,8 +1868,6 @@ event_sched_in(struct perf_event *event, · 1867 unmodified lines
18681868
18691869 perf_pmu_disable(event->pmu);
18701870
1871− event->tstamp_running += tstamp - event->tstamp_stopped;
1872−
18731871 perf_set_shadow_time(event, ctx, tstamp);
18741872
18751873 perf_log_itrace_start(event);
@@ -1881,6 +1879,8 @@ event_sched_in(struct perf_event *event, · 5 unmodified lines
18811879 goto out;
18821880 }
18831881
1882+ event->tstamp_running += tstamp - event->tstamp_stopped;
1883+
18841884 if (!is_software_event(event))
18851885 cpuctx->active_oncpu++;
18861886 if (!ctx->nr_active++)