]> git.baikalelectronics.ru Git - kernel.git/commit
perf stat: Avoid skew when reading events
authorMark Rutland <mark.rutland@arm.com>
Tue, 9 Aug 2016 13:04:29 +0000 (14:04 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 9 Aug 2016 13:48:32 +0000 (10:48 -0300)
commit8ff6ddaa2c89b5572bc03055906478a11b02aabe
tree2541787adfa3a98375ce43c69decc16d84935050
parent99f649cde8422f63e0bf20fe1589e663f36a9efe
perf stat: Avoid skew when reading events

When we don't have a tracee (i.e. we're attaching to a task or CPU),
counters can still be running after our workload finishes, and can still
be running as we read their values. As we read events one-by-one, there
can be arbitrary skew between values of events, even within a group.
This means that ratios within an event group are not reliable.

This skew can be seen if measuring a group of identical events, e.g:

  # perf stat -a -C0 -e '{cycles,cycles}' sleep 1

To avoid this, we must stop groups from counting before we read the
values of any constituent events. This patch adds and makes use of a new
disable_counters() helper, which disables group leaders (and thus each
group as a whole). This mirrors the use of enable_counters() for
starting event groups in the absence of a tracee.

Closing a group leader splits the group, and without a disabled group
leader the newly split events will begin counting. Thus to ensure counts
are reliable we must defer closing group leaders until all counts have
been read. To do so this patch removes the event closing logic from the
read_counters() helper, explicitly closes the events using
perf_evlist__close(), which also aids legibility.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1470747869-3567-1-git-send-email-mark.rutland@arm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-stat.c