]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
perf pmu: Add helper function is_pmu_core to detect PMU CORE devices
authorGanapatrao Kulkarni <ganapatrao.kulkarni@cavium.com>
Wed, 7 Feb 2018 00:07:00 +0000 (01:07 +0100)
committerStefan Bader <stefan.bader@canonical.com>
Wed, 14 Mar 2018 10:42:24 +0000 (11:42 +0100)
BugLink: https://bugs.launchpad.net/bugs/1747523
On some platforms, PMU core devices sysfs name is not cpu.
Adding function is_pmu_core to detect PMU core devices using
core device specific hints in sysfs.

For arm64 platforms, all core devices have file "cpus" in sysfs.

Signed-off-by: Ganapatrao Kulkarni <ganapatrao.kulkarni@cavium.com>
Tested-by: Shaokun Zhang <zhangshaokun@hisilicon.com>
Tested-by: Jin Yao <yao.jin@linux.intel.com>
Acked-by: Will Deacon <will.deacon@arm.com>
Link: https://lkml.kernel.org/n/tip-y1woxt1k2pqqwpprhonnft2s@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
(cherry picked from commit 14b22ae028de56cca980171db625d1e9925c8fba)
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

index 6dbec11b4effe4e25acf7a0433a92872bf4f6db0..3fb59dbf68ef0d17a33a45acba385fb523e40272 100644 (file)
@@ -529,6 +529,34 @@ static bool pmu_is_uncore(const char *name)
        return !!cpus;
 }
 
+/*
+ *  PMU CORE devices have different name other than cpu in sysfs on some
+ *  platforms. looking for possible sysfs files to identify as core device.
+ */
+static int is_pmu_core(const char *name)
+{
+       struct stat st;
+       char path[PATH_MAX];
+       const char *sysfs = sysfs__mountpoint();
+
+       if (!sysfs)
+               return 0;
+
+       /* Look for cpu sysfs (x86 and others) */
+       scnprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu", sysfs);
+       if ((stat(path, &st) == 0) &&
+                       (strncmp(name, "cpu", strlen("cpu")) == 0))
+               return 1;
+
+       /* Look for cpu sysfs (specific to arm) */
+       scnprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/cpus",
+                               sysfs, name);
+       if (stat(path, &st) == 0)
+               return 1;
+
+       return 0;
+}
+
 /*
  * Return the CPU id as a raw string.
  *
@@ -602,15 +630,18 @@ static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu)
         */
        i = 0;
        while (1) {
-               const char *pname;
 
                pe = &map->table[i++];
                if (!pe->name)
                        break;
 
-               pname = pe->pmu ? pe->pmu : "cpu";
-               if (strncmp(pname, name, strlen(pname)))
-                       continue;
+               if (!is_pmu_core(name)) {
+                       /* check for uncore devices */
+                       if (pe->pmu == NULL)
+                               continue;
+                       if (strncmp(pe->pmu, name, strlen(pe->pmu)))
+                               continue;
+               }
 
                /* need type casts to override 'const' */
                __perf_pmu__new_alias(head, NULL, (char *)pe->name,