Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752759AbdHXMEz (ORCPT ); Thu, 24 Aug 2017 08:04:55 -0400 Received: from mail-by2nam03on0086.outbound.protection.outlook.com ([104.47.42.86]:32801 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752380AbdHXMEt (ORCPT ); Thu, 24 Aug 2017 08:04:49 -0400 From: Ganapatrao Kulkarni To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Will.Deacon@arm.com, catalin.marinas@arm.com, mark.rutland@arm.com, acme@kernel.org, alexander.shishkin@linux.intel.com, peterz@infradead.org, mingo@redhat.com, jnair@caviumnetworks.com, zhangshaokun@hisilicon.com, Jonathan.Cameron@huawei.com, Robert.Richter@cavium.com, gklkml16@gmail.com Subject: [PATCH v6 3/4] perf utils: Add helper function is_pmu_core to detect PMU CORE devices Date: Thu, 24 Aug 2017 17:33:48 +0530 Message-Id: <20170824120349.2323-4-ganapatrao.kulkarni@cavium.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170824120349.2323-1-ganapatrao.kulkarni@cavium.com> References: <20170824120349.2323-1-ganapatrao.kulkarni@cavium.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: BM1PR01CA0095.INDPRD01.PROD.OUTLOOK.COM (10.174.208.11) To CO2PR07MB2567.namprd07.prod.outlook.com (10.166.201.18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5b17869c-293c-464a-e5b4-08d4eae850ee X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:CO2PR07MB2567; X-Microsoft-Exchange-Diagnostics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zyMYJ7fdaXFjpOg00IbEsMmBZzljTVS03QvE3rpmxC0k4ok96JlW1IQeyiln+IAeUseEqfUWpwHxUDpBgI61EBmA3QzJBNsqsUmNeL3a0zF8vZrrsmuQCCcJPG882GagKjWTMbLGldFm24OUj/3oZhtOmvj4C7lSomVYSUjUqwdfhTTC08klfJ/58zXUmo2X/y73z97cV674suXZDNRiKvbqBPDfJOfY6dIJo610eED3NAsZDXDg2WI2r+u5Ywx4LxaIHuQEtUKyhI9f+JnO2F14KjRNDo+jxs4zuO8euGiSo02MxrtDvk7i60n5crkusacL3kcPBsXmDhAYm3rdDfl6hEcGeK29ZFso4DAdUj;4:8ef9Izz/GktD+XzSaaTiEuO0zVAkL1VG6wp0HZ5H0Qo5bYibmCUyO07trmC6W7BXivsDz6BNa9HZ9UAoC1ehtgWoSvNq0JQA0aX6mXkXb+flMns9uKci+MFnzrc6/B6XwbPFoe7vw5kk2Y6XcN6RemGAzp6hh/g8MFoq2nYvpRoZCxvNGqk7TWjQaMMehpAsSWaacSm8waL7ccDvyf5SnGwZacP1mOPGLQDtnFfT4AHltUu834WdozT3d+EYSOHL X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93001095)(100000703101)(100105400095)(3002001)(6041248)(20161123562025)(20161123555025)(20161123558100)(20161123560025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:CO2PR07MB2567;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:CO2PR07MB2567; X-Forefront-PRVS: 04097B7F7F X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(7370300001)(4630300001)(6009001)(189002)(199003)(97736004)(25786009)(105586002)(42186005)(189998001)(110136004)(2950100002)(6512007)(106356001)(2906002)(68736007)(4326008)(33646002)(53936002)(5660300001)(6116002)(3846002)(6506006)(50986999)(47776003)(48376002)(7350300001)(5003940100001)(86362001)(7736002)(305945005)(50226002)(66066001)(8676002)(72206003)(81166006)(1076002)(7416002)(81156014)(50466002)(36756003)(101416001)(6486002)(5009440100003)(76176999)(478600001)(217873001);DIR:OUT;SFP:1101;SCL:1;SRVR:CO2PR07MB2567;H:mypc.cavium.com.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Ganapatrao.Kulkarni@cavium.com; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CO2PR07MB2567;23:cYYszBuNFyjXpx2PBJSHdIovlZH8AgHijt5CSaz92?= =?us-ascii?Q?9/8XqLKD16+va2OydkRdGuNi+J5l3IKtXQA+ht+ECAco6hexLgN/NmLuCKfD?= =?us-ascii?Q?V73BRKBV62Jix9ikl7LYrdaMw/2/79L6hYIffREOydZgVqxVuKjQpR9ar1FP?= =?us-ascii?Q?wrv1qO61hNg3LTh5hnHfSxo6PfKXikM1trztGswENuuqEZlsqFSIERXvOD0g?= =?us-ascii?Q?Zt41R9dGXee9Is9V2tD+qnzIwD0o0oZ8iEtT4f4aT8jzP7Q4Ppe2srzoqvVX?= =?us-ascii?Q?jhtqrvaBK7CQuvjZ+dL2/FoeZ6m9prW5aCUbWFuuIjrSCaUEw7R2P+4tQ+E3?= =?us-ascii?Q?u4pJPuNztMJHUEiHMjXRHemIJLhmY/xZytTPk2oSHfNfqMkPFiFhP6400EWC?= =?us-ascii?Q?osfDdKY9+a15XUKAvfAJOKpSBzzILQFnxES/LtwSAv54DbzMG5hp9mnvdxmu?= =?us-ascii?Q?cKBjOlLRlptrnjedSYbQPehzUA4jDhUFUp/n+Q5/Y4C1OmCNpz1F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iqu/9zF+1zkuTPG8zz/RZMPnPnxb38d2ga/RtqxxPtgu3wO0R6lQWtNkm7Rv8hZ10mdem5+LCTZx3XPH8WrwPAK/uix+i16p7rvkmNLCbJw5oh5/ntEf2Ljhl8FzMiDVux+Q==;5:5FwpJtIjC/GNpZPvC5X31vCXXoS6z4HDEnoe5EtEBprPlWA0Q/5bvSpbNZV2tpwSBWikQAAuGp/oZiGnXfKSOaGaVkppKqst1sBoCecfTwX5AYup2pfO9/VShQVtBVODSpTJEZuqbx+MbzjKneF47E8xBoP52oZX4XIqgEtuN5I=;24:03L9vmSCmuUp+Hv+ixOeFIX7CRpqBWOXm5S6TR1QwBj9QpxO+FnHN66Pos2+3iWV7oJXsSY0l9j2249MT8cFtzWQg47lB2DleOI/srneblI=;7:lOuWz7tDM3CX9sRaAVREvLERcRNATM33I8hY3zvImltwumESqK4JqNKOKGs8ktn9SssJ8r26pGj17Gd5kRQUJ2usm4h4CwRQc8TwCeD2EHx9eftxRuoJxlb1rsbrI1HCtVSCTCfYTY+khZgZuM7KqiaOXb54JmxhfnzB6sEdwRxGJTu7DxC0iaa9vLyr8rWC1fFZAcx5ioDoUFf03M12nDNBKi70TSCgt+frljFsUjg= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2017 12:04:43.5353 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO2PR07MB2567 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2115 Lines: 76 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. Tested-by: Shaokun Zhang Signed-off-by: Ganapatrao Kulkarni --- 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 aefdbd1..c2fe70f 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -506,6 +506,34 @@ static struct cpu_map *pmu_cpumask(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 @@ -558,15 +586,18 @@ static void pmu_add_cpu_aliases(struct list_head *head, const char *name, */ 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, -- 2.9.4