File perf-pmu-extract-function-to-get-json-alias-map.patch of Package perf
120
1
From: Andi Kleen <ak@linux.intel.com>
2
Date: Thu, 31 Aug 2017 12:40:30 -0700
3
Subject: perf pmu: Extract function to get JSON alias map
4
Git-commit: d77ade9f4199c77c63e2ae382a8c8fbe0582ede2
5
Patch-mainline: v4.15-rc1
6
References: bsc#1081960
7
8
Extract the code to get the per cpu JSON alias into a separate function
9
for reuse. No behavior changes.
10
11
Signed-off-by: Andi Kleen <ak@linux.intel.com>
12
Acked-by: Jiri Olsa <jolsa@kernel.org>
13
Link: http://lkml.kernel.org/r/20170831194036.30146-6-andi@firstfloor.org
14
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
15
Signed-off-by: Tony Jones <tonyj@suse.de>
16
---
17
tools/perf/util/pmu.c | 49 +++++++++++++++++++++++++++++++++----------------
18
tools/perf/util/pmu.h | 2 ++
19
2 files changed, 35 insertions(+), 16 deletions(-)
20
21
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
22
index ac16a9db1fb5..ed25d7f88731 100644
23
--- a/tools/perf/util/pmu.c
24
+++ b/tools/perf/util/pmu.c
25
26
return NULL;
27
}
28
29
-/*
30
- * From the pmu_events_map, find the table of PMU events that corresponds
31
- * to the current running CPU. Then, add all PMU events from that table
32
- * as aliases.
33
- */
34
-static void pmu_add_cpu_aliases(struct list_head *head, const char *name)
35
+static char *perf_pmu__getcpuid(void)
36
{
37
- int i;
38
- struct pmu_events_map *map;
39
- struct pmu_event *pe;
40
char *cpuid;
41
static bool printed;
42
43
44
if (!cpuid)
45
cpuid = get_cpuid_str();
46
if (!cpuid)
47
- return;
48
+ return NULL;
49
50
if (!printed) {
51
pr_debug("Using CPUID %s\n", cpuid);
52
printed = true;
53
}
54
+ return cpuid;
55
+}
56
+
57
+struct pmu_events_map *perf_pmu__find_map(void)
58
+{
59
+ struct pmu_events_map *map;
60
+ char *cpuid = perf_pmu__getcpuid();
61
+ int i;
62
63
i = 0;
64
- while (1) {
65
+ for (;;) {
66
map = &pmu_events_map[i++];
67
- if (!map->table)
68
- goto out;
69
+ if (!map->table) {
70
+ map = NULL;
71
+ break;
72
+ }
73
74
if (!strcmp(map->cpuid, cpuid))
75
break;
76
}
77
+ free(cpuid);
78
+ return map;
79
+}
80
+
81
+/*
82
+ * From the pmu_events_map, find the table of PMU events that corresponds
83
+ * to the current running CPU. Then, add all PMU events from that table
84
+ * as aliases.
85
+ */
86
+static void pmu_add_cpu_aliases(struct list_head *head, const char *name)
87
+{
88
+ int i;
89
+ struct pmu_events_map *map;
90
+ struct pmu_event *pe;
91
+
92
+ map = perf_pmu__find_map();
93
+ if (!map)
94
+ return;
95
96
/*
97
* Found a matching PMU events table. Create aliases
98
99
(char *)pe->metric_expr,
100
(char *)pe->metric_name);
101
}
102
-
103
-out:
104
- free(cpuid);
105
}
106
107
struct perf_event_attr * __weak
108
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
109
index 389e9729331f..060f6abba8ed 100644
110
--- a/tools/perf/util/pmu.h
111
+++ b/tools/perf/util/pmu.h
112
113
114
struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu);
115
116
+struct pmu_events_map *perf_pmu__find_map(void);
117
+
118
#endif /* __PMU_H */
119
120