linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] perf,tools: get correct cpu id for print_aggr
@ 2015-06-29 19:55 kan.liang
  2015-06-29 19:55 ` [PATCH 2/2] perf,tools: check and re-organize evsel cpu maps kan.liang
  2015-06-30  6:46 ` [PATCH 1/2] perf,tools: get correct cpu id for print_aggr Jiri Olsa
  0 siblings, 2 replies; 12+ messages in thread
From: kan.liang @ 2015-06-29 19:55 UTC (permalink / raw)
  To: acme, jolsa
  Cc: ak, namhyung, eranian, adrian.hunter, dsahern, a.p.zijlstra,
	mingo, linux-kernel, Kan Liang

From: Kan Liang <kan.liang@intel.com>

print_aggr fails to print per-core/per-socket statistics after commit
b7f0c203586b ("perf evlist: Propagate cpu maps to evsels in an evlist"),
if events have differnt cpus. Because in print_aggr, aggr_get_id needs
index (not cpu id) to find core/pkg id.
This patch introduced perf_evsel__get_cpumap_index to get the index by
cpu id for a given event. The index can be used to find correct cpu id
for print_aggr.

Here is an example.
Counting events cycles,uncore_imc_0/cas_count_read/. (Uncore event has
cpumask 0,18)

"perf stat -e cycles,uncore_imc_0/cas_count_read/ -C0,18 --per-core
sleep 2"

Without this patch, it failes to get CPU 18 result.
 Performance counter stats for 'CPU(s) 0,18':

S0-C0           1            7526851      cycles
S0-C0           1               1.05 MiB  uncore_imc_0/cas_count_read/
S1-C0           0      <not counted>      cycles
S1-C0           0      <not counted> MiB  uncore_imc_0/cas_count_read/

With this patch, it can get both CPU0 and CPU18 result.
 Performance counter stats for 'CPU(s) 0,18':

S0-C0           1            6327768      cycles
S0-C0           1               0.47 MiB  uncore_imc_0/cas_count_read/
S1-C0           1             330228      cycles
S1-C0           1               0.29 MiB  uncore_imc_0/cas_count_read/

Signed-off-by: Kan Liang <kan.liang@intel.com>
---
 tools/perf/builtin-stat.c |  1 +
 tools/perf/util/cpumap.c  |  4 ++--
 tools/perf/util/evsel.c   | 14 ++++++++++++++
 tools/perf/util/evsel.h   |  2 ++
 4 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 37e301a..a3ea735 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -708,6 +708,7 @@ static void print_aggr(char *prefix)
 			nr = 0;
 			for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
 				cpu2 = perf_evsel__cpus(counter)->map[cpu];
+				cpu2 = perf_evsel__get_cpumap_index(cpu2, evsel_list->cpus);
 				s2 = aggr_get_id(evsel_list->cpus, cpu2);
 				if (s2 != id)
 					continue;
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 3667e21..34843e5 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -232,7 +232,7 @@ int cpu_map__get_socket(struct cpu_map *map, int idx)
 	char path[PATH_MAX];
 	int cpu, ret;
 
-	if (idx > map->nr)
+	if ((idx > map->nr) || (idx < 0))
 		return -1;
 
 	cpu = map->map[idx];
@@ -296,7 +296,7 @@ int cpu_map__get_core(struct cpu_map *map, int idx)
 	char path[PATH_MAX];
 	int cpu, ret, s;
 
-	if (idx > map->nr)
+	if ((idx > map->nr) || (idx < 0))
 		return -1;
 
 	cpu = map->map[idx];
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 2936b30..32094d3 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -974,6 +974,20 @@ int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
 	return 0;
 }
 
+int perf_evsel__get_cpumap_index(int cpu, struct cpu_map *evsel_cpus)
+{
+	int i;
+
+	if (evsel_cpus == NULL)
+		return -1;
+
+	for (i = 0; i < evsel_cpus->nr; i++) {
+		if (cpu == evsel_cpus->map[i])
+			return i;
+	}
+	return -1;
+}
+
 static int get_group_fd(struct perf_evsel *evsel, int cpu, int thread)
 {
 	struct perf_evsel *leader = evsel->leader;
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 4a7ed56..05e68a0 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -355,4 +355,6 @@ typedef int (*attr__fprintf_f)(FILE *, const char *, const char *, void *);
 int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,
 			     attr__fprintf_f attr__fprintf, void *priv);
 
+int perf_evsel__get_cpumap_index(int cpu, struct cpu_map *evsel_cpus);
+
 #endif /* __PERF_EVSEL_H */
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-07-02 16:10 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-29 19:55 [PATCH 1/2] perf,tools: get correct cpu id for print_aggr kan.liang
2015-06-29 19:55 ` [PATCH 2/2] perf,tools: check and re-organize evsel cpu maps kan.liang
2015-06-30 12:14   ` Jiri Olsa
2015-06-30 13:42     ` Liang, Kan
2015-06-30 13:54       ` Jiri Olsa
2015-06-30 14:42         ` acme
2015-07-02 16:08           ` Jiri Olsa
2015-06-30 15:52   ` Stephane Eranian
2015-06-30 16:45     ` Liang, Kan
2015-07-02 16:10       ` Jiri Olsa
2015-06-30  6:46 ` [PATCH 1/2] perf,tools: get correct cpu id for print_aggr Jiri Olsa
2015-06-30 13:24   ` Liang, Kan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).