From nobody Mon Apr 6 15:50:54 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 0DAB33168FB for ; Wed, 18 Mar 2026 23:46:05 +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=1773877567; cv=none; b=WOiqEJ2rp+CVLkmr5h+Svo0lwtojhsylePkopDvYMqBA/MOXH7UhrO2Qaae1G4Ng+U4KebiYoc7vriYP0ZGnkEXkht+OG76x1w1gFDO3kYTrZYr1WwI3pFOeb71UXVOkJaMG+3hT0A2m6hP6hyifpgxjoyMAGLvcUNhi3froRaM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773877567; c=relaxed/simple; bh=U8LqxsgGl8pPzMoHQSm3GXUaosjRDy/a3rvRqghM3i4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JcI/12Y75DEJYmFaKCGs+0f8fhD4XefKyGbUiWbjgAA/hZ9VsE6kb0IccXk501VF6fNgH6EKXeWmY3HG2nL4RjmMa3rvbDMixkivIr5aPOlF91hcU0cSOkQVRPDLhYyVAilEoKF8T64fk0Sd1vii/pnsFcS6hrwqjG3+yGiL/+s= 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=YJJpnqBk; 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="YJJpnqBk" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-128d285d6c3so410710c88.1 for ; Wed, 18 Mar 2026 16:46:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773877565; x=1774482365; 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=YJJpnqBkiT68ho/nAKjUhO1hO5eOO8U6zswV3CoyDTPuxhLx+HivLXX/LajsfnAsxy 9do3LJPLgQqmEpdLeqAcl8bORSDkbNTyYpmJSdRIUPVImQTAFo/CYdvWPmQoi2vsJcjw NqIvapejS5CLO/ByLAf227R/xLhjnEHLa3LDCTYqh9J9wKB9OCL9ogSkwIfYC1RfPWJK 7lZNt9vg7ltxNpEywW3fyC4KFIjfF6595g6YycP8IxZn91JqyEitJSvGmJY+SF0BT8fU mV+/hlW0ks3ySin7OZZ0Ewni9fu91kvBNP7L/vy3QILF6IPccn0valXkFhc3Bp1toUms Mydw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773877565; x=1774482365; 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=EE8VIedaaAWzH/8hWFIbBM3hSqsb1nNLintkHV7u3tZfcxOKLIqZyVL7Ny51tLgN2/ v09YVlA9UkxrVk8F9hE5hMMurw0nENhfIJy6R1ed33TU6g0XtOFAegY6SB8M9nKHHa0v +qlCs9aaS9rGHJMBe0SASNYqmN+283sLlmrb0KpyB8Cjtfhz40QVZGSwSbyd+kUhamHs N/A42rayYEg89bMz7Gt/PWfU6VeiXuttLgE674e5k3slm3BQvyGuGSb1W/NM6YN6DhrB GQg2QLmvdAZ7hGpIqYCGebD+gP3L5yDSkZiHn7Yj+QaUexkjqp3qv0CwTauNeeJQxFDt sXWQ== X-Forwarded-Encrypted: i=1; AJvYcCWWuKbZBqJO+mvuNHNfuXJq6PW0lshpGtMTv8LDT5q9IWTCvwXDcm3Tvq12TOIhZgMxBUWh4S1w4NwC7tU=@vger.kernel.org X-Gm-Message-State: AOJu0YzCxnaDQmSlpZMZXLCPhEk6j5yTqHSkg581YVuwihMn5CVL+9FJ CLahMTyN6hXd7DIOABCdAh4i4hSHEC3wVlFxtWYDHbWIOkqIWpz1B+V0SnIHEp5CZD9iITtmfNE ye9DmYUDtkA== X-Received: from dlbvs5.prod.google.com ([2002:a05:7022:3f05:b0:128:cff2:6560]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:250f:b0:128:ea68:27f4 with SMTP id a92af1059eb24-1299baa0042mr2372545c88.4.1773877564922; Wed, 18 Mar 2026 16:46:04 -0700 (PDT) Date: Wed, 18 Mar 2026 16:45:56 -0700 In-Reply-To: <20260318234600.730340-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> <20260318234600.730340-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260318234600.730340-2-irogers@google.com> Subject: [PATCH v8 1/5] perf evsel: Improve falling back from cycles From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com Cc: irogers@google.com, 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, 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 15:50:54 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 262143932EB for ; Wed, 18 Mar 2026 23:46:08 +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=1773877569; cv=none; b=DnQEDu90XEu691K97NC4VCYLh/FOjuK4a+KksRfwUV8N5aeVLF0s6aZ/xBFH/8a+qtuyCyxBY3umEYoPjuIL/cgeiqCpjO+BiRqVQ2IrK4sQ3h4q7IaIdzupKdxG06upoDSTIkE7/IsFOUa/zV2n3cZml7zPoBEWzglST8qwHgg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773877569; c=relaxed/simple; bh=AT0BGB6UrGLZA1M+tVNdNXzlDjYmvZvAEkPOTSTH+IM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=bnrH1cYHvNHJ7Pbxg2cZuDBv8/pgZgahm3YcO8qSKag6CYbUNzwM85J1TjRFFUPeNI0izEjpVLcIDzOQQxpgShnAaZFnIBqkLGQMVWO1xzX7cMKRJkhGGL9UtuRuBNdAtxptkVmPemfQQMReekDgtm6VjROs/65Mc2LhyIrTWrU= 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=eFFxukJo; 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="eFFxukJo" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2bdf6fe90a9so405835eec.1 for ; Wed, 18 Mar 2026 16:46:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773877567; x=1774482367; 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=eFFxukJoIwm93af97U7nWY6GelLr3kLO3o8PC/hgxic/A4hEwADtw6vt8BoOVz+Npa aq2MeH1HdlEyIO0Y6ydLETH79WejFjlv6ODR67Um9BG/Uf6y/o8q/kKyW46pot75pQGD 1Sac//uGc0KmOu3k5fgLGxREy6m27jJLfMNpqLVMESOVLVWf83y742JQSofwrw0as3Kd 9QRTan4A8ftYlwSSqb7ph9YCHpXNnKn9D5mBaBmkx3wc0wosGS4FEpaKO+dtDiyazFzV t0QuYVyG0A271ugqIE4xi1v4igz/v0TvgEIAet14Jrmq5ACYNQ/NT+54iXFUc6OzXpKI +Ofw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773877567; x=1774482367; 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=P5WbLiPEcFW/7YK0TxBa3t9r/8Prtrdg9jzBkPjsU1S10hQCaKczOCu0loULMOPp6M MjlxXSlw6wRmY6fHsEzD1mmS1r7CkMx1YbFIGVhdU/aJtGUXOOGaCfb9cUannaNY2h7y UKuzNdTiIRS6b9ZbzzHAgYXcl5ZDQ/YTIG73UcIv/rgGScrtg/cEDE2H1yQOZ41S5JMx XcmepEpjBXsW5QVCuO1r81jUNClXwfiEqpwe+nbujRoRtbICS9uwTVVPjHAbj23bcR6N 0vvDtq9TPji2LK3rLQTkv2SAe55uHzacV0LYOURTE+B+xOmSjPjXdh5pUpbBBnNRAKDe 1Fkw== X-Forwarded-Encrypted: i=1; AJvYcCWWD/jrhDP5Z7fM5E0jQSlcIJjhLbUGt1+hqID9kF1NR9iD/6NiWNXZ087DadhmnFIp+lVlwe7XEwZw55o=@vger.kernel.org X-Gm-Message-State: AOJu0Yx/4grQZMoXs3g63j19s3hI2Lf41lYaFaQ66sNta9kItJ8Aq1er moM/QodX/OXKhxFWkxq/1Mjg2mzp85Fi4ghyhyxJ3BQjQCdI7MhEaYPYNNOgFZxa+pSFViMJlT3 Tyx3/Ix8Xwg== X-Received: from dyckg8.prod.google.com ([2002:a05:7301:d188:b0:2c0:b1d7:935c]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:2152:b0:2c0:cb34:7d54 with SMTP id 5a478bee46e88-2c0e5110301mr2350996eec.28.1773877567053; Wed, 18 Mar 2026 16:46:07 -0700 (PDT) Date: Wed, 18 Mar 2026 16:45:57 -0700 In-Reply-To: <20260318234600.730340-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> <20260318234600.730340-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260318234600.730340-3-irogers@google.com> Subject: [PATCH v8 2/5] perf target: Constify simple check functions From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com Cc: irogers@google.com, 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, 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 15:50:54 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 6E938392C5A for ; Wed, 18 Mar 2026 23:46:10 +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=1773877571; cv=none; b=Gcsc3D4W60pPdIzLHcysJntwEWxUyzc/7ULzoOIcReyU7+VkuqQL0dZNfWKhVZW//7hkGZdykBX7KmE8kJlLElqvCiRyIY4fDLinmygQKMvfNY3yiGmzlM7Ye1bUuCLUsvjxvkvKjNeMYSPBq1ih6/u8obp+oki4sc46Orch5Jg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773877571; c=relaxed/simple; bh=A0GmPbCjJnn1aBXkaKYVs2MSN28WJDd3xDZa3Kc40Go=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ZF8ZRaZX4Spy88I17lGb+tqDMmakLHRVxAL59nfvMj6pCqs2f9cPjvw4YUz4YkScq8bOQqqarU8cWlcn5QVCk2JVuWcRcduAfPF225VkfS3t1NMPUTqe0p6Cuf/q9ukNu0pqkc45tluNmc+Caj5t9D3hyJLK9UNbb8lVCV5ZMJs= 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=iEdIfV69; 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="iEdIfV69" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2ba8013a9e3so392974eec.0 for ; Wed, 18 Mar 2026 16:46:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773877569; x=1774482369; 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=iEdIfV69T+tyM0zjCMfTP58dENPRL7GP5hT9vTvlkAs63Jun1Ba47HloosEgKTGvkc NzqGDNxUSCAF5FxniAP/Id/EuCkaMOdh6XV8K8TQqqu2/a/dCXfRGs1zXyT8MgNPVb9R 9Y7WIlunDSdcvsWoZAH6v34eu1XL0kKXx4xS2z2yzmOEuZfLbXAMudxP0ZM4SEY60Hjs JRAxpISZSYmAFr9UXTnAN2vMY4BdgLmqVJFw9Y8oSBfaZ3gfcAKYFuPxYaluXCpFZaWC aXqsYCKcTK/cur0Yr8gcSxDpl/DL3ky0U/aLwaMYhQSijXFqrejapj9FwsNZ9BuGhFdn BQLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773877569; x=1774482369; 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=X18+6aqKrVRpYxSVy1gd9sTNM1eHY+7goWkCS0o+DnFWa33eOz5P6DE2xFvEUXCI6J qF4XlvMhmsqohKGnBHWvw/vj49r2E0eJKn7dAUrJmTS+uQR5QgC31DdKSRN9b9dxoxxk 50ErZpXbR9ulY10hp7zE4cAN4W57ciTAfAM2AfTpcB8sFIL84saO7916alRwXhO+5Wfl i3r2lytRuSjztTXRVwV4hltNDTN86geo+IehDw7ZndEsQDHMBFIdtq8G8A54o+zkmHOG iDUuZ2Ws+tKIW/OQR7soo9LE6qY0q2Sju0dKBIc9mAoubkN0CIr97KNNyG8Y35+J97We 8THg== X-Forwarded-Encrypted: i=1; AJvYcCVM2Xfmz8MtCdY8H50gkDxtF9+YNa2cImzRhM/5fKjrnMHYrtUV4dXx4+AENa81l6UCDATRxgw1f1dsUFM=@vger.kernel.org X-Gm-Message-State: AOJu0Yzdo0Lsrt0lQXWmoIofLaIFB1M5F8wSjBD8YTQlmAyWACO5eNf5 uBo3wO9h/Bnvi5giTtAVx2q2ox+gPSYgI1ivQf8xJZfIYUGvCi7+qYpXifW4pi+KjbbWlQ4F4z8 JEY4KaVtivw== X-Received: from dybsy18.prod.google.com ([2002:a05:7301:7012:b0:2be:798b:cb2f]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:693c:3011:b0:2be:1779:3289 with SMTP id 5a478bee46e88-2c0e518a4eamr2682053eec.35.1773877569345; Wed, 18 Mar 2026 16:46:09 -0700 (PDT) Date: Wed, 18 Mar 2026 16:45:58 -0700 In-Reply-To: <20260318234600.730340-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> <20260318234600.730340-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260318234600.730340-4-irogers@google.com> Subject: [PATCH v8 3/5] perf evsel: Constify option arguments to config functions From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com Cc: irogers@google.com, 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, 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 15:50:54 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 A93ED393DC7 for ; Wed, 18 Mar 2026 23:46:12 +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=1773877574; cv=none; b=tHBCMZt0RfILHKpJNdDJd/O0Nt6uczywcqo0eftLsvhnR2PGAmoq/qcdKvZEBzDBqgWinyQqDtZYdrACqa8I/vdOawqeJHK4Ia4HqSagCm8TAS9D1w785VXzMGpdxUmyqVVsmBsV8cETUStBHzD6HOmXT3FCn89ktzGeQMendME= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773877574; c=relaxed/simple; bh=kXBUwxcNAtcUv23zqcN/GI6JSLZG7/N7o+6cy4C0vDw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ZhTwYDZAEZVQIN8jQmQsAk9r2n4Rj/Vp9wRCI7LqZiR7qmoKOxzkZRv36ZcWAztyTd9WGUVPVXNV5weJogMgq7R88NyzfAyS4E0OnA1A6+FjVwRS4y8LWz04G/Z6jjC5R7lJ81RtHf/8Kmq79hj2rIl5nx+btqTvlPcNOCceamc= 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=nlQirk1I; 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="nlQirk1I" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-12776bebeb3so11974157c88.1 for ; Wed, 18 Mar 2026 16:46:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773877572; x=1774482372; 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=EJuo9PIukgRXPN5KtnhW8Qv30Kc+cVHS/OAPU6GYygI=; b=nlQirk1In8q8faomGffNal0H0qOkxH7EGlG+qnVmxuW7tYm2EH86Ib/EtwMH3BT840 DpT4ZQLQ3OgNr9nkIc4Q9GpEGGgm5JhFjCARvlDYvQb4HfI1lBVaHgbX7334yRCaGXuj eG9MnS2wKOc0Vbg8N9exQ2SLx6cAgxqZZIMAGCaOVq0mZ5iYCebgdyuV3KavRBsxPgyE IB6sXWLh8bZxcDmOuZNONnG/LsDJnKjjWEZTfQM5AxPcKqtMEhE021AeEZIvwmpRobMA o5xJ92y843euTQVKjmD1u3NczKTq7GY6IaGn+5ip6iSJr7S5LFbPel/PkF3vS+krMgGD 8pbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773877572; x=1774482372; 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=EJuo9PIukgRXPN5KtnhW8Qv30Kc+cVHS/OAPU6GYygI=; b=q+ATDYee6B55XtH9cPExzhAcAU78gWKHjBBjvQJ6gf6I8fOHLAIgh5j1qQ7RBYKtyo nKR2QFKG4+x1DXfjmQUFHHBcfNSWcIRFgYxqeAtmdJQ0PfqVWaj3tyAxF4B62+oBuSfr gZwbCjvZJjhneLuBx3HC96tWsRNZHPKnFiMogpwLQpJ63wkmqiZ9thIXCdYqZ5wmo4ti j/oQzChDHpySOCD7FzwRJwQ/gtJGsN0+SWA0uAMSZ95ZWz36mlgRv78ZVxUd0N/hZZDW N6oGw88VmtZm8bq1QSSSvzTVH2H3xzO2k9Bx90yfGEKUtRJXb+EmYqgQP4BuexUu5SJa Jm7Q== X-Forwarded-Encrypted: i=1; AJvYcCW1IHpojyCg1L9idp4ua5l4fY0V/X2O6Nzi0ycTiJ4Kah3fx8f7tjsBEV73HzM+2iu9Z/Jz1not/COhbtE=@vger.kernel.org X-Gm-Message-State: AOJu0YwgH2tzm4LspjbRJR9yQFOvjdEfWX4C/TOC6C+RSKbRkNcgT2MG yPsJeITERzLsYXoBgJxvMBPr8BeDGE40xXynFVJc2aafB2ZaD9+cAa7p1CXYQ6qZs0Bmej90uAj 3EM9grpKlwg== X-Received: from dlbsn8.prod.google.com ([2002:a05:7022:b908:b0:128:d8ae:727f]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:90e:b0:127:9b6b:2b08 with SMTP id a92af1059eb24-129a07e66dfmr2829811c88.6.1773877571789; Wed, 18 Mar 2026 16:46:11 -0700 (PDT) Date: Wed, 18 Mar 2026 16:45:59 -0700 In-Reply-To: <20260318234600.730340-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> <20260318234600.730340-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260318234600.730340-5-irogers@google.com> Subject: [PATCH v8 4/5] perf callchain: Refactor callchain option parsing From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com Cc: irogers@google.com, 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, 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 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 | 65 ++++++++------------------------- tools/perf/builtin-top.c | 25 +++++++++---- tools/perf/builtin-trace.c | 9 ++++- tools/perf/util/callchain.c | 73 ++++++++++++++++++++++++++++++------- tools/perf/util/callchain.h | 12 ++---- 5 files changed, 104 insertions(+), 80 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 40917a0be238..59b8125d1b13 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -2975,65 +2975,30 @@ 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 configured by + * .perfconfig. It does, however, enable it. + */ + if (callchain_param.record_mode !=3D CALLCHAIN_NONE) { + callchain_param.enabled =3D true; + 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 +3490,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..b6726f4dffb3 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,24 @@ 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 configured by + * .perfconfig. It does, however, enable it. + */ + if (callchain->record_mode !=3D CALLCHAIN_NONE) { + callchain->enabled =3D true; + 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 15:50:54 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 B2187393DF7 for ; Wed, 18 Mar 2026 23:46:14 +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=1773877577; cv=none; b=Gu56O/tIwA4TU+xbmyttZBRUCy91fR9UG1E//zuDKUg6Y5Pt3wzy0W1g78dAiLxuhTGqlFEgEhlFWcZChNTP+D3uO/fpw0N//02ywWTQpqR6asjVhYMqz1CiHip5wS45gi+QOHK2wEMS4A22qc+sqrVgqOwfIRR5dGGiXxB/rgA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773877577; c=relaxed/simple; bh=hWlHUlY1KBEUso+82QhexCptJkL/cgS7z0Uij0nS5pg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=u+/Po6X64RUidF2lof79vqIub7RWFWBizXewoPg3nswW0izGUU8cMAGhMhXq/zBiLet94B0UxxhzB2Mz0Nn1Rvth1sTNJcMjD/yKngSWTMOp9H/+ULPK77YbP0sh3/Mak73AcNfalgOo+XW5H93ILVOARKKiWR5iBNvPp+A/noI= 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=CrPe8RqG; 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="CrPe8RqG" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-128d285d6c3so410818c88.1 for ; Wed, 18 Mar 2026 16:46:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773877574; x=1774482374; 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=nMY8e2nXchz3cJrJ3A0a9fKJa//sBNfOk9+ZFibdgVs=; b=CrPe8RqGQjz0fHvMyzBYex/mYXEl5TtIbiTc8BrrR/OavjP850DLgDTeKc/Cneeq2L 3zfKOY36UVRC0cCJEznWLiiPcuG3N93+nUcMnCv8SofbVw1UGLckO+uvpUEiS12szoVn D6cywXOcG52W/2T2aOIsrU5iDYnGcoig1zRBiTxnrg54m8tLyHEQCIQ3y9RDt3/lk4vM 4OpwyuGSlgLTE23OZ2kc0hzPH/sfSb3ycy46F0GzZGGWn4Aix8loXPLPDAusdiLCEuW1 MEw7FWBsti7o+fMpY1rE3q8P6LcW0PbiTvz25Vv1StpizWMfb3XLNb7d4MkivQsvvii7 n8Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773877574; x=1774482374; 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=nMY8e2nXchz3cJrJ3A0a9fKJa//sBNfOk9+ZFibdgVs=; b=qTZOV2G3+ts5Zmqu2j821bUldRX4CmRF0ouCHVg299IPEwUgf4JpmKbAuoygKgCHNn PPMIyFRQWG9w0GVA2rhOJ98tQBAqiD7HcdKVzvwF8TBX8swuzONGfg5Jyhf1QPww9GJ7 heD6CTh/NmVUyleG6eob6h4EI/irvzy81zX4kpZ1LkcY+poo8R76k6YkU0gqznfhQvx0 OxHR59s3q2VOH2t994NSHSHo9fuSQPb2TsVoH7f/q/G1Tb/0v92XzHLkFxE6nKKbeXyX bd0hztxbeR8YJUcll5ZFu+ObjuB1J0/J1nrF+eist2MdjxDo5feyfEzSy3XYCBPgPYy3 999g== X-Forwarded-Encrypted: i=1; AJvYcCXdc+nm8mde9efElbV4CjGdhxTChxKgkauzD+7VfoomVsfE908/xe2qntQGFglEH/W5P7YObt65mDHzkMY=@vger.kernel.org X-Gm-Message-State: AOJu0YzVwNbrI1UFwfQnmOfqI86ZEbDIF7Vzrv4NqcNfeCm0eKG3fPdp 7RiqrE4IX+aZKOBMgid0SQxMGO2O2Wlf4Ud+6y0peRYKoskcrpBNKj3+peQQXM/trj9vjWJnVNx rCGHX4Kvnog== X-Received: from dlbur23.prod.google.com ([2002:a05:7022:ea57:b0:128:cd31:49b]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:701b:420a:20b0:12a:6a64:81f1 with SMTP id a92af1059eb24-12a6a648484mr155494c88.5.1773877573748; Wed, 18 Mar 2026 16:46:13 -0700 (PDT) Date: Wed, 18 Mar 2026 16:46:00 -0700 In-Reply-To: <20260318234600.730340-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> <20260318234600.730340-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260318234600.730340-6-irogers@google.com> Subject: [PATCH v8 5/5] perf evlist: Improve default event for s390 From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com Cc: irogers@google.com, 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, 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 some of the target initialization earlier in builtin-top and builtin-record, 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 | 18 +++++++++++------- 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, 64 insertions(+), 35 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 59b8125d1b13..3276ffdc3141 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 @@ -2995,7 +2996,9 @@ static int record_callchain_opt(const struct option *= opt, 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 @@ -4095,8 +4098,11 @@ int cmd_record(int argc, const char **argv) =20 perf_debuginfod_setup(&record.debuginfod); =20 - /* Make system wide (-a) the default target. */ - if (!argc && target__none(&rec->opts.target)) + /* + * Use system wide (-a) for the default target (ie. when no + * workload). User ID filtering also implies system-wide. + */ + if ((!argc && target__none(&rec->opts.target)) || rec->uid_str) rec->opts.target.system_wide =3D true; =20 if (nr_cgroups && !rec->opts.target.system_wide) { @@ -4274,7 +4280,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; @@ -4303,9 +4310,6 @@ int cmd_record(int argc, const char **argv) err =3D parse_uid_filter(rec->evlist, uid); if (err) goto out; - - /* User ID filtering implies system wide. */ - rec->opts.target.system_wide =3D true; } =20 /* Enable ignoring missing threads when -p option is defined. */ diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index b6726f4dffb3..37950efb28ac 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 @@ -1420,7 +1421,7 @@ callchain_opt(const struct option *opt, const char *a= rg __maybe_unused, int unse 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 @@ -1705,8 +1706,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; @@ -1799,12 +1809,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 @@ -1818,9 +1822,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