From nobody Mon Apr 6 21:31:16 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 6CD3537E2F7 for ; Tue, 17 Mar 2026 17:57:19 +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=1773770241; cv=none; b=UwXHGMSeZf73hQQEKQoTt6B/KRH6LPmLGV0+EeoDtVdc7A49oINOSDUe1qPda6F4dlkQgB9SHY6nXqjdjHVLVJQZBwy2BHfqVYj3hW0YyYmOyp6PoJxCarfGDvLA9p7f18A5CBxMCVkARGBYmNkgKtgrSjqubQkAGbpf9UNr4YM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773770241; 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=RGbyr00ZyELZm4MMRmvYMc7xaSeoTzGmGuN0sYs3w3Iqk8Uus7+eKdDZFP5WF4QjI2RjSlSedlRK9dNzhWPoOO+RxmFlpf1fdIdVUAKQAPjKNpO+bJE9QxFuewBOjl0y7bQX1pJyzZJ25t/A2BOiJuewDfrNGT54eUI9ZbLbzH8= 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=oQ09o728; 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="oQ09o728" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2bea61591fdso104918994eec.0 for ; Tue, 17 Mar 2026 10:57:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773770238; x=1774375038; 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=oQ09o728Vx81HGsHiHK0d37s3KPTWB2Cl61nLKZT9WT40UxI8S0RzI8zjXMd2G3og3 AfWe/lThC9i14oki8dXwoeGhjl9VSVcvnW+GUD1F6BurtjSuMg+/+hDrSnAbVL1Zjgrw IXlj8vHa5CVSJqHlxv7NiG71FiebqED+x5ytlPJuwdSDkNUAWb6O9FTIgvHYV0uAs0Ak CKDyKOZz/hXOrXsBd+SVOI/eQvRY5T5akDycZIVpDemNMWxrDfhg/9TKvrYZHEDFMGVV 0Ho5kB2nPHjYRScJUWWog3rSkJvB9qRW8/DP639FHAR023+4r9KiRGZrZTxEzgOAsC8I DPqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773770238; x=1774375038; 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=ALx2hRnUgF8OnG/buh0vtq19oRAutW2XJwuw6KZQHtflKGMjGqXP+zBgP0d3zHrxk3 cZGfGnJJd0gNYwCxNstRKcGimZ0LmSv8e8sKL6XX/57rbJPZi99p5lt5Y01w/QHfDFOl HRs9kKD5EYpeSy3+ls3StCOP9ejoBdvmSCbYBLYRb3q4eD4lWH6GFMOFCoXCpdCqxMhH lTniCoSJhVPTp4qdRYvJPqcgYxEKhAVSVok6rbHr38edmb7i1nZAf3sXckql6zw/B3qD yJqQf7hYy7wYyOg/0Bz/47uNicEnNOkqe1Vm/P8TzuJEk362RszedLdCvnTY/0ggOddZ rMDA== X-Forwarded-Encrypted: i=1; AJvYcCVKGciy89TE4aIaJB80vfDwAUxxWUZ+nYLBkiYtUFupsH4KYfAdfzF0e8CGWJ9imAmIQdO6YSFOBJ8tO1g=@vger.kernel.org X-Gm-Message-State: AOJu0YwF25X9+C9T+ndb7imoM0u73mjRcW+US285F0u7YBdtujJB3a1Z KSiCz0zEr8QbdVNk/kBLGZarihPd9zLm95G8dE74MG89CdWPUUmoyYaItIcY+d67yOyQuGu/Ovb rHFh7h/Xrcg== X-Received: from dycmh3.prod.google.com ([2002:a05:693c:2583:b0:2be:2e48:5d13]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:6790:b0:2c0:ad52:e657 with SMTP id 5a478bee46e88-2c0e50cb1bcmr159118eec.21.1773770208351; Tue, 17 Mar 2026 10:56:48 -0700 (PDT) Date: Tue, 17 Mar 2026 10:56:38 -0700 In-Reply-To: <20260317175642.161647-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: <20260317175642.161647-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260317175642.161647-2-irogers@google.com> Subject: [PATCH v6 1/5] perf evsel: Improve falling back from cycles From: Ian Rogers To: tmricht@linux.ibm.com Cc: irogers@google.com, acme@kernel.org, agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, namhyung@kernel.org, sumanthk@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch to using evsel__match rather than comparing perf_event_attr values, this is robust on hybrid architectures. Ensure evsel->pmu matches the evsel->core.attr. Remove exclude bits that get set in other fallback attempts when switching the event. Log the event name with modifiers when switching the event on fallback. Signed-off-by: Ian Rogers Tested-by: Thomas Richter --- tools/perf/util/evsel.c | 45 ++++++++++++++++++++++++++++------------- tools/perf/util/evsel.h | 2 ++ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index f59228c1a39e..bd14d9bbc91f 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3785,25 +3785,42 @@ bool evsel__fallback(struct evsel *evsel, struct ta= rget *target, int err, { int paranoid; =20 - if ((err =3D=3D ENOENT || err =3D=3D ENXIO || err =3D=3D ENODEV) && - evsel->core.attr.type =3D=3D PERF_TYPE_HARDWARE && - evsel->core.attr.config =3D=3D PERF_COUNT_HW_CPU_CYCLES) { + if ((err =3D=3D ENODEV || err =3D=3D ENOENT || err =3D=3D ENXIO) && + evsel__match(evsel, HARDWARE, HW_CPU_CYCLES)) { /* - * If it's cycles then fall back to hrtimer based cpu-clock sw - * counter, which is always available even if no PMU support. - * - * PPC returns ENXIO until 2.6.37 (behavior changed with commit - * b0a873e). + * If it's the legacy hardware cycles event fails then fall back + * to hrtimer based cpu-clock sw counter, which is always + * available even if no PMU support. PPC returned ENXIO rather + * than ENODEV or ENOENT until 2.6.37. */ - evsel->core.attr.type =3D PERF_TYPE_SOFTWARE; + evsel->pmu =3D perf_pmus__find_by_type(PERF_TYPE_SOFTWARE); + assert(evsel->pmu); /* software is a "well-known" and can't fail PMU typ= e. */ + + /* Configure the event. */ + evsel->core.attr.type =3D PERF_TYPE_SOFTWARE; evsel->core.attr.config =3D target__has_cpu(target) ? PERF_COUNT_SW_CPU_CLOCK : PERF_COUNT_SW_TASK_CLOCK; - scnprintf(msg, msgsize, - "The cycles event is not supported, trying to fall back to %s", - target__has_cpu(target) ? "cpu-clock" : "task-clock"); + evsel->core.is_pmu_core =3D false; + + /* Remove excludes for new event. */ + if (evsel->fallenback_eacces) { + evsel->core.attr.exclude_kernel =3D 0; + evsel->core.attr.exclude_hv =3D 0; + evsel->fallenback_eacces =3D false; + } + if (evsel->fallenback_eopnotsupp) { + evsel->core.attr.exclude_guest =3D 0; + evsel->fallenback_eopnotsupp =3D false; + } =20 + /* Name is recomputed by evsel__name. */ zfree(&evsel->name); + + /* Log message. */ + scnprintf(msg, msgsize, + "The cycles event is not supported, trying to fall back to %s", + evsel__name(evsel)); return true; } else if (err =3D=3D EACCES && !evsel->core.attr.exclude_kernel && (paranoid =3D perf_event_paranoid()) > 1) { @@ -3830,7 +3847,7 @@ bool evsel__fallback(struct evsel *evsel, struct targ= et *target, int err, " samples", paranoid); evsel->core.attr.exclude_kernel =3D 1; evsel->core.attr.exclude_hv =3D 1; - + evsel->fallenback_eacces =3D true; return true; } else if (err =3D=3D EOPNOTSUPP && !evsel->core.attr.exclude_guest && !evsel->exclude_GH) { @@ -3851,7 +3868,7 @@ bool evsel__fallback(struct evsel *evsel, struct targ= et *target, int err, /* Apple M1 requires exclude_guest */ scnprintf(msg, msgsize, "Trying to fall back to excluding guest samples"= ); evsel->core.attr.exclude_guest =3D 1; - + evsel->fallenback_eopnotsupp =3D true; return true; } no_fallback: diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index a3d754c029a0..97f57fab28ce 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -124,6 +124,8 @@ struct evsel { bool default_metricgroup; /* A member of the Default metricgroup */ bool default_show_events; /* If a default group member, show the event = */ bool needs_uniquify; + bool fallenback_eacces; + bool fallenback_eopnotsupp; struct hashmap *per_pkg_mask; int err; int script_output_type; --=20 2.53.0.851.ga537e3e6e9-goog From nobody Mon Apr 6 21:31:16 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 C7E3F37EFE1 for ; Tue, 17 Mar 2026 17:56:51 +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=1773770212; cv=none; b=uvHU2YGTlDmZzVu5wjKeMR3tT0Tsw0s8DKt/TMCRWSsi32v+AxkyQfNTwIe9weBGn28Ql6P9YgLIh0Gm32Ozzz732uoR3LIkLlrYCENv9ZCFFppb22TE9UHk1wZjztYbzNeW38rqDjx3ESVEhWfeUGXUgQkD6yjs3UItfE4c+PA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773770212; c=relaxed/simple; bh=4mSJoDt19c1s52Ar2qiFo/PGbNpyNgJireRDLID11TM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Ki2KmF1C0ZSFlqM7fGyXR9MGJQJ8xLKdyev9vTjAjNGk1Ba2cTQ7wkZ1DqORBReXFsT6sILzME/53xCQ4HAzM2L9QWQj5uY7ERT+hZjF/cwSXOWRwUWr3v5N74ktkrc+HReyg1lZ9ZuBhaTVzVTmYCwZ387lTjQ0QJRkajwkn0E= 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=b0MEFX3n; 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="b0MEFX3n" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-128d285d6c3so3354880c88.1 for ; Tue, 17 Mar 2026 10:56:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773770211; x=1774375011; 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=b0MEFX3nyUIlJFr4lNpX+j6cumxZqSK9Xp88Yu+hYw39NTaqlky/tYTHlZ57J0wqwv 5Xaj8YvytaXWYYCY2m5M8zF5v/8XIh21LU5l/dBPY1XYgJs/pEaVbwXGCRkn2ZkSziUB wSf8bthyQ+HxgFTPVzmwJwi/3+gOhgwk5nrGaU/OIRd5RI2IbC7Viek0okDn7BmaoOkU AhrkzQ73/C/3YPGwZ8tTIPQSB5SPf+eJpImnjWMC+I6OjyE8IktRFWmcy/Q/xGgNKy8c Z9/Uh6CClpNiJWbM3M8HmxIomvWGrcgM2/V+O7Qo/IqifyXZ7a7JYRUmxVdyWNU2yO8+ tDXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773770211; x=1774375011; 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=PuJDJsygs/RALrw5YUQ+nV10/gIwatAdA7nqOz0ql8fQEpKGOIquPf1s9AjTGuj9wj OuQCH+u5KEWyREJJ6i24TRrU0x92dLZ5PQ3N6AHDFTjMadk+GvseVD9zepCD8LeP6iT5 G7M1kXLeJWey9IQfc+WMYwr9F6HZ6eYV0V04Boc60W6kPw8erdSVGVSuboRbOm4odRo/ Cgut/2dXvGLfirOE5QnyZg5JVsTHSMKs/zvhSuX/uvNvETVy6iqjyYiumRHLEdu4q5wj zhQwXepA1o7Gi2BqVPlE/xKUpXNKfsA3AV1dDS05dC4yiPHBIyIqCW9iqWFHfrsFFraC GMqA== X-Forwarded-Encrypted: i=1; AJvYcCVbBtTuZfsxnogCQDGRGP2T/9O70OsEtYTgCYu7/jbFm1xZFIozVYNO5ebF2Vy6AxqToBfaBUVCkdP66lM=@vger.kernel.org X-Gm-Message-State: AOJu0YzrVhg/BUW5MJAcTQG5uVfc4L2omcRaHJNk43axKwq+YLFnYer1 d4hjrNEHr28+B3+14/OCH2y74g48DYxpUvetx+MHg3YaxDEWat/kJkF51P/RRk0x59Q4f8YbbTW eANyDs7IQXw== X-Received: from dyw20.prod.google.com ([2002:a05:7300:8814:b0:2bd:fbeb:5cfb]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:60f:b0:128:df3d:cd97 with SMTP id a92af1059eb24-129a7177e06mr175017c88.35.1773770210718; Tue, 17 Mar 2026 10:56:50 -0700 (PDT) Date: Tue, 17 Mar 2026 10:56:39 -0700 In-Reply-To: <20260317175642.161647-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: <20260317175642.161647-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260317175642.161647-3-irogers@google.com> Subject: [PATCH v6 2/5] perf target: Constify simple check functions From: Ian Rogers To: tmricht@linux.ibm.com Cc: irogers@google.com, acme@kernel.org, agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, namhyung@kernel.org, sumanthk@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow the target to be const in callers. Signed-off-by: Ian Rogers Tested-by: Thomas Richter --- tools/perf/util/target.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/target.h b/tools/perf/util/target.h index 84ebb9c940c6..bc2bff9c6842 100644 --- a/tools/perf/util/target.h +++ b/tools/perf/util/target.h @@ -49,22 +49,22 @@ uid_t parse_uid(const char *str); =20 int target__strerror(struct target *target, int errnum, char *buf, size_t = buflen); =20 -static inline bool target__has_task(struct target *target) +static inline bool target__has_task(const struct target *target) { return target->tid || target->pid; } =20 -static inline bool target__has_cpu(struct target *target) +static inline bool target__has_cpu(const struct target *target) { return target->system_wide || target->cpu_list; } =20 -static inline bool target__none(struct target *target) +static inline bool target__none(const struct target *target) { return !target__has_task(target) && !target__has_cpu(target); } =20 -static inline bool target__enable_on_exec(struct target *target) +static inline bool target__enable_on_exec(const struct target *target) { /* * Normally enable_on_exec should be set if: @@ -75,12 +75,12 @@ static inline bool target__enable_on_exec(struct target= *target) return target__none(target) && !target->initial_delay; } =20 -static inline bool target__has_per_thread(struct target *target) +static inline bool target__has_per_thread(const struct target *target) { return target->system_wide && target->per_thread; } =20 -static inline bool target__uses_dummy_map(struct target *target) +static inline bool target__uses_dummy_map(const struct target *target) { bool use_dummy =3D false; =20 --=20 2.53.0.851.ga537e3e6e9-goog From nobody Mon Apr 6 21:31:16 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 2B5A437EFF5 for ; Tue, 17 Mar 2026 17:56:54 +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=1773770215; cv=none; b=LpZTYgUP9lH36i0BLqbjqHVAvKVyuZ97SeHcyWxxx/v+NInB7tzC47OI6KdVt5fXQ68qrwnHOKw5ub2Zb9n7KTBUZLLSsQ2cLwZkCa1RHBD+2YRSRGp6TMoM1ti696EInKWceHmLdMfa0Yakszc8BQfehYjSSyEpakBcbWz8S9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773770215; c=relaxed/simple; bh=YnHls8NIVjy5Ei7a4hKc1qV28zK+UaZo7VK2CAN8c3w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LuFxnzjv0uRd4yRExxsHl4bTVzeInFwYcvv/xsE+Sa9OenIyQYXfL3smcYIj/OfJbznFTUF1AaHQfE8CPoW+2OT8NbXpbsmKJKTIXbwB2u4TKjaGZ6s5HffFI3qKnZZF6RpMB/PEku0HZ+8Lvr1jpQFUUbJ7k4+AqYisKwHfwWA= 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=ougIvL7E; 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="ougIvL7E" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2bead0a9123so2072885eec.1 for ; Tue, 17 Mar 2026 10:56:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773770213; x=1774375013; 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=ougIvL7E76jUUfEYd6e7fJILp0+C/OSnnajGRqFkDULtrsMdv9Ye9fa+d3tFzPax6k rDSSFnkeL3ENi42CMnc63O/unAJkXTl7yOODBg32tgWWqDmYxm/RUt2GCVR52NPFEs6E 7BDRCoku1sj+PS2QzqWHRl+IGOR8/gQebwRrRDHyPkPnllfPGwZVio9D/MWCVXsVqSSa w00Bo/2fdBiVx+7qJrAxL9+Wo1n5Vd/zWN83fZzig5mtMHPqTeJK4T+fU4RVFFSV7crQ yObJg3n/HIPZFUaVnBNQAJoW6xIGaMxasU/L8Ib70KlVI3W9y7ulo5QsHHC5whqF0AbA OswA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773770213; x=1774375013; 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=ALIL0GoZH7XPi5U6G5NvDIWuQNcKTj4TGbF9WOd/s6tiPbEIKbfj8ZGI+KxpjwV69h zKwJmSlTYq4iGHEFsqSRVZVs/E/t4oG5HFpRcXC0gq3iDLXHXiWVvb2jrzXpzXEKBf2x gq8hB27c5KVKwz3+NWl2Tcu5mxiS+1ZrotVu9WSNUX1+E1A1MwYR6BxA6OJwfAFUQUE9 sMmcCZ6J1zL3zW94OAHVteBmcAYJRQjrsnx2MQYQ52XmcKPBecQZbL08uy4+OU+9EgEo Qz5Buh9hrOxSuMg8yJVmG5fVNLCQuk8E788PVkwggubc+8wxbUgGf/ygICs17Y3qmauB Lsmw== X-Forwarded-Encrypted: i=1; AJvYcCUHzp2sJR5YkqRs87KZGCA/RupUhtAkAqb83mNNSHB8XGm4axKn6zOfoDZp+FefmVyNedhnuqh4SCFglJg=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2QKORqx8qvi6I5ya/zosCT1zSVTPqMUF7jVgLV2CZPT4WraO+ +PbDzl3NgjiZqaihg0JmYPbNc7137nf7YPsjQ2BVm+vxnfg/SCW71jBMNREuZ1t53Z2OlzULTI2 YuIBTrhv3kw== X-Received: from dycmh3.prod.google.com ([2002:a05:693c:2583:b0:2be:2e48:5d13]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:dc87:b0:2bd:dd33:7996 with SMTP id 5a478bee46e88-2c0e503eb8amr177097eec.19.1773770213078; Tue, 17 Mar 2026 10:56:53 -0700 (PDT) Date: Tue, 17 Mar 2026 10:56:40 -0700 In-Reply-To: <20260317175642.161647-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: <20260317175642.161647-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260317175642.161647-4-irogers@google.com> Subject: [PATCH v6 3/5] perf evsel: Constify option arguments to config functions From: Ian Rogers To: tmricht@linux.ibm.com Cc: irogers@google.com, acme@kernel.org, agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, namhyung@kernel.org, sumanthk@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The options are used to configure the evsel but are not themselves configured. Make the arguments const to better capture this. Signed-off-by: Ian Rogers Tested-by: Thomas Richter --- tools/perf/util/evsel.c | 20 ++++++++++---------- tools/perf/util/evsel.h | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index bd14d9bbc91f..54c8922a8e47 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1015,8 +1015,8 @@ uint16_t evsel__e_machine(struct evsel *evsel, uint32= _t *e_flags) return perf_session__e_machine(session, e_flags); } =20 -static void __evsel__config_callchain(struct evsel *evsel, struct record_o= pts *opts, - struct callchain_param *param) +static void __evsel__config_callchain(struct evsel *evsel, const struct re= cord_opts *opts, + const struct callchain_param *param) { bool function =3D evsel__is_function_event(evsel); struct perf_event_attr *attr =3D &evsel->core.attr; @@ -1080,14 +1080,14 @@ static void __evsel__config_callchain(struct evsel = *evsel, struct record_opts *o attr->defer_callchain =3D 1; } =20 -void evsel__config_callchain(struct evsel *evsel, struct record_opts *opts, - struct callchain_param *param) +void evsel__config_callchain(struct evsel *evsel, const struct record_opts= *opts, + const struct callchain_param *param) { if (param->enabled) return __evsel__config_callchain(evsel, opts, param); } =20 -static void evsel__reset_callgraph(struct evsel *evsel, struct callchain_p= aram *param) +static void evsel__reset_callgraph(struct evsel *evsel, const struct callc= hain_param *param) { struct perf_event_attr *attr =3D &evsel->core.attr; =20 @@ -1106,7 +1106,7 @@ static void evsel__reset_callgraph(struct evsel *evse= l, struct callchain_param * =20 static void evsel__apply_ratio_to_prev(struct evsel *evsel, struct perf_event_attr *attr, - struct record_opts *opts, + const struct record_opts *opts, const char *buf) { struct perf_event_attr *prev_attr =3D NULL; @@ -1170,7 +1170,7 @@ static void evsel__apply_ratio_to_prev(struct evsel *= evsel, } =20 static void evsel__apply_config_terms(struct evsel *evsel, - struct record_opts *opts, bool track) + const struct record_opts *opts, bool track) { struct evsel_config_term *term; struct list_head *config_terms =3D &evsel->config_terms; @@ -1445,7 +1445,7 @@ void __weak arch_evsel__apply_ratio_to_prev(struct ev= sel *evsel __maybe_unused, { } =20 -static void evsel__set_default_freq_period(struct record_opts *opts, +static void evsel__set_default_freq_period(const struct record_opts *opts, struct perf_event_attr *attr) { if (opts->freq) { @@ -1490,8 +1490,8 @@ bool evsel__is_offcpu_event(struct evsel *evsel) * enable/disable events specifically, as there's no * initial traced exec call. */ -void evsel__config(struct evsel *evsel, struct record_opts *opts, - struct callchain_param *callchain) +void evsel__config(struct evsel *evsel, const struct record_opts *opts, + const struct callchain_param *callchain) { struct evsel *leader =3D evsel__leader(evsel); struct perf_event_attr *attr =3D &evsel->core.attr; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 97f57fab28ce..339b5c08a33d 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -287,10 +287,10 @@ void evsel__set_priv_destructor(void (*destructor)(vo= id *priv)); =20 struct callchain_param; =20 -void evsel__config(struct evsel *evsel, struct record_opts *opts, - struct callchain_param *callchain); -void evsel__config_callchain(struct evsel *evsel, struct record_opts *opts, - struct callchain_param *callchain); +void evsel__config(struct evsel *evsel, const struct record_opts *opts, + const struct callchain_param *callchain); +void evsel__config_callchain(struct evsel *evsel, const struct record_opts= *opts, + const struct callchain_param *callchain); =20 int __evsel__sample_size(u64 sample_type); void evsel__calc_id_pos(struct evsel *evsel); --=20 2.53.0.851.ga537e3e6e9-goog From nobody Mon Apr 6 21:31:16 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 8050F37D13C for ; Tue, 17 Mar 2026 17:56:56 +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=1773770221; cv=none; b=G2drzwCJHCMMVT+3p/WaFTfxGzcEh0wxhWC40xyUnzQFuai+c9anCCl57DPctxSGYX8jorGtUG06hZzT3X2UqWw+4Ze74dKoEnGWYKtX35+SENY2qF3zTkMuod3oswFadYRtH2dwZRYodP4oXvcEKjR609fXx2yxMi4UnWzr4BI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773770221; c=relaxed/simple; bh=oCd9ibRBbD6GKXObZhn/WeEylDjDnw5Az3UCHbCsiDs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LiZFuhMjlSlLZinOPvU1assrSaKxntM/3pt3dc568EI2nMWj2aTE7eRdyzi/7i8bEkuJo6PZWaDB6OCRc9BoPjr0BHM7+XmKvp5k9RLuhA42W4oDIeZeMuolZ5vtzsJMais6kg0fyPeFhU9vixcVscyThEwrgyprIgjAMdjTJro= 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=jvr4vTLX; 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="jvr4vTLX" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2ba9a744f7dso5615146eec.0 for ; Tue, 17 Mar 2026 10:56:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773770216; x=1774375016; 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=e6S1xFZkYbjODhZybmDgeTik769fsYInNqc4i+88298=; b=jvr4vTLXWHbfwIVJ+DdR4wa2zuW50dbhARN/o4fYOuDMl2dpKYaXWYWmCUChDSlVzZ /bG2TwzY6jsmKTBBmp92rt3gj+hWJViN3vPVAklprA8l0bzNu5TnG4aY5S8ItRPsexvM GVD4HJeQogmZJmOloJdKd1B+OAwstxuPLklbmezDb334vcOOXGuJYiaXdZqz1Rasd7zb kGXCMPoBEKqWv8MdoMr1CrG9MDvYuYZOpwiXg4/ceyOETN4hC402SSVceqlXDGWy3A0C 5CG83cUfJ4TKKLbGlxUQQc8KoMICI+kpnwnYNIVPztdfYf89e1beazfzCfY6G3Mtz3JW 1GTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773770216; x=1774375016; 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=e6S1xFZkYbjODhZybmDgeTik769fsYInNqc4i+88298=; b=qHQm//fp4JvgM+JAuY7fDvcXWTifdOXiGFoxCsofreuNYSKIkk8RTfS+UeAn2uNdij oS6jGSW9EAhxZaZJnv3zJ/YvHZbklq6c1qBCSWrH78gC+NPvlzJla5CPFgo0PcgIx45i sowMFWDTDq31xbVOi9Vk+zW8ED9GjRqXyvhXoe8dw1x8gyzjAzusM8/VvpCh+iwwNfLp IESIfcM+neaF7CXysNXUvnc/MIhvFGQIpiubLmdr17qhNuisSDTEMYP2zHaH7i6BWB0q 3a5L2FiOoMc62ktSv2n2/YDwfKtn3R1Qr8J9cQ3kqMU1xkHcKn1xYNwMBJh4GS/XObXD 3/rA== X-Forwarded-Encrypted: i=1; AJvYcCUXh/71Fvu8vGk3NXGmIDnj+oD75fzF+YMkMmXrITnw8SlBiQItGqlVFN48YwLrulw2rZY4sibQ3uSxPr8=@vger.kernel.org X-Gm-Message-State: AOJu0YzNyL1SAic5UMtS0XKZJKxNTOgcrNSq5ZX+/1bStbdC4PzaVmw1 rl4JReCZIeoCw8C7zXgKVw7FEeTQ8RexLT5t+LXfsBLRWoPb1GQUqPIjZ10sfUdKwf6dXAu5shK aQfYPsOkwgw== X-Received: from dybso14.prod.google.com ([2002:a05:7301:690e:b0:2c0:b988:33bc]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:693c:3014:b0:2be:78ad:dbc6 with SMTP id 5a478bee46e88-2c0e5238cdfmr124396eec.33.1773770215550; Tue, 17 Mar 2026 10:56:55 -0700 (PDT) Date: Tue, 17 Mar 2026 10:56:41 -0700 In-Reply-To: <20260317175642.161647-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: <20260317175642.161647-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260317175642.161647-5-irogers@google.com> Subject: [PATCH v6 4/5] perf callchain: Refactor callchain option parsing From: Ian Rogers To: tmricht@linux.ibm.com Cc: irogers@google.com, acme@kernel.org, agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, namhyung@kernel.org, sumanthk@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" record_opts__parse_callchain is shared by builtin-record and builtin-trace, it is declared in callchain.h. Move the declaration to callchain.c for consistency with the header. In other cases make the option callback a small static stub that then calls into callchain.c. Make the no argument '-g' callchain option just a short-cut for '--call-graph fp' so that there is consistency in how the arguments are handled. This requires the const char* string to be strdup-ed in __parse_callchain_report_opt. For consistency also make parse_callchain_record use strdup and remove some unnecessary casts. Also, be more explicit with comments about the '-g' behavior if there is a .perfconfig file setting. Signed-off-by: Ian Rogers Tested-by: Thomas Richter --- tools/perf/builtin-record.c | 60 +++++------------------------- tools/perf/builtin-top.c | 20 ++++++---- tools/perf/builtin-trace.c | 9 ++++- tools/perf/util/callchain.c | 73 ++++++++++++++++++++++++++++++------- tools/perf/util/callchain.h | 12 ++---- 5 files changed, 94 insertions(+), 80 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 40917a0be238..26223f9505c2 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -2975,65 +2975,25 @@ static int __cmd_record(struct record *rec, int arg= c, const char **argv) return status; } =20 -static void callchain_debug(struct callchain_param *callchain) -{ - static const char *str[CALLCHAIN_MAX] =3D { "NONE", "FP", "DWARF", "LBR" = }; - - pr_debug("callchain: type %s\n", str[callchain->record_mode]); - - if (callchain->record_mode =3D=3D CALLCHAIN_DWARF) - pr_debug("callchain: stack dump size %d\n", - callchain->dump_size); -} - -int record_opts__parse_callchain(struct record_opts *record, - struct callchain_param *callchain, - const char *arg, bool unset) -{ - int ret; - callchain->enabled =3D !unset; - - /* --no-call-graph */ - if (unset) { - callchain->record_mode =3D CALLCHAIN_NONE; - pr_debug("callchain: disabled\n"); - return 0; - } - - ret =3D parse_callchain_record_opt(arg, callchain); - if (!ret) { - /* Enable data address sampling for DWARF unwind. */ - if (callchain->record_mode =3D=3D CALLCHAIN_DWARF && - !record->record_data_mmap_set) - record->record_data_mmap =3D true; - callchain_debug(callchain); - } - - return ret; -} - -int record_parse_callchain_opt(const struct option *opt, +static int record_parse_callchain_opt(const struct option *opt, const char *arg, int unset) { return record_opts__parse_callchain(opt->value, &callchain_param, arg, un= set); } =20 -int record_callchain_opt(const struct option *opt, - const char *arg __maybe_unused, - int unset __maybe_unused) +static int record_callchain_opt(const struct option *opt, + const char *arg __maybe_unused, + int unset) { - struct callchain_param *callchain =3D opt->value; - - callchain->enabled =3D true; - - if (callchain->record_mode =3D=3D CALLCHAIN_NONE) - callchain->record_mode =3D CALLCHAIN_FP; + /* The -g option only sets the callchain if not already configure by .per= fconfig. */ + if (callchain_param.record_mode !=3D CALLCHAIN_NONE) + return 0; =20 - callchain_debug(callchain); - return 0; + return record_opts__parse_callchain(opt->value, &callchain_param, "fp", u= nset); } =20 + static int perf_record_config(const char *var, const char *value, void *cb) { struct record *rec =3D cb; @@ -3525,7 +3485,7 @@ static struct option __record_options[] =3D { OPT_CALLBACK(0, "mmap-flush", &record.opts, "number", "Minimal number of bytes that is extracted from mmap data pages (de= fault: 1)", record__mmap_flush_parse), - OPT_CALLBACK_NOOPT('g', NULL, &callchain_param, + OPT_CALLBACK_NOOPT('g', NULL, &record.opts, NULL, "enables call-graph recording" , &record_callchain_opt), OPT_CALLBACK(0, "call-graph", &record.opts, diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 710604c4f6f6..5d2587228975 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -1386,13 +1386,6 @@ static int __cmd_top(struct perf_top *top) return ret; } =20 -static int -callchain_opt(const struct option *opt, const char *arg, int unset) -{ - symbol_conf.use_callchain =3D true; - return record_callchain_opt(opt, arg, unset); -} - static int parse_callchain_opt(const struct option *opt, const char *arg, int unset) { @@ -1413,6 +1406,19 @@ parse_callchain_opt(const struct option *opt, const = char *arg, int unset) return parse_callchain_top_opt(arg); } =20 +static int +callchain_opt(const struct option *opt, const char *arg __maybe_unused, in= t unset) +{ + struct callchain_param *callchain =3D opt->value; + + /* The -g option only sets the callchain if not already configure by .per= fconfig. */ + if (callchain->record_mode !=3D CALLCHAIN_NONE) + return 0; + + return parse_callchain_opt(opt, "fp", unset); +} + + static int perf_top_config(const char *var, const char *value, void *cb __= maybe_unused) { if (!strcmp(var, "top.call-graph")) { diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 1c38f3d16a31..f487fbaa0ad6 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -5300,6 +5300,13 @@ static int trace__parse_summary_mode(const struct op= tion *opt, const char *str, return 0; } =20 +static int trace_parse_callchain_opt(const struct option *opt, + const char *arg, + int unset) +{ + return record_opts__parse_callchain(opt->value, &callchain_param, arg, un= set); +} + static int trace__config(const char *var, const char *value, void *arg) { struct trace *trace =3D arg; @@ -5447,7 +5454,7 @@ int cmd_trace(int argc, const char **argv) OPT_BOOLEAN('f', "force", &trace.force, "don't complain, do it"), OPT_CALLBACK(0, "call-graph", &trace.opts, "record_mode[,record_size]", record_callchain_help, - &record_parse_callchain_opt), + &trace_parse_callchain_opt), OPT_BOOLEAN(0, "libtraceevent_print", &trace.libtraceevent_print, "Use libtraceevent to print the tracepoint arguments."), OPT_BOOLEAN(0, "kernel-syscall-graph", &trace.kernel_syscallchains, diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 8ff0898799ee..f879b84f8ff9 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -30,6 +30,7 @@ #include "map.h" #include "callchain.h" #include "branch.h" +#include "record.h" #include "symbol.h" #include "thread.h" #include "util.h" @@ -170,7 +171,7 @@ static int get_stack_size(const char *str, unsigned lon= g *_size) static int __parse_callchain_report_opt(const char *arg, bool allow_record_opt) { - char *tok; + char *tok, *arg_copy; char *endptr, *saveptr =3D NULL; bool minpcnt_set =3D false; bool record_opt_set =3D false; @@ -182,12 +183,17 @@ __parse_callchain_report_opt(const char *arg, bool al= low_record_opt) if (!arg) return 0; =20 - while ((tok =3D strtok_r((char *)arg, ",", &saveptr)) !=3D NULL) { + arg_copy =3D strdup(arg); + if (!arg_copy) + return -ENOMEM; + + tok =3D strtok_r(arg_copy, ",", &saveptr); + while (tok) { if (!strncmp(tok, "none", strlen(tok))) { callchain_param.mode =3D CHAIN_NONE; callchain_param.enabled =3D false; symbol_conf.use_callchain =3D false; - return 0; + goto out; } =20 if (!parse_callchain_mode(tok) || @@ -214,30 +220,35 @@ __parse_callchain_report_opt(const char *arg, bool al= low_record_opt) unsigned long size =3D 0; =20 if (get_stack_size(tok, &size) < 0) - return -1; + goto err_out; callchain_param.dump_size =3D size; try_stack_size =3D false; } else if (!minpcnt_set) { /* try to get the min percent */ callchain_param.min_percent =3D strtod(tok, &endptr); if (tok =3D=3D endptr) - return -1; + goto err_out; minpcnt_set =3D true; } else { /* try print limit at last */ callchain_param.print_limit =3D strtoul(tok, &endptr, 0); if (tok =3D=3D endptr) - return -1; + goto err_out; } next: - arg =3D NULL; + tok =3D strtok_r(NULL, ",", &saveptr); } =20 if (callchain_register_param(&callchain_param) < 0) { pr_err("Can't register callchain params\n"); - return -1; + goto err_out; } +out: + free(arg_copy); return 0; +err_out: + free(arg_copy); + return -1; } =20 int parse_callchain_report_opt(const char *arg) @@ -257,14 +268,12 @@ int parse_callchain_record(const char *arg, struct ca= llchain_param *param) int ret =3D -1; =20 /* We need buffer that we know we can write to. */ - buf =3D malloc(strlen(arg) + 1); + buf =3D strdup(arg); if (!buf) return -ENOMEM; =20 - strcpy(buf, arg); - - tok =3D strtok_r((char *)buf, ",", &saveptr); - name =3D tok ? : (char *)buf; + tok =3D strtok_r(buf, ",", &saveptr); + name =3D tok ? : buf; =20 do { /* Framepointer style */ @@ -328,6 +337,44 @@ int parse_callchain_record(const char *arg, struct cal= lchain_param *param) return ret; } =20 +static void callchain_debug(const struct callchain_param *callchain) +{ + static const char *str[CALLCHAIN_MAX] =3D { "NONE", "FP", "DWARF", "LBR" = }; + + pr_debug("callchain: type %s\n", str[callchain->record_mode]); + + if (callchain->record_mode =3D=3D CALLCHAIN_DWARF) + pr_debug("callchain: stack dump size %d\n", + callchain->dump_size); +} + +int record_opts__parse_callchain(struct record_opts *record, + struct callchain_param *callchain, + const char *arg, bool unset) +{ + int ret; + + callchain->enabled =3D !unset; + + /* --no-call-graph */ + if (unset) { + callchain->record_mode =3D CALLCHAIN_NONE; + pr_debug("callchain: disabled\n"); + return 0; + } + + ret =3D parse_callchain_record_opt(arg, callchain); + if (!ret) { + /* Enable data address sampling for DWARF unwind. */ + if (callchain->record_mode =3D=3D CALLCHAIN_DWARF && + !record->record_data_mmap_set) + record->record_data_mmap =3D true; + callchain_debug(callchain); + } + + return ret; +} + int perf_callchain_config(const char *var, const char *value) { char *endptr; diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index df54ddb8c0cb..06d463ccc7a0 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h @@ -9,11 +9,13 @@ =20 struct addr_location; struct evsel; +struct hist_entry; +struct hists; struct ip_callchain; struct map; struct perf_sample; +struct record_opts; struct thread; -struct hists; =20 #define HELP_PAD "\t\t\t\t" =20 @@ -237,14 +239,6 @@ struct callchain_cursor *get_tls_callchain_cursor(void= ); int callchain_cursor__copy(struct callchain_cursor *dst, struct callchain_cursor *src); =20 -struct option; -struct hist_entry; - -int record_parse_callchain_opt(const struct option *opt, const char *arg, = int unset); -int record_callchain_opt(const struct option *opt, const char *arg, int un= set); - -struct record_opts; - int record_opts__parse_callchain(struct record_opts *record, struct callchain_param *callchain, const char *arg, bool unset); --=20 2.53.0.851.ga537e3e6e9-goog From nobody Mon Apr 6 21:31:16 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 35A4337CD42 for ; Tue, 17 Mar 2026 17:56:59 +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=1773770224; cv=none; b=l/f26MR8LI1ZIy7fAZYqYATkpp2dZUP65hRbcxLNrC/NPFQAhIp+SaXHiM+RS4lmPuAo1LadgnhWqDiH/sF0/cMjaCxVVP6vrPxOoEK5RCRX6JPzqHrNJHNcUxaxcNU+c2CsXmfqOX9s9uwVCuTeZBxUmBSXh/t48hptvPTif8w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773770224; c=relaxed/simple; bh=d5pvIfQ6xcigH9j/9OyJB9iVHO88rUeVRxWZEvR0zSY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=biCKiernRU6fPtPPzxvdD43BV6S+VLKf/Hgdhj5rd1QIoDwE+tCZDxyT/uzrKvJQgsQl/BBuuDnRL2I12Wi7H0e1URfAUfUvNMAO03uF9biRPc3rvlS+9yIg6+QCnqa2MqvssUdUZjQFsdiQ912ZxGqDPWjT07sRnGxA6sJhS5A= 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=Qgm79p1a; 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="Qgm79p1a" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2c0bddb9196so1291379eec.1 for ; Tue, 17 Mar 2026 10:56:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773770218; x=1774375018; 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=lEgf/kr/qS+QFmeXxQE7lOMnSFqHvQJ5TUUD2h52kZw=; b=Qgm79p1aRtFjNmOflkiMCx+2/vYbAiWesppJnD4ND6SmKOpgC4X895SWR/+bXV8OJm V3S6i6Iboi3QEF7zqoNJSSItimjGsPlEwaScWXvZwSPcIzb3bptppEp/FN2lgD+TubTe QVa5K8/r/E01gXgss9+Xe36SfbHtMJy78eIdfLPqs57q1BX6v8f7oPH6FLvXHOQjCU5T bKPU32LisruGo961zIIK3HNxaqJ/ffpMDwVA/iPMy0191W2WixoL+NAxEABY7b1Pyb13 hgfLcHHvWRLva9uVj9GpZR6bT7bhjnHrsJWJaZYE6MMqB3D9lLAOo/SVDazMKMD0Bj5t 0APQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773770218; x=1774375018; 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=lEgf/kr/qS+QFmeXxQE7lOMnSFqHvQJ5TUUD2h52kZw=; b=sEfFR1DYtBCa+BzD3Tu1X5lW4lhJVlHx0RzgGMpGe/MtVl5hv7Iyh4Zr/646dgo2z8 ULeJaNQ8Z1ogmule/Pm1hjfRKVG51aXY8A6fTdHyX0hEraMR3HoXC2dhvLd3krgQwI6H 5FDyXv3dzfHU1FJh0+4gGl7qSBjpcEVE2QCB4UV5K9JZd26OFDK/vSgQO8D4tl7MJ0LO 80LiSsYP0v0kYiicmF2y7NE+KyDQ7fNOZno6WNgf/beGbr6TBZnKL5Nq6fyaoyJcHYSH 43PPXTAW07bPUda3oNjDqbT9wF6UhEuOX1c0F5KgPPgaAIqlJU0US0zduPP2uZ0d5X62 SULw== X-Forwarded-Encrypted: i=1; AJvYcCXcZ0JhfBLTbq71P4zXuHoNUjnObtmXqokTlCKM/9XuQa5YcJzsnE9ILkYcX5HPrJyHwCzdfxa1YifTTFw=@vger.kernel.org X-Gm-Message-State: AOJu0YwEl5BVc84jYWa6Nfa+n9fTwWB+4Q0AalakfX/RZKyxHpce9AbK ZuefAhv1jheadCZeD1V90NMgTF++YLJBR8sUjOAb+qbSHjVtr2tQ283YC2eAM4ny+C9Da3DXbc+ e0FYtnuqS7g== X-Received: from dyaw2-n2.prod.google.com ([2002:a05:693c:4142:20b0:2be:aaeb:7e1b]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:320b:b0:2ba:a60a:15e6 with SMTP id 5a478bee46e88-2c0e5062a64mr166169eec.16.1773770218066; Tue, 17 Mar 2026 10:56:58 -0700 (PDT) Date: Tue, 17 Mar 2026 10:56:42 -0700 In-Reply-To: <20260317175642.161647-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: <20260317175642.161647-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260317175642.161647-6-irogers@google.com> Subject: [PATCH v6 5/5] perf evlist: Improve default event for s390 From: Ian Rogers To: tmricht@linux.ibm.com Cc: irogers@google.com, acme@kernel.org, agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, namhyung@kernel.org, sumanthk@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Frame pointer callchains are not supported on s390 and dwarf callchains are only supported on software events. Switch the default event from the hardware 'cycles' event to the software 'cpu-clock' or 'task-clock' on s390 if callchains are enabled. Move the target initialization earlier in builtin-top so it is ready for use by evlist__new_default. If frame pointer callchains are requested on s390 show a warning. Modify the '-g' option of `perf top` and `perf record` to default to dwarf callchains on s390. Signed-off-by: Ian Rogers Tested-by: Thomas Richter --- tools/perf/builtin-record.c | 8 ++++-- tools/perf/builtin-top.c | 49 ++++++++++++++++---------------- 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, 72 insertions(+), 43 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 26223f9505c2..a03acfe66c27 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -55,6 +55,7 @@ #include "asm/bug.h" #include "perf.h" #include "cputopo.h" +#include "dwarf-regs.h" =20 #include #include @@ -2990,7 +2991,9 @@ static int record_callchain_opt(const struct option *= opt, if (callchain_param.record_mode !=3D CALLCHAIN_NONE) return 0; =20 - return record_opts__parse_callchain(opt->value, &callchain_param, "fp", u= nset); + return record_opts__parse_callchain(opt->value, &callchain_param, + EM_HOST !=3D EM_S390 ? "fp" : "dwarf", + unset); } =20 =20 @@ -4269,7 +4272,8 @@ int cmd_record(int argc, const char **argv) record.opts.tail_synthesize =3D true; =20 if (rec->evlist->core.nr_entries =3D=3D 0) { - struct evlist *def_evlist =3D evlist__new_default(); + struct evlist *def_evlist =3D evlist__new_default(&rec->opts.target, + callchain_param.enabled); =20 if (!def_evlist) goto out; diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 5d2587228975..f13560d5b1a3 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -56,6 +56,7 @@ #include "util/debug.h" #include "util/ordered-events.h" #include "util/pfm.h" +#include "dwarf-regs.h" =20 #include #include @@ -1415,7 +1416,7 @@ callchain_opt(const struct option *opt, const char *a= rg __maybe_unused, int unse if (callchain->record_mode !=3D CALLCHAIN_NONE) return 0; =20 - return parse_callchain_opt(opt, "fp", unset); + return parse_callchain_opt(opt, EM_HOST !=3D EM_S390 ? "fp" : "dwarf", un= set); } =20 =20 @@ -1700,8 +1701,30 @@ 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 (top.uid_str) { + uid_t uid =3D parse_uid(top.uid_str); + + if (uid =3D=3D UINT_MAX) { + ui__error("Invalid User: %s", top.uid_str); + status =3D -EINVAL; + goto out_delete_evlist; + } + status =3D parse_uid_filter(top.evlist, uid); + if (status) + goto out_delete_evlist; + } + + if (target__none(target)) + target->system_wide =3D true; + if (!top.evlist->core.nr_entries) { - struct evlist *def_evlist =3D evlist__new_default(); + struct evlist *def_evlist =3D evlist__new_default(target, callchain_para= m.enabled); =20 if (!def_evlist) goto out_delete_evlist; @@ -1794,28 +1817,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); - - if (uid =3D=3D UINT_MAX) { - ui__error("Invalid User: %s", top.uid_str); - status =3D -EINVAL; - goto out_delete_evlist; - } - status =3D parse_uid_filter(top.evlist, uid); - if (status) - goto out_delete_evlist; - } - - 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