From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752693AbdLFQko (ORCPT ); Wed, 6 Dec 2017 11:40:44 -0500 Received: from terminus.zytor.com ([65.50.211.136]:54549 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752352AbdLFQkl (ORCPT ); Wed, 6 Dec 2017 11:40:41 -0500 Date: Wed, 6 Dec 2017 08:39:27 -0800 From: tip-bot for Ganapatrao Kulkarni Message-ID: Cc: yao.jin@linux.intel.com, zhangshaokun@hisilicon.com, will.deacon@arm.com, mingo@kernel.org, acme@redhat.com, hpa@zytor.com, ganapatrao.kulkarni@cavium.com, tglx@linutronix.de, linux-kernel@vger.kernel.org Reply-To: linux-kernel@vger.kernel.org, tglx@linutronix.de, ganapatrao.kulkarni@cavium.com, hpa@zytor.com, acme@redhat.com, mingo@kernel.org, will.deacon@arm.com, zhangshaokun@hisilicon.com, yao.jin@linux.intel.com To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf pmu: Add helper function is_pmu_core to detect PMU CORE devices Git-Commit-ID: 14b22ae028de56cca980171db625d1e9925c8fba X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 14b22ae028de56cca980171db625d1e9925c8fba Gitweb: https://git.kernel.org/tip/14b22ae028de56cca980171db625d1e9925c8fba Author: Ganapatrao Kulkarni AuthorDate: Thu, 24 Aug 2017 16:30:58 +0530 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 5 Dec 2017 15:43:51 -0300 perf pmu: Add helper function is_pmu_core to detect PMU CORE devices 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 Tested-by: Shaokun Zhang Tested-by: Jin Yao Acked-by: Will Deacon Link: https://lkml.kernel.org/n/tip-y1woxt1k2pqqwpprhonnft2s@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/pmu.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 4e7dd3a..732ff57 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -537,6 +537,34 @@ static bool pmu_is_uncore(const char *name) } /* + * 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. * * Each architecture should provide a more precise id string that @@ -609,7 +637,6 @@ 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) { @@ -618,9 +645,13 @@ static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu) 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,