Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp870028ybl; Fri, 13 Dec 2019 05:59:06 -0800 (PST) X-Google-Smtp-Source: APXvYqyUSxFRbzc+qxphMLUmA5dbOR8IaxMXlU25WtGzW+GSfQAJfmJUYrWCYWjBJgQxobaIsOJG X-Received: by 2002:a9d:7592:: with SMTP id s18mr15401479otk.130.1576245546669; Fri, 13 Dec 2019 05:59:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576245546; cv=none; d=google.com; s=arc-20160816; b=WY8IMOD9zQp6pYcgdyXaHLE7cJqUXraO8aAeYgaIqxHRbSf3kUd28/+LWYGhIkDhYv CnIWw+UKatZOL5iH5cD/2qDtCz5cjrZjoLtBoa0ztA9FrD9s6zKmAN0rIb7qrUWlWWKS FANtfUciNistMvoPM4cTkcuO9rnY4aZJeoHnU6MYs6M6P1JpFWspOudMtw2nEMNixhku ib7QOFq9uJqN9bywCHJxzVw6dSZHLfybe1CS3vzGMV9JYCy1eWBarccUqXBH0HzA/A28 vA7k0DO4JMrSCNLA9lG1zS+O5y1QHt9XEkjQDn99y/KBDZG6SQv8sSwLRAD9b5B6uJfh +sFA== 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 y191si5220645oia.160.2019.12.13.05.58.55; Fri, 13 Dec 2019 05:59:06 -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 S1727648AbfLMN6I (ORCPT + 99 others); Fri, 13 Dec 2019 08:58:08 -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 Content-Type: text/plain 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 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; } -- 2.17.1