From nobody Sun Nov 24 01:46:01 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 E0CF9217320 for ; Thu, 7 Nov 2024 16:20:43 +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=1730996445; cv=none; b=cCSnGjdlOeD+nxc23ir7h4BY1/glRxGefkLMo4YwVvGHqRy24qS6gQDcajQotf0v//Il0NpBNFD+7HJ5cYdldS1Aal0itjY9/w6WPxnu61kD336HoFHJiyDyTHUL7nQXWCyStC6dHCAzzwMR1/+mgWB+DCke5XVRoC8NAJIB6rI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730996445; c=relaxed/simple; bh=OQ+ILS6ZdIDbpDd6fnm+5OYFklVHCZ8ERtWBLEZnFyg=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=LWw2WkNUX8beA2Np/9wQDbD6nQiAAvfuPVYBKKf+2NohM3Y8hbVvlOrfqrA87OoxAaciHFccwjPX/DIX//IxIhCBq2McpqA2B+Db8oPGzTDrDtpFpzHrh9pQAJtcJDTRgrqrg2UrAr0QfO1vTtRRnieooJWEkJQfBBJFTAxVtFM= 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=zUcVm2ZX; 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="zUcVm2ZX" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e32ff6f578eso2897818276.1 for ; Thu, 07 Nov 2024 08:20:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730996443; x=1731601243; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6Zi7/BGIzk4kmPbaIIn5N5Q89D8reWg5dpAnu28NGJw=; b=zUcVm2ZXhGnSypH0GLkeSotuc0HUk4N/11XDq7hA1rvqRRCuts+swxtmwH8mby9NYG FjPmoUKFr7AYaBUm+ridTTXCuC0L5AzkyI2y171yuta8Nem/IG+AQX5jvIMSv0de6LEd 1hs2CfsGXyalmc5dPq7VBzh6/W+r+vzlV4N8DAOtavaWVaLt9lmX5FqpgvkHjpRXsXAx Oi1WgYyrmu4beez7OADsPLKcUDMKTbGRilw5olJeN+/bagoRtc0ZXgbe+6wcLiDKri6I XrMs5M6mE3VS7jtwNBZfw5FE3xP8nAjxru+zbvP8riHx4UVz5gbFjkrOy3xTAafQw/45 uEug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730996443; x=1731601243; h=cc: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=6Zi7/BGIzk4kmPbaIIn5N5Q89D8reWg5dpAnu28NGJw=; b=I4sd1KQu1Z7RTafiimg5erKyCF5EedOt+TcOhhWsCBnIUu87bInQViePvePHOfR4iR 8ljVY61Evl22HQJFOxqeS5vrGAX/4xQVhXl5WSbZv/MLd54LhZ40rXRFhzUUJFQ276l3 mZAusNcPWGRMlgY8GwPCqx+imvUur8g9kGsRPFReQ9l+a4RJMd/+fTy3/C8MlQEBAffy log/BEFKj2lV5ClxhS0MyItOcU5wgw93ZwdD9vp5BCGN7XWKHJgROe1SjUMi4EOQGgj/ O9b4P3rUvJkAyQ7c2S7Os63uS3EO2lvO7w2QUFAhOynHzZRFhHKk45jNsg3wo4j7OBii kiGA== X-Forwarded-Encrypted: i=1; AJvYcCXgVrx1xN5fvuUJ9wEJTN2M4DyYdc+2CZ2QV1laDEudtRIgWUIOL8qfICvFtQRao6zlGK6ghAw7mnWwWXY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8h2joUczFk6ga9wUwGkUoOUWfbi6dSACvCFWJyhX7+Yvmuvj+ E43pG5SUWa1hKNkY0q9VkdeozVMBT6O2pY3b6IpjD152nwXnXLi6XC7fRvVGNZdT16CNulb6eCc sIhM43Q== X-Google-Smtp-Source: AGHT+IH0/hEWrV52DVmrj7Z6n0WIT9Ut3IVouygX8jmB/XLHKPkNRIO9up6ksFd2vuXYZmCZkrEILwBAMRRP X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc7:bda:7167:18d8]) (user=irogers job=sendgmr) by 2002:a25:d843:0:b0:e29:7454:e773 with SMTP id 3f1490d57ef6-e337e1d738cmr33276.5.1730996442881; Thu, 07 Nov 2024 08:20:42 -0800 (PST) Date: Thu, 7 Nov 2024 08:20:28 -0800 In-Reply-To: <20241107162035.52206-1-irogers@google.com> Message-Id: <20241107162035.52206-2-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 1/8] perf jevents: fix breakage when do perf stat on system metric 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 Cc: stable@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xu Yang When do perf stat on sys metric, perf tool output nothing now: $ perf stat -a -M imx95_ddr_read.all -I 1000 $ This command runs on an arm64 machine and the Soc has one DDR hw pmu except one armv8_cortex_a55 pmu. Their maps show as follows: const struct pmu_events_map pmu_events_map[] =3D { { .arch =3D "arm64", .cpuid =3D "0x00000000410fd050", .event_table =3D { .pmus =3D pmu_events__arm_cortex_a55, .num_pmus =3D ARRAY_SIZE(pmu_events__arm_cortex_a55) }, .metric_table =3D { .pmus =3D NULL, .num_pmus =3D 0 } }, static const struct pmu_sys_events pmu_sys_event_tables[] =3D { { .event_table =3D { .pmus =3D pmu_events__freescale_imx95_sys, .num_pmus =3D ARRAY_SIZE(pmu_events__freescale_imx95_sys) }, .metric_table =3D { .pmus =3D pmu_metrics__freescale_imx95_sys, .num_pmus =3D ARRAY_SIZE(pmu_metrics__freescale_imx95_sys) }, .name =3D "pmu_events__freescale_imx95_sys", }, Currently, pmu_metrics_table__find() will return NULL when only do perf stat on sys metric. Then parse_groups() will never be called to parse sys metric_name, finally perf tool will exit directly. This should be a common problem. To fix the issue, this will keep the logic before commit f20c15d13f01 ("perf pmu-events: Remember the perf_events_map for a PMU") to return a empty metric table rather than a NULL pointer. This should be fine since the removed part just check if the table match provided metric_name. Without these code, the code in parse_groups() will also check the validity of metrci_name too. Fixes: f20c15d13f01 ("perf pmu-events: Remember the perf_events_map for a P= MU") Cc: stable@vger.kernel.org Signed-off-by: Xu Yang Acked-by: Ian Rogers Signed-off-by: Ian Rogers Reviewed-by: James Clark Tested-by: Xu Yang --- tools/perf/pmu-events/empty-pmu-events.c | 12 +----------- tools/perf/pmu-events/jevents.py | 12 +----------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-even= ts/empty-pmu-events.c index 2b7516946ded..b8719dab264d 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -585,17 +585,7 @@ const struct pmu_metrics_table *perf_pmu__find_metrics= _table(struct perf_pmu *pm if (!map) return NULL; =20 - if (!pmu) - return &map->metric_table; - - for (size_t i =3D 0; i < map->metric_table.num_pmus; i++) { - const struct pmu_table_entry *table_pmu =3D &map->metric_t= able.pmus[i]; - const char *pmu_name =3D &big_c_string[table_pmu->pmu_name= .offset]; - - if (pmu__name_match(pmu, pmu_name)) - return &map->metric_table; - } - return NULL; + return &map->metric_table; } =20 const struct pmu_events_table *find_core_events_table(const char *arch, co= nst char *cpuid) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jeven= ts.py index 6e71b09dbc2a..70f4fd5395fb 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -1101,17 +1101,7 @@ const struct pmu_metrics_table *perf_pmu__find_metri= cs_table(struct perf_pmu *pm if (!map) return NULL; =20 - if (!pmu) - return &map->metric_table; - - for (size_t i =3D 0; i < map->metric_table.num_pmus; i++) { - const struct pmu_table_entry *table_pmu =3D &map->metric_t= able.pmus[i]; - const char *pmu_name =3D &big_c_string[table_pmu->pmu_name= .offset]; - - if (pmu__name_match(pmu, pmu_name)) - return &map->metric_table; - } - return NULL; + return &map->metric_table; } =20 const struct pmu_events_table *find_core_events_table(const char *arch, co= nst char *cpuid) --=20 2.47.0.199.ga7371fff76-goog From nobody Sun Nov 24 01:46:01 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 25FD1218928 for ; Thu, 7 Nov 2024 16:20:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730996447; cv=none; b=EwP/JKRQteA8OnJ2StK8XC1GAJuByvhkQlZ6rqkgoFvaKjSbiaPbZoFJqzcAIkUVR1cVN4iQVepHvzP+C9NKlLrMn+JoJK4gKV/G+htnSYnDxJq72k1b5ogG9a6WgbZrXyX4EV6JJ//jotgdZDBsf5gKq3sBU1R+9Dz2y+WfOCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730996447; c=relaxed/simple; bh=7oem3ThhepX9gsZkLkU3ubM5v/EmPX06HEqwbDIU+q4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=iDZ6/eT3v9pZ6UP2YwDs0WIKBf2XI3XPy1fGS0NvdEi6nAHOrYUWQeGxbOUxg66pqpD4bdL+EKiBx4hnErrd0a0lbzsWXR/bAa9YIvqYpUOfgAwiFaEQaI7516o2KA+9S0UVN4EaDrO3pSVJN6STK2WQyiwjF06zU4ZxZtxyQuo= 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=bw6IXehJ; arc=none smtp.client-ip=209.85.128.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="bw6IXehJ" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ea8a238068so19814967b3.1 for ; Thu, 07 Nov 2024 08:20:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730996445; x=1731601245; 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=l25I5Jel5U2/0S9AyIDPTs5/QytgoUZMY3CNnmJZTzE=; b=bw6IXehJkYX4+BylYkDNFo3v8i1Zha1jQ7CrufGEmzY7ZL70rx23yE7mh0TG98s9qa WowOS5guH95BGTOKoOvJZ9leIId9buWx1Q+Cpp604ni+ThgEBO5gi8p3FdNDd6sSyOxD u1FqF5Jq8/c0W0zHXNEVjgxhWjwAl2glo2dfS84vpRjAvXlpEUZCPLN5K69rAxK1BEiA JXTAjRw+MsRxMsYS1Tx7/l1Z7XZzJgDyeHqfoOKG6qC4BlKajjGtJr7qIQ/TKtxDiUzW +MkVJUQ+qkCbs1ziswB9+jus9Gp0T1uCicaMg7i/Gqf8YyN+furRmQ+fVqLd1YNkPH08 S1PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730996445; x=1731601245; 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=l25I5Jel5U2/0S9AyIDPTs5/QytgoUZMY3CNnmJZTzE=; b=ZHYMzGWwxviop0+TIEWeE1JtQdlKhAmj7RGqaV0lVdWG/BFnlHIUe99RYkMUk8WV68 1Z+aVgj+0N2WLMLpEX6W8pgmhnmmOILK0+/8lP3VLjeFWCimyEr/o2jw6L/3eiRhqzMa jcVu2muTtD4oORtLkVtzfsYV8Td9SkgqSwBXEsauqXlaR9HxJt532vbvumLdlHJwM9Ic IF5tlDxxDeXwjk8M+OEaH4jj26xYx+P8lFp+L0XBt/cTqzD73eYk0B0U62pczt0hnfPO qVGQ3ezB9/piddmzTTvopLOvdM9xczox2sip626HLuf/WuKldDYS4WKzSdAnJqKv9+RP 2gMA== X-Forwarded-Encrypted: i=1; AJvYcCVaB2JUA6kVmZ2lGaYVswgYRSvmCQKUXc+6a1iLpAHuTZefnxY/MjqjEddVP7wRcb5QCnAheLYYbobvJrc=@vger.kernel.org X-Gm-Message-State: AOJu0YzjgJ08pRTq0xwcGfqecFqipdEp4ajf1PXbu2YcEBVareQxK0Iq k+DlLfYkVbD0UxXDLKmbMVZ/Gjj88USYia/qV7dgTctwRZj5fBB+QqN+vZexcK1IR0jninRVNlK G5jegfg== X-Google-Smtp-Source: AGHT+IFnTI4IcNJ51YDO3rsAiQCbXWeV3EQq6I2FsC+sGE3SpDVNd7WlWxpa52LoAfCUNYpttoUYsg4Abinq X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc7:bda:7167:18d8]) (user=irogers job=sendgmr) by 2002:a05:690c:6313:b0:6e3:6414:80c5 with SMTP id 00721157ae682-6eadbedccc8mr2287b3.0.1730996445083; Thu, 07 Nov 2024 08:20:45 -0800 (PST) Date: Thu, 7 Nov 2024 08:20:29 -0800 In-Reply-To: <20241107162035.52206-1-irogers@google.com> Message-Id: <20241107162035.52206-3-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 2/8] perf header: Move is_cpu_online to numa bench 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" The helper function is only used in the NUMA benchmark as typically online CPUs are determined through perf_cpu_map__new_online_cpus(). Reduce the scope of the function for now. Signed-off-by: Ian Rogers Reviewed-by: James Clark Tested-by: Xu Yang --- tools/perf/bench/numa.c | 53 ++++++++++++++++++++++++++++++++++++++++ tools/perf/util/header.c | 51 -------------------------------------- tools/perf/util/header.h | 1 - 3 files changed, 53 insertions(+), 52 deletions(-) diff --git a/tools/perf/bench/numa.c b/tools/perf/bench/numa.c index 1fbd7c947abc..19be2aaf4dc0 100644 --- a/tools/perf/bench/numa.c +++ b/tools/perf/bench/numa.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -35,6 +36,7 @@ =20 #include "../util/header.h" #include "../util/mutex.h" +#include #include #include =20 @@ -533,6 +535,57 @@ static int parse_cpu_list(const char *arg) return 0; } =20 +/* + * Check whether a CPU is online + * + * Returns: + * 1 -> if CPU is online + * 0 -> if CPU is offline + * -1 -> error case + */ +static int is_cpu_online(unsigned int cpu) +{ + char *str; + size_t strlen; + char buf[256]; + int status =3D -1; + struct stat statbuf; + + snprintf(buf, sizeof(buf), + "/sys/devices/system/cpu/cpu%d", cpu); + if (stat(buf, &statbuf) !=3D 0) + return 0; + + /* + * Check if /sys/devices/system/cpu/cpux/online file + * exists. Some cases cpu0 won't have online file since + * it is not expected to be turned off generally. + * In kernels without CONFIG_HOTPLUG_CPU, this + * file won't exist + */ + snprintf(buf, sizeof(buf), + "/sys/devices/system/cpu/cpu%d/online", cpu); + if (stat(buf, &statbuf) !=3D 0) + return 1; + + /* + * Read online file using sysfs__read_str. + * If read or open fails, return -1. + * If read succeeds, return value from file + * which gets stored in "str" + */ + snprintf(buf, sizeof(buf), + "devices/system/cpu/cpu%d/online", cpu); + + if (sysfs__read_str(buf, &str, &strlen) < 0) + return status; + + status =3D atoi(str); + + free(str); + return status; +} + static int parse_setup_cpu_list(void) { struct thread_data *td; diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index a6386d12afd7..55c28e4377ec 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -987,57 +987,6 @@ static int write_dir_format(struct feat_fd *ff, return do_write(ff, &data->dir.version, sizeof(data->dir.version)); } =20 -/* - * Check whether a CPU is online - * - * Returns: - * 1 -> if CPU is online - * 0 -> if CPU is offline - * -1 -> error case - */ -int is_cpu_online(unsigned int cpu) -{ - char *str; - size_t strlen; - char buf[256]; - int status =3D -1; - struct stat statbuf; - - snprintf(buf, sizeof(buf), - "/sys/devices/system/cpu/cpu%d", cpu); - if (stat(buf, &statbuf) !=3D 0) - return 0; - - /* - * Check if /sys/devices/system/cpu/cpux/online file - * exists. Some cases cpu0 won't have online file since - * it is not expected to be turned off generally. - * In kernels without CONFIG_HOTPLUG_CPU, this - * file won't exist - */ - snprintf(buf, sizeof(buf), - "/sys/devices/system/cpu/cpu%d/online", cpu); - if (stat(buf, &statbuf) !=3D 0) - return 1; - - /* - * Read online file using sysfs__read_str. - * If read or open fails, return -1. - * If read succeeds, return value from file - * which gets stored in "str" - */ - snprintf(buf, sizeof(buf), - "devices/system/cpu/cpu%d/online", cpu); - - if (sysfs__read_str(buf, &str, &strlen) < 0) - return status; - - status =3D atoi(str); - - free(str); - return status; -} - #ifdef HAVE_LIBBPF_SUPPORT static int write_bpf_prog_info(struct feat_fd *ff, struct evlist *evlist __maybe_unused) diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index a63a361f20f4..e91e89d22537 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h @@ -196,7 +196,6 @@ int write_padded(struct feat_fd *fd, const void *bf, =20 #define MAX_CACHE_LVL 4 =20 -int is_cpu_online(unsigned int cpu); int build_caches_for_cpu(u32 cpu, struct cpu_cache_level caches[], u32 *cn= tp); =20 /* --=20 2.47.0.199.ga7371fff76-goog From nobody Sun Nov 24 01:46:01 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 244B521894A for ; Thu, 7 Nov 2024 16:20:47 +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=1730996449; cv=none; b=jSI90vN4zNyCmC4cWkpCbXkYT3+G0Nf+/4mmJNxmXUXuvrtQ0Eg7mrqRK0vCrYUw1lI3lT/SugLwN76sQ0+R0Df4moEbZUQiXxFHUWT6PB8Zo6Ngjadcup6AhfJGyD9ORqFgt8uO7na9l473OrLC/C+H+gPK0X/edWRxK8aJZQk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730996449; c=relaxed/simple; bh=UGgs7qpyQsaOAD/+38PffSoTksURxSZGP6Fxx9r4zHE=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=h0FXcGItQypk9Q7ftuIpeq0/fVGElyof5boR6LxcMZwyaZvXi6TqtJbsIvUeinIfpkUN7X6U+zEPbghETDfKbF/z8+yuHdTf2Dsdi4p4Yb6ldgwOKDKzbs23N+9YVnWK3tPg8IvLw6KLRxUjQCUEKyaYfXiUKR/qwytg/A/327Y= 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=rDKcSvbv; 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="rDKcSvbv" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e2954ada861so2000332276.3 for ; Thu, 07 Nov 2024 08:20:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730996447; x=1731601247; 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=QeV5H6hULi4PmNWhXYnKicIpV1Vf/5KV4yP0bFilR2g=; b=rDKcSvbvM083GVA9yBW6NxSP+6ueGE08VbwHqnkxkWtv0EOIE/SwlAg4pbqVCbYO73 NEpB/TZ2/nDamaKLgdFf96h5kmt9Us4PhNZhlGDwbJQLZJuXacQ87eYh8PYpaWNh0dzQ /SbB0tiUYHfGll/odbtn4IWY4kGhvvazJuEV9t7Dgs/3NjzraDnp76bOHyY6bX2Lyd4S z0hQ6UFe5SIczg94515OxBsVV7F4Oc2zDQwbMNkaCFoQ2SLKoF2XkPgb4BnltBtXA6JX l5L6sqBSEXyMcdQXcYweWuLUYShNq6q90xy2ZR5zaRDkNUHVCdVODW6rv4G4U7UoyH1H x5dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730996447; x=1731601247; 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=QeV5H6hULi4PmNWhXYnKicIpV1Vf/5KV4yP0bFilR2g=; b=QNRs4WmoduPVCNXAaYntTupgUGr8nxcIHtRxRGmRB/0oe9+d+P35Qrm+4u4AyXstex Obql8NNeO2ZhSREd6TLgbSk4SqqbHrXCS8Xo/2HSx2E9/oppIeb4YiMeMnmCFBaoLDAx 8f8A+EiVg5QT0rhJsIpf/4By/caqpH62k1lcUAAlpi+ezITew28BlIUqZS6cVL5y8xxM QIbddqYkceuMGcr6SafEcjtA3206U2/gLX83FQUZobME5W23QXeArk7lp+KEIgjCU0Xi qVwWJ3QbcZZECgxBMgAhm7f5Z8c2hJgweqXR+Yz6onb8bpznu/uRd1riUILl+F+7OTWq 59/w== X-Forwarded-Encrypted: i=1; AJvYcCVCIf7fowLAJ76U2oqpNs+cl90LRURGbAzCLqvgemzaCC70au29QOLO1SQazoBJMEoIxeGi4IeDZ/Y40rM=@vger.kernel.org X-Gm-Message-State: AOJu0YwIgF6APIgupNN/trcoCygRI6ebLX9snw7vrKr2sOonFtpn5993 nmcWtTfNGLlEhYBqR6ChBMxC6eZ7C/IYLOswUVT3PdGsJjU30noHpki66N3M1RPrVPL9PBi19FN +EjfrXA== X-Google-Smtp-Source: AGHT+IGjhnQlyx60uwo4p9IkAZDT92KIybjWbIW3SuIDxmWBljHRgORYz+qbzqRTmwlk3UFalbtBGeNtiEp3 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc7:bda:7167:18d8]) (user=irogers job=sendgmr) by 2002:a25:8382:0:b0:e2b:ce2f:787a with SMTP id 3f1490d57ef6-e3087a603e2mr94177276.3.1730996447029; Thu, 07 Nov 2024 08:20:47 -0800 (PST) Date: Thu, 7 Nov 2024 08:20:30 -0800 In-Reply-To: <20241107162035.52206-1-irogers@google.com> Message-Id: <20241107162035.52206-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: <20241107162035.52206-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Subject: [PATCH v2 3/8] perf header: Refactor get_cpuid to take a CPU for ARM 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" ARM BIG.little has no notion of a constant CPUID for both core types. To reflect this reality, change the get_cpuid function to also pass in a possibly unused logical cpu. If the dummy value (-1) is passed in then ARM can, as currently happens, select the first logical CPU's "CPUID". The changes to ARM getcpuid happen in a follow up change. Signed-off-by: Ian Rogers Reviewed-by: James Clark Tested-by: Xu Yang --- tools/perf/arch/arm64/util/header.c | 2 +- tools/perf/arch/loongarch/util/header.c | 2 +- tools/perf/arch/powerpc/util/header.c | 2 +- tools/perf/arch/riscv/util/header.c | 2 +- tools/perf/arch/s390/util/header.c | 2 +- tools/perf/arch/x86/util/auxtrace.c | 3 ++- tools/perf/arch/x86/util/header.c | 2 +- tools/perf/builtin-kvm.c | 4 +++- tools/perf/util/env.c | 3 ++- tools/perf/util/header.c | 9 +++++---- tools/perf/util/header.h | 2 +- 11 files changed, 19 insertions(+), 14 deletions(-) diff --git a/tools/perf/arch/arm64/util/header.c b/tools/perf/arch/arm64/ut= il/header.c index 741df3614a09..760c21784713 100644 --- a/tools/perf/arch/arm64/util/header.c +++ b/tools/perf/arch/arm64/util/header.c @@ -50,7 +50,7 @@ static int _get_cpuid(char *buf, size_t sz, struct perf_c= pu_map *cpus) return ret; } =20 -int get_cpuid(char *buf, size_t sz) +int get_cpuid(char *buf, size_t sz, struct perf_cpu cpu __maybe_unused) { struct perf_cpu_map *cpus =3D perf_cpu_map__new_online_cpus(); int ret; diff --git a/tools/perf/arch/loongarch/util/header.c b/tools/perf/arch/loon= garch/util/header.c index d962dff55512..f1f0b116962d 100644 --- a/tools/perf/arch/loongarch/util/header.c +++ b/tools/perf/arch/loongarch/util/header.c @@ -70,7 +70,7 @@ static char *_get_cpuid(void) return cpuid; } =20 -int get_cpuid(char *buffer, size_t sz) +int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused) { int ret =3D 0; char *cpuid =3D _get_cpuid(); diff --git a/tools/perf/arch/powerpc/util/header.c b/tools/perf/arch/powerp= c/util/header.c index 251cdbf58a4d..6d1a63a2922f 100644 --- a/tools/perf/arch/powerpc/util/header.c +++ b/tools/perf/arch/powerpc/util/header.c @@ -24,7 +24,7 @@ static bool is_compat_mode(void) } =20 int -get_cpuid(char *buffer, size_t sz) +get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused) { unsigned long pvr; int nb; diff --git a/tools/perf/arch/riscv/util/header.c b/tools/perf/arch/riscv/ut= il/header.c index 1b29030021ee..ebac294c877f 100644 --- a/tools/perf/arch/riscv/util/header.c +++ b/tools/perf/arch/riscv/util/header.c @@ -81,7 +81,7 @@ static char *_get_cpuid(void) return cpuid; } =20 -int get_cpuid(char *buffer, size_t sz) +int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused) { char *cpuid =3D _get_cpuid(); int ret =3D 0; diff --git a/tools/perf/arch/s390/util/header.c b/tools/perf/arch/s390/util= /header.c index 7933f6871c81..2add1a561242 100644 --- a/tools/perf/arch/s390/util/header.c +++ b/tools/perf/arch/s390/util/header.c @@ -27,7 +27,7 @@ #define SYSINFO "/proc/sysinfo" #define SRVLVL "/proc/service_levels" =20 -int get_cpuid(char *buffer, size_t sz) +int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused) { char *cp, *line =3D NULL, *line2; char type[8], model[33], version[8], manufacturer[32], authorization[8]; diff --git a/tools/perf/arch/x86/util/auxtrace.c b/tools/perf/arch/x86/util= /auxtrace.c index 354780ff1605..ecbf61a7eb3a 100644 --- a/tools/perf/arch/x86/util/auxtrace.c +++ b/tools/perf/arch/x86/util/auxtrace.c @@ -55,11 +55,12 @@ struct auxtrace_record *auxtrace_record__init(struct ev= list *evlist, int *err) { char buffer[64]; + struct perf_cpu cpu =3D perf_cpu_map__min(evlist->core.all_cpus); int ret; =20 *err =3D 0; =20 - ret =3D get_cpuid(buffer, sizeof(buffer)); + ret =3D get_cpuid(buffer, sizeof(buffer), cpu); if (ret) { *err =3D ret; return NULL; diff --git a/tools/perf/arch/x86/util/header.c b/tools/perf/arch/x86/util/h= eader.c index a51444a77a5f..690f86cbbb1c 100644 --- a/tools/perf/arch/x86/util/header.c +++ b/tools/perf/arch/x86/util/header.c @@ -58,7 +58,7 @@ __get_cpuid(char *buffer, size_t sz, const char *fmt) } =20 int -get_cpuid(char *buffer, size_t sz) +get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused) { return __get_cpuid(buffer, sz, "%s,%u,%u,%u$"); } diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 099ce3ebf67c..274568d712d1 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -1226,7 +1226,9 @@ static int cpu_isa_config(struct perf_kvm_stat *kvm) int err; =20 if (kvm->live) { - err =3D get_cpuid(buf, sizeof(buf)); + struct perf_cpu cpu =3D {-1}; + + err =3D get_cpuid(buf, sizeof(buf), cpu); if (err !=3D 0) { pr_err("Failed to look up CPU type: %s\n", str_error_r(err, buf, sizeof(buf))); diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index ccb464026642..93cabdd7ff43 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -373,7 +373,8 @@ int perf_env__read_pmu_mappings(struct perf_env *env) int perf_env__read_cpuid(struct perf_env *env) { char cpuid[128]; - int err =3D get_cpuid(cpuid, sizeof(cpuid)); + struct perf_cpu cpu =3D {-1}; + int err =3D get_cpuid(cpuid, sizeof(cpuid), cpu); =20 if (err) return err; diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 55c28e4377ec..60b42ddc3dac 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -856,18 +856,19 @@ int __weak strcmp_cpuid_str(const char *mapcpuid, con= st char *cpuid) * default get_cpuid(): nothing gets recorded * actual implementation must be in arch/$(SRCARCH)/util/header.c */ -int __weak get_cpuid(char *buffer __maybe_unused, size_t sz __maybe_unused) +int __weak get_cpuid(char *buffer __maybe_unused, size_t sz __maybe_unused, + struct perf_cpu cpu __maybe_unused) { return ENOSYS; /* Not implemented */ } =20 -static int write_cpuid(struct feat_fd *ff, - struct evlist *evlist __maybe_unused) +static int write_cpuid(struct feat_fd *ff, struct evlist *evlist) { + struct perf_cpu cpu =3D perf_cpu_map__min(evlist->core.all_cpus); char buffer[64]; int ret; =20 - ret =3D get_cpuid(buffer, sizeof(buffer)); + ret =3D get_cpuid(buffer, sizeof(buffer), cpu); if (ret) return -1; =20 diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index e91e89d22537..b77f89de12dd 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h @@ -201,7 +201,7 @@ int build_caches_for_cpu(u32 cpu, struct cpu_cache_leve= l caches[], u32 *cntp); /* * arch specific callback */ -int get_cpuid(char *buffer, size_t sz); +int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu); =20 char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused); int strcmp_cpuid_str(const char *s1, const char *s2); --=20 2.47.0.199.ga7371fff76-goog From nobody Sun Nov 24 01:46:01 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 Reviewed-by: James Clark Tested-by: Xu Yang --- 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 From nobody Sun Nov 24 01:46:01 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 89A41218D9C for ; Thu, 7 Nov 2024 16:20:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730996454; cv=none; b=k0LsZD+XJ5ji4FoFqsyKKbirj/Q3JZiqiBvStBlmwB/J+VCXCDCpXtceUZLKoGomlcMi6AXzOikA+ktdYaYZwobGHjAWj/XeFSMywhzg8TUjODEdN/xcBEd87wz4jx7+VrQYAiDk0cfyg/nGmHQPPLiGREugjrSSdCWP2VE2q4A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730996454; c=relaxed/simple; bh=Y+vKqYUCxSTt4LSzTKZWPT5tUEvVlBLoT2ItWD2c1T0=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=HkIx4cgnSI5fVWXs2Cmy6gs/+dz+2vmJ+NHTXKUyBXlqdMUi9dJBMIYU+7gVqX1eNxH6nwKNgBjfn+17bm2TYUaaK2d0IcvnS0fAVIMgIpIfrvME86Zs+k5rrJKJU0WAPM1j3eAkIJ6mgmwrQuyys/qf7CKHcZYaCrA+e4VXvHE= 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=TigUJTlb; arc=none smtp.client-ip=209.85.128.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="TigUJTlb" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e32e8436adso15600147b3.0 for ; Thu, 07 Nov 2024 08:20:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730996451; x=1731601251; 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=0JtSX1ivElzP67Gy896L9Ack6oYznxDX7izzc96bZIU=; b=TigUJTlbcdzBY865SF6TLU6X/36VeQI3ZTNC4uTDQZFQJYYJkBAxuRx+K+f53SMgfy t7Qi+YTKICuy5pqQAVs/c3FSG7HXbGWHzf/AdzQARPhEs4QoLJPryQ7lBT7AKdDL8T7F genJS5hKBtSIeDfiNcdBeAK/STK80P2STSnZ/xdMPILTQeufTAOJeh77yW6jXaHBS5PA AlWsBIXijR346CfOlXArkF71uVPe+utcp/QneDZ0Q/GJF2kAsmHD4GOT4i3yUzXLAAbu QrY2Slc7YSTTH+iiJ4U+bA7g2lEVEuhjscL8heV+o4BpqC9Pu5hiXKiPHG+w3VhQBUq5 LQvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730996451; x=1731601251; 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=0JtSX1ivElzP67Gy896L9Ack6oYznxDX7izzc96bZIU=; b=FZLIuLoRE2oHollGvNne5DXGOxE7j5iRFGaKa6zhYBNKIztmLmOHh7Gve5vY0DMRDB iCOv7Bdqx3eD4eyosPXAgVWAZv1ePWY7mHqdHOgCVEp4TOMrG013pdup7GdbOdLhUl+n TSWMon5iyspSDvhl7PcnzIf+vG1WjnzIb0oWKVOrVAkf1RD1zenW9ybaMHCBLP2Oin+9 Tc9HwwAJHmy53z4FZnExsH+cm1dIpecGhRkLo8e6VLp0lYMHyTLRue5j0OyPAfWEcYH3 w5z2qaCt1WJ3GHHPqWWmw1YoYi5Vt4zi4GTHFxZw/HBFoT6aVd/l3JErC1fbAQlqxyf1 O8zA== X-Forwarded-Encrypted: i=1; AJvYcCV65a1NbbyLfUbSbCI+aFgOFJTSG40cHSNX2pG5e/GNUZNjdCXYJhWUio9DtgHA9LqSiBCZ3cJsIn8aRWc=@vger.kernel.org X-Gm-Message-State: AOJu0YyLciVgVBHSMCuvWV2o3dRY6DS9qkDRi75td2T8swoWI3yJ6uNE sf/DFt93cuxSF8dcRTyI4lZKCKLDg0sINDwLdz3/0FUi5RwijEviIAahuoHKBKJrFqGc2osuW/F JWwlNXQ== X-Google-Smtp-Source: AGHT+IE0rx0KSxGHx6soYbCIVed3oUzDZtt0AEkgb4Fc4ntlPFe4VEdCSprC19W+Uf9rSJ3fRj2/Oar0I4CM X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc7:bda:7167:18d8]) (user=irogers job=sendgmr) by 2002:a81:a788:0:b0:6e3:14c3:379a with SMTP id 00721157ae682-6eadbe8b9c4mr2657b3.0.1730996451467; Thu, 07 Nov 2024 08:20:51 -0800 (PST) Date: Thu, 7 Nov 2024 08:20:32 -0800 In-Reply-To: <20241107162035.52206-1-irogers@google.com> Message-Id: <20241107162035.52206-6-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 5/8] perf header: Avoid transitive PMU includes 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" Currently satisfied via header.h. Note, pmu.h includes parse-events.h. Signed-off-by: Ian Rogers Reviewed-by: James Clark Tested-by: Xu Yang --- tools/perf/tests/expr.c | 2 ++ tools/perf/util/env.c | 1 + tools/perf/util/probe-event.c | 1 + 3 files changed, 4 insertions(+) diff --git a/tools/perf/tests/expr.c b/tools/perf/tests/expr.c index e3aa9d4fcf3a..d60f1ac1d720 100644 --- a/tools/perf/tests/expr.c +++ b/tools/perf/tests/expr.c @@ -4,6 +4,8 @@ #include "util/expr.h" #include "util/hashmap.h" #include "util/header.h" +#include "util/pmu.h" +#include "util/pmus.h" #include "util/smt.h" #include "tests.h" #include diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 93cabdd7ff43..e2843ca2edd9 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -12,6 +12,7 @@ #include #include #include +#include "pmu.h" #include "pmus.h" #include "strbuf.h" #include "trace/beauty/beauty.h" diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index a580aa2cd512..d399c7e03341 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -40,6 +40,7 @@ #include "session.h" #include "string2.h" #include "strbuf.h" +#include "parse-events.h" =20 #include #include --=20 2.47.0.199.ga7371fff76-goog From nobody Sun Nov 24 01:46:01 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 05FD82194AD for ; Thu, 7 Nov 2024 16:20:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730996457; cv=none; b=JQ3MakOJeR8ou/VeUhv2suUxUaLxD8CmM5jQkF5i6gM5PIVNdtUCRrX0d/KNVOvyDk84D1PMuHkXFC7OuL31FnwoGPK8eFYxD3/ZLQ9xhP3/+NBiXwtjD6TEcTP2KOx7ABpESQOJdnixiairhRyhqys+nMadwYX8hKH0aLbEQhI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730996457; c=relaxed/simple; bh=9EF1TGVg1ZOZB+TPo+1DL+h3b5xxvM3S9FrE7MOPldw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=hn8qNfLv295QrShFU2oXlzbT7rLE62pIUwIkui7ePlhXp1venmlh+AaY4z74Np/CRWn6ov5JEao0wn/VS0BLK05TgZvFwNuf45ga9lLpFFyMkW7Zf1ZlPWDTGha4TA0j5uIrV0oawPvZ21ULkCez8nqMCALEmIIQwB4eahvalPE= 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=DAG82vN2; arc=none smtp.client-ip=209.85.128.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="DAG82vN2" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6eaae8b12bfso20687647b3.3 for ; Thu, 07 Nov 2024 08:20:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730996454; x=1731601254; 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=BNy1FRpj8/1QEngNFxKx7wmbD9P/Pjo7orcxaU6dEKo=; b=DAG82vN2sa842QPu4lA/ycVONuJV8qwlsyQ2zbL55jBjm0jF70D0GlLwUSAC3ByPba Vz/hLr+ezZ4hnh/LZ+xqihqRZe8ZoSkpwSIUmX6KfUJ1VW86NgJip/ne6Gt6M0aujKa7 vCgxPcWLbW2QOYr/c6nIxhBdo4NtPSp0vxl1l+84foYfZWhkyNxG8Irgm171I4Hnid2K w2H+073uG9siEgmtDVABunSAyCyExwnauip0wOHY9C3FWH8rWhVdxaY3tZq0kQwOFPZA 2tVWKJnm+CH9/hnyn/OjlPT7yPVNlUImk+P0SAPPb79eiEEsS+4LEKRxtHaRcf/eKM2W vODw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730996454; x=1731601254; 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=BNy1FRpj8/1QEngNFxKx7wmbD9P/Pjo7orcxaU6dEKo=; b=wsrV9aIWRTKjmxWBr57QdwMbc9fHrzky0DGfkdP2nx2yaiYcUTRfIg+2PqJBxdFPJR V4bZdMGkB3XyFDFPMGoqiqaXnT4Hupr5e1ueIfABjcMjEz5A4wo2FrSRdlDlCp9FEIPT AvMSWZl/W/EN7XetfOgBbqlnzMc3DU0mM8BaLAdbJzrHa/OMfg9ecz1ElfenZaXIBCr2 aUxb+68vG+dlEFMZyrFwyQTjTFoEtwCs/BZ5f+w2A8bcETqLHjbpezk0lLr16KUBioth 5vFilFXvFjb33VC5e0MbpLe+vMQfIJJOkMkrtuYOygOQp8EM8d8LSM+Fxs96tGqc+xCe KfZg== X-Forwarded-Encrypted: i=1; AJvYcCVnCg9utHJHNUb/0FDVGcwpcjFsHeKCyKeeTW0FD8i40I9Kpdp61bQkxzJj7yB9nJoO025GbiBiRwAS/M4=@vger.kernel.org X-Gm-Message-State: AOJu0YyUIdRLHZiTtqPjbxGZ9B74/YCTpFfjev7BCxteftqLtcjv+FB9 W87WmvwVrwN9s9NyBZZ/esYsMGVuC979J7/ieXmd2e7g2e3BJF78gu8DT7MEGPbrYxwBAIJcjaV H6i2AmQ== X-Google-Smtp-Source: AGHT+IF4o6bpUrdsgSbNe4Bu/BuAk9SE4ksnFBT/PaXli53lqcszQOtkE6Vd8ny3nyEQsyM2sz60EKfeohh/ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc7:bda:7167:18d8]) (user=irogers job=sendgmr) by 2002:a81:de03:0:b0:6e2:371f:4aef with SMTP id 00721157ae682-6eadaf980f4mr79067b3.3.1730996453699; Thu, 07 Nov 2024 08:20:53 -0800 (PST) Date: Thu, 7 Nov 2024 08:20:33 -0800 In-Reply-To: <20241107162035.52206-1-irogers@google.com> Message-Id: <20241107162035.52206-7-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 6/8] perf header: Pass a perf_cpu rather than a PMU to get_cpuid_str 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" On ARM the cpuid is dependent on the core type of the CPU in question. The PMU was passed for the sake of the CPU map but this means in places a temporary PMU is created just to pass a CPU value. Just pass the CPU and fix up the callers. As there are no longer PMU users in header.h, shuffle forward declarations earlier to work around build failures. Signed-off-by: Ian Rogers Reviewed-by: James Clark Tested-by: Xu Yang --- tools/perf/arch/arm64/util/arm-spe.c | 14 ++------------ tools/perf/arch/arm64/util/header.c | 12 ++++-------- tools/perf/arch/loongarch/util/header.c | 2 +- tools/perf/arch/powerpc/util/header.c | 2 +- tools/perf/arch/riscv/util/header.c | 2 +- tools/perf/arch/s390/util/header.c | 4 ++-- tools/perf/arch/x86/util/header.c | 3 +-- tools/perf/pmu-events/empty-pmu-events.c | 5 ++++- tools/perf/pmu-events/jevents.py | 5 ++++- tools/perf/tests/expr.c | 7 +++---- tools/perf/util/expr.c | 6 +++--- tools/perf/util/header.c | 22 +++++++++++++++++++++- tools/perf/util/header.h | 19 ++++++++++--------- tools/perf/util/pmu.c | 20 -------------------- tools/perf/util/pmu.h | 1 - 15 files changed, 57 insertions(+), 67 deletions(-) diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/u= til/arm-spe.c index 7ccdea3cd461..22b19dcc6beb 100644 --- a/tools/perf/arch/arm64/util/arm-spe.c +++ b/tools/perf/arch/arm64/util/arm-spe.c @@ -23,6 +23,7 @@ #include "../../../util/debug.h" #include "../../../util/auxtrace.h" #include "../../../util/record.h" +#include "../../../util/header.h" #include "../../../util/arm-spe.h" #include // reallocarray =20 @@ -85,22 +86,11 @@ static int arm_spe_save_cpu_header(struct auxtrace_reco= rd *itr, struct arm_spe_recording *sper =3D container_of(itr, struct arm_spe_recording, itr); struct perf_pmu *pmu =3D NULL; - struct perf_pmu tmp_pmu; - char cpu_id_str[16]; char *cpuid =3D NULL; u64 val; =20 - snprintf(cpu_id_str, sizeof(cpu_id_str), "%d", cpu.cpu); - tmp_pmu.cpus =3D perf_cpu_map__new(cpu_id_str); - if (!tmp_pmu.cpus) - return -ENOMEM; - /* Read CPU MIDR */ - cpuid =3D perf_pmu__getcpuid(&tmp_pmu); - - /* The CPU map will not be used anymore, release it */ - perf_cpu_map__put(tmp_pmu.cpus); - + cpuid =3D get_cpuid_allow_env_override(cpu); if (!cpuid) return -ENOMEM; val =3D strtol(cpuid, NULL, 16); diff --git a/tools/perf/arch/arm64/util/header.c b/tools/perf/arch/arm64/ut= il/header.c index f0907daad3ae..f445a2dd6293 100644 --- a/tools/perf/arch/arm64/util/header.c +++ b/tools/perf/arch/arm64/util/header.c @@ -62,22 +62,18 @@ int get_cpuid(char *buf, size_t sz, struct perf_cpu cpu) return EINVAL; } =20 -char *get_cpuid_str(struct perf_pmu *pmu) +char *get_cpuid_str(struct perf_cpu cpu) { - char *buf =3D NULL; + char *buf =3D malloc(MIDR_SIZE); int res; =20 - if (!pmu || !pmu->cpus) - return NULL; - - buf =3D malloc(MIDR_SIZE); if (!buf) return NULL; =20 /* read midr from list of cpus mapped to this pmu */ - res =3D get_cpuid(buf, MIDR_SIZE, perf_cpu_map__min(pmu->cpus)); + res =3D get_cpuid(buf, MIDR_SIZE, cpu); if (res) { - pr_err("failed to get cpuid string for PMU %s\n", pmu->name); + pr_err("failed to get cpuid string for CPU %d\n", cpu.cpu); free(buf); buf =3D NULL; } diff --git a/tools/perf/arch/loongarch/util/header.c b/tools/perf/arch/loon= garch/util/header.c index f1f0b116962d..0c6d823334a2 100644 --- a/tools/perf/arch/loongarch/util/header.c +++ b/tools/perf/arch/loongarch/util/header.c @@ -90,7 +90,7 @@ int get_cpuid(char *buffer, size_t sz, struct perf_cpu cp= u __maybe_unused) return ret; } =20 -char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused) +char *get_cpuid_str(struct perf_cpu cpu __maybe_unused) { return _get_cpuid(); } diff --git a/tools/perf/arch/powerpc/util/header.c b/tools/perf/arch/powerp= c/util/header.c index 6d1a63a2922f..c7df534dbf8f 100644 --- a/tools/perf/arch/powerpc/util/header.c +++ b/tools/perf/arch/powerpc/util/header.c @@ -42,7 +42,7 @@ get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __= maybe_unused) } =20 char * -get_cpuid_str(struct perf_pmu *pmu __maybe_unused) +get_cpuid_str(struct perf_cpu cpu __maybe_unused) { char *bufp; unsigned long pvr; diff --git a/tools/perf/arch/riscv/util/header.c b/tools/perf/arch/riscv/ut= il/header.c index ebac294c877f..4b839203d4a5 100644 --- a/tools/perf/arch/riscv/util/header.c +++ b/tools/perf/arch/riscv/util/header.c @@ -98,7 +98,7 @@ int get_cpuid(char *buffer, size_t sz, struct perf_cpu cp= u __maybe_unused) } =20 char * -get_cpuid_str(struct perf_pmu *pmu __maybe_unused) +get_cpuid_str(struct perf_cpu cpu __maybe_unused) { return _get_cpuid(); } diff --git a/tools/perf/arch/s390/util/header.c b/tools/perf/arch/s390/util= /header.c index 2add1a561242..db54677a17d2 100644 --- a/tools/perf/arch/s390/util/header.c +++ b/tools/perf/arch/s390/util/header.c @@ -137,11 +137,11 @@ int get_cpuid(char *buffer, size_t sz, struct perf_cp= u cpu __maybe_unused) return (nbytes >=3D sz) ? ENOBUFS : 0; } =20 -char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused) +char *get_cpuid_str(struct perf_cpu cpu) { char *buf =3D malloc(128); =20 - if (buf && get_cpuid(buf, 128)) + if (buf && get_cpuid(buf, 128, cpu)) zfree(&buf); return buf; } diff --git a/tools/perf/arch/x86/util/header.c b/tools/perf/arch/x86/util/h= eader.c index 690f86cbbb1c..412977f8aa83 100644 --- a/tools/perf/arch/x86/util/header.c +++ b/tools/perf/arch/x86/util/header.c @@ -63,8 +63,7 @@ get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __= maybe_unused) return __get_cpuid(buffer, sz, "%s,%u,%u,%u$"); } =20 -char * -get_cpuid_str(struct perf_pmu *pmu __maybe_unused) +char *get_cpuid_str(struct perf_cpu cpu __maybe_unused) { char *buf =3D malloc(128); =20 diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-even= ts/empty-pmu-events.c index b8719dab264d..51ca8d61c15d 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -515,13 +515,16 @@ static const struct pmu_events_map *map_for_pmu(struc= t perf_pmu *pmu) } last_map_search; static bool has_last_result, has_last_map_search; const struct pmu_events_map *map =3D NULL; + struct perf_cpu cpu =3D {-1}; char *cpuid =3D NULL; size_t i; =20 if (has_last_result && last_result.pmu =3D=3D pmu) return last_result.map; =20 - cpuid =3D perf_pmu__getcpuid(pmu); + if (pmu) + cpu =3D perf_cpu_map__min(pmu->cpus); + cpuid =3D get_cpuid_allow_env_override(cpu); =20 /* * On some platforms which uses cpus map, cpuid can be NULL for diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jeven= ts.py index 70f4fd5395fb..b5ff872e2beb 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -1031,13 +1031,16 @@ static const struct pmu_events_map *map_for_pmu(str= uct perf_pmu *pmu) } last_map_search; static bool has_last_result, has_last_map_search; const struct pmu_events_map *map =3D NULL; + struct perf_cpu cpu =3D {-1}; char *cpuid =3D NULL; size_t i; =20 if (has_last_result && last_result.pmu =3D=3D pmu) return last_result.map; =20 - cpuid =3D perf_pmu__getcpuid(pmu); + if (pmu) + cpu =3D perf_cpu_map__min(pmu->cpus); + cpuid =3D get_cpuid_allow_env_override(cpu); =20 /* * On some platforms which uses cpus map, cpuid can be NULL for diff --git a/tools/perf/tests/expr.c b/tools/perf/tests/expr.c index d60f1ac1d720..41ff1affdfcd 100644 --- a/tools/perf/tests/expr.c +++ b/tools/perf/tests/expr.c @@ -4,10 +4,9 @@ #include "util/expr.h" #include "util/hashmap.h" #include "util/header.h" -#include "util/pmu.h" -#include "util/pmus.h" #include "util/smt.h" #include "tests.h" +#include #include #include #include @@ -78,8 +77,8 @@ static int test__expr(struct test_suite *t __maybe_unused= , int subtest __maybe_u struct expr_parse_ctx *ctx; bool is_intel =3D false; char strcmp_cpuid_buf[256]; - struct perf_pmu *pmu =3D perf_pmus__find_core_pmu(); - char *cpuid =3D perf_pmu__getcpuid(pmu); + struct perf_cpu cpu =3D {-1}; + char *cpuid =3D get_cpuid_allow_env_override(cpu); char *escaped_cpuid1, *escaped_cpuid2; =20 TEST_ASSERT_VAL("get_cpuid", cpuid); diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c index 5e3732bc2fa5..f289044a1f7c 100644 --- a/tools/perf/util/expr.c +++ b/tools/perf/util/expr.c @@ -8,7 +8,6 @@ #include "debug.h" #include "evlist.h" #include "expr.h" -#include "pmu.h" #include "smt.h" #include "tool_pmu.h" #include @@ -16,6 +15,7 @@ #include "util/hashmap.h" #include "util/header.h" #include "util/pmu.h" +#include #include #include #include @@ -456,8 +456,8 @@ double expr__strcmp_cpuid_str(const struct expr_parse_c= tx *ctx __maybe_unused, bool compute_ids __maybe_unused, const char *test_id) { double ret; - struct perf_pmu *pmu =3D perf_pmus__find_core_pmu(); - char *cpuid =3D perf_pmu__getcpuid(pmu); + struct perf_cpu cpu =3D {-1}; + char *cpuid =3D get_cpuid_allow_env_override(cpu); =20 if (!cpuid) return NAN; diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 60b42ddc3dac..06ca5762f61f 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -819,11 +819,31 @@ static int write_group_desc(struct feat_fd *ff, * Each architecture should provide a more precise id string that * can be use to match the architecture's "mapfile". */ -char * __weak get_cpuid_str(struct perf_pmu *pmu __maybe_unused) +char * __weak get_cpuid_str(struct perf_cpu cpu __maybe_unused) { return NULL; } =20 +char *get_cpuid_allow_env_override(struct perf_cpu cpu) +{ + char *cpuid; + static bool printed; + + cpuid =3D getenv("PERF_CPUID"); + if (cpuid) + cpuid =3D strdup(cpuid); + if (!cpuid) + cpuid =3D get_cpuid_str(cpu); + if (!cpuid) + return NULL; + + if (!printed) { + pr_debug("Using CPUID %s\n", cpuid); + printed =3D true; + } + return cpuid; +} + /* Return zero when the cpuid from the mapfile.csv matches the * cpuid string generated on this platform. * Otherwise return non-zero. diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index 3bb768455a60..5201af6305f4 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h @@ -10,9 +10,14 @@ #include #include #include "env.h" -#include "pmu.h" #include =20 +struct evlist; +union perf_event; +struct perf_header; +struct perf_session; +struct perf_tool; + enum { HEADER_RESERVED =3D 0, /* always cleared */ HEADER_FIRST_FEATURE =3D 1, @@ -92,8 +97,6 @@ struct perf_pipe_file_header { u64 size; }; =20 -struct perf_header; - int perf_file_header__read(struct perf_file_header *header, struct perf_header *ph, int fd); =20 @@ -125,11 +128,6 @@ struct perf_header_feature_ops { bool synthesize; }; =20 -struct evlist; -struct perf_session; -struct perf_tool; -union perf_event; - extern const char perf_version_string[]; =20 int perf_session__read_header(struct perf_session *session); @@ -204,6 +202,9 @@ int build_caches_for_cpu(u32 cpu, struct cpu_cache_leve= l caches[], u32 *cntp); */ int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu); =20 -char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused); +char *get_cpuid_str(struct perf_cpu cpu); + +char *get_cpuid_allow_env_override(struct perf_cpu cpu); + int strcmp_cpuid_str(const char *s1, const char *s2); #endif /* __PERF_HEADER_H */ diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 0789758598c0..514cb865f57b 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -818,26 +818,6 @@ static int is_sysfs_pmu_core(const char *name) return file_available(path); } =20 -char *perf_pmu__getcpuid(struct perf_pmu *pmu) -{ - char *cpuid; - static bool printed; - - cpuid =3D getenv("PERF_CPUID"); - if (cpuid) - cpuid =3D strdup(cpuid); - if (!cpuid) - cpuid =3D get_cpuid_str(pmu); - if (!cpuid) - return NULL; - - if (!printed) { - pr_debug("Using CPUID %s\n", cpuid); - printed =3D true; - } - return cpuid; -} - __weak const struct pmu_metrics_table *pmu_metrics_table__find(void) { return perf_pmu__find_metrics_table(NULL); diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index b86b3c3685a2..fba3fc608b64 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -260,7 +260,6 @@ void perf_pmu__arch_init(struct perf_pmu *pmu); void pmu_add_cpu_aliases_table(struct perf_pmu *pmu, const struct pmu_events_table *table); =20 -char *perf_pmu__getcpuid(struct perf_pmu *pmu); const struct pmu_metrics_table *pmu_metrics_table__find(void); bool pmu_uncore_identifier_match(const char *compat, const char *id); =20 --=20 2.47.0.199.ga7371fff76-goog From nobody Sun Nov 24 01:46:01 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 877DD219C91 for ; Thu, 7 Nov 2024 16:20:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730996459; cv=none; b=HayMQlFgc5FQ9OTbx/QkCabUPIitFtndJXOjJRRTxSz4VxwqgFMyOo3LA//Q7WtTbg7/yshEK9HYyd/+PRKOUZH31QkYEdjKIRImzVsjdawOrkmBsFK4Uhjyw/0p4hPhGExLCm7D1KNLNtAxBcd/s+uMYxWRGrRG0xWGxdD/zBo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730996459; c=relaxed/simple; bh=CajUs616qyGppVWZm3vfBDC8+tgu0BtGWij+wkPy5Mo=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=EQgtA6BB0crn63ltuUB/VS66H+4sMIs8yovH0JLoCv3giPKd2Pfnlz3k+FKmbP+9P3YwQJx99d8XNlPSnGMXoekUA9I3u9zid1zMocqHAxeMFSDeROed2Rdcmj+oERirWY2OmHLsOxdIKCAy7ZdQ8/fwLSfvCgyaukZoGVus1Vw= 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=18y3afOa; arc=none smtp.client-ip=209.85.128.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="18y3afOa" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ea90b6ee2fso20080717b3.1 for ; Thu, 07 Nov 2024 08:20:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730996456; x=1731601256; 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=OmDxOz/jwQKQ9IxxvIQzkp5N2zsrObhsgCU4K9BCHGc=; b=18y3afOaEsuDgT2+2V/ctSZfF7MOErusX0gPmmS7dk/dJUuWKWeY+/SEuzQzG3SQVD FQlFFsGyu/+qKJ4S+zCA3SeCnidWhMzhg2IHp17TrKt13FWPBv/O10JszKGSSWuH3MyE zQcudwDuI5AXsiq/d8hn7tdgeOopHqe+WjZ1U2xbs2yZ3tVQE61N0SXRkP1JA9lDgAbj FgG0ifHH6eb3kTdRI6EfvjhMPbsAtWPGRp76hjDbJORywkduLAFZXbhEuUTiDAuWWoYa V/ldZY+U/i3S6mTVcbUpERgHnH7bchh+UKKe0CstIPdJv94hZ153EIQqIoHsTrDVpoUh JcFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730996456; x=1731601256; 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=OmDxOz/jwQKQ9IxxvIQzkp5N2zsrObhsgCU4K9BCHGc=; b=jzpuMvehmgSjdLlwEyzjaBDTAXF96ATEvuXXPoRoUe/lG9q8v9lHVEcpRE1YNdHzyb DTckpfhD6Rl9ogBq/TTV1tyVzHUE22TJaWJ7qSKeHTkBAIHfKZrchi3T8Bq8dFhZllbp wpOSlnBMIVw65lVgYM+ZyxMp9XDLur4AjRzGUKdBGyvBeI7fryehiB7sBETrB+xt6MY0 QIJ3vWA4w9ZTXqGmcNBpVVOUXlaMjvh6HJXOtQMwAd6YyPziwm7tSKiE1hRAKVdys5K0 mR1pJUKYZ6OQtf4yREY0VBCwQpapN78TjrixFu4V++hZvMaT4Poj4u31MgaNUOyE++/N /g2A== X-Forwarded-Encrypted: i=1; AJvYcCV71NsHRA4i/387InAQtKLxsAfmsmx0ZxOjuwJL0hOXu/1TRqNVIq1+EfkVfMbLgsUxqj4EHql6nmcbEc0=@vger.kernel.org X-Gm-Message-State: AOJu0Yx30Pc46TL64GKND4y5/2YThlPoquvruqamXnFTCfi4CC7eNJBm DMReC3yN59lZdofCi3yaRfxzmBwUWU3sV1+3sFluauXDsCjfKLr0gr1ZJlrPYBhKHeVrGH+2Ypx A31bWag== X-Google-Smtp-Source: AGHT+IHCkQtw3cbe4yQXJVnOkaPBqQ3DtdlxV254RMwS9iWgJ8X5235+bgRmL2AfqDh6oANhnB+TqaB5uCbI X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc7:bda:7167:18d8]) (user=irogers job=sendgmr) by 2002:a81:de03:0:b0:6e2:371f:4aef with SMTP id 00721157ae682-6eadaf980f4mr79097b3.3.1730996456017; Thu, 07 Nov 2024 08:20:56 -0800 (PST) Date: Thu, 7 Nov 2024 08:20:34 -0800 In-Reply-To: <20241107162035.52206-1-irogers@google.com> Message-Id: <20241107162035.52206-8-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 7/8] perf jevents: Add map_for_cpu 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" The PMU is no longer part of the map finding process and for metrics doesn't make sense as they lack a PMU. Signed-off-by: Ian Rogers Reviewed-by: James Clark Tested-by: Xu Yang --- tools/perf/pmu-events/empty-pmu-events.c | 20 +++++++++++++------- tools/perf/pmu-events/jevents.py | 20 +++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-even= ts/empty-pmu-events.c index 51ca8d61c15d..17306e316a3c 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -503,11 +503,11 @@ int pmu_metrics_table__for_each_metric(const struct p= mu_metrics_table *table, return 0; } =20 -static const struct pmu_events_map *map_for_pmu(struct perf_pmu *pmu) +static const struct pmu_events_map *map_for_cpu(struct perf_cpu cpu) { static struct { const struct pmu_events_map *map; - struct perf_pmu *pmu; + struct perf_cpu cpu; } last_result; static struct { const struct pmu_events_map *map; @@ -515,15 +515,12 @@ static const struct pmu_events_map *map_for_pmu(struc= t perf_pmu *pmu) } last_map_search; static bool has_last_result, has_last_map_search; const struct pmu_events_map *map =3D NULL; - struct perf_cpu cpu =3D {-1}; char *cpuid =3D NULL; size_t i; =20 - if (has_last_result && last_result.pmu =3D=3D pmu) + if (has_last_result && last_result.cpu.cpu =3D=3D cpu.cpu) return last_result.map; =20 - if (pmu) - cpu =3D perf_cpu_map__min(pmu->cpus); cpuid =3D get_cpuid_allow_env_override(cpu); =20 /* @@ -555,12 +552,21 @@ static const struct pmu_events_map *map_for_pmu(struc= t perf_pmu *pmu) has_last_map_search =3D true; } out_update_last_result: - last_result.pmu =3D pmu; + last_result.cpu =3D cpu; last_result.map =3D map; has_last_result =3D true; return map; } =20 +static const struct pmu_events_map *map_for_pmu(struct perf_pmu *pmu) +{ + struct perf_cpu cpu =3D {-1}; + + if (pmu) + cpu =3D perf_cpu_map__min(pmu->cpus); + return map_for_cpu(cpu); +} + const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu= *pmu) { const struct pmu_events_map *map =3D map_for_pmu(pmu); diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jeven= ts.py index b5ff872e2beb..e44b72e56ac3 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -1019,11 +1019,11 @@ int pmu_metrics_table__for_each_metric(const struct= pmu_metrics_table *table, return 0; } =20 -static const struct pmu_events_map *map_for_pmu(struct perf_pmu *pmu) +static const struct pmu_events_map *map_for_cpu(struct perf_cpu cpu) { static struct { const struct pmu_events_map *map; - struct perf_pmu *pmu; + struct perf_cpu cpu; } last_result; static struct { const struct pmu_events_map *map; @@ -1031,15 +1031,12 @@ static const struct pmu_events_map *map_for_pmu(str= uct perf_pmu *pmu) } last_map_search; static bool has_last_result, has_last_map_search; const struct pmu_events_map *map =3D NULL; - struct perf_cpu cpu =3D {-1}; char *cpuid =3D NULL; size_t i; =20 - if (has_last_result && last_result.pmu =3D=3D pmu) + if (has_last_result && last_result.cpu.cpu =3D=3D cpu.cpu) return last_result.map; =20 - if (pmu) - cpu =3D perf_cpu_map__min(pmu->cpus); cpuid =3D get_cpuid_allow_env_override(cpu); =20 /* @@ -1071,12 +1068,21 @@ static const struct pmu_events_map *map_for_pmu(str= uct perf_pmu *pmu) has_last_map_search =3D true; } out_update_last_result: - last_result.pmu =3D pmu; + last_result.cpu =3D cpu; last_result.map =3D map; has_last_result =3D true; return map; } =20 +static const struct pmu_events_map *map_for_pmu(struct perf_pmu *pmu) +{ + struct perf_cpu cpu =3D {-1}; + + if (pmu) + cpu =3D perf_cpu_map__min(pmu->cpus); + return map_for_cpu(cpu); +} + const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu= *pmu) { const struct pmu_events_map *map =3D map_for_pmu(pmu); --=20 2.47.0.199.ga7371fff76-goog From nobody Sun Nov 24 01:46:01 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 9EA91219CA3 for ; Thu, 7 Nov 2024 16:20:59 +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=1730996461; cv=none; b=lQDH9GMkqR60d69cPmftywB51OLhzJMF7WBxpgpAGw+Oo52GUrObJyJjzGjVT/BWjGKYxDchRyzkznKHS5/VIxzw1jTFky5DPxFfe6Sqofth1ahb2lU+mnBOryqGJtzB0VDsFmInx9O/Bdaq1qvXM8/k6oERre1TTBM4ih1CJPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730996461; c=relaxed/simple; bh=yZE5usv7POpAFkWXsWAe3Jof3/secgiiDH647AJzosE=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Hwfh64GnJsit7e1hVONIBk1RcfWjf0EpJtuC/FKZ2+EnKheaLnp1DFiAVkqdq725IjFvC1x/GASyYDbUsTkUFq0WCWwR1DI8LkEzNbtTQ2XmU1C7LWfec/6Da1YxTlr28C2eQFCQ805sqrPAED7ZpabUUgMsbHJ1YW4qFeLN2xM= 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=R7yQO+Re; 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="R7yQO+Re" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e293b3e014aso1705686276.3 for ; Thu, 07 Nov 2024 08:20:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730996459; x=1731601259; 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=gW9+CPTVwMKZIVurnVHCFx7TIdR/e/ydt61yKCEQTG0=; b=R7yQO+ReOWcwDT7SKiA2vlfmB2fzWyeqivDUjPzqUXtnkR1732jWoKBlOho1J6hZTV NbQGpNt6rQ12yvZltZY54/bwRwrYIfduRD24huPhvxFCKMELozDMZ8rdwijLDh6TmM1h O7z8oMTzqrbPC8kNRLppVBaNR4GgL3auJ7e0BrfibhX5yTnPDzGf7glO+ZNDhimT46o4 23OK7VwMzE75gNK4UhtLCIlQWAaCYM367pIMmjreAumwDrnV5t3fiTl67IhDJXyJfnod AeVX7TrtIgsVu5Olv3XOrUQ+ty65RpUTCDVH/QlV2Z2iQXMMU+pYR175M4b0+UFTYFZh OwhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730996459; x=1731601259; 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=gW9+CPTVwMKZIVurnVHCFx7TIdR/e/ydt61yKCEQTG0=; b=HsIAZCD91TvRwY/dy3C8zMs3Txn2q6g2WQ8jm7MEFRICsDrU+e3HaYwL8j2A0ogTPj DLTgsL4g7bEh0L948LVjapxvICR/WEAYWnlIR4qjfK566Mi6YKxZsq5/lyXzk+RJGQqJ aSKl1tRuFph3xjv++LWgzJXSw8o67zO1LdVimFJuduITdvt2xNC0yLfXhyL8C/u6Hy1u Q7K8qDrtJXok/j3iPo3Cp8Vvjihl/80Pgyi6/xI8keWPc4L7wzFR/virAUeJ+5uZuIMr PGRT1Nln7T4GYbgD0IoQveEpRtY4wDOoBLJOleULAGKha3kS/oapGuSW463RvRN6U2vv gkTQ== X-Forwarded-Encrypted: i=1; AJvYcCULLcQz/ArzjsJJirylSKfbsmhk1h2FBDJEYPM2l4l0kdUzzTQj6tzjNtLfJ0PwRkKDqqMn55Mhdb4s5gY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0LL35dpocnLXuQ+8cBtIfCq3ClNKQfE/SlB/7M8TvNnMlum2y LZ4d2aD2jnCcxzzMhjI6BS0acFl6FQU7Eq2+iR0HQBHf651pWZmVXwwAQ05qLV3bkbyEtjWtMtr 9h3zr7w== X-Google-Smtp-Source: AGHT+IEYlgs/V2F/Aoj+pbdeOvGuquRFfNPybrBK44Ua6MKMX5mUoZiZ1vNXICCo8jUP4hj+0QFM6lTQ0dhC X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc7:bda:7167:18d8]) (user=irogers job=sendgmr) by 2002:a25:acd7:0:b0:e24:a28e:9399 with SMTP id 3f1490d57ef6-e337e3878cfmr1276.4.1730996458511; Thu, 07 Nov 2024 08:20:58 -0800 (PST) Date: Thu, 7 Nov 2024 08:20:35 -0800 In-Reply-To: <20241107162035.52206-1-irogers@google.com> Message-Id: <20241107162035.52206-9-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 8/8] perf pmu: Move pmu_metrics_table__find and remove ARM override 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" Move pmu_metrics_table__find to the jevents.py generated pmu-events.c and remove indirection override for ARM. The movement removes perf_pmu__find_metrics_table that exists to enable the ARM override. The ARM override isn't necessary as just the CPUID, not PMU, is used in the metric table lookup. On non-ARM the CPU argument is just ignored for the CPUID, for ARM -1 is passed so that the CPUID for the first logical CPU is read. Signed-off-by: Ian Rogers Reviewed-by: James Clark Tested-by: Xu Yang --- tools/perf/arch/arm64/util/pmu.c | 20 -------------------- tools/perf/pmu-events/empty-pmu-events.c | 10 ++++------ tools/perf/pmu-events/jevents.py | 10 ++++------ tools/perf/pmu-events/pmu-events.h | 2 +- tools/perf/util/pmu.c | 5 ----- tools/perf/util/pmu.h | 1 - 6 files changed, 9 insertions(+), 39 deletions(-) diff --git a/tools/perf/arch/arm64/util/pmu.c b/tools/perf/arch/arm64/util/= pmu.c index a0964b191fcb..895fb0d0610c 100644 --- a/tools/perf/arch/arm64/util/pmu.c +++ b/tools/perf/arch/arm64/util/pmu.c @@ -1,29 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 =20 -#include -#include "../../../util/cpumap.h" -#include "../../../util/header.h" #include "../../../util/pmu.h" #include "../../../util/pmus.h" #include "../../../util/tool_pmu.h" #include -#include - -const struct pmu_metrics_table *pmu_metrics_table__find(void) -{ - struct perf_pmu *pmu; - - /* Metrics aren't currently supported on heterogeneous Arm systems */ - if (perf_pmus__num_core_pmus() > 1) - return NULL; - - /* Doesn't matter which one here because they'll all be the same */ - pmu =3D perf_pmus__find_core_pmu(); - if (pmu) - return perf_pmu__find_metrics_table(pmu); - - return NULL; -} =20 u64 tool_pmu__cpu_slots_per_cycle(void) { diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-even= ts/empty-pmu-events.c index 17306e316a3c..1c7a2cfa321f 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -587,14 +587,12 @@ const struct pmu_events_table *perf_pmu__find_events_= table(struct perf_pmu *pmu) return NULL; } =20 -const struct pmu_metrics_table *perf_pmu__find_metrics_table(struct perf_p= mu *pmu) +const struct pmu_metrics_table *pmu_metrics_table__find(void) { - const struct pmu_events_map *map =3D map_for_pmu(pmu); - - if (!map) - return NULL; + struct perf_cpu cpu =3D {-1}; + const struct pmu_events_map *map =3D map_for_cpu(cpu); =20 - return &map->metric_table; + return map ? &map->metric_table : NULL; } =20 const struct pmu_events_table *find_core_events_table(const char *arch, co= nst char *cpuid) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jeven= ts.py index e44b72e56ac3..d781a377757a 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -1103,14 +1103,12 @@ const struct pmu_events_table *perf_pmu__find_event= s_table(struct perf_pmu *pmu) return NULL; } =20 -const struct pmu_metrics_table *perf_pmu__find_metrics_table(struct perf_p= mu *pmu) +const struct pmu_metrics_table *pmu_metrics_table__find(void) { - const struct pmu_events_map *map =3D map_for_pmu(pmu); - - if (!map) - return NULL; + struct perf_cpu cpu =3D {-1}; + const struct pmu_events_map *map =3D map_for_cpu(cpu); =20 - return &map->metric_table; + return map ? &map->metric_table : NULL; } =20 const struct pmu_events_table *find_core_events_table(const char *arch, co= nst char *cpuid) diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu= -events.h index 5435ad92180c..675562e6f770 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -103,7 +103,7 @@ int pmu_metrics_table__for_each_metric(const struct pmu= _metrics_table *table, pm void *data); =20 const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu= *pmu); -const struct pmu_metrics_table *perf_pmu__find_metrics_table(struct perf_p= mu *pmu); +const struct pmu_metrics_table *pmu_metrics_table__find(void); const struct pmu_events_table *find_core_events_table(const char *arch, co= nst char *cpuid); const struct pmu_metrics_table *find_core_metrics_table(const char *arch, = const char *cpuid); int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data); diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 514cb865f57b..45838651b361 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -818,11 +818,6 @@ static int is_sysfs_pmu_core(const char *name) return file_available(path); } =20 -__weak const struct pmu_metrics_table *pmu_metrics_table__find(void) -{ - return perf_pmu__find_metrics_table(NULL); -} - /** * Return the length of the PMU name not including the suffix for uncore P= MUs. * diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index fba3fc608b64..7b3e71194e49 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -260,7 +260,6 @@ void perf_pmu__arch_init(struct perf_pmu *pmu); void pmu_add_cpu_aliases_table(struct perf_pmu *pmu, const struct pmu_events_table *table); =20 -const struct pmu_metrics_table *pmu_metrics_table__find(void); bool pmu_uncore_identifier_match(const char *compat, const char *id); =20 int perf_pmu__convert_scale(const char *scale, char **end, double *sval); --=20 2.47.0.199.ga7371fff76-goog