From nobody Sun Nov 24 03:53:09 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F53A218D75 for ; Thu, 7 Nov 2024 16:20:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730996451; cv=none; b=BVMHiSjicmSlflFu9AJ6zy/keF/FqGmxBk6gznGEu0ex2rdx0MIK3BZ3/Nb/uhHcXkyuP2/zCY5/481aHvc88c4ULydVLgrRFpYF+Tj3p4GCzqiFKj2+obfDlXShB43w+/oVQ3O+hJtyPNxBFST3urpqtASJcRqHcwMf/+9+QII= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730996451; c=relaxed/simple; bh=OHfFGp0ifWb+zyyGJptLLNowSsK7ixiaUATGyiRfl38=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=MiR59uKu8S5FyYThSiahwAQ4quLGpSBeFG6yLtk7inAfTv7aVx3PhZcAbNkpvrkdHFxpqNE1jzBuIOaWAEgHwZQT9neqzOIkco4XHnleCRrzHmPfVNRlSnWssT/kqdhv7KTuapj4Wxk34Lf3D4p0oWBmn9PdBUUvi8X2K6xB9K4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=OaglWSka; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OaglWSka" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e30df208cadso2753780276.0 for ; Thu, 07 Nov 2024 08:20:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730996449; x=1731601249; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=cITlh9ATOoPVTRO1t6obQAYHyRTBK7FrpPuOEFqdekQ=; b=OaglWSkaljUPgg4eVEsSCQX2Nr0aFgb5yZ9D7HsF+RpKKsdiEFay1LmjPh+7atoe/T IFkRb1uLrX7pA4TnAOf79eNM7ILpg1vPfgX5y5QDfEy2R6AUN0EFAUAh7G1eq0gc8Fb+ ICyjm0qHw9DvHfrX8svdw3G5gWgjgbkF4xTLHl2Stth7hnohWcM/p/VvEeANKzB32sXB tmtQl+zuXue6o7p1k2K51+JnvYdBz7vjfarlkcJzdxrLusQDQveVMGEen5zexJ9CjHRF dpRhjp7aOLJscmb02417GG+hZoO9vSgtbE736exp7WqoK4XA5FAo1U+4Wcozws7SK26k cbsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730996449; x=1731601249; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cITlh9ATOoPVTRO1t6obQAYHyRTBK7FrpPuOEFqdekQ=; b=YfRO0E3DqPCp32pWWz0jHEjp/xCLyFOG98gUsyaY5nitdQKX7PNH/15mnPq1cdk1rY olsQj/GtqxYcmPc6H7vTfE9xZR+nKuuEaLaIdH+HAJLoDvEq7PKEO9CcsaoTAez+i3WM JXc9mW9JsVxKOHG3Cu4+ID6mHk8SB3q79hfBQQM7oPH1YRC9tWmMJjT6yzVG4bey7Lj3 dgos9/YKVqy7xvg5fyHks5L8dt9VpQS6EIoT7CUiXcWOhvjXHAjSBnqzNaf6JRsEkDon ZRY6gkn98+Xk3UHZanY5zevFN5qeQFr4lbqtTuetNAA2+Rmcui8G6TB+p1zm5zw/8Obp GxcQ== X-Forwarded-Encrypted: i=1; AJvYcCUa3qQ73wYh3HMtspTxY+6xsDyqbOGmaNh6vBSc9LpaxZ//8evBQrSPiuc3fWs1yYBGNwC4WqJSBV3tCfw=@vger.kernel.org X-Gm-Message-State: AOJu0YyACHI3me0ET1mjrM+3r2AgyRpSNCkMcQs8HSoG1W2g3fM0Qr1q dqR+SBjciZzWT8rn2UfFN5zdnEh/4VqYH+gtKS/zqpuzoW3dWIO20Wcc/pLUgBnpDsq2VkD0C4i pGAYpAA== X-Google-Smtp-Source: AGHT+IG1fNyhU6PNjCD8QiB4AIaYMuHJ0Ff8pcK56s0BAFMRxuWOpx7ZU0605y5qL9fF+7F7l6kf2Vho1N3/ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc7:bda:7167:18d8]) (user=irogers job=sendgmr) by 2002:a25:ef08:0:b0:e26:3788:9ea2 with SMTP id 3f1490d57ef6-e337e037c8emr122276.0.1730996449164; Thu, 07 Nov 2024 08:20:49 -0800 (PST) Date: Thu, 7 Nov 2024 08:20:31 -0800 In-Reply-To: <20241107162035.52206-1-irogers@google.com> Message-Id: <20241107162035.52206-5-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241107162035.52206-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Subject: [PATCH v2 4/8] perf arm64 header: Use cpu argument in get_cpuid From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Huacai Chen , Bibo Mao , Athira Rajeev , Ben Zong-You Xie , Alexandre Ghiti , Sandipan Das , Benjamin Gray , Xu Yang , Ravi Bangoria , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Yicong Yang , "Masami Hiramatsu (Google)" , Dima Kogan , "Dr. David Alan Gilbert" , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the cpu to read the MIDR file requested. If the "any" value (-1) is passed that keep the behavior of returning the first MIDR file that can be read. Signed-off-by: Ian Rogers --- tools/perf/arch/arm64/util/header.c | 63 ++++++++++++++--------------- tools/perf/util/header.h | 1 + 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/tools/perf/arch/arm64/util/header.c b/tools/perf/arch/arm64/ut= il/header.c index 760c21784713..f0907daad3ae 100644 --- a/tools/perf/arch/arm64/util/header.c +++ b/tools/perf/arch/arm64/util/header.c @@ -14,55 +14,52 @@ #define MIDR_REVISION_MASK GENMASK(3, 0) #define MIDR_VARIANT_MASK GENMASK(23, 20) =20 -static int _get_cpuid(char *buf, size_t sz, struct perf_cpu_map *cpus) +static int _get_cpuid(char *buf, size_t sz, struct perf_cpu cpu) { + char path[PATH_MAX]; + FILE *file; const char *sysfs =3D sysfs__mountpoint(); - struct perf_cpu cpu; - int idx, ret =3D EINVAL; =20 + assert(cpu.cpu !=3D -1); if (!sysfs || sz < MIDR_SIZE) return EINVAL; =20 - perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - char path[PATH_MAX]; - FILE *file; - - scnprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d" MIDR, - sysfs, cpu.cpu); - - file =3D fopen(path, "r"); - if (!file) { - pr_debug("fopen failed for file %s\n", path); - continue; - } - - if (!fgets(buf, MIDR_SIZE, file)) { - fclose(file); - continue; - } - fclose(file); + scnprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d" MIDR, sysfs, cpu.= cpu); =20 - /* got midr break loop */ - ret =3D 0; - break; + file =3D fopen(path, "r"); + if (!file) { + pr_debug("fopen failed for file %s\n", path); + return EINVAL; } =20 - return ret; + if (!fgets(buf, MIDR_SIZE, file)) { + pr_debug("Failed to read file %s\n", path); + fclose(file); + return EINVAL; + } + fclose(file); + return 0; } =20 -int get_cpuid(char *buf, size_t sz, struct perf_cpu cpu __maybe_unused) +int get_cpuid(char *buf, size_t sz, struct perf_cpu cpu) { - struct perf_cpu_map *cpus =3D perf_cpu_map__new_online_cpus(); - int ret; + struct perf_cpu_map *cpus; + int idx; + + if (cpu.cpu !=3D -1) + return _get_cpuid(buf, sz, cpu); =20 + cpus =3D perf_cpu_map__new_online_cpus(); if (!cpus) return EINVAL; =20 - ret =3D _get_cpuid(buf, sz, cpus); - - perf_cpu_map__put(cpus); + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { + int ret =3D _get_cpuid(buf, sz, cpu); =20 - return ret; + if (ret =3D=3D 0) + return 0; + } + return EINVAL; } =20 char *get_cpuid_str(struct perf_pmu *pmu) @@ -78,7 +75,7 @@ char *get_cpuid_str(struct perf_pmu *pmu) return NULL; =20 /* read midr from list of cpus mapped to this pmu */ - res =3D _get_cpuid(buf, MIDR_SIZE, pmu->cpus); + res =3D get_cpuid(buf, MIDR_SIZE, perf_cpu_map__min(pmu->cpus)); if (res) { pr_err("failed to get cpuid string for PMU %s\n", pmu->name); free(buf); diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index b77f89de12dd..3bb768455a60 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h @@ -11,6 +11,7 @@ #include #include "env.h" #include "pmu.h" +#include =20 enum { HEADER_RESERVED =3D 0, /* always cleared */ --=20 2.47.0.199.ga7371fff76-goog