From nobody Tue Apr 7 01:01:26 2026 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.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 37FC73803C3 for ; Tue, 17 Mar 2026 05:53:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773726823; cv=none; b=bC/jUXEvXxxae9FuBUQuh6u0eeTBW82qETylAllopKTDoDrAG0Py7GBjtuwQUI87aw4W13tsZPV0344uofNDH8mncQEE/QqUWDtkmGHCiaboCLUDuo3SvQAZonztIcjoxhwZxcCWAJFzty4XN7dUJxbFSNFPR2CHjPRmMRV8cBw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773726823; c=relaxed/simple; bh=wVIk574MaJ1ryn6M1d5QWZAOYLPanqIo/c++6wESi+o=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AJ4tyubCB+s+yjCo2xsIwsq85GLIsn442ibmudE3GMul3y1BcT7x9ZqxPyREaXJAvLk7sfUXS22jKClliOexWm+ooUb9ueY6h/UfzWFG9E4I0HWOSKi+QQd+33LsHxPWwCApIdNxaDpZ68eq0sNx2y7S7Y4Q1H+19ImiiSQXeBA= 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=MRqxRyLa; arc=none smtp.client-ip=209.85.214.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="MRqxRyLa" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2b051befbb8so27309275ad.2 for ; Mon, 16 Mar 2026 22:53:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773726820; x=1774331620; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BC7DFlkd9xaG2royXDyXDCwOCftcIJRM1qoiGuRC8ho=; b=MRqxRyLaIvo3tpzZaKLBDWkql2Zxe/wwtzOBVu1szYKPELi6FbdARCqKTQ0iFNDTHO RW4BxWUws7HUEcrA7b4cE9dPGys0hf2d/hkkVRN6akt+MzaVCIHElo5fc4zv10Myn0WQ o4WsPbTvqXxifeSJ0yMXaHZMxW+jIH30m6pThwsYCkP5Y2g16P0pp2V891BMKZpU6wLQ tuAaozUA/geN1olQld/6GlDKD/GzEF21zu/Mbf4s8N0lOuxA8TV210degSYIhURQZBSw 0pt4oeUhDVNa8HNqtjrmdJ6LyIokiU+biTTFTrMwgKQYQ7+PpvNR1JPRg86YsE4qWolb LPww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773726820; x=1774331620; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BC7DFlkd9xaG2royXDyXDCwOCftcIJRM1qoiGuRC8ho=; b=LR2JxbIIjYUNG+pzzSm90Pl030svYvk9lPlCaLSqYhLmFJyLm461draMZrNHpJaWv3 501CbHWYz7wbvSWcMQzj+l5kf+5Iw+2dapy9JhQYeJ0NvSXJe0kphrM7KRCq7Z5tkzGT ko4FOOJfjRLP3wLvGXSFt806N7l/FQ29mng+OLcCeRnTuhOvD1kVO9ngkYN5CqyU9RH7 EvfqeHQi79ZWx6tcm6vDTCyqi2N9hxBukZj5ULidsi15LlELT0wFHZaOLxM3sA6vDW1L zf91y165nAbBf373OwFUYKq+Hx4jFwRgnryxa1bhWvCAwc5Uw+kJmbdptJuygEoDLQhE vB9Q== X-Forwarded-Encrypted: i=1; AJvYcCUXWMhs+9pPryHBeCYaz6naUS5Pn8zAMduYtPZDE+aIzv9Di95v3oBz3rIOXsm8eAattlvaiiPOJTpPzOw=@vger.kernel.org X-Gm-Message-State: AOJu0YwAsncudkajwCqIw3dm+TOMo19mPfEiHaxY2kDctFWmZrQnpTJC nzIzIaI24kTNxeRQq0z/m48cdG11mTUxrOIhOlcCNcaw4hhbySSy3NC06apbLHc2+LBksmhZkYW Lc52DFxNKPA== X-Received: from plan1.prod.google.com ([2002:a17:903:4041:b0:2b0:5ba8:77e7]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:22c4:b0:2b0:5cb4:d89d with SMTP id d9443c01a7336-2b05cb4d98dmr50571635ad.29.1773726820372; Mon, 16 Mar 2026 22:53:40 -0700 (PDT) Date: Mon, 16 Mar 2026 22:53:30 -0700 In-Reply-To: <20260317055334.760347-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260317030601.567422-1-irogers@google.com> <20260317055334.760347-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260317055334.760347-2-irogers@google.com> Subject: [PATCH v5 1/5] perf evsel: Improve falling back from cycles From: Ian Rogers To: tmricht@linux.ibm.com Cc: irogers@google.com, acme@kernel.org, agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, namhyung@kernel.org, sumanthk@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch to using evsel__match rather than comparing perf_event_attr values, this is robust on hybrid architectures. Ensure evsel->pmu matches the evsel->core.attr. Remove exclude bits that get set in other fallback attempts when switching the event. Log the event name with modifiers when switching the event on fallback. Signed-off-by: Ian Rogers --- tools/perf/util/evsel.c | 45 ++++++++++++++++++++++++++++------------- tools/perf/util/evsel.h | 2 ++ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index f59228c1a39e..bd14d9bbc91f 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3785,25 +3785,42 @@ bool evsel__fallback(struct evsel *evsel, struct ta= rget *target, int err, { int paranoid; =20 - if ((err =3D=3D ENOENT || err =3D=3D ENXIO || err =3D=3D ENODEV) && - evsel->core.attr.type =3D=3D PERF_TYPE_HARDWARE && - evsel->core.attr.config =3D=3D PERF_COUNT_HW_CPU_CYCLES) { + if ((err =3D=3D ENODEV || err =3D=3D ENOENT || err =3D=3D ENXIO) && + evsel__match(evsel, HARDWARE, HW_CPU_CYCLES)) { /* - * If it's cycles then fall back to hrtimer based cpu-clock sw - * counter, which is always available even if no PMU support. - * - * PPC returns ENXIO until 2.6.37 (behavior changed with commit - * b0a873e). + * If it's the legacy hardware cycles event fails then fall back + * to hrtimer based cpu-clock sw counter, which is always + * available even if no PMU support. PPC returned ENXIO rather + * than ENODEV or ENOENT until 2.6.37. */ - evsel->core.attr.type =3D PERF_TYPE_SOFTWARE; + evsel->pmu =3D perf_pmus__find_by_type(PERF_TYPE_SOFTWARE); + assert(evsel->pmu); /* software is a "well-known" and can't fail PMU typ= e. */ + + /* Configure the event. */ + evsel->core.attr.type =3D PERF_TYPE_SOFTWARE; evsel->core.attr.config =3D target__has_cpu(target) ? PERF_COUNT_SW_CPU_CLOCK : PERF_COUNT_SW_TASK_CLOCK; - scnprintf(msg, msgsize, - "The cycles event is not supported, trying to fall back to %s", - target__has_cpu(target) ? "cpu-clock" : "task-clock"); + evsel->core.is_pmu_core =3D false; + + /* Remove excludes for new event. */ + if (evsel->fallenback_eacces) { + evsel->core.attr.exclude_kernel =3D 0; + evsel->core.attr.exclude_hv =3D 0; + evsel->fallenback_eacces =3D false; + } + if (evsel->fallenback_eopnotsupp) { + evsel->core.attr.exclude_guest =3D 0; + evsel->fallenback_eopnotsupp =3D false; + } =20 + /* Name is recomputed by evsel__name. */ zfree(&evsel->name); + + /* Log message. */ + scnprintf(msg, msgsize, + "The cycles event is not supported, trying to fall back to %s", + evsel__name(evsel)); return true; } else if (err =3D=3D EACCES && !evsel->core.attr.exclude_kernel && (paranoid =3D perf_event_paranoid()) > 1) { @@ -3830,7 +3847,7 @@ bool evsel__fallback(struct evsel *evsel, struct targ= et *target, int err, " samples", paranoid); evsel->core.attr.exclude_kernel =3D 1; evsel->core.attr.exclude_hv =3D 1; - + evsel->fallenback_eacces =3D true; return true; } else if (err =3D=3D EOPNOTSUPP && !evsel->core.attr.exclude_guest && !evsel->exclude_GH) { @@ -3851,7 +3868,7 @@ bool evsel__fallback(struct evsel *evsel, struct targ= et *target, int err, /* Apple M1 requires exclude_guest */ scnprintf(msg, msgsize, "Trying to fall back to excluding guest samples"= ); evsel->core.attr.exclude_guest =3D 1; - + evsel->fallenback_eopnotsupp =3D true; return true; } no_fallback: diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index a3d754c029a0..97f57fab28ce 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -124,6 +124,8 @@ struct evsel { bool default_metricgroup; /* A member of the Default metricgroup */ bool default_show_events; /* If a default group member, show the event = */ bool needs_uniquify; + bool fallenback_eacces; + bool fallenback_eopnotsupp; struct hashmap *per_pkg_mask; int err; int script_output_type; --=20 2.53.0.851.ga537e3e6e9-goog From nobody Tue Apr 7 01:01:26 2026 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.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 484F837FF78 for ; Tue, 17 Mar 2026 05:53:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773726824; cv=none; b=mJEeLIWOi+0LaODmOZYnYY5rqGfVsAXtl4i8W2AB5EUX7IITQvwyA6m6LLs8D8weOneFjHpsJiX4gsSxJDKMqIhWZp403Grr1wNTKMlM87s9cTVFpljObL5TSrk/r4S0MCHXJSopBGVGFmszxP6iTkrmByPpIs/kGXrlWmifJ7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773726824; c=relaxed/simple; bh=4mSJoDt19c1s52Ar2qiFo/PGbNpyNgJireRDLID11TM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lozcGHC4FT+xrtJVOChIylXtYi/fw0BaWVIb+HzGzPDi6in2ggIpld2pdIseI4359Ih0D1X7OxrCm4QGex8rTByLsxGPlWrC+ifuXkNmsIm8ForVc370qTlRs7vKTZ9xYtSuunDkV1TZoz1g5PK7yEa8XENVoT9Tlt3HAsc4JCE= 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=e2jppqV2; arc=none smtp.client-ip=209.85.210.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="e2jppqV2" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-82a5ee4a9acso96033b3a.1 for ; Mon, 16 Mar 2026 22:53:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773726823; x=1774331623; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=jjPd8hYb03Ftsdibhr+aMw0AWnG2dzFR9qnmX2QMSHk=; b=e2jppqV2bBUIRMl1d+AbvCcolwtdLSX0AOG2FdGsjQE8e3rgmk1H/inwS8Ziq5DBxx 9ab6UF53qr73utPneH0bCbPXZfGpBlNuf41imZ0/xJW6AuOKYC+4DgAWIayFlZ8yAMx/ AiojvGIaPzfzRqlgmfnJF9QVsi0n470bu2uuLZUCe+Y372vjYLF4B2sNC7QSsDu+sUMm H4f4T+58a76p7ENqT+lgl0dw1swTsOX5x9WozmCbcdEreoWjNGHhK4QWGOpdLucvf6++ dnoVdNLd1SFnlChPeirJdaIvU0FGF384MEdUP2vh1JK3L9NntgFtk7nliJkA87nQu7hX l+qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773726823; x=1774331623; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jjPd8hYb03Ftsdibhr+aMw0AWnG2dzFR9qnmX2QMSHk=; b=U8VWpyb64OsrxFa2tiSFTJzLbwS11+Q1eARJALTWCkqOMKC9n79DRbDQVP1hFoiBxn fw0KUq23UQC3LK3UZFmUTmo7T6RSaeFgIVcUbnTCkZftKDr2GG2Jcpdc6Nq9b25oUcCO ySTycx7XVTDtlKuud/FyYGd7MhfRzx5i/adGPd3d+IPLV46d3lVK1EV39YJOr3Vy1fmt wQTdJr1owGMlxlQO0sMbG0QQEwoYrwSgnIyy0a3Rv1oijhkkf9RGJ7Rem4J2Y+rJnAKn HEit0nFrpu6h37FJtK3WsS9Ha2Puh5hsf/GvuUvNHse3cIiecPFw7aSiaCBG64NvQOCY ElXg== X-Forwarded-Encrypted: i=1; AJvYcCUrhN7WvhFcl+uzyyjMZ03hFqUnB+Jf3Z+R4JiHea1MgRAGap8a+jCG1s6yziNspMvLE7+jQBNbhLKVqWE=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6Wozw/BuQNckhubnYvsVu1DMkPC9xEiqHVEDNTdiUTDLPKYEL ybI1Wry/hHe1Gct5OnxG3QgKwrnn/yr6A2CqyTFL75SYIHFkHsT85Cc5rLnprsqAfSuv62qgUpX GFNM/WpTItw== X-Received: from pfld9.prod.google.com ([2002:a05:6a00:1989:b0:824:a502:8fea]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:22c4:b0:827:2f87:ac03 with SMTP id d2e1a72fcca58-82a198fb8f3mr15205658b3a.43.1773726822422; Mon, 16 Mar 2026 22:53:42 -0700 (PDT) Date: Mon, 16 Mar 2026 22:53:31 -0700 In-Reply-To: <20260317055334.760347-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260317030601.567422-1-irogers@google.com> <20260317055334.760347-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260317055334.760347-3-irogers@google.com> Subject: [PATCH v5 2/5] perf target: Constify simple check functions From: Ian Rogers To: tmricht@linux.ibm.com Cc: irogers@google.com, acme@kernel.org, agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, namhyung@kernel.org, sumanthk@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow the target to be const in callers. Signed-off-by: Ian Rogers --- tools/perf/util/target.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/target.h b/tools/perf/util/target.h index 84ebb9c940c6..bc2bff9c6842 100644 --- a/tools/perf/util/target.h +++ b/tools/perf/util/target.h @@ -49,22 +49,22 @@ uid_t parse_uid(const char *str); =20 int target__strerror(struct target *target, int errnum, char *buf, size_t = buflen); =20 -static inline bool target__has_task(struct target *target) +static inline bool target__has_task(const struct target *target) { return target->tid || target->pid; } =20 -static inline bool target__has_cpu(struct target *target) +static inline bool target__has_cpu(const struct target *target) { return target->system_wide || target->cpu_list; } =20 -static inline bool target__none(struct target *target) +static inline bool target__none(const struct target *target) { return !target__has_task(target) && !target__has_cpu(target); } =20 -static inline bool target__enable_on_exec(struct target *target) +static inline bool target__enable_on_exec(const struct target *target) { /* * Normally enable_on_exec should be set if: @@ -75,12 +75,12 @@ static inline bool target__enable_on_exec(struct target= *target) return target__none(target) && !target->initial_delay; } =20 -static inline bool target__has_per_thread(struct target *target) +static inline bool target__has_per_thread(const struct target *target) { return target->system_wide && target->per_thread; } =20 -static inline bool target__uses_dummy_map(struct target *target) +static inline bool target__uses_dummy_map(const struct target *target) { bool use_dummy =3D false; =20 --=20 2.53.0.851.ga537e3e6e9-goog From nobody Tue Apr 7 01:01:26 2026 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.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 CF25B3803E8 for ; Tue, 17 Mar 2026 05:53:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773726828; cv=none; b=kNOjPcA9sSlnjhxC9jox0v+W7pZOj72rCdmPUAWm6WbW+lYhsynjotiDa/HTJ4h3OR1BfNCBd8Oy+Zuwz7NCt1fB8skaYEAYytdh1OroeMdNUNJt+azGF6XPoIw2KotyAQEnQz3iGKm05JkxohfAkPMkU5EPh7rXjO5qSmDctto= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773726828; c=relaxed/simple; bh=YnHls8NIVjy5Ei7a4hKc1qV28zK+UaZo7VK2CAN8c3w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=CpTOsJ+yq+WdsbifLZeP1oVrzPV7FKqk9wo6+uHX8jyRGuekN2jcIWHZthCcwilHRljZBIw9KnJu7xzk2ti5Et3PfYsffU5r+EN6S0EittDp+2T+0j/j0YG+D/5ZKbTem9FuWs+mPeRA7obBekC6zB4yE4eREtGJZ7Xhv9/v6fY= 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=CZaH7B0f; arc=none smtp.client-ip=74.125.82.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="CZaH7B0f" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2bdc1b30ac8so81194592eec.1 for ; Mon, 16 Mar 2026 22:53:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773726826; x=1774331626; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=4sR/GkKKCK4vlTKAx1HdQnSDfMDIglmN+8LdctHHquI=; b=CZaH7B0f+C3xa/FsGjzd/HvczyHWkhOwyx965AwK3zmQoiBc/JrHWYAd3CCIUY559M 3vlDLuP0SLRA9sLA67mNoOndErkPDHBQCcvHcBuIQsapKb+yudMkJscfxgNsEu/W4rCZ pJ8QYrTeQTgEdXv6aWgP/aI1euy+TwESvLxg9Y68sfg/qXzz/YBiw5xfU/rTpH/gPQUy iPs+4WxLbpOlG+R9H6PgjYDbcONPmTfZBkCbPgE4i3CKM+kX/0cr9sBduLVV9fvKfANC K70a1U/WMO80EylvO10jHUgoaFF4nAxHuG5Iog46I0xTe5hn/2Iy1eMh9C2DBaSGxXjM 9hIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773726826; x=1774331626; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4sR/GkKKCK4vlTKAx1HdQnSDfMDIglmN+8LdctHHquI=; b=I1BCeZuEbCR7MIJdjjD3ISrY6CqhuYYq8ksQNpaMNkAJjHlP8yhA/6GvU/VnUbeP/3 cKPkIoT91dGmu8jshKZXeMp74XIq2mNXPhHaZq++Ew+XEf06qUuEbI9HNRgpA8zhZ5Sg u93PCU2hMTF/SzPTDRul1VnB2Qs8nsvI0V8a3dMwd3iMIzQQA4OpirXiXOx+Aki2CESR Eo1/HiN2Kp9xrr98KoxblQwBXLoxhPQ5qnyAbsSQ2Bu/9yfntXeHvKAV9mLc1cp/OsiY CYkQo6dZRkxy2lOSBx8psJaZ/vYd+QFOYr6ECv3PKGDJuJ6CK7u5dN4lj2MSM9eq9ASN PFTQ== X-Forwarded-Encrypted: i=1; AJvYcCX6b9kpR4ijUfRUxLIHFppwQx01pYh1+sPK7rj3YNRPHUr7QYMc66MucS36JgQkLu9dIsgymhzABlgih4o=@vger.kernel.org X-Gm-Message-State: AOJu0YwAaYFJJxCpJQxR2AU/IFeVsAq31OHqf1MZ6Ks4Qd2ln3CcuwYX ByrTQTNr75Y/3pRvYgz53LcbEigEPw9gCCaFCmsms0T80B4HIXrbABu2nN9mPCPkegtYycdj6DA BqCBGOQfhQQ== X-Received: from dybvz8.prod.google.com ([2002:a05:7301:7a08:b0:2be:2465:40e5]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:4308:b0:2c0:d690:7b8 with SMTP id 5a478bee46e88-2c0d6901e3cmr1075723eec.23.1773726825768; Mon, 16 Mar 2026 22:53:45 -0700 (PDT) Date: Mon, 16 Mar 2026 22:53:32 -0700 In-Reply-To: <20260317055334.760347-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260317030601.567422-1-irogers@google.com> <20260317055334.760347-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260317055334.760347-4-irogers@google.com> Subject: [PATCH v5 3/5] perf evsel: Constify option arguments to config functions From: Ian Rogers To: tmricht@linux.ibm.com Cc: irogers@google.com, acme@kernel.org, agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, namhyung@kernel.org, sumanthk@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The options are used to configure the evsel but are not themselves configured. Make the arguments const to better capture this. Signed-off-by: Ian Rogers --- tools/perf/util/evsel.c | 20 ++++++++++---------- tools/perf/util/evsel.h | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index bd14d9bbc91f..54c8922a8e47 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1015,8 +1015,8 @@ uint16_t evsel__e_machine(struct evsel *evsel, uint32= _t *e_flags) return perf_session__e_machine(session, e_flags); } =20 -static void __evsel__config_callchain(struct evsel *evsel, struct record_o= pts *opts, - struct callchain_param *param) +static void __evsel__config_callchain(struct evsel *evsel, const struct re= cord_opts *opts, + const struct callchain_param *param) { bool function =3D evsel__is_function_event(evsel); struct perf_event_attr *attr =3D &evsel->core.attr; @@ -1080,14 +1080,14 @@ static void __evsel__config_callchain(struct evsel = *evsel, struct record_opts *o attr->defer_callchain =3D 1; } =20 -void evsel__config_callchain(struct evsel *evsel, struct record_opts *opts, - struct callchain_param *param) +void evsel__config_callchain(struct evsel *evsel, const struct record_opts= *opts, + const struct callchain_param *param) { if (param->enabled) return __evsel__config_callchain(evsel, opts, param); } =20 -static void evsel__reset_callgraph(struct evsel *evsel, struct callchain_p= aram *param) +static void evsel__reset_callgraph(struct evsel *evsel, const struct callc= hain_param *param) { struct perf_event_attr *attr =3D &evsel->core.attr; =20 @@ -1106,7 +1106,7 @@ static void evsel__reset_callgraph(struct evsel *evse= l, struct callchain_param * =20 static void evsel__apply_ratio_to_prev(struct evsel *evsel, struct perf_event_attr *attr, - struct record_opts *opts, + const struct record_opts *opts, const char *buf) { struct perf_event_attr *prev_attr =3D NULL; @@ -1170,7 +1170,7 @@ static void evsel__apply_ratio_to_prev(struct evsel *= evsel, } =20 static void evsel__apply_config_terms(struct evsel *evsel, - struct record_opts *opts, bool track) + const struct record_opts *opts, bool track) { struct evsel_config_term *term; struct list_head *config_terms =3D &evsel->config_terms; @@ -1445,7 +1445,7 @@ void __weak arch_evsel__apply_ratio_to_prev(struct ev= sel *evsel __maybe_unused, { } =20 -static void evsel__set_default_freq_period(struct record_opts *opts, +static void evsel__set_default_freq_period(const struct record_opts *opts, struct perf_event_attr *attr) { if (opts->freq) { @@ -1490,8 +1490,8 @@ bool evsel__is_offcpu_event(struct evsel *evsel) * enable/disable events specifically, as there's no * initial traced exec call. */ -void evsel__config(struct evsel *evsel, struct record_opts *opts, - struct callchain_param *callchain) +void evsel__config(struct evsel *evsel, const struct record_opts *opts, + const struct callchain_param *callchain) { struct evsel *leader =3D evsel__leader(evsel); struct perf_event_attr *attr =3D &evsel->core.attr; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 97f57fab28ce..339b5c08a33d 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -287,10 +287,10 @@ void evsel__set_priv_destructor(void (*destructor)(vo= id *priv)); =20 struct callchain_param; =20 -void evsel__config(struct evsel *evsel, struct record_opts *opts, - struct callchain_param *callchain); -void evsel__config_callchain(struct evsel *evsel, struct record_opts *opts, - struct callchain_param *callchain); +void evsel__config(struct evsel *evsel, const struct record_opts *opts, + const struct callchain_param *callchain); +void evsel__config_callchain(struct evsel *evsel, const struct record_opts= *opts, + const struct callchain_param *callchain); =20 int __evsel__sample_size(u64 sample_type); void evsel__calc_id_pos(struct evsel *evsel); --=20 2.53.0.851.ga537e3e6e9-goog From nobody Tue Apr 7 01:01:26 2026 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (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 2EFAF3803C0 for ; Tue, 17 Mar 2026 05:53:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773726830; cv=none; b=BBveWHWSR/C1QjTM1YgJ/GAyTcVU2lg3H/aRfdGMDPRFpOydpSsVT2eaHIKf1gq+ivJdtk4s2hebsy9xOhvsQNWUV4vpG+3rv9JHRe3jd0ihrrZuCRtVc21bQnXfuPqnvVxfN4/CCGnzAW9+y+jekk+HnxtolfrBs9J6r//MBgM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773726830; c=relaxed/simple; bh=NGYnryMhEdIBmDPY7BmWjrHAQZEWEyXEqXN7d4e1LD4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Cy7okEHcgs9tJIEdeCu0gI/oIuyrpEYy9lU7FfjtwrnSvcz4bKBzEohuNLCpFhp2xqNrSP9kl4GVjUuYiwvthpEuj7jLrs0gMjvOnlTIU2SGeX2aiiZj5ZAeEzhip6QzU0MIHSpbHu71+Fzxo8V6hs1spq22fR+v+sF31vKgDyw= 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=rd4VONSz; arc=none smtp.client-ip=74.125.82.73 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="rd4VONSz" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-12721cd1a2aso41009450c88.1 for ; Mon, 16 Mar 2026 22:53:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773726828; x=1774331628; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=dsJEhWEmvNQrHkNRryerc+5Jcaj55mH9xilOwt1mqeI=; b=rd4VONSzMKGBl2T2Ebki61KjT/36/14Toyh5OWi8ocMBTiHTc6VWXB/TTchQE8csco RJ3t1ksYQPpofeqyIYuhXXI7uBFuQrnkbveHww0auB27R5BhINnsc5eVHkNwde4G3ufo iec5NdL4QCsZzxCYJAviAIBp6LOL+L4lnjJ7wWLv6lpSkdqZOTuW25nsfLTKSSy+5uq0 lyCMq1ICdebk5xCvzIkCvsQizRP/MkuOtV92T6pmH1IBhr8lSM8aKB8ze20hrUdg8YN7 PhfqAGxOm9cRnDl8BLGkFo/k9jB47i9kNKXTuq/97g3b89Z8EvTFbWXgcZq/64vhHxdP KpyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773726828; x=1774331628; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dsJEhWEmvNQrHkNRryerc+5Jcaj55mH9xilOwt1mqeI=; b=iJIcq3bNONV4mBFwW+FylYlxCxyOqy1xExL9iAIJl5LgJCYupHXYfTa/CO+oRFn0vs 4hvNc49gPYqj98/xfuCNz4KsEld3zYYo6JWG6o7QPUorNPY4UQfUq2S2jl8jglCZTIvF bYUO6huoRKiPA0e4NJNWR71eGputulmJmypV6Wh81ZZ2czMSN+n2US8q6yqha1U1Gjj1 3biW3ypQZ1HT2YjWTp/3Wk/Q8GL8wGLq1cI6KVz/kiyx1NDCCUQh5AKioeBOSyw+6VEU YTBhF1NlZWXdkuDUcRW5kzJFkUyawlpOnpRcN7rvx9EdyuDRJ9Q+Xu+TjR4RwcZ6ZpjN o4Pg== X-Forwarded-Encrypted: i=1; AJvYcCXBquHu0rs0wFP5ouwPlsp9qUG1Z2TZWs2OApGA3b+4iXkvRV0BMt7QozO5RP7Q4gu9ScSiFf0/Xpn23yI=@vger.kernel.org X-Gm-Message-State: AOJu0YybqJq4D4iiT3vGc5kINCXl/afzb3T9lxdxAZat15vkp9tq88nC bzGf+7c+WaRG9eTp+yIkQ8m89xmO19JWCUl4pxSoYhqjbp5ZMI/mfdmCbwU4aOJh8UV/0iOt04H xbhv0AjNytg== X-Received: from dycng12.prod.google.com ([2002:a05:7300:ce0c:b0:2c0:cd67:64cd]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:ad28:b0:2be:833c:1486 with SMTP id 5a478bee46e88-2bea559090cmr7205419eec.18.1773726827933; Mon, 16 Mar 2026 22:53:47 -0700 (PDT) Date: Mon, 16 Mar 2026 22:53:33 -0700 In-Reply-To: <20260317055334.760347-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260317030601.567422-1-irogers@google.com> <20260317055334.760347-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260317055334.760347-5-irogers@google.com> Subject: [PATCH v5 4/5] perf callchain: Refactor callchain option parsing From: Ian Rogers To: tmricht@linux.ibm.com Cc: irogers@google.com, acme@kernel.org, agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, namhyung@kernel.org, sumanthk@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" record_opts__parse_callchain is shared by builtin-record and builtin-trace, it is declared in callchain.h. Move the declaration to callchain.c for consistency with the header. In other cases make the option callback a small static stub that then calls into callchain.c. Make the no argument '-g' callchain option just a short-cut for '--call-graph fp' so that there is consistency in how the arguments are handled. Signed-off-by: Ian Rogers --- tools/perf/builtin-record.c | 58 +++++-------------------------------- tools/perf/builtin-top.c | 14 ++++----- tools/perf/builtin-trace.c | 9 +++++- tools/perf/util/callchain.c | 39 +++++++++++++++++++++++++ tools/perf/util/callchain.h | 12 ++------ 5 files changed, 64 insertions(+), 68 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 40917a0be238..af1fe6b7c65c 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -2975,65 +2975,21 @@ static int __cmd_record(struct record *rec, int arg= c, const char **argv) return status; } =20 -static void callchain_debug(struct callchain_param *callchain) -{ - static const char *str[CALLCHAIN_MAX] =3D { "NONE", "FP", "DWARF", "LBR" = }; - - pr_debug("callchain: type %s\n", str[callchain->record_mode]); - - if (callchain->record_mode =3D=3D CALLCHAIN_DWARF) - pr_debug("callchain: stack dump size %d\n", - callchain->dump_size); -} - -int record_opts__parse_callchain(struct record_opts *record, - struct callchain_param *callchain, - const char *arg, bool unset) -{ - int ret; - callchain->enabled =3D !unset; - - /* --no-call-graph */ - if (unset) { - callchain->record_mode =3D CALLCHAIN_NONE; - pr_debug("callchain: disabled\n"); - return 0; - } - - ret =3D parse_callchain_record_opt(arg, callchain); - if (!ret) { - /* Enable data address sampling for DWARF unwind. */ - if (callchain->record_mode =3D=3D CALLCHAIN_DWARF && - !record->record_data_mmap_set) - record->record_data_mmap =3D true; - callchain_debug(callchain); - } - - return ret; -} - -int record_parse_callchain_opt(const struct option *opt, +static int record_parse_callchain_opt(const struct option *opt, const char *arg, int unset) { return record_opts__parse_callchain(opt->value, &callchain_param, arg, un= set); } =20 -int record_callchain_opt(const struct option *opt, - const char *arg __maybe_unused, - int unset __maybe_unused) +static int record_callchain_opt(const struct option *opt, + const char *arg __maybe_unused, + int unset) { - struct callchain_param *callchain =3D opt->value; - - callchain->enabled =3D true; - - if (callchain->record_mode =3D=3D CALLCHAIN_NONE) - callchain->record_mode =3D CALLCHAIN_FP; - - callchain_debug(callchain); - return 0; + return record_opts__parse_callchain(opt->value, &callchain_param, "fp", u= nset); } =20 + static int perf_record_config(const char *var, const char *value, void *cb) { struct record *rec =3D cb; @@ -3525,7 +3481,7 @@ static struct option __record_options[] =3D { OPT_CALLBACK(0, "mmap-flush", &record.opts, "number", "Minimal number of bytes that is extracted from mmap data pages (de= fault: 1)", record__mmap_flush_parse), - OPT_CALLBACK_NOOPT('g', NULL, &callchain_param, + OPT_CALLBACK_NOOPT('g', NULL, &record.opts, NULL, "enables call-graph recording" , &record_callchain_opt), OPT_CALLBACK(0, "call-graph", &record.opts, diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 710604c4f6f6..2a949d956d0b 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -1386,13 +1386,6 @@ static int __cmd_top(struct perf_top *top) return ret; } =20 -static int -callchain_opt(const struct option *opt, const char *arg, int unset) -{ - symbol_conf.use_callchain =3D true; - return record_callchain_opt(opt, arg, unset); -} - static int parse_callchain_opt(const struct option *opt, const char *arg, int unset) { @@ -1413,6 +1406,13 @@ parse_callchain_opt(const struct option *opt, const = char *arg, int unset) return parse_callchain_top_opt(arg); } =20 +static int +callchain_opt(const struct option *opt, const char *arg __maybe_unused, in= t unset) +{ + return parse_callchain_opt(opt, "fp", unset); +} + + static int perf_top_config(const char *var, const char *value, void *cb __= maybe_unused) { if (!strcmp(var, "top.call-graph")) { diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 1c38f3d16a31..f487fbaa0ad6 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -5300,6 +5300,13 @@ static int trace__parse_summary_mode(const struct op= tion *opt, const char *str, return 0; } =20 +static int trace_parse_callchain_opt(const struct option *opt, + const char *arg, + int unset) +{ + return record_opts__parse_callchain(opt->value, &callchain_param, arg, un= set); +} + static int trace__config(const char *var, const char *value, void *arg) { struct trace *trace =3D arg; @@ -5447,7 +5454,7 @@ int cmd_trace(int argc, const char **argv) OPT_BOOLEAN('f', "force", &trace.force, "don't complain, do it"), OPT_CALLBACK(0, "call-graph", &trace.opts, "record_mode[,record_size]", record_callchain_help, - &record_parse_callchain_opt), + &trace_parse_callchain_opt), OPT_BOOLEAN(0, "libtraceevent_print", &trace.libtraceevent_print, "Use libtraceevent to print the tracepoint arguments."), OPT_BOOLEAN(0, "kernel-syscall-graph", &trace.kernel_syscallchains, diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 8ff0898799ee..d97421fbf159 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -30,6 +30,7 @@ #include "map.h" #include "callchain.h" #include "branch.h" +#include "record.h" #include "symbol.h" #include "thread.h" #include "util.h" @@ -328,6 +329,44 @@ int parse_callchain_record(const char *arg, struct cal= lchain_param *param) return ret; } =20 +static void callchain_debug(const struct callchain_param *callchain) +{ + static const char *str[CALLCHAIN_MAX] =3D { "NONE", "FP", "DWARF", "LBR" = }; + + pr_debug("callchain: type %s\n", str[callchain->record_mode]); + + if (callchain->record_mode =3D=3D CALLCHAIN_DWARF) + pr_debug("callchain: stack dump size %d\n", + callchain->dump_size); +} + +int record_opts__parse_callchain(struct record_opts *record, + struct callchain_param *callchain, + const char *arg, bool unset) +{ + int ret; + + callchain->enabled =3D !unset; + + /* --no-call-graph */ + if (unset) { + callchain->record_mode =3D CALLCHAIN_NONE; + pr_debug("callchain: disabled\n"); + return 0; + } + + ret =3D parse_callchain_record_opt(arg, callchain); + if (!ret) { + /* Enable data address sampling for DWARF unwind. */ + if (callchain->record_mode =3D=3D CALLCHAIN_DWARF && + !record->record_data_mmap_set) + record->record_data_mmap =3D true; + callchain_debug(callchain); + } + + return ret; +} + int perf_callchain_config(const char *var, const char *value) { char *endptr; diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index df54ddb8c0cb..06d463ccc7a0 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h @@ -9,11 +9,13 @@ =20 struct addr_location; struct evsel; +struct hist_entry; +struct hists; struct ip_callchain; struct map; struct perf_sample; +struct record_opts; struct thread; -struct hists; =20 #define HELP_PAD "\t\t\t\t" =20 @@ -237,14 +239,6 @@ struct callchain_cursor *get_tls_callchain_cursor(void= ); int callchain_cursor__copy(struct callchain_cursor *dst, struct callchain_cursor *src); =20 -struct option; -struct hist_entry; - -int record_parse_callchain_opt(const struct option *opt, const char *arg, = int unset); -int record_callchain_opt(const struct option *opt, const char *arg, int un= set); - -struct record_opts; - int record_opts__parse_callchain(struct record_opts *record, struct callchain_param *callchain, const char *arg, bool unset); --=20 2.53.0.851.ga537e3e6e9-goog From nobody Tue Apr 7 01:01:26 2026 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.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 82E7A3803E1 for ; Tue, 17 Mar 2026 05:53:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773726833; cv=none; b=nmoPF9H4aJmQO4vwScBvYUPMtNYqAhQpSPpwlbOdsqbicJY0t9MmktMRKUqVpNSL3QtAdR7aGj+qRSwRN5DKnjKwtrloV5ENwlkppBPK2wcdJ42CMAH/KpsvVThAtBMPNXOiKyY56lHIZgZV0gDF5AwZShmR7KRYtvC4yJYIbBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773726833; c=relaxed/simple; bh=Axfy6NjjxmduxcvXsqF3sLzos55b1PwttR68soQDBPY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GJ/tcIRB4stVFtnf7dTOCkX6QlWp+pDrZIrkQ7uYEkkaLKuyW1QAdZEs98kQ3kVXufJDyRRFAQN5qV9XRg5YbIe/wppDbHzv9eSbl9whTwnFKEg+pTTcARKEC4ist39Q1Poa7eThb168lsENuL78LYr2XwRtTwRWOpf997j38s4= 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=iS9Y4Ddj; arc=none smtp.client-ip=74.125.82.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="iS9Y4Ddj" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2bead0a9123so22512190eec.1 for ; Mon, 16 Mar 2026 22:53:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773726831; x=1774331631; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=1y9l7GOlMwY9cVT1XEv6vvs7n+TqRuMl4hN3XZ5vC3w=; b=iS9Y4Ddja3dTnD5SNFBcWYNOLjUYUn0OPtVJ6K8M3HK0AO4IzlKEKzxM4pDbSQvd5f sCmOJVNOc7Av2AYsBh3HiKJK/053rmnHVYIjy3u5xDPaS4XsOhA4Dx52OylX9AKVNNch hUC5jqa1WFEF7jocdfnKEJXfuxzdR7pxWi9AMcNR6UF7aEHwJxZBev4lo5BX8ZU6fMpb E1HVF1uxbKRI7r87OIe5d8HBsgJeLu8KM3Ceb5efg/yzf6cnvP0r0rqhtJPD4oBqF3vC eGnXFcZpR7r0P1qzUckg74rWo9QuryT93pyt71vOE2IVtdHxjNBgzpVR5QZ09s8Jd44X y+0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773726831; x=1774331631; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1y9l7GOlMwY9cVT1XEv6vvs7n+TqRuMl4hN3XZ5vC3w=; b=ATmH/nLhA29PeAvM6BwNTBipDQrIlTI2hvxmWcCdSocb1JzF8FekN84vn3yA3+I3D0 9rM4Kr/wK/4KSotCjX4T/oflV7yGqTmSR69QmfQLAHt/3H2nBaJkzF/G4A79IzSLseIM 5kxxeFYrFNRiqdwjtpH9IJttT8Ym9TD19OttYqL2mQXrKu3rRT4yEUNEN59J69TMzOxR QrSzCdELMVynKa7agGeRldmbCFmIC5LgDiq2A5puMU6DTwzOpnN545WnYMsVauNyEK5P 7SCevZcV4DgxXJ3UDbmw2XzOvnLzTg+1vC9bZIHeGnfbApbt9zuaWnXd79q5ghR84icH h7yg== X-Forwarded-Encrypted: i=1; AJvYcCWvFmky6jTJtLcKT7Wk5wWRePHAcexJCsW48ljc/+4Y7WbTFXbb67povw/07quguwomk6mvNaOca7tFKLU=@vger.kernel.org X-Gm-Message-State: AOJu0YxySRFs+Lc6HYKkhxQ3uQSvnVD0mzDpHAr6kYNzo1DfabzK4zKi b+H31OAJ2WJ/qF+CzbQ8HKujKfm+uTz6PzSs6m5sE6kQ1B1uBwjlR2gYkcXr0mzJx2gQIz1Nd77 Kk38meRf1wA== X-Received: from dyek37.prod.google.com ([2002:a05:7300:6425:b0:2c0:c2b7:5f36]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:2f8a:b0:2c0:dd6e:7c87 with SMTP id 5a478bee46e88-2c0dd6ea02emr56147eec.32.1773726830473; Mon, 16 Mar 2026 22:53:50 -0700 (PDT) Date: Mon, 16 Mar 2026 22:53:34 -0700 In-Reply-To: <20260317055334.760347-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260317030601.567422-1-irogers@google.com> <20260317055334.760347-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260317055334.760347-6-irogers@google.com> Subject: [PATCH v5 5/5] perf evlist: Improve default event for s390 From: Ian Rogers To: tmricht@linux.ibm.com Cc: irogers@google.com, acme@kernel.org, agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, namhyung@kernel.org, sumanthk@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Frame pointer callchains are not supported on s390 and dwarf callchains are only supported on software events. Switch the default event from cycles to cpu-clock or task-clock on s390 if callchains are enabled. If frame pointer callchains are requested on s390 show a warning. Modify the '-g' option of `perf top` and `perf record` to default to dwarf callchains on s390. Signed-off-by: Ian Rogers Tested-by: Thomas Richter --- tools/perf/builtin-record.c | 8 ++++++-- tools/perf/builtin-top.c | 5 +++-- tools/perf/tests/event_update.c | 4 +++- tools/perf/tests/expand-cgroup.c | 4 +++- tools/perf/tests/perf-record.c | 7 +++++-- tools/perf/tests/topology.c | 4 +++- tools/perf/util/evlist.c | 32 +++++++++++++++++++++----------- tools/perf/util/evlist.h | 2 +- tools/perf/util/evsel.c | 5 +++++ 9 files changed, 50 insertions(+), 21 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index af1fe6b7c65c..ef97c7a54088 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -55,6 +55,7 @@ #include "asm/bug.h" #include "perf.h" #include "cputopo.h" +#include "dwarf-regs.h" =20 #include #include @@ -2986,7 +2987,9 @@ static int record_callchain_opt(const struct option *= opt, const char *arg __maybe_unused, int unset) { - return record_opts__parse_callchain(opt->value, &callchain_param, "fp", u= nset); + return record_opts__parse_callchain(opt->value, &callchain_param, + EM_HOST !=3D EM_S390 ? "fp" : "dwarf", + unset); } =20 =20 @@ -4265,7 +4268,8 @@ int cmd_record(int argc, const char **argv) record.opts.tail_synthesize =3D true; =20 if (rec->evlist->core.nr_entries =3D=3D 0) { - struct evlist *def_evlist =3D evlist__new_default(); + struct evlist *def_evlist =3D evlist__new_default(&rec->opts.target, + callchain_param.enabled); =20 if (!def_evlist) goto out; diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 2a949d956d0b..84211a78977e 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -56,6 +56,7 @@ #include "util/debug.h" #include "util/ordered-events.h" #include "util/pfm.h" +#include "dwarf-regs.h" =20 #include #include @@ -1409,7 +1410,7 @@ parse_callchain_opt(const struct option *opt, const c= har *arg, int unset) static int callchain_opt(const struct option *opt, const char *arg __maybe_unused, in= t unset) { - return parse_callchain_opt(opt, "fp", unset); + return parse_callchain_opt(opt, EM_HOST !=3D EM_S390 ? "fp" : "dwarf", un= set); } =20 =20 @@ -1695,7 +1696,7 @@ int cmd_top(int argc, const char **argv) goto out_delete_evlist; =20 if (!top.evlist->core.nr_entries) { - struct evlist *def_evlist =3D evlist__new_default(); + struct evlist *def_evlist =3D evlist__new_default(target, callchain_para= m.enabled); =20 if (!def_evlist) goto out_delete_evlist; diff --git a/tools/perf/tests/event_update.c b/tools/perf/tests/event_updat= e.c index cb9e6de2e033..facc65e29f20 100644 --- a/tools/perf/tests/event_update.c +++ b/tools/perf/tests/event_update.c @@ -8,6 +8,7 @@ #include "header.h" #include "machine.h" #include "util/synthetic-events.h" +#include "target.h" #include "tool.h" #include "tests.h" #include "debug.h" @@ -81,7 +82,8 @@ static int test__event_update(struct test_suite *test __m= aybe_unused, int subtes { struct evsel *evsel; struct event_name tmp; - struct evlist *evlist =3D evlist__new_default(); + struct target target =3D {}; + struct evlist *evlist =3D evlist__new_default(&target, /*sample_callchain= s=3D*/false); =20 TEST_ASSERT_VAL("failed to get evlist", evlist); =20 diff --git a/tools/perf/tests/expand-cgroup.c b/tools/perf/tests/expand-cgr= oup.c index c7b32a220ca1..dd547f2f77cc 100644 --- a/tools/perf/tests/expand-cgroup.c +++ b/tools/perf/tests/expand-cgroup.c @@ -8,6 +8,7 @@ #include "parse-events.h" #include "pmu-events/pmu-events.h" #include "pfm.h" +#include "target.h" #include #include #include @@ -99,7 +100,8 @@ out: for (i =3D 0; i < nr_events; i++) static int expand_default_events(void) { int ret; - struct evlist *evlist =3D evlist__new_default(); + struct target target =3D {}; + struct evlist *evlist =3D evlist__new_default(&target, /*sample_callchain= s=3D*/false); =20 TEST_ASSERT_VAL("failed to get evlist", evlist); =20 diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c index efbd9cd60c63..c6e31ab8a6b8 100644 --- a/tools/perf/tests/perf-record.c +++ b/tools/perf/tests/perf-record.c @@ -84,8 +84,11 @@ static int test__PERF_RECORD(struct test_suite *test __m= aybe_unused, int subtest CPU_ZERO_S(cpu_mask_size, cpu_mask); =20 perf_sample__init(&sample, /*all=3D*/false); - if (evlist =3D=3D NULL) /* Fallback for kernels lacking PERF_COUNT_SW_DUM= MY */ - evlist =3D evlist__new_default(); + if (evlist =3D=3D NULL) { /* Fallback for kernels lacking PERF_COUNT_SW_D= UMMY */ + struct target target =3D {}; + + evlist =3D evlist__new_default(&target, /*sample_callchains=3D*/false); + } =20 if (evlist =3D=3D NULL) { pr_debug("Not enough memory to create evlist\n"); diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index ec01150d208d..a34a7ab19a80 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c @@ -9,6 +9,7 @@ #include "evlist.h" #include "debug.h" #include "pmus.h" +#include "target.h" #include =20 #define TEMPL "/tmp/perf-test-XXXXXX" @@ -37,11 +38,12 @@ static int session_write_header(char *path) .path =3D path, .mode =3D PERF_DATA_MODE_WRITE, }; + struct target target =3D {}; =20 session =3D perf_session__new(&data, NULL); TEST_ASSERT_VAL("can't get session", !IS_ERR(session)); =20 - session->evlist =3D evlist__new_default(); + session->evlist =3D evlist__new_default(&target, /*sample_callchains=3D*/= false); TEST_ASSERT_VAL("can't get evlist", session->evlist); session->evlist->session =3D session; =20 diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 591bdf0b3e2a..c702741a9173 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -13,6 +13,7 @@ #include "util/mmap.h" #include "thread_map.h" #include "target.h" +#include "dwarf-regs.h" #include "evlist.h" #include "evsel.h" #include "record.h" @@ -98,38 +99,47 @@ struct evlist *evlist__new(void) return evlist; } =20 -struct evlist *evlist__new_default(void) +struct evlist *evlist__new_default(const struct target *target, bool sampl= e_callchains) { struct evlist *evlist =3D evlist__new(); bool can_profile_kernel; struct perf_pmu *pmu =3D NULL; + struct evsel *evsel; + char buf[256]; + int err; =20 if (!evlist) return NULL; =20 can_profile_kernel =3D perf_event_paranoid_check(1); =20 - while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { - char buf[256]; - int err; - - snprintf(buf, sizeof(buf), "%s/cycles/%s", pmu->name, + if (EM_HOST =3D=3D EM_S390 && sample_callchains) { + snprintf(buf, sizeof(buf), "software/%s/%s", + target__has_cpu(target) ? "cpu-clock" : "task-clock", can_profile_kernel ? "P" : "Pu"); err =3D parse_event(evlist, buf); - if (err) { - evlist__delete(evlist); - return NULL; + if (err) + goto out_err; + } else { + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { + snprintf(buf, sizeof(buf), "%s/cycles/%s", pmu->name, + can_profile_kernel ? "P" : "Pu"); + err =3D parse_event(evlist, buf); + if (err) + goto out_err; } } =20 + /* If there is only 1 event a sample identifier isn't necessary. */ if (evlist->core.nr_entries > 1) { - struct evsel *evsel; - evlist__for_each_entry(evlist, evsel) evsel__set_sample_id(evsel, /*can_sample_identifier=3D*/false); } =20 return evlist; +out_err: + evlist__delete(evlist); + return NULL; } =20 struct evlist *evlist__new_dummy(void) diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index d17c3b57a409..e507f5f20ef6 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -104,7 +104,7 @@ struct evsel_str_handler { }; =20 struct evlist *evlist__new(void); -struct evlist *evlist__new_default(void); +struct evlist *evlist__new_default(const struct target *target, bool sampl= e_callchains); struct evlist *evlist__new_dummy(void); void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus, struct perf_thread_map *threads); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 54c8922a8e47..5a294595a677 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1021,6 +1021,11 @@ static void __evsel__config_callchain(struct evsel *= evsel, const struct record_o bool function =3D evsel__is_function_event(evsel); struct perf_event_attr *attr =3D &evsel->core.attr; =20 + if (EM_HOST =3D=3D EM_S390 && param->record_mode =3D=3D CALLCHAIN_FP) { + pr_warning_once( + "Framepointer unwinding lacks kernel support. Use '--call-graph dwarf'\= n"); + } + evsel__set_sample_bit(evsel, CALLCHAIN); =20 attr->sample_max_stack =3D param->max_stack; --=20 2.53.0.851.ga537e3e6e9-goog