Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1623298

[PATCH 2/7] perf stat: Fix bug in handling events in error state

From Arnaldo Carvalho de Melo <acme@kernel.org>
Newsgroups linux.kernel
Subject [PATCH 2/7] perf stat: Fix bug in handling events in error state
Date 2017-04-13 21:40 +0200
Message-ID <tvSL1-7wP-31@gated-at.bofh.it> (permalink)
References <tvSKZ-7wP-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Stephane Eranian <eranian@google.com>

(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: Stephane Eranian <eranian@google.com>
Reviewed-by: David Carrillo-Cisneros <davidcc@google.com>
Acked-by: Jiri 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.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-stat.c | 12 +++++++++---
 tools/perf/util/evsel.c   |  4 ++--
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 868e086a6b59..610225b6326e 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -312,8 +312,12 @@ static int read_counter(struct perf_evsel *counter)
 			struct perf_counts_values *count;
 
 			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;
+			}
 
 			if (STAT_RECORD) {
 				if (perf_evsel__write_stat_event(counter, cpu, thread, count)) {
@@ -338,12 +342,14 @@ static int read_counter(struct perf_evsel *counter)
 static void read_counters(void)
 {
 	struct perf_evsel *counter;
+	int ret;
 
 	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);
 
-		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);
 	}
 }
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 8f5d86bd3501..3779b9f3f134 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1239,7 +1239,7 @@ int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread,
 	if (FD(evsel, cpu, thread) < 0)
 		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 0;
@@ -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)
 		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;
 
 	perf_evsel__compute_deltas(evsel, cpu, thread, &count);
-- 
2.9.3

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[GIT PULL 0/7] perf/core improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-04-13 21:40 +0200
  [PATCH 6/7] perf util: Hint missing file when tool tips fail to load Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-04-13 21:40 +0200
  [PATCH 3/7] perf trace: Add usage of --no-syscalls in man page Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-04-13 21:40 +0200
  [PATCH 5/7] tools build: Fix feature detection redefinion of build flags Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-04-13 21:40 +0200
  [PATCH 1/7] perf tools: Pass PYTHON config to feature detection Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-04-13 21:40 +0200
  [PATCH 4/7] perf tools: Disable JVMTI if no ELF support available Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-04-13 21:40 +0200
  [PATCH 2/7] perf stat: Fix bug in handling events in error state Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-04-13 21:40 +0200
  Re: [GIT PULL 0/7] perf/core improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-04-14 18:10 +0200
    Re: [GIT PULL 0/7] perf/core improvements and fixes Ingo Molnar <mingo@kernel.org> - 2017-04-17 10:20 +0200

csiph-web