Commit db49a717 authored by Stephane Eranian's avatar Stephane Eranian Committed by Arnaldo Carvalho de Melo

perf stat: Fix bug in handling events in error state

(This is a patch has been sitting in the Intel CQM/CMT driver series for
 a while, despite not depend on it. Sending it now independently since
 the series is being discarded.)

When an event is in error state, read() returns 0 instead of sizeof()
buffer. In certain modes, such as interval printing, ignoring the 0
return value may cause bogus count deltas to be computed and thus
invalid results printed.

This patch fixes this problem by modifying read_counters() to mark the
event as not scaled (scaled = -1) to force the printout routine to show
<NOT COUNTED>.
Signed-off-by: default avatarStephane Eranian <eranian@google.com>
Reviewed-by: default avatarDavid Carrillo-Cisneros <davidcc@google.com>
Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Paul Turner <pjt@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/20170412182301.44406-1-davidcc@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 7be6b316
...@@ -312,8 +312,12 @@ static int read_counter(struct perf_evsel *counter) ...@@ -312,8 +312,12 @@ static int read_counter(struct perf_evsel *counter)
struct perf_counts_values *count; struct perf_counts_values *count;
count = perf_counts(counter->counts, cpu, thread); count = perf_counts(counter->counts, cpu, thread);
if (perf_evsel__read(counter, cpu, thread, count)) if (perf_evsel__read(counter, cpu, thread, count)) {
counter->counts->scaled = -1;
perf_counts(counter->counts, cpu, thread)->ena = 0;
perf_counts(counter->counts, cpu, thread)->run = 0;
return -1; return -1;
}
if (STAT_RECORD) { if (STAT_RECORD) {
if (perf_evsel__write_stat_event(counter, cpu, thread, count)) { if (perf_evsel__write_stat_event(counter, cpu, thread, count)) {
...@@ -338,12 +342,14 @@ static int read_counter(struct perf_evsel *counter) ...@@ -338,12 +342,14 @@ static int read_counter(struct perf_evsel *counter)
static void read_counters(void) static void read_counters(void)
{ {
struct perf_evsel *counter; struct perf_evsel *counter;
int ret;
evlist__for_each_entry(evsel_list, counter) { evlist__for_each_entry(evsel_list, counter) {
if (read_counter(counter)) ret = read_counter(counter);
if (ret)
pr_debug("failed to read counter %s\n", counter->name); pr_debug("failed to read counter %s\n", counter->name);
if (perf_stat_process_counter(&stat_config, counter)) if (ret == 0 && perf_stat_process_counter(&stat_config, counter))
pr_warning("failed to process counter %s\n", counter->name); pr_warning("failed to process counter %s\n", counter->name);
} }
} }
......
...@@ -1239,7 +1239,7 @@ int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread, ...@@ -1239,7 +1239,7 @@ int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread,
if (FD(evsel, cpu, thread) < 0) if (FD(evsel, cpu, thread) < 0)
return -EINVAL; return -EINVAL;
if (readn(FD(evsel, cpu, thread), count, sizeof(*count)) < 0) if (readn(FD(evsel, cpu, thread), count, sizeof(*count)) <= 0)
return -errno; return -errno;
return 0; return 0;
...@@ -1257,7 +1257,7 @@ int __perf_evsel__read_on_cpu(struct perf_evsel *evsel, ...@@ -1257,7 +1257,7 @@ int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
if (evsel->counts == NULL && perf_evsel__alloc_counts(evsel, cpu + 1, thread + 1) < 0) if (evsel->counts == NULL && perf_evsel__alloc_counts(evsel, cpu + 1, thread + 1) < 0)
return -ENOMEM; return -ENOMEM;
if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) < 0) if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) <= 0)
return -errno; return -errno;
perf_evsel__compute_deltas(evsel, cpu, thread, &count); perf_evsel__compute_deltas(evsel, cpu, thread, &count);
......
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