From patchwork Fri Dec 13 13:54:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 181558 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp672888ile; Fri, 13 Dec 2019 05:58:11 -0800 (PST) X-Google-Smtp-Source: APXvYqyMfXLEo4aFOGjn124sCe6IdH2eedFBL9HA/0roTo5xG50p09hVu10pwmSaHLymnWkkyHN7 X-Received: by 2002:a9d:76c5:: with SMTP id p5mr15516579otl.61.1576245491397; Fri, 13 Dec 2019 05:58:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576245491; cv=none; d=google.com; s=arc-20160816; b=wMGWEUI3zMgB/fhBQ1kRuv/8+n43RUgrU+SVeGIAPE7tPY7WNQDkVS/52Op+GtrhFL uEEIxFUvRv2KdNc2f0dBqh9MweHoZgMHsZrukC97kGayG3dVowPLSX0TCaULZwfZHB9A +Jp/N1sPOF/FejMnqvpSqaF/DAp5vNc0rHrdpjcUdT+DoObrJc2AEJEdeo5PhfUA1dWy PPmMyMk8NOW+ANpp8bsY+I4jhex8Rj5apfir8QLWJU3AHDjegf+FMBBpRgcJcsICX7OI 8yL0D1pHHz7vv49d4KJiQdHoe1Tibp/+Ugps+yCJEfutk8dpzwCNJmvZ7lHkjb+LJqgx QkCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=tWAwrGXImXBbten6W04ifvYRgD2dv+oubfemNtA7Ius=; b=wAdQrovjc4GR9OQt5wxXUYaaYpgbEpX9KcbOjry1dr53PKCfGJQJW3tyhOSByf0oCv 75YNv+5pkXohQb+Ti/9yEkw8y+YIBzr+F9ChXgNxBngwI0/Czxxw8dt6ZndyuBUc0arL 9Uc89+KK8DQB3P0DCqdaw6A9N18EH2GVflUN0iiBoIAhNof5g3MMQbVAzQD4bcf77ScX 2BYXVb7WMdzzOnkjuBrzDVAOhtyVc21SI9a1rSezLMKu3l+rba6X3Jln2qdrC5v/35P3 SqxNsw7tCLJCfEtJg1Uq/QMmaWcorgqJLAsP2LxTiH4590rUGlDiIXHwf7fq9i8qZjo+ 0XnA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q5si4894717otc.56.2019.12.13.05.58.11; Fri, 13 Dec 2019 05:58:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727671AbfLMN6J (ORCPT + 27 others); Fri, 13 Dec 2019 08:58:09 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:7687 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727531AbfLMN6I (ORCPT ); Fri, 13 Dec 2019 08:58:08 -0500 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 28D915C864E049F2EFC2; Fri, 13 Dec 2019 21:58:01 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.439.0; Fri, 13 Dec 2019 21:57:50 +0800 From: John Garry To: , , , , , , CC: , , , , John Garry Subject: [PATCH] perf tools: Add arm64 version of get_cpuid() Date: Fri, 13 Dec 2019 21:54:15 +0800 Message-ID: <1576245255-210926-1-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add an arm64 version of get_cpuid(), which is used for various annotation and headers - for example, I now get the CPUID in "perf report --header", as shown in this snippet: # hostname : ubuntu # os release : 5.5.0-rc1-dirty # perf version : 5.5.rc1.gbf8a13dc9851 # arch : aarch64 # nrcpus online : 96 # nrcpus avail : 96 # cpuid : 0x00000000480fd010 Since much of the code to read the MIDR is already in get_cpuid_str(), factor out this code. Signed-off-by: John Garry -- 2.17.1 diff --git a/tools/perf/arch/arm64/util/header.c b/tools/perf/arch/arm64/util/header.c index a32e4b72a98f..d730666ab95d 100644 --- a/tools/perf/arch/arm64/util/header.c +++ b/tools/perf/arch/arm64/util/header.c @@ -1,8 +1,10 @@ #include #include #include +#include #include #include +#include #include "debug.h" #include "header.h" @@ -12,26 +14,21 @@ #define MIDR_VARIANT_SHIFT 20 #define MIDR_VARIANT_MASK (0xf << MIDR_VARIANT_SHIFT) -char *get_cpuid_str(struct perf_pmu *pmu) +static int _get_cpuid(char *buf, size_t sz, struct perf_cpu_map *cpus) { - char *buf = NULL; - char path[PATH_MAX]; const char *sysfs = sysfs__mountpoint(); - int cpu; u64 midr = 0; - struct perf_cpu_map *cpus; - FILE *file; + int cpu; - if (!sysfs || !pmu || !pmu->cpus) - return NULL; + if (!sysfs || sz < MIDR_SIZE) + return EINVAL; - buf = malloc(MIDR_SIZE); - if (!buf) - return NULL; + cpus = perf_cpu_map__get(cpus); - /* read midr from list of cpus mapped to this pmu */ - cpus = perf_cpu_map__get(pmu->cpus); for (cpu = 0; cpu < perf_cpu_map__nr(cpus); cpu++) { + char path[PATH_MAX]; + FILE *file; + scnprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d"MIDR, sysfs, cpus->map[cpu]); @@ -57,12 +54,48 @@ char *get_cpuid_str(struct perf_pmu *pmu) break; } - if (!midr) { + perf_cpu_map__put(cpus); + + if (!midr) + return EINVAL; + + return 0; +} + +int get_cpuid(char *buf, size_t sz) +{ + struct perf_cpu_map *cpus = perf_cpu_map__new(NULL); + int ret; + + if (!cpus) + return EINVAL; + + ret = _get_cpuid(buf, sz, cpus); + + perf_cpu_map__put(cpus); + + return ret; +} + +char *get_cpuid_str(struct perf_pmu *pmu) +{ + char *buf = NULL; + int res; + + if (!pmu || !pmu->cpus) + return NULL; + + buf = malloc(MIDR_SIZE); + if (!buf) + return NULL; + + /* read midr from list of cpus mapped to this pmu */ + res = _get_cpuid(buf, MIDR_SIZE, pmu->cpus); + if (res) { pr_err("failed to get cpuid string for PMU %s\n", pmu->name); free(buf); buf = NULL; } - perf_cpu_map__put(cpus); return buf; }