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

With cpu_list, perf stat should use event's cpu map.

Different events may have different cpu map. So the same index in cpu
map does not point to the same CPU id. perf_evsel__get_cpumap_index is
introduced to find out the CPU id's index for a given cpu map.

Signed-off-by: Kan Liang <kan.li...@intel.com>
---
 tools/perf/builtin-stat.c |  5 +++--
 tools/perf/util/evsel.h   | 24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index e598e4e..5ae8686 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -165,7 +165,7 @@ static inline void diff_timespec(struct timespec *r, struct 
timespec *a,
 
 static inline struct cpu_map *perf_evsel__cpus(struct perf_evsel *evsel)
 {
-       return (evsel->cpus && !target.cpu_list) ? evsel->cpus : 
evsel_list->cpus;
+       return evsel->cpus ? evsel->cpus : evsel_list->cpus;
 }
 
 static inline int perf_evsel__nr_cpus(struct perf_evsel *evsel)
@@ -302,7 +302,7 @@ static int create_perf_stat_counter(struct perf_evsel 
*evsel)
        attr->inherit = !no_inherit;
 
        if (target__has_cpu(&target))
-               return perf_evsel__open_per_cpu(evsel, perf_evsel__cpus(evsel));
+               return perf_evsel__open_per_cpu(evsel, evsel_list->cpus);
 
        if (!target__has_task(&target) && perf_evsel__is_group_leader(evsel)) {
                attr->disabled = 1;
@@ -1218,6 +1218,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(NULL, cpu2, 
evsel_list->cpus);
                                s2 = aggr_get_id(evsel_list->cpus, cpu2);
                                if (s2 != id)
                                        continue;
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index dcf202a..a633320 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -8,6 +8,7 @@
 #include <linux/types.h>
 #include "xyarray.h"
 #include "symbol.h"
+#include "cpumap.h"
 
 struct perf_counts_values {
        union {
@@ -359,4 +360,27 @@ static inline bool has_branch_callstack(struct perf_evsel 
*evsel)
 {
        return evsel->attr.branch_sample_type & PERF_SAMPLE_BRANCH_CALL_STACK;
 }
+
+static inline int perf_evsel__get_cpumap_index(struct perf_evsel *evsel,
+                                              int cpu,
+                                              struct cpu_map *evlist_cpus)
+{
+       struct cpu_map *cpus;
+       int i;
+
+       if (evlist_cpus == NULL)
+               return -1;
+
+       if (evsel && evsel->cpus)
+               cpus = evsel->cpus;
+       else
+               cpus = evlist_cpus;
+
+       for (i = 0; i < cpus->nr; i++) {
+               if (cpu == cpus->map[i])
+                       return i;
+       }
+       return -1;
+}
+
 #endif /* __PERF_EVSEL_H */
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to