Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp6073645ybv; Wed, 12 Feb 2020 05:35:30 -0800 (PST) X-Google-Smtp-Source: APXvYqyCBq63qNi8yLM5BFUhA2VWDmh4aH3tX+1O72aTaRywMdnYNOCPVMFOfk+9qGke0KCZfJ8I X-Received: by 2002:aca:6542:: with SMTP id j2mr6309618oiw.69.1581514530584; Wed, 12 Feb 2020 05:35:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581514530; cv=none; d=google.com; s=arc-20160816; b=kCN7nFfsutlV4+AJHqj2R2ttUWvYL1UivPigaDOlJYQbubE3rYjk/uu//Hhymia5oA ihtqP2mgxn7rXXMPYEHaRrw3BSx1rLdYDbpLRnEHShNRPUBeLVXANLrZILwqw5BUSWB3 Sg/Kvx4Hexgf1X7i2xOYR8YJUHc8wi4nUlAXhptxLCvniW/5gXtGaoCSk9aa6Sin1XHN Jlu0102TcYJNcxnvFYhXhDGfOiCKn8A81F2l87d+oSb01YZ47/i8IHKXVFmTJScLowlk 6FrpSHD9npMXTE3qrStKjxqN4XUOCpwFHAN/beMJORaeN2jfa6LAcUU2RQZrZRADVFCv l6nA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:date:from :dkim-signature; bh=ugXtyh0yqkVQHyvHMxbHhHFf3dGGd0T39RMzBP1EvyU=; b=ISDf3VpYf74KXAo2+AxjnXosipf8eFwThlkPQ54sVDThSDK5IwuS7I7LprGg0Takkf WiPJNKqBpZtDrj2wPITpI4y4LqW/uSAuEUB6pvyThiWte2332P7J/XkviC9u6JKwK9zW VSnlk4BWIlooYfd7iupTfydr5e+Cj1i99felfdZkuaB3X5q7Gy9gm/9GGDftiAvg6VgZ ew2UUiJ6wEsYAb/4GrimefEyKw2v0EdMqh/rKVWIHe5WBdK6gaA/+HZOmHLS/CY+xgAP J3QnAymtBElZ8y52wxlKcxYbPIC5CxOraRRUKoskhZNr63IFl00JEWvDaLBZBRO6saS9 KpiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fHieW51i; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j9si3310409oiw.133.2020.02.12.05.35.15; Wed, 12 Feb 2020 05:35:30 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fHieW51i; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727984AbgBLNfH (ORCPT + 99 others); Wed, 12 Feb 2020 08:35:07 -0500 Received: from mail-qt1-f194.google.com ([209.85.160.194]:38677 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727662AbgBLNfH (ORCPT ); Wed, 12 Feb 2020 08:35:07 -0500 Received: by mail-qt1-f194.google.com with SMTP id f3so1456498qtc.5 for ; Wed, 12 Feb 2020 05:35:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ugXtyh0yqkVQHyvHMxbHhHFf3dGGd0T39RMzBP1EvyU=; b=fHieW51iWr9OIEh60xrG9smqAN7YLFaOS9omwWD+xTSwwuG1XP6cWrzp5IDCK9c9LO KSOHJi/S/mDJEGKaWXvHf8ml+BOPy7WZgjX4AgUGYxDl+RqHvo/DqFfiOl7V0pMoPK9x EEGOjur/Ro78yyBMV7Xn1CSasgJiNVTPzTazR8Bo74cLGUl201ZUgpdcoeCkaQdcLYd4 jrdywINJ3QYFAFOJJhFcY8MiDNz3Uci/cOu78IR25w1wEFd5fTaDaUPNPdK29Q/4qqLL 0mgSSkOrTJo8u1erNubwOKBzAdiuGkVFh0WOfGTTVBSUT+WmrKIdTCeYjQssq7OGRwzv bDjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ugXtyh0yqkVQHyvHMxbHhHFf3dGGd0T39RMzBP1EvyU=; b=ELHcD+KxKpuiD6bzz3sVgB92JcUEuH02cFWmh8VWXLncHVVwhBaDiKVnDCgm4n37SQ 7j47w6UBVZ6r+sYB0uueFno5NRF9znw9aRiLu6n6aq98uHTNXC3B0hoo89+kKpGYcBZV w4QVfDQGonXADo5yP+ZbTLBiP1d5+walC6VSRhnT5HgIV7t6SeNdhKpZlajXvEIig4TX Fh8i0lrZlW9vXEQIa1kZDWcB/4kRXT+RliwbqjdxIP/BoTEjTAQQZXNwOyynGAZnuhTy Pxh+DiFa2ocGr9m6ARTnSJkGYwqAA4SY6GBxP4m+bfb2WMQsEeAN+m6RkJdbIjAKT7uY W8Rw== X-Gm-Message-State: APjAAAVufZVFIyAMP1gWASXG4naeFLf1W7IggWfQ3baGJM9vYSMFiMUp Iol/L1IG0EP8aqN1RyUK/DM= X-Received: by 2002:ac8:60d5:: with SMTP id i21mr7088024qtm.341.1581514505626; Wed, 12 Feb 2020 05:35:05 -0800 (PST) Received: from quaco.ghostprotocols.net ([179.97.37.151]) by smtp.gmail.com with ESMTPSA id 205sm185751qkd.61.2020.02.12.05.35.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Feb 2020 05:35:04 -0800 (PST) From: Arnaldo Carvalho de Melo X-Google-Original-From: Arnaldo Carvalho de Melo Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 335BC40A7D; Wed, 12 Feb 2020 10:35:02 -0300 (-03) Date: Wed, 12 Feb 2020 10:35:02 -0300 To: Shaokun Zhang Cc: John Garry , peterz@infradead.org, mingo@redhat.com, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, linux-kernel@vger.kernel.org, will@kernel.org, linux-arm-kernel@lists.infradead.org, linuxarm@huawei.com Subject: Re: [PATCH] perf tools: Add arm64 version of get_cpuid() Message-ID: <20200212133502.GB22501@kernel.org> References: <1576245255-210926-1-git-send-email-john.garry@huawei.com> <4ccf4455-b33d-441b-50ed-28211dd87c7c@hisilicon.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4ccf4455-b33d-441b-50ed-28211dd87c7c@hisilicon.com> X-Url: http://acmel.wordpress.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Wed, Feb 12, 2020 at 05:30:56PM +0800, Shaokun Zhang escreveu: > Hi John, > > I tested this patch on my new ARM64 Kunpeng 920 server. > [root@node1 zsk]# ./perf --version > perf version 5.6.rc1.g2cdb955b7252 > > Both perf list and perf stat can work. > > Tested-by: Shaokun Zhang Thanks for the test and for (re)bringing this patch to my attention, I'll process it now. Thanks! - Arnaldo > Thanks, > Shaokun > > On 2019/12/13 21:54, John Garry wrote: > > 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; > > } > > > -- - Arnaldo