Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752634AbdHXMEr (ORCPT ); Thu, 24 Aug 2017 08:04:47 -0400 Received: from mail-by2nam03on0082.outbound.protection.outlook.com ([104.47.42.82]:22979 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752380AbdHXMEo (ORCPT ); Thu, 24 Aug 2017 08:04:44 -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 2/4] perf tools arm64: Add support for get_cpuid_str function. Date: Thu, 24 Aug 2017 17:33:47 +0530 Message-Id: <20170824120349.2323-3-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: e6b03841-1952-4e66-4095-08d4eae84e21 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;CO2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qw3wuYObY49kfsAO/CUc0rPXl6iqainmUXediBOz6poUiWT9sliFeOFtvsq4zDhD/RcwvRCDux4UNCbTL2ie0A34SKANKLFXZQUiygjXgSwA7b6L2ou7bmz6U+1vd+0P2EgLcVDdTeRNXRsJFfcXkMz91DMnteSrhRBYyuM3Y/c1oPT06WZdG+FvLqavDAUkf8OSJT3vtLmfTU1J+Jij6BKNzdFL7p5keUflTgV6leuVpDe7YQ5gMKidAF7WFCvv2e5BIVpYQTzEXyk+Pe+a6AFfEGG5ez2tbosIiInWJ2o9clSRMv+8ne9wV9mwxBN8EwcEelOo6pXEvhNR0ZFZVvVuYugpIkIsbWeAUHpies;4:Zp+HSeXTHe9O/LPXgtZqsln6PQR19PlAW/ANQ4sNzvqlNeYi9I1MDCAPMHBIskoiTeDQnlv6IvKTvqVMsKlF9bVylZIwMrOtaRNzDHR5GtZAhuT97A78rC/NHWcQpjeMHLdXxU1sWq1SeCR3jLsUwo4K1FWQh9VJv76HXzIqTH11y6HnE+VbiUOhbS96ppRa0k6GXaVWMMqjYSUoNn34rhCXg+i+jM8lZ+SS3NdjBJKYCOTuECCnBCdfzGIEnTyactyb2TkhzvTjT9BbAiZv3PR/H7M+J3eXZEXV1/AuINo= X-Exchange-Antispam-Report-Test: UriScan:(209352067349851); 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)(6666003)(8676002)(72206003)(81166006)(1076002)(7416002)(81156014)(50466002)(36756003)(101416001)(6486002)(5009440100003)(76176999)(478600001);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:vQdwUdK/rz/8WVFEMxTMGApFBsauvgMOvxqiiY8jt?= =?us-ascii?Q?cc97wfn11xFEXYR8NWh7DasgK6BtNlzaDWaPJD+3jBQiTAIXBdHsoO5cxEl2?= =?us-ascii?Q?KeQtWiWtChtj8Ad9pV52BAPdLFwXZfMlKM5c3h93dxIIiweKeSSc0REjZcZn?= =?us-ascii?Q?5Z+d8ZCa54e9I7CJvU0emdAICEx0UbsH4NQOa8447u7R0sD8jjz3YbBBtfVS?= =?us-ascii?Q?xaRt4De83fkoqYU/vxmKRdfpeDXk0IAJWWDCumnP1I7Dpd6UztCnlP8XMCBi?= =?us-ascii?Q?DDpcvOu5vgoh/Sd/pdkupzo8DN3IeMFhdFnmnM1okM11XOAWrImjIcKU8HTS?= =?us-ascii?Q?G6JFMdUe2yeg7mefnhnjMeQHEHR5XH0v9pKD+ZhDAeHGvTB/5m9/GmMF2BVw?= =?us-ascii?Q?33iiMC9EqfQRoy+6kHek6q7mneGrFsLswQOAx/GXcWKa0NQgLDHbxuo3YD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QEUAk7UHdUWiSweqxg23GW+PIdFNievnEG+WZNtb8/g73QzBw38fpWIPv/mB0ScM5xb5t08IIFPW3TbQzRK35RYLLHgJmA4LPrF++YvSfj3JG/i2E4CRZPvTR1RAgh+Bw9Iug4DUPtvof7kW008I0iVdxuO6gb0L1r+33WdrIeAxv6w2UcYqHpVeOuDEBUZqLi5SIw==;5:O3hFoTU1YQ3Ts+AW16UCxr6TB6XY/ybjSMMj41ugIcGfvmWlVVLYTEIakuTH4noT2FpmEwU+kZzlNSdXapHrcrWxb6e6MPp5pmKK3GgFHbwRPTEpzqMLkFXT3iyDjUuboqUSd/0HVUGsHAa/5sNAQ6bjMsfNguQRIaknW8okdxE=;24:mUn0QkuA/1Xwgp7Tcz8eCdV2ZWyK3KtbVfbMDneX9Qhhg71geajP/Z0/eBnJj6GDcsZXz/4GWvmLxpjPRAiZa7Md2KVj69rzR7wDNkh+loo=;7:rhwjDJupA8ZaO+RuiFb8CT35AGY0MiNjhPdRfgrSN/iwdDDVR7ISv3M8Yli083fw93Fppmu6B3ng+n/6UO28uFO2E5QJMmQrixAJOuuJGr5j8K36qkHQ0Q2UoWV9n37aX2W4mmRMv8K+L59n+TavJuECUmCxiFvgk6irDmoDpzXPxtALxPJclRH+iD7PJWQaeXQ9LTOEvU60vvOq7xyjOXvuyHwSbL6bnDTuLmmDI0g= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2017 12:04:38.8165 (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: 2197 Lines: 87 function get_cpuid_str returns MIDR string of the first online cpu from the range of cpus associated with the pmu core device. Signed-off-by: Ganapatrao Kulkarni --- tools/perf/arch/arm64/util/Build | 1 + tools/perf/arch/arm64/util/header.c | 60 +++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 tools/perf/arch/arm64/util/header.c diff --git a/tools/perf/arch/arm64/util/Build b/tools/perf/arch/arm64/util/Build index cef6fb3..b1ab72d 100644 --- a/tools/perf/arch/arm64/util/Build +++ b/tools/perf/arch/arm64/util/Build @@ -1,3 +1,4 @@ +libperf-y += header.o libperf-$(CONFIG_DWARF) += dwarf-regs.o libperf-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o diff --git a/tools/perf/arch/arm64/util/header.c b/tools/perf/arch/arm64/util/header.c new file mode 100644 index 0000000..f02a32e --- /dev/null +++ b/tools/perf/arch/arm64/util/header.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include "header.h" + +#define MIDR "/regs/identification/midr_el1" +#define MIDR_SIZE 19 + +char *get_cpuid_str(struct perf_pmu *pmu) +{ + char *buf = NULL; + char path[PATH_MAX]; + const char *sysfs = sysfs__mountpoint(); + int cpu; + u64 midr = 0; + struct cpu_map *cpus; + FILE *file; + + if (!sysfs || !pmu->cpus) + return NULL; + + buf = malloc(MIDR_SIZE); + if (!buf) + return NULL; + + /* read midr from list of cpus mapped to this pmu */ + cpus = cpu_map__get(pmu->cpus); + for (cpu = 0; cpu < cpus->nr; cpu++) { + scnprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d"MIDR, + sysfs, cpus->map[cpu]); + + file = fopen(path, "r"); + if (!file) { + pr_debug("fopen failed for file %s\n", path); + continue; + } + + if (!fgets(buf, MIDR_SIZE, file)) + continue; + fclose(file); + + /* Ignore/clear Variant[23:20] and + * Revision[3:0] of MIDR + */ + midr = strtoul(buf, NULL, 16); + midr &= (~(0xf << 20 | 0xf)); + scnprintf(buf, MIDR_SIZE, "0x%016lx", midr); + /* got midr break loop */ + break; + } + + if (!midr) { + pr_err("failed to get cpuid string\n"); + free(buf); + buf = NULL; + } + + cpu_map__put(cpus); + return buf; +} -- 2.9.4