Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp6078349ybv; Wed, 12 Feb 2020 05:40:52 -0800 (PST) X-Google-Smtp-Source: APXvYqySJ9sP9yQaqaA2mu5re0UXMyqpvm8Sm4GNzpWW2KTDEIs6y6RLJGzZ4tsyvZaC0iMcBhxu X-Received: by 2002:a9d:6301:: with SMTP id q1mr9015207otk.299.1581514852004; Wed, 12 Feb 2020 05:40:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581514851; cv=none; d=google.com; s=arc-20160816; b=ftBYjfOAibR8hbyTGpb8FWf3e+mRprGrdQNXjHJNNIQI5vGOX5ESvTvgTic8x2P1CU /4e4yv8OZe/ECiL19eTu/w6EUlXjPuE9LxB0oKIUmI0xGQ5Ol1CwCACIWi42pOCDRiBe jjXagsCL3cb3O80QLnJcO1bDhRS3eABX7ZIHW0R2UiAiK6/hHj+W/gQNg6gICeDuKivB noZ7vUiR9C8UykOkWIpv0nSy4rgqVQCRVgibBhjgr7q6UeFTE4qwjTQOY3cOM9+t2VTH 72L7M/hIXuP8vuZEx9aQeUmtALRJxNB53bQWQ8eYEb3gf3+ISB+i+jxAVXnE+Em7mF6c 7f+Q== 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=OnBjhKKPWWjwGlSdDsblfiubmy6FG0ISMeKtWk1WU4E=; b=z+o6eSoAIhQEr25Aa0oxcL4KPHIKDEXgMTcoxJ2s8VQJZcBUT3DOqstp3Zu7yogIS8 zHfu5alwONPfe5cagtamMg9YOPwShGC4caRLVbqPMLnpaKoOSsFlBGe9ullFAWi44LFw UsMH+m1tl6Il6RD+clEtuwXpgztHaRSyPL3ImEdQz8kCrqzMIgaP28TtAly/uL6s7dwX nQymgWML5Oe3lcHU97Wo1M7LwtNd7vw37ptzgxqlggKNL4M1MoZKcY0fn9Mr1eNB+6Et XcPUE+IqwvrUGXVCRaVCza66iYBtykN/SlNJga4B/nKGvCgLnmlDCt1goTREQwIqBdzW l5zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KkgqACIe; 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 p1si236504otk.42.2020.02.12.05.40.39; Wed, 12 Feb 2020 05:40:51 -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=KkgqACIe; 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 S1727756AbgBLNk3 (ORCPT + 99 others); Wed, 12 Feb 2020 08:40:29 -0500 Received: from mail-qk1-f193.google.com ([209.85.222.193]:46696 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727439AbgBLNk3 (ORCPT ); Wed, 12 Feb 2020 08:40:29 -0500 Received: by mail-qk1-f193.google.com with SMTP id u124so1510047qkh.13 for ; Wed, 12 Feb 2020 05:40:28 -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=OnBjhKKPWWjwGlSdDsblfiubmy6FG0ISMeKtWk1WU4E=; b=KkgqACIe+Rj0gkGSWF6P69W+lldwdj7XkVvjVgjEApytFDFrpRce0JrHzrpqlFW2yY knUrrcX3ltS+iUcv5p7lhttaiQnqP1zgMCjN9KI1qPVHjFbaE3GPSAPJQ/pCFj2YYn6J f6kkCrcqJt0eI7KCibEQ33BJTAk0Q5XYRi1m1TlK+iNP/YrBjHn8VexfnQ+6h9SX0wKD sDE4/4OOdekJuOQ/jkKqwxsVfyBRDBRFOqZ+RqjXdlLHXO064vBL3tNffWfD5q41jApW XSIY6rPbfI5CA7ycihdZdzQutFBJNbqsSdSk06FJIGGpZiNXx1Y8CVCzOsvIoHPKeJ97 jCdg== 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=OnBjhKKPWWjwGlSdDsblfiubmy6FG0ISMeKtWk1WU4E=; b=EeSL5IM6BwhQS5urC+40oWgmo/pYDhaQxyBbxvqWTVxl/ma0ft4n1vpZ84dl4Hlg1f GIg6UkLGKgBzNKlBFne15E2q0hRWd6l9kliP5rHqWOOUjw5Sxh+Cnd0TJf5RA7kzNMob ctKBlx864UIlDrBRwsb9XzfzqltYao2OYLGXjMnmwkexziBESm71vPS34KSFoFwXDxT1 0dabzFfFuegDeIro+U8Y5f/5j0hHatrKIuuorImO6tihCn4tKhB13VQz2dldvtu7kQcP /7gycy9TuCws843n67UjxTZW2jyZulax9znLJ3ECbxjGpwDXkQoMfjEco9m5B46MI1qO LYog== X-Gm-Message-State: APjAAAUl5fD/UeoBUH5y9LWqop9pfb38N6M4UrumXylJ2hDpMIpiNzkK dpcY0qLEfNMFT2FL0Wu808s= X-Received: by 2002:a05:620a:1210:: with SMTP id u16mr10229390qkj.179.1581514827592; Wed, 12 Feb 2020 05:40:27 -0800 (PST) Received: from quaco.ghostprotocols.net ([179.97.37.151]) by smtp.gmail.com with ESMTPSA id w53sm154509qtb.91.2020.02.12.05.40.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Feb 2020 05:40:26 -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 9370140A7D; Wed, 12 Feb 2020 10:40:24 -0300 (-03) Date: Wed, 12 Feb 2020 10:40:24 -0300 To: John Garry Cc: 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: <20200212134024.GC22501@kernel.org> References: <1576245255-210926-1-git-send-email-john.garry@huawei.com> <1005f572-e32a-a90e-1572-c85a2f202fdf@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1005f572-e32a-a90e-1572-c85a2f202fdf@huawei.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 Tue, Jan 07, 2020 at 09:13:43AM +0000, John Garry escreveu: > On 13/12/2019 13:54, John Garry wrote: > > Hi Arnaldo, > > Do we need some reviews on this? Or was it missed/still catching up? Got lost in the holidays, devconf.cz, vacations, sorry, picking it up now, together with a Tested-by by Shaokun Zhang, some issues with the formatting of the patch: - Avoid starting lines with '#' as those will vanish when I use 'git am' - Separate the commit log message from the diff using a '---' at the begining of the line, otherwise 'git am' fails I fixed those up now, will test with my build containers, thanks. - Arnaldo > Cheers, > John > > > 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