]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
perf pmu: Extract function to get JSON alias map
authorAndi Kleen <ak@linux.intel.com>
Wed, 7 Feb 2018 00:07:00 +0000 (01:07 +0100)
committerStefan Bader <stefan.bader@canonical.com>
Wed, 14 Mar 2018 10:42:22 +0000 (11:42 +0100)
BugLink: https://bugs.launchpad.net/bugs/1747523
Extract the code to get the per cpu JSON alias into a separate function
for reuse. No behavior changes.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/20170831194036.30146-6-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
(cherry picked from commit d77ade9f4199c77c63e2ae382a8c8fbe0582ede2)
Signed-off-by: dann frazier <dann.frazier@canonical.com>
Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
tools/perf/util/pmu.c
tools/perf/util/pmu.h

index 1c4d7b4e4fb5725e9b952ef3b0fc69c5a63c2f26..0cd082c1450dc692065916b292bab148f04427b3 100644 (file)
@@ -540,16 +540,8 @@ char * __weak get_cpuid_str(void)
        return NULL;
 }
 
-/*
- * From the pmu_events_map, find the table of PMU events that corresponds
- * to the current running CPU. Then, add all PMU events from that table
- * as aliases.
- */
-static void pmu_add_cpu_aliases(struct list_head *head, const char *name)
+static char *perf_pmu__getcpuid(void)
 {
-       int i;
-       struct pmu_events_map *map;
-       struct pmu_event *pe;
        char *cpuid;
        static bool printed;
 
@@ -559,22 +551,50 @@ static void pmu_add_cpu_aliases(struct list_head *head, const char *name)
        if (!cpuid)
                cpuid = get_cpuid_str();
        if (!cpuid)
-               return;
+               return NULL;
 
        if (!printed) {
                pr_debug("Using CPUID %s\n", cpuid);
                printed = true;
        }
+       return cpuid;
+}
+
+struct pmu_events_map *perf_pmu__find_map(void)
+{
+       struct pmu_events_map *map;
+       char *cpuid = perf_pmu__getcpuid();
+       int i;
 
        i = 0;
-       while (1) {
+       for (;;) {
                map = &pmu_events_map[i++];
-               if (!map->table)
-                       goto out;
+               if (!map->table) {
+                       map = NULL;
+                       break;
+               }
 
                if (!strcmp(map->cpuid, cpuid))
                        break;
        }
+       free(cpuid);
+       return map;
+}
+
+/*
+ * From the pmu_events_map, find the table of PMU events that corresponds
+ * to the current running CPU. Then, add all PMU events from that table
+ * as aliases.
+ */
+static void pmu_add_cpu_aliases(struct list_head *head, const char *name)
+{
+       int i;
+       struct pmu_events_map *map;
+       struct pmu_event *pe;
+
+       map = perf_pmu__find_map();
+       if (!map)
+               return;
 
        /*
         * Found a matching PMU events table. Create aliases
@@ -599,9 +619,6 @@ static void pmu_add_cpu_aliases(struct list_head *head, const char *name)
                                (char *)pe->metric_expr,
                                (char *)pe->metric_name);
        }
-
-out:
-       free(cpuid);
 }
 
 struct perf_event_attr * __weak
index fe0de0502ce26b66fc2caa94a99ae1325807ab50..7ca675598b43a1d5cda8686969c426edf2db1ce4 100644 (file)
@@ -91,4 +91,6 @@ int perf_pmu__test(void);
 
 struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu);
 
+struct pmu_events_map *perf_pmu__find_map(void);
+
 #endif /* __PMU_H */