Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

Reported-and-Tested-by: Vince Weaver <vincent.weaver@maine.edu>
Fixes: 72f669c0086f ("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>

authored by

Peter Zijlstra and committed by
Thomas Gleixner
00a2916f cbfe8fa6

+2 -2
+2 -2
kernel/events/core.c
··· 1868 1868 1869 1869 perf_pmu_disable(event->pmu); 1870 1870 1871 - event->tstamp_running += tstamp - event->tstamp_stopped; 1872 - 1873 1871 perf_set_shadow_time(event, ctx, tstamp); 1874 1872 1875 1873 perf_log_itrace_start(event); ··· 1878 1880 ret = -EAGAIN; 1879 1881 goto out; 1880 1882 } 1883 + 1884 + event->tstamp_running += tstamp - event->tstamp_stopped; 1881 1885 1882 1886 if (!is_software_event(event)) 1883 1887 cpuctx->active_oncpu++;