From nobody Sun Nov 24 06:47:51 2024 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 2B6A91DED74 for ; Thu, 7 Nov 2024 07:16:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730963772; cv=none; b=Di/Uh7qX0h6WcieMfcSn7O5WmEvSbGYtANJxXSsEoRpKLeBwoD2qz9lrOiO7m1CqgBtiuoFFMAMoLNY0c2TCVO8Zx728TAhBf3eonsiOz/mjCsb/Ur7zSQsOlRMtEZTeg1a5JVckMRyAuOqPCNmHzyASRXIxycDf0P/mgeTx/Tw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730963772; c=relaxed/simple; bh=OHfFGp0ifWb+zyyGJptLLNowSsK7ixiaUATGyiRfl38=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=gEYAR+1hPC+QlpDsUkihd6gTaxqO482u7MjJrDAZRTJv1raevcXNZn39ZuNRdTcHOjrbHGOVQKV4rlgid/Y1lC9JVbghj1u4aGx7M/ehb9F44oMPmC5A0biUjH+KfjOjnooBOyW3zjT5dRPuyhodQUeE7Z9DWkMI98LeWhFXIvk= 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=sNZAJK3A; arc=none smtp.client-ip=209.85.219.201 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="sNZAJK3A" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e330f65bcd9so1073595276.1 for ; Wed, 06 Nov 2024 23:16:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730963770; x=1731568570; 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=sNZAJK3AWcEnfVeBJZ/b3Lr8LNM7UUyZUuCc8LmfxkApGLDORxS1mAAnCrrd9qdzjG iFUhbNwhPgM+DRMAla6GeS+1nMZh1o//OT7JC8BcBjjT7tfBma1Tp+uEZp1h6SM3zTQr 5M38fQSjkH7gfBplmwsAK8DChBWrcvXVOXp9v8VSwcLNn18Y4ZXpHkMrDAdnmWcL6J3D qmQY/c7YSw/ohX/rkQo7gXfpybJANHEx6rZAzf7lAZoSZheqUfab9CnR5RxcScGMCyRe naCxl+xoKPsmTHH/ORvM6roALAD6l8MqYm9z+NyiA2vvF9HKjRPfxkyQEFW1W15kE+a8 cpiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730963770; x=1731568570; 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=aiChiUhGG+YOcX9a7UApOaYs5rrTTYvJcA+grGTckK9wsIkZvBUKGVrIdQTF8prcG8 aIAvpmSmyFuWWKj32CzSl2vvDEQ1HDZjnz7jMKfqGlAkXg8SboJFbfrgAQlEYmLDwwou /QaAKiw9vZguV+7c4Ym/u9FyCWjVKRXWx9hhL29n2t4kxkf0KAS7efKjXfU2GMduwW42 XJn6S6IosP9LCD+E4M+eBtbn2LXA8feF6PU93korUWt5BqolOwAUB/pp3VorZe3neIDY 0ouMN48maSMbox93e2aYG/2+N2XXh5Ge9LFeIoQwRdTZLd62x5uUf+4crIKGzBhscTne ioSw== X-Forwarded-Encrypted: i=1; AJvYcCU3Yf8cHCtZVmkGCRA2kbu9pjnDgNL54B8QvTC1OouXigzlkAVyz9rpKDDbZm/evzCc7HUkiGmOHx7u6fs=@vger.kernel.org X-Gm-Message-State: AOJu0Yz5cE2XZIdvYAsMd4tA9IlDkVumKY1oJtb03DuamaLXZIZDwsao wvBoJgXcC4MOzfHGJQYu65OD6k2XscNZGrdmL29ivTmaw9rbbAQRpHVLsvEnHmi28lzwjb6JYk8 WQAkTyA== X-Google-Smtp-Source: AGHT+IG3hd8yCeGAX7h4k6RVex8boUD3HvG3dEWbSWvGpSoN2fs9Bh/9yh9W9X2pTJW73xmM0xEe1Jlq71HY X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc7:bda:7167:18d8]) (user=irogers job=sendgmr) by 2002:a25:901:0:b0:e2e:2c2e:277b with SMTP id 3f1490d57ef6-e33691e2433mr5319276.3.1730963770308; Wed, 06 Nov 2024 23:16:10 -0800 (PST) Date: Wed, 6 Nov 2024 23:15:56 -0800 In-Reply-To: <20241107071600.9082-1-irogers@google.com> Message-Id: <20241107071600.9082-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241107071600.9082-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Subject: [PATCH v1 3/7] 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