Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751665AbdHPHL2 (ORCPT ); Wed, 16 Aug 2017 03:11:28 -0400 Received: from mail-bn3nam01on0052.outbound.protection.outlook.com ([104.47.33.52]:23240 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751530AbdHPHLZ (ORCPT ); Wed, 16 Aug 2017 03:11:25 -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 2/4] perf tools arm64: Add support for get_cpuid_str function. Date: Wed, 16 Aug 2017 12:40:46 +0530 Message-Id: <20170816071048.26087-3-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: 09b10c19-2065-4bc8-017d-08d4e4760063 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;CO2PR07MB2567;3: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Hffznj/fBa6CBcoEuYBMx290vlwgReytcmjkqnh08PeqL0Fwuk641SEa5S1/bvYF+2Cm/l8wZL4q1sQT3uLA7q7cAjQo7mURBfui27hBvgyf12jGw6ZUMZ1YfoafJy61OQ+jk3PMpwoRJ66xIOzP3MiiC1cIB1WnrQy3SZv0IxuJT/yQ03y6bf5gKm0Mnm/CGCPz+pEqFeKwET9Z1hl8F0aOP50e01bn+kX49T230wDwh5EHrPF2ouDvpWZaR1AK7Vp75q6Por9lUDzXouxYOFFAq7wqmAjK0A1TKrFwuBYWoV1ecjFcJONz39ejTitbBBFuXFjEU/9;4:bn7OK1k019+ua+OM/lbiewt4gGyUCajcvOqo4gcTI/1GuUiOgeEzgZneEnOS9DQ4FYzP+FIczIkB+cxLTGCBoETH3tVQYl0QgVRUMDFwYBccfdAq+jgFFK51VOfwUm23I0maLmWbWHKSdpl3YWdENywRZ/l00BrlFrLgPd3NtmGaNSfGI4RtGfszfF9rRDptb+04X0DsXRhyljwkbWyTK8Z4TNX7B06GL73w9GIQ9dWgkpRS+tH1eWaH1FAxoJxjPk8I0GGvJ0iQypen9N01pzDKv0+b9jP9B33Vtcu2eH4= 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)(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);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:v4zLfbuex3MbJieWFXDrPwNF+1GyhewfpuCcl7WGv?= =?us-ascii?Q?l353HUJNySK2B3vNZhN6rS2LGgBbGXBbBC1RuDqLnUyz/B0y+dmwhy+jbV+n?= =?us-ascii?Q?aiGMAxU7OhZ5T+lZkdmf1uaP0Hh57fDc+Lt7CZeYGf6YZAWfTG74xHwNrd5Z?= =?us-ascii?Q?v9oWVTrLA1QKTIAq3Cl4x3PdOpdg6LsDRXY06Q4ZzoAiYdywf1EapO5BZ7HF?= =?us-ascii?Q?F7Jn9Zwn4hwgKsIfFsxBXQDRK59fU+ulsM0eJgy0hw6nnBD8o9ku+fzEPvSa?= =?us-ascii?Q?uSwB7rVNImQe2AByBufa+/yebKBzrNkAHJQKB2RaPtpS10epXT6QWIn2dFDb?= =?us-ascii?Q?4yhiDm3sCAIweDeJa6GU0gBN5DBaEqJXlKioyCNz7Va1eFoai3L6BfBjvFo1?= =?us-ascii?Q?FeDwfhqYUeAEIcLocadfhZ6yDKKXj4IHnQTXiqF0CyNvzfSvgZLqOEMj+5YX?= =?us-ascii?Q?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1n+VnbM3EMzNC6Ac2c7MzlonGitMmVvIvAM8boVkAVYOp64HTxmwnLGmfquZ8F/JDUy/C0+WTerYtKCHBsgjpDDk1RF0gTgO08vSpcWUZt7RylwAGyXBS7boqiHYV1Q5DvvD+5Uaq9NHcgegjeWtgJ7c+5YOnm9Aa0eABmAcH/UGscPMME8Q9t4VNzQuY7DuXW7W2Ond5FmVgFiEOc60A7NpXTcDNCgMw==;5:tyMg7q0dX7IenXgz/sEsj0jvpJLZTfLn2Az9bvt57i2tjym1Ym7mkJSyWXXoUMLR/guqzDcI372mitgSyieqGOOpo7WutKq8XxUfwTUe9DmDtISU7KAPS9fZ3qa0AO8D/lNhncjuxBnV1UilR0n1hg==;24:zPQktF3IyeSr8A2Bkfc3AllpP3orI8WTIMO87Ihum1R0N3ac439PwEfsLMKtbF0xiBndiTsboevf7e8bGnvGr+r3ByGlzNVs8En3o6/Gdbo=;7:akwvP9G4Ouema/90oflwX2wVHm3H7+oqB5XQy57xcmM//PGe1H54ZB6kDjMKpqkJ8IsLp07qp8bFlRMIieCcCfDnOxhuQ4JPsSGzKZfbUFgPzFCh20gnb4/6hD+6oUGEB36tWBdO/IV7dYO/NGGHq23jF5FLtwSeOTO8YJJYjmLNXgJYpM6nrEkjAsB1yqe3PC9oyzQCQT/d5kioK2fwAf3m+cDbN/RFNBRjTJPV9og= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2017 07:11:19.0201 (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: 2206 Lines: 88 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 | 61 +++++++++++++++++++++++++++++++++++++ 2 files changed, 62 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..713ef17 --- /dev/null +++ b/tools/perf/arch/arm64/util/header.c @@ -0,0 +1,61 @@ +#include +#include +#include +#include "header.h" + +#define MIDR "/regs/identification/midr_el1" +#define MIDR_SIZE 128 + +char *get_cpuid_str(struct perf_pmu *pmu) +{ + char *buf = NULL; + char *temp = NULL; + char path[PATH_MAX]; + const char *sysfs = sysfs__mountpoint(); + int cpu; + unsigned long long 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_err("fopen failed for file %s\n", path); + continue; + } + + temp = fgets(buf, MIDR_SIZE, file); + if (!temp) + continue; + fclose(file); + + /* Ignore/clear Variant[23:20] and + * Revision[3:0] of MIDR + */ + midr = strtoll(buf, NULL, 16); + midr &= (~(0xf << 20 | 0xf)); + scnprintf(buf, MIDR_SIZE, "0x%016llx", midr); + /* got midr break loop */ + break; + } + + if (!midr) { + free(buf); + buf = NULL; + } + + cpu_map__put(cpus); + return buf; +} -- 2.9.4