From nobody Mon Apr 6 16:45:58 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (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 6325C36164B for ; Wed, 18 Mar 2026 17:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773856705; cv=none; b=sXvvC6UHphUpmqnU1rNZEXoVFfwGa/SQPZOBJByP6k1QIYBhqDO2HjyWaLrl2BAx6PDJzbXRIcN9pfQ8e2fRDQF66ARWkPKiyoOrNxftGYl262r3urZk6Ep7fS4yjhuuJaGLUfxjIRyr39uNDCwDOhqW8TaSKDK8JB8Od+M+iFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773856705; c=relaxed/simple; bh=U8LqxsgGl8pPzMoHQSm3GXUaosjRDy/a3rvRqghM3i4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KKDLHW+U1SkfBIivk66d9+1TGynwEBraWgvdEJlTFsYbOQYkLzypWi5YX5uVlfhQwBJdYOldocJBD2VLetHKYOZxaFt6YYuzFGt6KUbMYXV/LxOTAnl99SOJ8XyzuhbmLyfNGMl/Bkz1gbDMBzlP9uJE8EiAuAAuQjQ0vJnvDtg= 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=DbZ7IAjj; arc=none smtp.client-ip=74.125.82.74 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="DbZ7IAjj" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-128d285d6c3so113860c88.1 for ; Wed, 18 Mar 2026 10:58:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773856703; x=1774461503; 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=FHgnOqAqVJ/nZ21E+abJVIPEw9OV5mDZ+DHTpPzA2N8=; b=DbZ7IAjjAMBj4vNmC/3wsbkbECDbPFjxwaAR9n7jS0qaambliKPOQxU2LRZrRgaoUC 68Sqnb3G+oM9WJvy/p5XyW4paqHO7VWkAc5XWgWGP86pFy0KQ5DEEFjG8QYh3t4jRKO3 UrKrDp4DiNTOlwH8DhlS0ITHQjA+yeUliewiYFA286iiUvcmdtHtubeWnGCk012c7fdL SXFI0UokI4gMyP8zkORTAr99XT2P4ozgm1nFwql06NXh5l6UZRzm0FMcCCfzS8gJoRNs MVll7/g1iyTWE64lecxodnaL8ItSN64hE52lq+2GvIM/loAdHz86aoMCIm0hNKGfapS2 lzhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773856703; x=1774461503; 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=FHgnOqAqVJ/nZ21E+abJVIPEw9OV5mDZ+DHTpPzA2N8=; b=W8pnYRQoVGOErIwj7KnclLZfq+dj1iPr8WtxlxYLJCajW2dtsP3YfxZDh2/OfA48Iz MoaDPYYZIOfzREihUTp5DmCFXIifYukptS74J5gOQvGg7AxYxrGMtLFZ3+ao8kNM+cEf n4HfmH24ppyRUJtEopiW1l7muW/CsfJ9a+Ke5Q8lNgtcTaS7McgqJG4qqJdc+aYZHSoO DdmjI0hLPdiJXY+fvLR09wixhGEMYwpgaozPXKjCBbtZTcmz9u/cF66otL9o8Esv4FOz 5zlDN3IS34/yrn8EUakCL6py99G7dHqqwiMJJ6tMK6z1NT22w4PcLwqTBNF3zbu/4Vzj VBCw== X-Forwarded-Encrypted: i=1; AJvYcCVmjhswmvH0oGjVQjRqN7Ifa2j0gmzRghdXiLz3jGIl8wRZ5Nl85R2w+6Nf1VF7jY1xZ1u5EhVEg25rop0=@vger.kernel.org X-Gm-Message-State: AOJu0Yxc7tfcMmqJ/FBYsfCLvJSPE4TkbSczx3z6I0pu4rP1Qjggojk2 gVPbXC145evLF/68lRvg/QEJxXw++xc5lTKdE+QFiNrEt8ot6u+falv3m5ijCCsEozs7PeAuSrV E+OGjvPWyUg== X-Received: from dlam9-n1.prod.google.com ([2002:a05:701b:2089:10b0:128:d017:6507]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:60f:b0:128:df3d:cd97 with SMTP id a92af1059eb24-129a7177e06mr1946352c88.35.1773856701973; Wed, 18 Mar 2026 10:58:21 -0700 (PDT) Date: Wed, 18 Mar 2026 10:58:04 -0700 In-Reply-To: <20260318175808.582009-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: <20260318175808.582009-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260318175808.582009-2-irogers@google.com> Subject: [PATCH v7 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 Tested-by: Thomas Richter --- 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 Mon Apr 6 16:45:58 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.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 66486376479 for ; Wed, 18 Mar 2026 17:58:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773856706; cv=none; b=l/Kv5J7lmv5d+XORm2ECZU9dRy5pavp7r0QgzDz21tEdQLg54z719sy+dRmxmBttEFUfC1h2GWx86qRdKVX4037LmYVFv59BNigUN3g07+u1Kgdw1PfNcXsWbZ+wuAem/eOUkRZGCWZn1rI0NG/SzOy6bQOi+SKzSZyauUkDQNM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773856706; c=relaxed/simple; bh=AT0BGB6UrGLZA1M+tVNdNXzlDjYmvZvAEkPOTSTH+IM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=SPGvPbxbw9MszFNRA+8j4r3j7JH30/rDk/UuFyYlgb16xMZYy0h1yQokjumT0RGCsPUeWNoWsPdkqtKt94Lc51qLcbsPR5HRLeg4hkGidQ9DMrhuHu7gbsPRPrGQv3ASPX9qVNwRZBpCs5VSgyzd2hpLSYVIkLnEUpbjy43t96g= 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=LWCfF2UN; arc=none smtp.client-ip=74.125.82.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="LWCfF2UN" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2bdf75bc88fso242497eec.0 for ; Wed, 18 Mar 2026 10:58:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773856704; x=1774461504; 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=tQVp2xNbIouZw2DsKLWRE3G9FMoorezshWZvQPd6XX0=; b=LWCfF2UNhL6Jch4lENdJtDfdQMjYCnFOzHoN2rh4tKKe5Cl42qytHZZ026UAWqrMOo ACUGTC9dreo1Onar5rihAFpmDq75OvJClxhU0djsBdTYxhxEYubWh1k/WoAlLqhNuioh xPjmUeRB1U8b6FeY3lKpWXprUVVQy7G3ARPugdyprX/kGGl0nqibWdN5tWzDd047j5Ro e3qsXozx637II3laFWyYyV0Ew89Hke29fEO3N270aLasXPVPKMaK8UY5NwCalFUfcqRY hdH8cMj1WgwSRCsfsIYfeKs2rmRj6Ssx/w71viUtstAcI0HaIoOs42/my5ISLXcx+zTf 3PPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773856704; x=1774461504; 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=tQVp2xNbIouZw2DsKLWRE3G9FMoorezshWZvQPd6XX0=; b=VrfR/bGQs6IHOvWICe/kmN7YkqBQzZ2lPdzXpiG7j+7mkXFig8e51Hu/f/PyLQh4/C YL+uz25o/9NsMnRwYFmvS+RrEdTl9pw8p89eCJhtU3QN2nn2GVBxXOwjmHjmQf8fw1SU vBZUJV9TUKBAIdBEl9fZKihqjQrBzP9xgUvtb/FkW3JFG3du4ZQfT/Ann4IqXAk9Ozkl 3YyW5BNjvDq6alZu4qBA4p0tAS+1Y20dmg6GtEGCfwSj1B4f2zheKoHBfjwdUEOcmnHP MQrY3fnKKur0EZVPsFXvCY/oc9xeIAixyoXTANL+ZfhmsH6JiEd3bSI1yQox5CELeQXW OnCQ== X-Forwarded-Encrypted: i=1; AJvYcCWUDk6YtP0j31AY1hMjyfnX0TM1onDIpn9Gm9xvuHHM/119CwHUca3mwji/NUFJ5L7Ce1mZlqGfxnCc7y0=@vger.kernel.org X-Gm-Message-State: AOJu0YxB8+l0mvjuzHDNoZffMBYswxxEkHOe5AkMhEm+T5Zy+loMlaer 3biCdH1kumlw9ML/+MmGMiQWMwGbwUhcA8claEkg8ledaHVu2K92oWwYeKeuZiYVJNQknI5Cn6Y u6j9mpECY9g== X-Received: from dycrm13.prod.google.com ([2002:a05:693c:2a0d:b0:2c0:d104:830b]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:dc91:b0:2b7:fdb6:ccf6 with SMTP id 5a478bee46e88-2c0e4fb8e1dmr2171218eec.14.1773856704365; Wed, 18 Mar 2026 10:58:24 -0700 (PDT) Date: Wed, 18 Mar 2026 10:58:05 -0700 In-Reply-To: <20260318175808.582009-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: <20260318175808.582009-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260318175808.582009-3-irogers@google.com> Subject: [PATCH v7 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 Tested-by: Thomas Richter --- 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 Mon Apr 6 16:45:58 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 79B703A7850 for ; Wed, 18 Mar 2026 17:58:27 +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=1773856709; cv=none; b=ixj6uj1wZH+mtXxAoyRfEwUuB2SI+bgXRKZMTFeyJozsZ8wB9R0jxJhRDLNM3g/paA1JjYKukvEoskvitLf1CfFFXi69xscUxENZMlb/k7nO9MAQN00wUn4QGqsOvZtduHatDRxUnGaLMH6XevV/x0KQ1MFb/70tPZGf/jWA0p0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773856709; c=relaxed/simple; bh=A0GmPbCjJnn1aBXkaKYVs2MSN28WJDd3xDZa3Kc40Go=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eQlK2RZxTdY9w4lANeEUkH3mE/vzUPGQC7w0zEpaIePamYXs0P9lSzW9pyNR1mby3QZW0i9A+mDMUIRIr5tOD9nlf7nXNf/DgYB+x2Ew5nabI2niN4rFV3huOgAmYVilJjpfKQmczyrTOvm3UhC89uSdC8OQK6AwXzZ1aLm6qf8= 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=i0j9hNqe; 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="i0j9hNqe" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-127337c8e52so3197752c88.1 for ; Wed, 18 Mar 2026 10:58:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773856707; x=1774461507; 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=nSZEuWL4PES8N47OQb2rrJbHDGRdHRzrhZzS2INVBJI=; b=i0j9hNqeYP8EiPRrn6b0Px8nZPj+jsInVA86ZFghwybxGjAt1WxDOGKoKtdTjtNE7i C46S93OzD0dDrsz5BNNgyJGZbpf9fj4GS63klkPkVqHNZyJkufFZJAWepRABCwO7p2I4 XzbkrPvEvoNgGAeFcUCzwA3gjvtrkvlN5G71iTUELKSsPhMnGmpTUnW6ezAHBDSPwLM2 cm0aR7zIeoEcR0pSYiqmOXYOP4eB4APssi1gP/5CC3uJSBJIIlZ3Mw+laZe4rU7BPpBK FfUdULBeW7wEvza6FFpbZ20gSgggRLaQbFWdVYabUtrm9cOrK1QYzM9zLKMSuw2Et6Xt KUvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773856707; x=1774461507; 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=nSZEuWL4PES8N47OQb2rrJbHDGRdHRzrhZzS2INVBJI=; b=EUELeba9kHY6Dr2XDrID0LmDi8Gng6oXPtqJfsar92yJ80wpQI1Sg548hZlD6IfWn3 1BB5q24daixPBOY4yJHBzfQpQ/DISlerVZCUSjOC1EF9esjc7NKetgVAp/TbTPsGHGSv hxR8HOVEh7yBrSBE/TzA+9ZlvDqC/0QwtPA42wdnKrbvWq2mFhoCt6pLlWCWjvmPQwjL sFDzTtM8g9J2+vdWf1JHfmaSpF7s3vh4VlZUecfOF/nEnsNnpSaMU6nyH1Pia70CxoWT ztHCWDWgj18CSStHBJ105HbNmyTE9YbR2BBI/mIyhO9qGZqcLqqbvgV49ff07uj9rAWs qWKA== X-Forwarded-Encrypted: i=1; AJvYcCWOq8Vzf0CXrTls2SxAcTI0S/YCcAFHYKH32F6DE338uSL2ba8XVnoQ2lR+SQIyzzbTDTCdyReTxinbDDQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxFGIClQENRUK3iSn7nsVuKX1hHel39GhEJtZhGkD//+V3W8X+U 0RpaFul7pnujdPtlShDUVDzTva6BTeZe1TOPSL8v9pGEAoXA2PO/B+0Aup98FJ8ayQrS4gZbhpy 5C6v6+dgEUA== X-Received: from dldz19-n1.prod.google.com ([2002:a05:701b:4193:10b0:127:8aee:c50c]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:125:b0:11b:9b9f:426b with SMTP id a92af1059eb24-129a715f0f3mr2275763c88.20.1773856706446; Wed, 18 Mar 2026 10:58:26 -0700 (PDT) Date: Wed, 18 Mar 2026 10:58:06 -0700 In-Reply-To: <20260318175808.582009-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: <20260318175808.582009-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260318175808.582009-4-irogers@google.com> Subject: [PATCH v7 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 Tested-by: Thomas Richter --- 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 Mon Apr 6 16:45:58 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (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 BDA9A3A7F78 for ; Wed, 18 Mar 2026 17:58:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773856711; cv=none; b=CLCOBcxdyRS2e7Fe/fkCdsOZGgo4t3CY9K85ve6iiv6tcNiAke6FSLCMbRSCcovI+JAACLSb6VHxniBCR8ohYbCeoFbuOv/vU3YMyTnefL0rxa8gxJaS9egtDDagjglzFZpooaoEWuErmJlx/y1KOJZPEvxNkJG6kAGPtJ7GQrs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773856711; c=relaxed/simple; bh=VynHbodWwy+JK/PZXN/ZPJWSVpu2Hji+rVLBlhNBGT0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=UCmhaDzKlgjwQD4gwAEQP9FIjZylppWPtYiUHf8HPzxvGFNKNCTW+RaAT71dq5kJzMATeq5iyV5u5M9xbqRV0O/fW1Zz2wp9XvamAjkDe9e8tkYJJD8x4Wl37H0g5claXeULvEvSESk0PI4d9eYr9N9TloHXRZhIJK3mCGdz7yE= 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=W/QqyG+e; arc=none smtp.client-ip=74.125.82.74 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="W/QqyG+e" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-127876be621so34522c88.1 for ; Wed, 18 Mar 2026 10:58:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773856709; x=1774461509; 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=E6hyJgw4C1gVTP8Dmq1+Zj6/J2J6L+bYpeRT5I66L9Q=; b=W/QqyG+e5MWmQAI/+UAfWQlb0eFbtwD+Fbm0+49j7PTZQJHwSVVKSmiseTvkzrfI8s Vdv28fd0lCkxlbHp7ubiFmKZkuaDNiCGLSSR4AGg8omuxVaADshUPAE/SQVHaUI2zc/6 CvOOujAPmJpD3G4VOFtMHqXawKrJwSDqGPueXAGBYCiS0wi+H1F/qAkybBCE1gjZ7tAD eT7CvT9Z6IvEwUKm8tvk1vtGr1OJmiGt3IE0SKQWqp8Bd2osdzlj/6SLPLf3Co8VA5JV XfG8sqdPm59vAQXqwVy56vitstnfVymWh7HmqFpFkJBCWQS3nZj7T8AqdLNU0aidMZM6 5ctA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773856709; x=1774461509; 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=E6hyJgw4C1gVTP8Dmq1+Zj6/J2J6L+bYpeRT5I66L9Q=; b=atHBrxrXKdDd+tfXO6d87X+ZXmNxknlNY0rUo+zi/sWehb4kUOAIICdT/oQ0K9Zxlz D8EMDZCpCvufTABb1MArb2Sj5B6tfUSrLm07LLLdu4jySFFpFxQXIQh2uQj7xGCtd47p Q6T06ii2tywZX6ZWkXFWTxSXkSOLvhoui4XwSdHEIG+gBtsNRd2qme6IySVfo731IcZB UzXbSr0X4JnuVXfct7GnPhONwFdjXhMVZR+pLSrYLuTsWhzo97pBVAl1BXxyga0nc/4W FhIe3HkXRqwn8qC1l5XZbVMtIwI0sgnIwGyoH9n38pAb2ORqIoPTTrsXIZNcmSc+I0Ho vexg== X-Forwarded-Encrypted: i=1; AJvYcCWbd/GYY7Sf6T80WKveEeo2LGvPQm8fsJ1Fhxfi9/FviqT8eCZ+Ssmsbqez52ONe22f36jC+zcrcDjmiyw=@vger.kernel.org X-Gm-Message-State: AOJu0Yzu3P/mg2x4pY/2mCetS8XjwYdocvf/JwtwKZKsz14DBR6vL5X8 K603QWhUKXoYgRxMT2CUFcqjxwrTrc5YCk0oCnyp5eV/SrqYiJXgdRYVfMp6j8IIST/ygMhMhj/ 8khityp+U7A== X-Received: from dlae16.prod.google.com ([2002:a05:701b:2310:b0:129:86:ce7b]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:1a81:b0:11f:46b4:449f with SMTP id a92af1059eb24-12a68594d79mr220833c88.24.1773856708771; Wed, 18 Mar 2026 10:58:28 -0700 (PDT) Date: Wed, 18 Mar 2026 10:58:07 -0700 In-Reply-To: <20260318175808.582009-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: <20260318175808.582009-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260318175808.582009-5-irogers@google.com> Subject: [PATCH v7 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. This requires the const char* string to be strdup-ed in __parse_callchain_report_opt. For consistency also make parse_callchain_record use strdup and remove some unnecessary casts. Also, be more explicit with comments about the '-g' behavior if there is a .perfconfig file setting. Signed-off-by: Ian Rogers Tested-by: Thomas Richter --- tools/perf/builtin-record.c | 60 +++++------------------------- tools/perf/builtin-top.c | 20 ++++++---- tools/perf/builtin-trace.c | 9 ++++- tools/perf/util/callchain.c | 73 ++++++++++++++++++++++++++++++------- tools/perf/util/callchain.h | 12 ++---- 5 files changed, 94 insertions(+), 80 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 40917a0be238..26223f9505c2 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -2975,65 +2975,25 @@ 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; + /* The -g option only sets the callchain if not already configure by .per= fconfig. */ + if (callchain_param.record_mode !=3D CALLCHAIN_NONE) + return 0; =20 - 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 +3485,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..5d2587228975 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,19 @@ 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) +{ + struct callchain_param *callchain =3D opt->value; + + /* The -g option only sets the callchain if not already configure by .per= fconfig. */ + if (callchain->record_mode !=3D CALLCHAIN_NONE) + return 0; + + 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..f879b84f8ff9 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" @@ -170,7 +171,7 @@ static int get_stack_size(const char *str, unsigned lon= g *_size) static int __parse_callchain_report_opt(const char *arg, bool allow_record_opt) { - char *tok; + char *tok, *arg_copy; char *endptr, *saveptr =3D NULL; bool minpcnt_set =3D false; bool record_opt_set =3D false; @@ -182,12 +183,17 @@ __parse_callchain_report_opt(const char *arg, bool al= low_record_opt) if (!arg) return 0; =20 - while ((tok =3D strtok_r((char *)arg, ",", &saveptr)) !=3D NULL) { + arg_copy =3D strdup(arg); + if (!arg_copy) + return -ENOMEM; + + tok =3D strtok_r(arg_copy, ",", &saveptr); + while (tok) { if (!strncmp(tok, "none", strlen(tok))) { callchain_param.mode =3D CHAIN_NONE; callchain_param.enabled =3D false; symbol_conf.use_callchain =3D false; - return 0; + goto out; } =20 if (!parse_callchain_mode(tok) || @@ -214,30 +220,35 @@ __parse_callchain_report_opt(const char *arg, bool al= low_record_opt) unsigned long size =3D 0; =20 if (get_stack_size(tok, &size) < 0) - return -1; + goto err_out; callchain_param.dump_size =3D size; try_stack_size =3D false; } else if (!minpcnt_set) { /* try to get the min percent */ callchain_param.min_percent =3D strtod(tok, &endptr); if (tok =3D=3D endptr) - return -1; + goto err_out; minpcnt_set =3D true; } else { /* try print limit at last */ callchain_param.print_limit =3D strtoul(tok, &endptr, 0); if (tok =3D=3D endptr) - return -1; + goto err_out; } next: - arg =3D NULL; + tok =3D strtok_r(NULL, ",", &saveptr); } =20 if (callchain_register_param(&callchain_param) < 0) { pr_err("Can't register callchain params\n"); - return -1; + goto err_out; } +out: + free(arg_copy); return 0; +err_out: + free(arg_copy); + return -1; } =20 int parse_callchain_report_opt(const char *arg) @@ -257,14 +268,12 @@ int parse_callchain_record(const char *arg, struct ca= llchain_param *param) int ret =3D -1; =20 /* We need buffer that we know we can write to. */ - buf =3D malloc(strlen(arg) + 1); + buf =3D strdup(arg); if (!buf) return -ENOMEM; =20 - strcpy(buf, arg); - - tok =3D strtok_r((char *)buf, ",", &saveptr); - name =3D tok ? : (char *)buf; + tok =3D strtok_r(buf, ",", &saveptr); + name =3D tok ? : buf; =20 do { /* Framepointer style */ @@ -328,6 +337,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 Mon Apr 6 16:45:58 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (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 4E1E52EBB89 for ; Wed, 18 Mar 2026 17:58:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773856713; cv=none; b=PLa8WP+7cXZw8BvlrOIhplI92WXcIVdJkp/vMoK12mIeW7f9/tkF8/+9lD+77LLgwcL4xN/qj6vhghi8wXRlUSXVWXeY0c+2qT0yGKaj3V8erIf19aD+TSwEPsjDiqbuiO4c3KgOj4HbkqtLIe/m7gz6DKpH1KHCwaUaSRWnWfc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773856713; c=relaxed/simple; bh=GPpwA85YpY3ve/jpJyD7fWcf24krXiV0PAh/fAaUiQc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=iTJ6A6tTzLYA5ZZq4CfKP/+vUHuwRhZ/e4h+739ZYRQ58P6Bya62Kb/avBMqiTY83PKdQOnSZms7QZtljjDpaHyg9FK1BBQ0qkpycK3/soKctMSfEG/81LRsxCtPxYh27F5k6ZtHFLKInM8mQU1J/s//1/3c9ClkEI1XFqiDKJ0= 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=E3ChCD28; arc=none smtp.client-ip=74.125.82.74 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="E3ChCD28" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-12721cd1a2aso3842340c88.1 for ; Wed, 18 Mar 2026 10:58:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773856711; x=1774461511; 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=bT3J+EWYQrSSWTHjOQc06GLH9CU25PGV/fk5O36CMLI=; b=E3ChCD28/FwunJh3w3NqmFUKkRj/4nyaulbCKeknyZq8ttBodbCqdDggvQcf4TThQc zX6eVuyanYRAz8URSi8urq0m/ofHlmiO49PTNcHSp5Gx3ddePr+DgG/t6QOQAw43R2yM tGDf6yhnbaahI/xpj9ujog0/RK/2T1a+lG36F4tde7NTvNrSPsZnVygwUmmF4V6ycuVN CCffc00KaIZghXiXWk8wNoVgwzZaW1ce2pNMx74b3ycTWZ0fHBqeaJb2uPPq0zQAKqr9 a51YVgu1uLCHJ3w1Yr8+TXq5DcO0z/OtZLSml45QGqWqyMAtgJK3R7Wh+fT8V10qQsDz FvyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773856711; x=1774461511; 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=bT3J+EWYQrSSWTHjOQc06GLH9CU25PGV/fk5O36CMLI=; b=ZmNAsTp0XU66IKzqdMas/CDXDEUHSGQDNhYkcGQxTZMOzqusiujqieVMj+n0GsCBnk 2zbDs9aPs9Aa4ensPCarC61+5lE5obPuAmDADI50RbevoPkLNxBldN2yYGMAPga4dzhg 7rKlq13Vg9gWysNOlcHj9GDtxa/jQQ1kltBdgw4ZpIqOCg45FZXTtoNMlQX/R2jz9/i/ VhOSThQ1vbEk3xVKSV9f+ZTspM3jkn4jcrfBlGeWowBkq9QNT4wTi52sEMF9bcQ5+WL8 j93AH4Aq1nj84AFRGEcPhLjnrOWQk9CPkTnHhHFUIFlUBYDYIhOsRr1KRAZLVmImERUV A6BA== X-Forwarded-Encrypted: i=1; AJvYcCVdbLlQPcRXWCDazuFgiFsjWJ/qCCM3406AmZ7ImSwVTlUEHP8lz0v86ontc52afL4igLbUjzNK2K62lE8=@vger.kernel.org X-Gm-Message-State: AOJu0Yxwfe+Ys0Eme9uh4VHweSUdw9zW+3TGV4CYfMJBcHUMNbt9YCQY aTgLU4diKz347I14IRg3sYljWEnx06a/OIbkw8zZKJ5D/ZonS2QCzefHM05ptJOdH9ky1FwOZwY DOb5LA+cHvg== X-Received: from dybuh11.prod.google.com ([2002:a05:7301:750b:b0:2be:82ee:95dc]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:2513:b0:122:2f4:b24b with SMTP id a92af1059eb24-1299d187bf1mr2286090c88.25.1773856711119; Wed, 18 Mar 2026 10:58:31 -0700 (PDT) Date: Wed, 18 Mar 2026 10:58:08 -0700 In-Reply-To: <20260318175808.582009-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: <20260318175808.582009-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260318175808.582009-6-irogers@google.com> Subject: [PATCH v7 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 the hardware 'cycles' event to the software 'cpu-clock' or 'task-clock' on s390 if callchains are enabled. Move the target initialization earlier in builtin-top so it is ready for use by evlist__new_default. 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 | 23 ++++++++++++----------- 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, 59 insertions(+), 30 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 26223f9505c2..a03acfe66c27 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 @@ -2990,7 +2991,9 @@ static int record_callchain_opt(const struct option *= opt, if (callchain_param.record_mode !=3D CALLCHAIN_NONE) return 0; =20 - 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 @@ -4269,7 +4272,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 5d2587228975..3cc339ec04e3 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 @@ -1415,7 +1416,7 @@ callchain_opt(const struct option *opt, const char *a= rg __maybe_unused, int unse if (callchain->record_mode !=3D CALLCHAIN_NONE) return 0; =20 - return parse_callchain_opt(opt, "fp", unset); + return parse_callchain_opt(opt, EM_HOST !=3D EM_S390 ? "fp" : "dwarf", un= set); } =20 =20 @@ -1700,8 +1701,17 @@ int cmd_top(int argc, const char **argv) if (annotate_check_args() < 0) goto out_delete_evlist; =20 + status =3D target__validate(target); + if (status) { + target__strerror(target, status, errbuf, BUFSIZ); + ui__warning("%s\n", errbuf); + } + + if (target__none(target)) + target->system_wide =3D true; + 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; @@ -1794,12 +1804,6 @@ int cmd_top(int argc, const char **argv) goto out_delete_evlist; } =20 - status =3D target__validate(target); - if (status) { - target__strerror(target, status, errbuf, BUFSIZ); - ui__warning("%s\n", errbuf); - } - if (top.uid_str) { uid_t uid =3D parse_uid(top.uid_str); =20 @@ -1813,9 +1817,6 @@ int cmd_top(int argc, const char **argv) goto out_delete_evlist; } =20 - if (target__none(target)) - target->system_wide =3D true; - if (evlist__create_maps(top.evlist, target) < 0) { ui__error("Couldn't create thread/CPU maps: %s\n", errno =3D=3D ENOENT ? "No such process" : str_error_r(errno, errbuf, = sizeof(errbuf))); 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