From nobody Tue Apr 7 01:02:04 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 B5F5E28314E for ; Tue, 17 Mar 2026 03:06:13 +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=1773716774; cv=none; b=rX+NjvQKkZiCXJ8KvO2IFbmFmsU4oBm6H0F+r5Vi6W5DHN1KqpsPDH3HJVi04Oloyx2ZL1v4A1fx6KJsItqwk9P0vpbJmWQmEI+akyP72xFyNI/jqW3IU0pGxn2YSRBEmxkMxIDqOP9eetbnrqZwJEDaGL7bMJazqNqJVrUi8Fg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773716774; c=relaxed/simple; bh=wVIk574MaJ1ryn6M1d5QWZAOYLPanqIo/c++6wESi+o=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=bgVGTt/r2lq0hzDTFCPEzj5/vuUohqmBX5r+P1XgziqZLodrpe16EgMypvLcvNL/3t/NfbPWqrb7ZmZhndiIny8Z6y442NovIYMT9wwbluUkEgsT/vjsIqLxzMJ+0F7VVTaYGhWRsO7IZzaoE1cmxvqmHWsUp/3AWfoiBToSuN4= 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=kc5Zsrc7; 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="kc5Zsrc7" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-127337c8e52so102716213c88.1 for ; Mon, 16 Mar 2026 20:06:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773716773; x=1774321573; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BC7DFlkd9xaG2royXDyXDCwOCftcIJRM1qoiGuRC8ho=; b=kc5Zsrc75XtQXWMlr9QFNaqSkuB0Pj8HMKsqmsEzWKZbEvzDTHgUz6fbuDR8tSHJDW BJgJ0d5HDruUjQ2v6cJ5RgM0PiQxJmqPNQk5XIq+PskB4v6pyhS6FS6z3sMPdPz5KxUZ QqLas6rMF+IJVjy38ioJGeSXyPiJbkv3goNLqDaHGkv8Mk0MUFTMEFNS3FDJu+xEJL+5 Pu4D9ATtznrdbkZjzWfaKWXvdv8d0NuJtTx94SMQ+V17LFHJkGehlrqsGzZ63/tUk8vi DG7Be8QMjqqbCpnQAYvimeCnxbOevh4zpk6SYdcBYxucHaU9120kZ/TB0FSVyJgGWwS1 dggw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773716773; x=1774321573; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BC7DFlkd9xaG2royXDyXDCwOCftcIJRM1qoiGuRC8ho=; b=CD91SPaSxGdXATgc70wGun+R/xsAxgPsDD6x/4f73/fxLi2JYm2sZv0PWiQsYNfh8P YcKgSThYCIY2xkATQ5s6n382zE1msv74Ym2M1R+5LbwVgapH7UT615hdvhqiVE80WUan hhyi9updXL0cqQOcjlcIHvAs7lS7MVo3oWZL7tbTZRayQmCR6nHVlXmi8mhaetMpzBgS I1CMiALHfbqwdckVbiSQSQbuqBfTGvrv+Gwa7M4JnyFauDKGv3lHV5Q20xZAKmf4TMVZ 2p8iDVE0nOQD8ckpYb38mwCAUt/DDmYDGoYf2P5ZbbUcj6stsjE/yRNzn8oIZoQfNG4W JM9g== X-Forwarded-Encrypted: i=1; AJvYcCXqlwg2oMtTTLxgHqiGkmjFdbEkURYhXE/RQyuBsePFUwHNVLBful+bzcP1a6VKGV9XlfqI3LddTEs0Xkw=@vger.kernel.org X-Gm-Message-State: AOJu0YxNVg/4BLXN11Td1ZFjloByqLV80AQGkInp4sAg2+cAHyD63ydN NmUIIKmevW6c4XnokasJRYdQAuao4VUpD6/sdaNFjZWLnca4lbg8ejeU4i0yqGCE+V8MA7j5Vi5 /coA0Sc8/Xw== X-Received: from dlae14.prod.google.com ([2002:a05:701b:230e:b0:128:d97e:9ee4]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:2393:b0:11b:2de8:6271 with SMTP id a92af1059eb24-128f3e350bcmr7954454c88.39.1773716772453; Mon, 16 Mar 2026 20:06:12 -0700 (PDT) Date: Mon, 16 Mar 2026 20:05:57 -0700 In-Reply-To: <20260317030601.567422-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260317030601.567422-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260317030601.567422-2-irogers@google.com> Subject: [PATCH v4 1/5] perf evsel: Improve falling back from cycles From: Ian Rogers To: tmricht@linux.ibm.com Cc: irogers@google.com, acme@kernel.org, agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, namhyung@kernel.org, sumanthk@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch to using evsel__match rather than comparing perf_event_attr values, this is robust on hybrid architectures. Ensure evsel->pmu matches the evsel->core.attr. Remove exclude bits that get set in other fallback attempts when switching the event. Log the event name with modifiers when switching the event on fallback. Signed-off-by: Ian Rogers --- tools/perf/util/evsel.c | 45 ++++++++++++++++++++++++++++------------- tools/perf/util/evsel.h | 2 ++ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index f59228c1a39e..bd14d9bbc91f 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3785,25 +3785,42 @@ bool evsel__fallback(struct evsel *evsel, struct ta= rget *target, int err, { int paranoid; =20 - if ((err =3D=3D ENOENT || err =3D=3D ENXIO || err =3D=3D ENODEV) && - evsel->core.attr.type =3D=3D PERF_TYPE_HARDWARE && - evsel->core.attr.config =3D=3D PERF_COUNT_HW_CPU_CYCLES) { + if ((err =3D=3D ENODEV || err =3D=3D ENOENT || err =3D=3D ENXIO) && + evsel__match(evsel, HARDWARE, HW_CPU_CYCLES)) { /* - * If it's cycles then fall back to hrtimer based cpu-clock sw - * counter, which is always available even if no PMU support. - * - * PPC returns ENXIO until 2.6.37 (behavior changed with commit - * b0a873e). + * If it's the legacy hardware cycles event fails then fall back + * to hrtimer based cpu-clock sw counter, which is always + * available even if no PMU support. PPC returned ENXIO rather + * than ENODEV or ENOENT until 2.6.37. */ - evsel->core.attr.type =3D PERF_TYPE_SOFTWARE; + evsel->pmu =3D perf_pmus__find_by_type(PERF_TYPE_SOFTWARE); + assert(evsel->pmu); /* software is a "well-known" and can't fail PMU typ= e. */ + + /* Configure the event. */ + evsel->core.attr.type =3D PERF_TYPE_SOFTWARE; evsel->core.attr.config =3D target__has_cpu(target) ? PERF_COUNT_SW_CPU_CLOCK : PERF_COUNT_SW_TASK_CLOCK; - scnprintf(msg, msgsize, - "The cycles event is not supported, trying to fall back to %s", - target__has_cpu(target) ? "cpu-clock" : "task-clock"); + evsel->core.is_pmu_core =3D false; + + /* Remove excludes for new event. */ + if (evsel->fallenback_eacces) { + evsel->core.attr.exclude_kernel =3D 0; + evsel->core.attr.exclude_hv =3D 0; + evsel->fallenback_eacces =3D false; + } + if (evsel->fallenback_eopnotsupp) { + evsel->core.attr.exclude_guest =3D 0; + evsel->fallenback_eopnotsupp =3D false; + } =20 + /* Name is recomputed by evsel__name. */ zfree(&evsel->name); + + /* Log message. */ + scnprintf(msg, msgsize, + "The cycles event is not supported, trying to fall back to %s", + evsel__name(evsel)); return true; } else if (err =3D=3D EACCES && !evsel->core.attr.exclude_kernel && (paranoid =3D perf_event_paranoid()) > 1) { @@ -3830,7 +3847,7 @@ bool evsel__fallback(struct evsel *evsel, struct targ= et *target, int err, " samples", paranoid); evsel->core.attr.exclude_kernel =3D 1; evsel->core.attr.exclude_hv =3D 1; - + evsel->fallenback_eacces =3D true; return true; } else if (err =3D=3D EOPNOTSUPP && !evsel->core.attr.exclude_guest && !evsel->exclude_GH) { @@ -3851,7 +3868,7 @@ bool evsel__fallback(struct evsel *evsel, struct targ= et *target, int err, /* Apple M1 requires exclude_guest */ scnprintf(msg, msgsize, "Trying to fall back to excluding guest samples"= ); evsel->core.attr.exclude_guest =3D 1; - + evsel->fallenback_eopnotsupp =3D true; return true; } no_fallback: diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index a3d754c029a0..97f57fab28ce 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -124,6 +124,8 @@ struct evsel { bool default_metricgroup; /* A member of the Default metricgroup */ bool default_show_events; /* If a default group member, show the event = */ bool needs_uniquify; + bool fallenback_eacces; + bool fallenback_eopnotsupp; struct hashmap *per_pkg_mask; int err; int script_output_type; --=20 2.53.0.851.ga537e3e6e9-goog From nobody Tue Apr 7 01:02:04 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 026D42C11F8 for ; Tue, 17 Mar 2026 03:06:15 +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=1773716778; cv=none; b=lgPBszPzmCE/CMXgOEzf6lzGUL9CSW5EEzNUU0RUcHdNUyrQid3X+eZTQagM+n4Q9vuPYVm/OhqHifWJfGsA/zrVGkWHomlOJbM3fnyXc1EJ6k+cRe0YTIfQ9+kJ4VJI4mH8HznLUSsOik/zo3kdvqZ63lSBBN9jlyda09kTsRY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773716778; c=relaxed/simple; bh=4mSJoDt19c1s52Ar2qiFo/PGbNpyNgJireRDLID11TM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=I1v1wLsAil0vMRFRcA80a9okLlyzJlEjUeWZJiWiElzDXVUxOZSuCcqns+RmaSy4LjMkEeaITYh2tbvvjXIBvx813VoMualkneMQ+GT3KSXnPuOIDvdqc1RNCd0OMltrIPBkUgg8X5Lm4WoDzSLykdLxtIHljo1YG97A+XFIdzA= 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=HP0tPOAR; 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="HP0tPOAR" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-128d0b690feso106724189c88.0 for ; Mon, 16 Mar 2026 20:06:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773716775; x=1774321575; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=jjPd8hYb03Ftsdibhr+aMw0AWnG2dzFR9qnmX2QMSHk=; b=HP0tPOARz4AVg+nU+dQLdliv3gbLBE1W7dMxYtdFa6KKfj57ZZxwoDaIgh60MFvy1e SAuhFGzTAv/N2if3rk+0KWoXyO+CII+jwhKeFVMZyseL1GtCPnLXH5JPI2wA/bN79+uV f8qSu33FxWr6ACkz0ep9yEQDA4t5bsP9mLj4iOqOOT3GtPVXgY9iSMw4imkDfHIiXaNr OaRgUvRXqowEsSDzXjAtD8B7/RG9ulCCf88hDEjTMPQkQEPwm9sRSiFUGGAiBub8fzrI FPj/GV0C7+p1UHrNp+DPZzZzy3wCRo1NhmYiC0FnijDbpaptYP4m4dmLI5BJgeAR3dKr A7kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773716775; x=1774321575; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jjPd8hYb03Ftsdibhr+aMw0AWnG2dzFR9qnmX2QMSHk=; b=JIrrEJB++J3Xz1/Ec2doq0f6ALcAvTTVpz8SPMsuIblzctCRa93JV3lIdAp4gojLiq g7nKoq5Brw+pvXOu9jSmpy4nL8P/0fKVZZ49He62oeD12LeihksoEXDSt5HXdoB/mAsD LTSwYhCR5UsQL+V3LRMxarTPBQbsB3QNZTtU7f6/qLUijilX3t3Vd9yzpYP7CBUu2CcE IofAdRTiye0WozE4jzmzp8NLy1kFLhdMrnnO3Ax9rib/PhnXN79hoBkAmzxZcMZQGhnw GAmN6QSjxkkY6mtpierhdzy8mtshM2HOGqVOj0SMeOrR1rvxLrOMSxgAMrLqdCrCL2Jq CPYw== X-Forwarded-Encrypted: i=1; AJvYcCVYEpDIHcs0j99UNu04IndJ2sbqAS+PjpFrK0coGx68COn9DDCcPx/pjIrwX1KrkrpDsv2HQyE8KjYo5yA=@vger.kernel.org X-Gm-Message-State: AOJu0Yw2JcqYqUnCBgooUquGfgziWXIvpCoNu/2vnzMCqCvDS6K2acJX hFPRsDBHTCt/DcBgOfrA+PJxazLyqOpWzIbD2xWFwOzAafbK92/bFl/jyNAZ+I3ygoZLZi45u14 vEgNgJrt5Eg== X-Received: from dlbrs10.prod.google.com ([2002:a05:7022:f68a:b0:128:cf1e:df72]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:2207:b0:11d:c86c:652e with SMTP id a92af1059eb24-128f3d1bb6bmr8508921c88.5.1773716774841; Mon, 16 Mar 2026 20:06:14 -0700 (PDT) Date: Mon, 16 Mar 2026 20:05:58 -0700 In-Reply-To: <20260317030601.567422-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260317030601.567422-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260317030601.567422-3-irogers@google.com> Subject: [PATCH v4 2/5] perf target: Constify simple check functions From: Ian Rogers To: tmricht@linux.ibm.com Cc: irogers@google.com, acme@kernel.org, agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, namhyung@kernel.org, sumanthk@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow the target to be const in callers. Signed-off-by: Ian Rogers --- tools/perf/util/target.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/target.h b/tools/perf/util/target.h index 84ebb9c940c6..bc2bff9c6842 100644 --- a/tools/perf/util/target.h +++ b/tools/perf/util/target.h @@ -49,22 +49,22 @@ uid_t parse_uid(const char *str); =20 int target__strerror(struct target *target, int errnum, char *buf, size_t = buflen); =20 -static inline bool target__has_task(struct target *target) +static inline bool target__has_task(const struct target *target) { return target->tid || target->pid; } =20 -static inline bool target__has_cpu(struct target *target) +static inline bool target__has_cpu(const struct target *target) { return target->system_wide || target->cpu_list; } =20 -static inline bool target__none(struct target *target) +static inline bool target__none(const struct target *target) { return !target__has_task(target) && !target__has_cpu(target); } =20 -static inline bool target__enable_on_exec(struct target *target) +static inline bool target__enable_on_exec(const struct target *target) { /* * Normally enable_on_exec should be set if: @@ -75,12 +75,12 @@ static inline bool target__enable_on_exec(struct target= *target) return target__none(target) && !target->initial_delay; } =20 -static inline bool target__has_per_thread(struct target *target) +static inline bool target__has_per_thread(const struct target *target) { return target->system_wide && target->per_thread; } =20 -static inline bool target__uses_dummy_map(struct target *target) +static inline bool target__uses_dummy_map(const struct target *target) { bool use_dummy =3D false; =20 --=20 2.53.0.851.ga537e3e6e9-goog From nobody Tue Apr 7 01:02:04 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 1A2C12C11E7 for ; Tue, 17 Mar 2026 03:06:18 +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=1773716779; cv=none; b=gjU8+0J0gEJkrdNIn3VRraANaNpp1LhnTrHdZZkO2thWCBM5gf1b7niIe+DA4BhW8TCXHw9miqtF2OJko9HutHyu2zQiMyAneMkPrFePr1JyM9QdnRg/mmAYUiuPWdEg6YEg4oYrBV7hmDc9SBSQ1KRC9bbeG3B3eE+yy7tXpZg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773716779; c=relaxed/simple; bh=YnHls8NIVjy5Ei7a4hKc1qV28zK+UaZo7VK2CAN8c3w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fcy8ZSv2Avm4UYjmqN9n6IDOSHdkx7D5ZbxnxY25bma51iA03ec0kNrSODlmep5poPVzaShIqZ0qD3a8xZI8HQwSreHtf1GNBcc0ITPP9A1fQqpMdT5YrvU4Ed+wASXlv+kMo867e9yWZ6zpSj/Bf+25Ct2YEWrxizKLxHsIVtM= 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=phgrFpbQ; 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="phgrFpbQ" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2ba9a744f7dso5090616eec.0 for ; Mon, 16 Mar 2026 20:06:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773716777; x=1774321577; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=4sR/GkKKCK4vlTKAx1HdQnSDfMDIglmN+8LdctHHquI=; b=phgrFpbQhbW8TOEegw+TiIH53Xfx/T8UxSvC1oxAxR+QrNUdTfAGhzEuzfCPdEPgrY vt/Ejcj5Hpycr94HElZ9FzstGoMEDIiJ8ef+ySmUxqQw9m8tngbyzRS8Axbw1ed1M3jo PisUcYOkWSLE2/haTAzmkkAswQGYjpLvy8KOdw2zfOlC2KcIUXdL5aM3pCjFNULvP687 8MCx0hm7fCm+qnNEExk+GGxMj2T+ljIh6Z9SsdVKf3ul7NNi3vO/v6pr/FRD3TbyV1vR iMXq7n3p3aDdUzDTomMB5LsMg0E7qVLkGNkTBiGecFDH7c7VUkaIBpPnWNKbeo5bxcR9 KvPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773716777; x=1774321577; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4sR/GkKKCK4vlTKAx1HdQnSDfMDIglmN+8LdctHHquI=; b=qRdUzYhm5dHoDk7Npo9c+jyw5pXkgFLSU1doa/4fWrjtVD5wnW7VfOeq+trZHinW+T N8pPqiCK5F8qHhkfAPQEBqcruiUtXN+6fVDBA1jg8RLl1aHlfJgYjXvsDIZ/72b5IWy8 EBEOZf2lXyOqHkj/LXKwRy4uej5jpeV+kGW0lxoniPHgCCJq92kI48Gb/roVJocNNSfd gVZjNHzsllxRRhrjIrf5lxvC1N4PHbwhvsEl4tcRds3X/p/bFXN8KjaM4stDg3BIyckb +Tddj9qyCLhrrVc0YZCDuKJNXjxqz0ik31KbzF3OwroB5s3jrKlrSZN61Mv+P0fD9Kmr ++MA== X-Forwarded-Encrypted: i=1; AJvYcCUcPD0a8SLF0NAvkGYSAnWqiHUUhQgyDRsr6KsyMDGCnj2yhg8+oCGruwpDSKBq+P8oZnaSyiG8Ld0I9ho=@vger.kernel.org X-Gm-Message-State: AOJu0Yw+wVTnG+pNjKiLCGlcZL/i9nONcGFybH8+DMEYcAXlh4/mYmA4 lPaW27lFIgppXDOIhk30lCS/6pEEVrLa1lJhqwouWHCYrBuhP8v5oaMwfEI3iZe7Eab3QbTagB0 liSDO4wrQ/A== X-Received: from dycsb4.prod.google.com ([2002:a05:693c:3004:b0:2be:71e1:f4b]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:693c:6319:b0:2c0:d67f:35f4 with SMTP id 5a478bee46e88-2c0d67f479emr566320eec.0.1773716776986; Mon, 16 Mar 2026 20:06:16 -0700 (PDT) Date: Mon, 16 Mar 2026 20:05:59 -0700 In-Reply-To: <20260317030601.567422-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260317030601.567422-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260317030601.567422-4-irogers@google.com> Subject: [PATCH v4 3/5] perf evsel: Constify option arguments to config functions From: Ian Rogers To: tmricht@linux.ibm.com Cc: irogers@google.com, acme@kernel.org, agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, namhyung@kernel.org, sumanthk@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The options are used to configure the evsel but are not themselves configured. Make the arguments const to better capture this. Signed-off-by: Ian Rogers --- tools/perf/util/evsel.c | 20 ++++++++++---------- tools/perf/util/evsel.h | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index bd14d9bbc91f..54c8922a8e47 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1015,8 +1015,8 @@ uint16_t evsel__e_machine(struct evsel *evsel, uint32= _t *e_flags) return perf_session__e_machine(session, e_flags); } =20 -static void __evsel__config_callchain(struct evsel *evsel, struct record_o= pts *opts, - struct callchain_param *param) +static void __evsel__config_callchain(struct evsel *evsel, const struct re= cord_opts *opts, + const struct callchain_param *param) { bool function =3D evsel__is_function_event(evsel); struct perf_event_attr *attr =3D &evsel->core.attr; @@ -1080,14 +1080,14 @@ static void __evsel__config_callchain(struct evsel = *evsel, struct record_opts *o attr->defer_callchain =3D 1; } =20 -void evsel__config_callchain(struct evsel *evsel, struct record_opts *opts, - struct callchain_param *param) +void evsel__config_callchain(struct evsel *evsel, const struct record_opts= *opts, + const struct callchain_param *param) { if (param->enabled) return __evsel__config_callchain(evsel, opts, param); } =20 -static void evsel__reset_callgraph(struct evsel *evsel, struct callchain_p= aram *param) +static void evsel__reset_callgraph(struct evsel *evsel, const struct callc= hain_param *param) { struct perf_event_attr *attr =3D &evsel->core.attr; =20 @@ -1106,7 +1106,7 @@ static void evsel__reset_callgraph(struct evsel *evse= l, struct callchain_param * =20 static void evsel__apply_ratio_to_prev(struct evsel *evsel, struct perf_event_attr *attr, - struct record_opts *opts, + const struct record_opts *opts, const char *buf) { struct perf_event_attr *prev_attr =3D NULL; @@ -1170,7 +1170,7 @@ static void evsel__apply_ratio_to_prev(struct evsel *= evsel, } =20 static void evsel__apply_config_terms(struct evsel *evsel, - struct record_opts *opts, bool track) + const struct record_opts *opts, bool track) { struct evsel_config_term *term; struct list_head *config_terms =3D &evsel->config_terms; @@ -1445,7 +1445,7 @@ void __weak arch_evsel__apply_ratio_to_prev(struct ev= sel *evsel __maybe_unused, { } =20 -static void evsel__set_default_freq_period(struct record_opts *opts, +static void evsel__set_default_freq_period(const struct record_opts *opts, struct perf_event_attr *attr) { if (opts->freq) { @@ -1490,8 +1490,8 @@ bool evsel__is_offcpu_event(struct evsel *evsel) * enable/disable events specifically, as there's no * initial traced exec call. */ -void evsel__config(struct evsel *evsel, struct record_opts *opts, - struct callchain_param *callchain) +void evsel__config(struct evsel *evsel, const struct record_opts *opts, + const struct callchain_param *callchain) { struct evsel *leader =3D evsel__leader(evsel); struct perf_event_attr *attr =3D &evsel->core.attr; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 97f57fab28ce..339b5c08a33d 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -287,10 +287,10 @@ void evsel__set_priv_destructor(void (*destructor)(vo= id *priv)); =20 struct callchain_param; =20 -void evsel__config(struct evsel *evsel, struct record_opts *opts, - struct callchain_param *callchain); -void evsel__config_callchain(struct evsel *evsel, struct record_opts *opts, - struct callchain_param *callchain); +void evsel__config(struct evsel *evsel, const struct record_opts *opts, + const struct callchain_param *callchain); +void evsel__config_callchain(struct evsel *evsel, const struct record_opts= *opts, + const struct callchain_param *callchain); =20 int __evsel__sample_size(u64 sample_type); void evsel__calc_id_pos(struct evsel *evsel); --=20 2.53.0.851.ga537e3e6e9-goog From nobody Tue Apr 7 01:02:04 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 0101A2C11D7 for ; Tue, 17 Mar 2026 03:06:21 +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=1773716783; cv=none; b=UKWAygFwT369HDI05SGwXtZ7FFQxzCNwrZccKg13vTZ2mbcFqlO40JDCODGD4gFV6puA8wvZZC0yChAzxTmWWvRL+k1QipMhXhfKvoA9HlBTqwQXQ3u2vh766vi/W9ZBWkWCKvOUYh+I5+wUzkw45EQvAVZOV0yYVWllkCGZKOc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773716783; c=relaxed/simple; bh=wFHt+RXPYaoMpN49aVwmknQS6OkUFFM8RCJ8fUdhfGo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lTxu+mKgZN/pHj0hVCAoT2rtejw7Egzv1030KMj7xh6BYdOXU0toTl4DQCn17btmm/os+rEAzl3z6u7qCBKXS1DHpTCn4VFaxC3CEwPT2bGLrLHek5bH3hP0ARo9vSms/KdQOtlxXps5PDChsPPW8VkM+nhRgE62WVutUFcnytA= 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=CR/xH+Xv; 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="CR/xH+Xv" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-127337c8e52so102719101c88.1 for ; Mon, 16 Mar 2026 20:06:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773716781; x=1774321581; 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=JtlcpARj3/CUpU+u9sBllSJiui9gfcTa1xLpo8ZWqOw=; b=CR/xH+Xv1ZDirm47BNXSADybqEA8t4iS7izG9uCbY0o2ZEwwamIq/hgDB2bvJAdudt LCmkoLejd7puAgMWBT2TOx82/B9imILStxYluGJjCs0gA+i3Z3kcCCYjpAJWHarWi0dz snfePmwYca5y6gQ3B/aJSYV10IjgPJ4UHTVN0EN+KTeAT8GkUdfXvoKW3uwLXYYGhpYD IISaJmv6EtKtXBpXXMh10h2nK2waUkMKXlw7/553V6bPCL3S0WT1uYArhdj17HzpRMT4 WTUieHpgWtLw3YQLvWenL3oanXMGYJhFXWezYV24jz21U8G3iviN2Cd3VfSyXapW3sgV tuOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773716781; x=1774321581; 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=JtlcpARj3/CUpU+u9sBllSJiui9gfcTa1xLpo8ZWqOw=; b=nsuR2ajiratpYqv45yc/iTMNU5hXlU8IYBqXzm+q8jxfJto1y/MKHf4TJFLCibVT3i uTxThd3eJ2Of8Ci45O6w2XXSLxJ0ondViApxCuwL2AW5CmcMPP6OMe9vsawvrMiZtg0e 8Itc47BuGO8noU3aVQ8BK1Te6A0rF0K0eEy4cSWyOv906MJ8b0fVFBQfrynpHSuiIMS3 uFNsn3rRg3mmr5cz48dL7r6eZUP0yctZbD3n0r5txQSHPYPL93WdwI3ROMDppE2myqQM zqDQgZu+2kBHoHZndPnG8nSXHD71Yw6hYLrzXP+mu+bLhSEIM+ccMiWB7c/z5vSWpAnZ 91Cg== X-Forwarded-Encrypted: i=1; AJvYcCUlC3VYxZLc3E0Njj2xb5S08UL/M90hr1ssrH/aQIzUnZ31mTxshDFsfVG/IqYpeyGVoBLbO+1XlNP8jAo=@vger.kernel.org X-Gm-Message-State: AOJu0YwIIl8dBtltGrwjMK1P9luD8j+jOjCB4IifIYIUkWuy9RFXa+oc 1S0+tIUoE21zrbBmhn+hB+FtvWvMnPNuAB4WCaY2dftruQPSDmA6Eyw9wYXqB0VgijQism2P7xB 1/jczstMqNA== X-Received: from dlec14-n2.prod.google.com ([2002:a05:701b:428e:20b0:128:d754:39d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:e25:b0:121:a01a:8e2f with SMTP id a92af1059eb24-128f3e471camr6960875c88.42.1773716779361; Mon, 16 Mar 2026 20:06:19 -0700 (PDT) Date: Mon, 16 Mar 2026 20:06:00 -0700 In-Reply-To: <20260317030601.567422-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260317030601.567422-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260317030601.567422-5-irogers@google.com> Subject: [PATCH v4 4/5] perf callchain: Move callchain option parsing out of builtin 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, record_callchain_opt, record_parse_callchain_opt are shared by builtin-record, builtin-top and builtin-trace, they are declared in callchain.h. Move the declarations to callchain.c for consistency with the header. Signed-off-by: Ian Rogers --- tools/perf/builtin-record.c | 59 ----------------------------------- tools/perf/util/callchain.c | 61 +++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 59 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 40917a0be238..e65cd7bf1477 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -2975,65 +2975,6 @@ static int __cmd_record(struct record *rec, int argc= , 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, - const char *arg, - int unset) -{ - return record_opts__parse_callchain(opt->value, &callchain_param, arg, un= set); -} - -int record_callchain_opt(const struct option *opt, - const char *arg __maybe_unused, - int unset __maybe_unused) -{ - struct callchain_param *callchain =3D opt->value; - - callchain->enabled =3D true; - - if (callchain->record_mode =3D=3D CALLCHAIN_NONE) - callchain->record_mode =3D CALLCHAIN_FP; - - callchain_debug(callchain); - return 0; -} - static int perf_record_config(const char *var, const char *value, void *cb) { struct record *rec =3D cb; diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 8ff0898799ee..1203d9d23fda 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include =20 @@ -30,6 +31,7 @@ #include "map.h" #include "callchain.h" #include "branch.h" +#include "record.h" #include "symbol.h" #include "thread.h" #include "util.h" @@ -328,6 +330,65 @@ 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 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); +} + +int record_callchain_opt(const struct option *opt, + const char *arg __maybe_unused, + int unset __maybe_unused) +{ + struct callchain_param *callchain =3D opt->value; + + callchain->enabled =3D true; + + if (callchain->record_mode =3D=3D CALLCHAIN_NONE) + callchain->record_mode =3D CALLCHAIN_FP; + + callchain_debug(callchain); + return 0; +} + int perf_callchain_config(const char *var, const char *value) { char *endptr; --=20 2.53.0.851.ga537e3e6e9-goog From nobody Tue Apr 7 01:02:04 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 3EA2C2C029D for ; Tue, 17 Mar 2026 03:06:24 +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=1773716786; cv=none; b=ha7TQZ6W220ZjoYUn1CztEb/S0NzdySKhgX0m6I1+ipeiK4rrKbwQvukA40/RdhdHGvex15TBPw965omU6/kG8g90iMi1VLTSjhUBgB1qY9/4cF52ttJ4WxuPD14qJZcvy1SPRaIWkg0E1KsxgMlqWb6UZotJSBR/kzChpmjEbY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773716786; c=relaxed/simple; bh=0T5+Gr3wi71gLdCCrZTsYWqFzob7IGKsffItAl2oKd8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=oPzCGalcKiuaz+R1c8vP1Q6X02g+7ZLbfr/zDlvOwu4rDc/xcJ7Fmt95Fs9jVbTb5bvejUSO9yxe0L7AlumQ7UR0TX7XHj6OEPDOSVJct5lPsTpmViTVcM6THEQTh5FRyj4YqNv8sNlEYI+DvXuPDswwkeo3TcxPVX5S+azh2ec= 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=PuULf5cb; 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="PuULf5cb" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-128edc72e5bso23758338c88.1 for ; Mon, 16 Mar 2026 20:06:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773716783; x=1774321583; 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=/bQJ/BLiJ4Z3TZocKrA/GIS6qvvcfJbGWDZdIMkxhtU=; b=PuULf5cbvUXsvIbxGFZ/vxsZT1TCEFPc0pU4NSAHKi8Rs7vrKi/lrZkf7px63rEULu 3PmsqPw6EbEauN0K+NIuM+jBAfZ4zpCQeULIqG75F3rs77FuUbKm6TA9XwxCKninNyw2 EbJ35tCn6TtSJhN3AyHUp0Fs27sbPw/FpHBELSGtTJYc/1AbECT5Mk6Vi/8rhYrGNcIr 2NRxrxiL499poePKopO87bYyEm+XfLRgr+RY71ahNpQZ4qq+29G67NeuZkg8IZLBh7vd T0k6fn9XCsB4IwXLlkHH4jlW/IEWqGIuBy+XsOMICpZMS/DJxgj5suCrf447FaWSqckq txAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773716783; x=1774321583; 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=/bQJ/BLiJ4Z3TZocKrA/GIS6qvvcfJbGWDZdIMkxhtU=; b=qkjhdV3fFWHEVEQtqa1vsjcVh0T1vXzoHksp7or7awjg/UgyCZJHNy+TMKFuWF/fUf qTwKb4TuvSAgbh85bvtibpf4WSYFbWnBevYMdVOaqe+9YdP1kXNH/O5VDQ93Bpi82IlI ec5Nsl2m4yyldQfn7JlvZfZXKKg+aJYQH9JopPxJ7BzSH+pD9GaRlMuLi3pcR58ymvt4 4mTMYOnHPJ1DkhGdOrDHofHUOVVC680z8UG3K3kGNDf2dRDXhYmNIkQ2OkqsgUKXKI0h wqwZ9McGurPTYGGtYm7irW2QZIodt0uywWGHLcwZPW1OaMYJj6MdLpl9V0Bg0UhI5KCX r8yg== X-Forwarded-Encrypted: i=1; AJvYcCXaHbOz+NmHboXWGp2P6R1QvwahCOtzfE0mkie4rS2NPX3q1VVZYM5pWT/h3nEOC89bnF76x4fce1TcuMw=@vger.kernel.org X-Gm-Message-State: AOJu0YyCRJGKYndYFapOvBXqOsSQjmxptPOMo93xnmQv6pq7fQDoAGKJ nKh5Rs5rMSHNXTcvcMWJwc+tVriiRZY/J/EtKsK4T10hbty2ilANdFlQC4Z7rLVU8tRa6KBUjze Zpu98jasJhA== X-Received: from dlboy10.prod.google.com ([2002:a05:7022:128a:b0:128:f497:319c]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:422:b0:127:3440:e5d5 with SMTP id a92af1059eb24-128f3dc591cmr7312597c88.21.1773716783156; Mon, 16 Mar 2026 20:06:23 -0700 (PDT) Date: Mon, 16 Mar 2026 20:06:01 -0700 In-Reply-To: <20260317030601.567422-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260317030601.567422-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260317030601.567422-6-irogers@google.com> Subject: [PATCH v4 5/5] perf evlist: Improve default event for s390 From: Ian Rogers To: tmricht@linux.ibm.com Cc: irogers@google.com, acme@kernel.org, agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, namhyung@kernel.org, sumanthk@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Frame pointer callchains are not supported on s390 and dwarf callchains are only supported on software events. Switch the default event from cycles to cpu-clock or task-clock on s390 if callchains are enabled. If frame pointer callchains are requested on s390, warn and switch to dwarf callchains. Signed-off-by: Ian Rogers --- tools/perf/builtin-record.c | 5 +++-- tools/perf/builtin-top.c | 2 +- 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/callchain.c | 16 ++++++++-------- tools/perf/util/evlist.c | 32 +++++++++++++++++++++----------- tools/perf/util/evlist.h | 2 +- tools/perf/util/evsel.c | 5 +++++ 10 files changed, 53 insertions(+), 28 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index e65cd7bf1477..604c00c58152 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -3466,7 +3466,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, @@ -4250,7 +4250,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 710604c4f6f6..58bab595b024 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -1695,7 +1695,7 @@ int cmd_top(int argc, const char **argv) goto out_delete_evlist; =20 if (!top.evlist->core.nr_entries) { - struct evlist *def_evlist =3D evlist__new_default(); + struct evlist *def_evlist =3D evlist__new_default(target, callchain_para= m.enabled); =20 if (!def_evlist) goto out_delete_evlist; diff --git a/tools/perf/tests/event_update.c b/tools/perf/tests/event_updat= e.c index cb9e6de2e033..facc65e29f20 100644 --- a/tools/perf/tests/event_update.c +++ b/tools/perf/tests/event_update.c @@ -8,6 +8,7 @@ #include "header.h" #include "machine.h" #include "util/synthetic-events.h" +#include "target.h" #include "tool.h" #include "tests.h" #include "debug.h" @@ -81,7 +82,8 @@ static int test__event_update(struct test_suite *test __m= aybe_unused, int subtes { struct evsel *evsel; struct event_name tmp; - struct evlist *evlist =3D evlist__new_default(); + struct target target =3D {}; + struct evlist *evlist =3D evlist__new_default(&target, /*sample_callchain= s=3D*/false); =20 TEST_ASSERT_VAL("failed to get evlist", evlist); =20 diff --git a/tools/perf/tests/expand-cgroup.c b/tools/perf/tests/expand-cgr= oup.c index c7b32a220ca1..dd547f2f77cc 100644 --- a/tools/perf/tests/expand-cgroup.c +++ b/tools/perf/tests/expand-cgroup.c @@ -8,6 +8,7 @@ #include "parse-events.h" #include "pmu-events/pmu-events.h" #include "pfm.h" +#include "target.h" #include #include #include @@ -99,7 +100,8 @@ out: for (i =3D 0; i < nr_events; i++) static int expand_default_events(void) { int ret; - struct evlist *evlist =3D evlist__new_default(); + struct target target =3D {}; + struct evlist *evlist =3D evlist__new_default(&target, /*sample_callchain= s=3D*/false); =20 TEST_ASSERT_VAL("failed to get evlist", evlist); =20 diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c index efbd9cd60c63..c6e31ab8a6b8 100644 --- a/tools/perf/tests/perf-record.c +++ b/tools/perf/tests/perf-record.c @@ -84,8 +84,11 @@ static int test__PERF_RECORD(struct test_suite *test __m= aybe_unused, int subtest CPU_ZERO_S(cpu_mask_size, cpu_mask); =20 perf_sample__init(&sample, /*all=3D*/false); - if (evlist =3D=3D NULL) /* Fallback for kernels lacking PERF_COUNT_SW_DUM= MY */ - evlist =3D evlist__new_default(); + if (evlist =3D=3D NULL) { /* Fallback for kernels lacking PERF_COUNT_SW_D= UMMY */ + struct target target =3D {}; + + evlist =3D evlist__new_default(&target, /*sample_callchains=3D*/false); + } =20 if (evlist =3D=3D NULL) { pr_debug("Not enough memory to create evlist\n"); diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index ec01150d208d..a34a7ab19a80 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c @@ -9,6 +9,7 @@ #include "evlist.h" #include "debug.h" #include "pmus.h" +#include "target.h" #include =20 #define TEMPL "/tmp/perf-test-XXXXXX" @@ -37,11 +38,12 @@ static int session_write_header(char *path) .path =3D path, .mode =3D PERF_DATA_MODE_WRITE, }; + struct target target =3D {}; =20 session =3D perf_session__new(&data, NULL); TEST_ASSERT_VAL("can't get session", !IS_ERR(session)); =20 - session->evlist =3D evlist__new_default(); + session->evlist =3D evlist__new_default(&target, /*sample_callchains=3D*/= false); TEST_ASSERT_VAL("can't get evlist", session->evlist); session->evlist->session =3D session; =20 diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 1203d9d23fda..bc3c1e955b02 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -30,6 +30,7 @@ #include "machine.h" #include "map.h" #include "callchain.h" +#include "dwarf-regs.h" #include "branch.h" #include "record.h" #include "symbol.h" @@ -378,14 +379,13 @@ int record_callchain_opt(const struct option *opt, const char *arg __maybe_unused, int unset __maybe_unused) { - struct callchain_param *callchain =3D opt->value; - - callchain->enabled =3D true; - - if (callchain->record_mode =3D=3D CALLCHAIN_NONE) - callchain->record_mode =3D CALLCHAIN_FP; - - callchain_debug(callchain); + callchain_param.enabled =3D true; + if (callchain_param.record_mode =3D=3D CALLCHAIN_NONE) { + /* s390 lacks kernel framepoint unwinding. */ + record_opts__parse_callchain(opt->value, &callchain_param, + EM_HOST !=3D EM_S390 ? "fp" : "dwarf", + /*unset=3D*/0); + } return 0; } =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