Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751782AbdHPHLg (ORCPT ); Wed, 16 Aug 2017 03:11:36 -0400 Received: from mail-bn3nam01on0057.outbound.protection.outlook.com ([104.47.33.57]:59984 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751620AbdHPHLa (ORCPT ); Wed, 16 Aug 2017 03:11:30 -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, Robert.Richter@cavium.com, gpkulkarni@gmail.com Subject: [PATCH v5 3/4] perf utils: Add helper function is_pmu_core to detect PMU CORE devices Date: Wed, 16 Aug 2017 12:40:47 +0530 Message-Id: <20170816071048.26087-4-ganapatrao.kulkarni@cavium.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170816071048.26087-1-ganapatrao.kulkarni@cavium.com> References: <20170816071048.26087-1-ganapatrao.kulkarni@cavium.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: BM1PR01CA0112.INDPRD01.PROD.OUTLOOK.COM (10.174.208.28) To CO2PR07MB2567.namprd07.prod.outlook.com (10.166.201.18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d7a85c49-fc4e-4b27-1a20-08d4e4760357 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: 1;CO2PR07MB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7bLDlh1eaHnAARAMrvlwuFBjtmt/tCqmDFHkkVTLVy+BOfeuf5FiUoA5xUFq+EMFpVdujj8PrNyqI8BUDFKlDQzY7VwT4np1srwZA/Zj7AfjKUSyQOfcCYb5FJcQeXHP+XoQBLoR9kx2+B3i4G926rBe+K4yuoS/nlAnICAad3pHBMMMP6HGfwO9lMOuaTdRBRXKbuCBZtLJN62V8qxq2jANcrrAiMNM51S25aMztDLHs09GNOk49Ygz6djZjIgF6NUe9lDZaEhtbt34sA8siXApfaCcpab5gpEMkRjL/G30R0dmV3KGt1bmLZJ+PBnCsX3yOP4/F2RwfnqK7/bxBZmxQ;4:o1GRMoAeal45gkDiL1IWaq99CW7M1u6C9Kk9gGAR9hswdR8mPHo65G6OX+SlVC3FCaHZixOpRckeDoGwFcCXkz7vWSz0GOgcaUFh5gjgUt8b7F367LJTFaxYNfHKZn3Fjj5B97Xtqg866MWk25+unr86ZmcdM9EsV0f2jIYwmTCh6SzhzbkDMck+Hp3skGumBXsKUfnB6n3kP93KPV/+Nlisuq+vcKQaXbTBuR6NMAzfZZcxHOFhn08rg64GGjja 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)(93006095)(93001095)(100000703101)(100105400095)(3002001)(10201501046)(6041248)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123560025)(20161123564025)(20161123558100)(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: 0401647B7F X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(7370300001)(6009001)(199003)(189002)(86362001)(36756003)(50986999)(76176999)(5003940100001)(7350300001)(106356001)(105586002)(69596002)(33646002)(97736004)(53416004)(47776003)(72206003)(478600001)(42186005)(25786009)(66066001)(101416001)(6512007)(189998001)(110136004)(4326008)(53936002)(5009440100003)(50466002)(6486002)(50226002)(2906002)(1076002)(6506006)(48376002)(68736007)(6116002)(6666003)(3846002)(81166006)(2950100002)(81156014)(7416002)(5660300001)(8676002)(305945005)(7736002)(217873001);DIR:OUT;SFP:1101;SCL:1;SRVR:CO2PR07MB2567;H:mypc.caveonetworks.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX: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:WLh2WWm10xulrOTNh4X64/dEM0DpC0cGrb2UxzvS/?= =?us-ascii?Q?qkpzuAM5JjxWCnST/dvDwdz54z+aW7FFMAGjKenSd5YTW1xtY+pUiC9faPUB?= =?us-ascii?Q?JK56RIxSjHJ2crNwlziKTOVk1UZF3iSxEqNPjcmbIBbVAtOQeRV2lC/u5+Ml?= =?us-ascii?Q?2wqp1UibXGE75eUD5ViUY1oGoCM1qtgS60fcuUasvt00Q2Wf80Xe6D9SdNr4?= =?us-ascii?Q?UJ3oG2zLyj2hmn+JobCZ6kSkSzTKgLBgg06X8jRT8mKBRfm7mQIxyYMEUFpN?= =?us-ascii?Q?+VrL2kRHOKSWdR2dk3pGQJjUyyGOjKXzppxfxyySOM2hFbBNQRDeBF9JLOH+?= =?us-ascii?Q?tY2hMZG1onFxlwSYoA6fsmdCzUu/6NeBVvfbXX9j2W48FLp7w/4Vt/iCVQRa?= =?us-ascii?Q?W58Nqb0SWt0wN1KsGWGw24FzQRh6vomCRhJc/dOfZ8FvpiLsh3o6Oc3RZwCr?= =?us-ascii?Q?bzTddKItKeJDuo6CR3Hvpn6wsmHKbVE3aTpwgy4ROK+m/J6maX90nYpJvyyL?= =?us-ascii?Q?U/ks+bX47VvnqyLbR/W5EpFw8NlDGnol6+L5ZrPAkTar3VbyUzjOVClBxidg?= =?us-ascii?Q?sdB5laVtwG9/S42FTjapZhuOuyUbwnlX4hSQtKNv8y+2J7XGN2UtmjvieTrk?= =?us-ascii?Q?c27Oad+yy5tIfs+Rz+HmUYnPcBKlYicAo3Dc1DvNziWTCwJxSQZkGFsgt3i+?= =?us-ascii?Q?l02DV7Kj5qv+dyOYl3e629AuyES3SDpP1e/zhMd9kAjPMM0dEC78dkq6H9Q+?= =?us-ascii?Q?s9Z3n6y/YJElMJP9wb6yM0ub/VM9C6+dK7LRrvY2NEW+8LbZi2oCxTzvXBGe?= =?us-ascii?Q?NwrojYsdPeHIID++92/Bd8QRyCsqp5i8M2snZ2N2oo5O9x0urXT17WliGSZm?= =?us-ascii?Q?oHRzckCZXUKvQIAZKsD4RSHA9gD/B48wnENj9Y8lrrYEVmSJi74ikMPQArq9?= =?us-ascii?Q?bDIyx1afxu40HlF15eU1smKyU/0s5hE87mzsGnycTxvd+Ga4WWyWsI0yVU6H?= =?us-ascii?Q?57zRmDwxSirLMTg9PCvPuKlVeFA4bqK9gDy7pYZuU2tPrwrvtEgYCKkKDi4u?= =?us-ascii?Q?53pVsOj5A8nmeWUbaLFfBBAvXURrIEuII4EWNqZS7WlYnG84WOmDmmsxGjdf?= =?us-ascii?Q?aUPQx6DA6XzcKbL+aoBMgPU4LqI4opVNPy5NKxwm338J/bkWvMaEsCw4N0rs?= =?us-ascii?Q?1A6H3WeLrayODu53umyhC25dHeSAdClrh1FwmxvEk2w57SO+CPmHCFFwg=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1;CO2PR07MB2567;6:HMZFL6sLkabd6l9MYmWspuqEXNCBQnV+31ak14ZpHo0fDgbZ6G5XTOIwvb8ltPGt+5/LfwAqa1P2S51uvDgO3bZ5qfhT5tC2rFKBOi3xuzPbqhZXB4Os0j5BkOc9cOfnMKf5pyYVz/iteIKtAC0E2yIOTstd6WMEhDrtOIUiWt91fAmRg9BPUBL/z7Vh+Gzpixz7wBkDhpTljyE/Wta+/fCLtV1y2RJP8K5s2hFaqTeHEa8IicrhH9AWFjirvPVoZ23thlJF9wonO4zcBw+NGR4vYdPyuXYGl+qY7JGC5SgMfGQZ+7TwoE3UD0Tfh8xPJFYE2iQ4YH9CJ4i5BdzSpg==;5:sBl8u34joynSmZ5GaaWJADdoslXmveoQ1gFM4v4NBP3b8G6qVJ3uCxmpp/9HZ49xYXQeWPhchkpgWKeKxmRfpV64XBth1U4oFyW6crYORm+hfjtImvMFOYA/UIeOk5GYjQka+LRN77qY7onJV15UFA==;24:ou3k7tiCwU13W529HrO12n8mziuiBNielFVlF3fDGcS9jxqOayoVm/t3c3Q7vyyByhD3qZQk9bHz8As1O/gyt7NbhZ7nmR2N+vcJyCMreT8=;7:93xC/1zR6U3EG/yyEgjvCIcbQLZzfjC2VBcXNz6LOkIpCaT2p6SE5AVyNAHJ7mOnZUmCl+fD/0Tx1Kq1HSgoabtY5+MtZQBDQNoNdDZTjJMFWxZrcDpUNklTvntUlzrkgqgydsSxV1VNE1IEvFvrbII+Xormg+hrxO/jIQyeuKzcQW8ii3ABH94ruwhQye8FIwTSvaGDV3zrbQhh7ZZGSK+I+vyhZQTRrI4yNbJPes4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2017 07:11:23.5990 (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: 2194 Lines: 81 On some platforms, PMU core devices sysfs name is not cpu. Adding function is_pmu_core to detect as core device 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 | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index aefdbd1..0057d1c 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -506,6 +506,39 @@ 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(); + const char **template; + const char *templates[] = { + "%s/bus/event_source/devices/%s/cpus", + NULL + }; + + if (!sysfs) + return 0; + + /* Look for cpu sysfs */ + snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu", sysfs); + if ((stat(path, &st) == 0) && + (strncmp(name, "cpu", strlen("cpu")) == 0)) + return 1; + + for (template = templates; *template; template++) { + snprintf(path, PATH_MAX, *template, 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 +591,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