From nobody Tue Jun 23 10:12:08 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EED9AC433F5 for ; Mon, 7 Mar 2022 17:19:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244421AbiCGRU0 (ORCPT ); Mon, 7 Mar 2022 12:20:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240304AbiCGRUV (ORCPT ); Mon, 7 Mar 2022 12:20:21 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EB17774847; Mon, 7 Mar 2022 09:19:26 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id ADB0C153B; Mon, 7 Mar 2022 09:19:26 -0800 (PST) Received: from e121896.arm.com (unknown [10.57.41.31]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E7FA53FA45; Mon, 7 Mar 2022 09:19:24 -0800 (PST) From: James Clark To: acme@kernel.org, linux-perf-users@vger.kernel.org, anshuman.khandual@arm.com Cc: german.gomez@arm.com, leo.yan@linaro.com, James Clark , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-kernel@vger.kernel.org Subject: [PATCH 1/4] perf: Add error message for unsupported branch stack cases Date: Mon, 7 Mar 2022 17:19:14 +0000 Message-Id: <20220307171917.2555829-2-james.clark@arm.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20220307171917.2555829-1-james.clark@arm.com> References: <20220307171917.2555829-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" EOPNOTSUPP is a possible return value when branch stacks are requested but they aren't enabled in the kernel or hardware. It's also returned if they aren't supported on the specific event type. The currently printed error message about sampling/overflow-interrupts is not correct in this case. Add a check for branch stacks before sample_period is checked because sample_period is also set (to the default value) when using branch stacks. Before this change (when branch stacks aren't supported): perf record -j any Error: cycles: PMU Hardware doesn't support sampling/overflow-interrupts. Try 'p= erf stat' After this change: perf record -j any Error: cycles: PMU Hardware or event type doesn't support branch stack sampling. Signed-off-by: James Clark Reviewed-by: Anshuman Khandual --- tools/perf/util/evsel.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 22d3267ce294..4e10a4ec11c7 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2909,6 +2909,10 @@ int evsel__open_strerror(struct evsel *evsel, struct= target *target, "No such device - did you specify an out-of-range profile CPU?"); break; case EOPNOTSUPP: + if (evsel->core.attr.sample_type & PERF_SAMPLE_BRANCH_STACK) + return scnprintf(msg, size, + "%s: PMU Hardware or event type doesn't support branch stack sampling.", + evsel__name(evsel)); if (evsel->core.attr.aux_output) return scnprintf(msg, size, "%s: PMU Hardware doesn't support 'aux_output' feature", --=20 2.28.0 From nobody Tue Jun 23 10:12:08 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4399DC433F5 for ; Mon, 7 Mar 2022 17:19:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244434AbiCGRUa (ORCPT ); Mon, 7 Mar 2022 12:20:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244414AbiCGRUX (ORCPT ); Mon, 7 Mar 2022 12:20:23 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 429B677AB9; Mon, 7 Mar 2022 09:19:29 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 13695153B; Mon, 7 Mar 2022 09:19:29 -0800 (PST) Received: from e121896.arm.com (unknown [10.57.41.31]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4E1673FA45; Mon, 7 Mar 2022 09:19:27 -0800 (PST) From: James Clark To: acme@kernel.org, linux-perf-users@vger.kernel.org, anshuman.khandual@arm.com Cc: german.gomez@arm.com, leo.yan@linaro.com, James Clark , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-kernel@vger.kernel.org Subject: [PATCH 2/4] perf: Print branch stack entry type in --dump-raw-trace Date: Mon, 7 Mar 2022 17:19:15 +0000 Message-Id: <20220307171917.2555829-3-james.clark@arm.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20220307171917.2555829-1-james.clark@arm.com> References: <20220307171917.2555829-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This can help with debugging issues. It only prints when -j save_type is used otherwise an empty string is printed. Before the change: 101603801707130 0xa70 [0x630]: PERF_RECORD_SAMPLE(IP, 0x2): 1108/1108: 0x= ffff9c1df24c period: 10694 addr: 0 ... branch stack: nr:64 ..... 0: 0000ffff9c26029c -> 0000ffff9c26f340 0 cycles P 0 ..... 1: 0000ffff9c2601bc -> 0000ffff9c26f340 0 cycles P 0 After the change: 101603801707130 0xa70 [0x630]: PERF_RECORD_SAMPLE(IP, 0x2): 1108/1108: 0x= ffff9c1df24c period: 10694 addr: 0 ... branch stack: nr:64 ..... 0: 0000ffff9c26029c -> 0000ffff9c26f340 0 cycles P 0 CALL ..... 1: 0000ffff9c2601bc -> 0000ffff9c26f340 0 cycles P 0 IND_CALL Signed-off-by: James Clark --- tools/perf/util/session.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index f54282d5c648..3b8dfe603e50 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1159,14 +1159,15 @@ static void branch_stack__printf(struct perf_sample= *sample, bool callstack) struct branch_entry *e =3D &entries[i]; =20 if (!callstack) { - printf("..... %2"PRIu64": %016" PRIx64 " -> %016" PRIx64 " %hu cycles %= s%s%s%s %x\n", + printf("..... %2"PRIu64": %016" PRIx64 " -> %016" PRIx64 " %hu cycles %= s%s%s%s %x %s\n", i, e->from, e->to, (unsigned short)e->flags.cycles, e->flags.mispred ? "M" : " ", e->flags.predicted ? "P" : " ", e->flags.abort ? "A" : " ", e->flags.in_tx ? "T" : " ", - (unsigned)e->flags.reserved); + (unsigned)e->flags.reserved, + e->flags.type ? branch_type_name(e->flags.type) : ""); } else { printf("..... %2"PRIu64": %016" PRIx64 "\n", i, i > 0 ? e->from : e->to); --=20 2.28.0 From nobody Tue Jun 23 10:12:08 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3824DC433FE for ; Mon, 7 Mar 2022 17:19:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236315AbiCGRUe (ORCPT ); Mon, 7 Mar 2022 12:20:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244433AbiCGRUa (ORCPT ); Mon, 7 Mar 2022 12:20:30 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A4D4A8565F; Mon, 7 Mar 2022 09:19:31 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6F392153B; Mon, 7 Mar 2022 09:19:31 -0800 (PST) Received: from e121896.arm.com (unknown [10.57.41.31]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A94963FA45; Mon, 7 Mar 2022 09:19:29 -0800 (PST) From: James Clark To: acme@kernel.org, linux-perf-users@vger.kernel.org, anshuman.khandual@arm.com Cc: german.gomez@arm.com, leo.yan@linaro.com, James Clark , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-kernel@vger.kernel.org Subject: [PATCH 3/4] perf: Refactor perf script branch stack printing Date: Mon, 7 Mar 2022 17:19:16 +0000 Message-Id: <20220307171917.2555829-4-james.clark@arm.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20220307171917.2555829-1-james.clark@arm.com> References: <20220307171917.2555829-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Remove duplicate code so that future changes to flags are always made to all 3 printing variations. Signed-off-by: James Clark Reviewed-by: Anshuman Khandual --- tools/perf/builtin-script.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 9e032343f1c6..fac2e9470926 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -857,6 +857,15 @@ mispred_str(struct branch_entry *br) return br->flags.predicted ? 'P' : 'M'; } =20 +static int print_bstack_flags(FILE *fp, struct branch_entry *br) +{ + return fprintf(fp, "/%c/%c/%c/%d ", + mispred_str(br), + br->flags.in_tx ? 'X' : '-', + br->flags.abort ? 'A' : '-', + br->flags.cycles); +} + static int perf_sample__fprintf_brstack(struct perf_sample *sample, struct thread *thread, struct perf_event_attr *attr, FILE *fp) @@ -895,11 +904,7 @@ static int perf_sample__fprintf_brstack(struct perf_sa= mple *sample, printed +=3D fprintf(fp, ")"); } =20 - printed +=3D fprintf(fp, "/%c/%c/%c/%d ", - mispred_str(entries + i), - entries[i].flags.in_tx ? 'X' : '-', - entries[i].flags.abort ? 'A' : '-', - entries[i].flags.cycles); + printed +=3D print_bstack_flags(fp, entries + i); } =20 return printed; @@ -941,11 +946,7 @@ static int perf_sample__fprintf_brstacksym(struct perf= _sample *sample, printed +=3D map__fprintf_dsoname(alt.map, fp); printed +=3D fprintf(fp, ")"); } - printed +=3D fprintf(fp, "/%c/%c/%c/%d ", - mispred_str(entries + i), - entries[i].flags.in_tx ? 'X' : '-', - entries[i].flags.abort ? 'A' : '-', - entries[i].flags.cycles); + printed +=3D print_bstack_flags(fp, entries + i); } =20 return printed; @@ -991,11 +992,7 @@ static int perf_sample__fprintf_brstackoff(struct perf= _sample *sample, printed +=3D map__fprintf_dsoname(alt.map, fp); printed +=3D fprintf(fp, ")"); } - printed +=3D fprintf(fp, "/%c/%c/%c/%d ", - mispred_str(entries + i), - entries[i].flags.in_tx ? 'X' : '-', - entries[i].flags.abort ? 'A' : '-', - entries[i].flags.cycles); + printed +=3D print_bstack_flags(fp, entries + i); } =20 return printed; --=20 2.28.0 From nobody Tue Jun 23 10:12:08 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CDE5C433EF for ; Mon, 7 Mar 2022 17:19:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234943AbiCGRUi (ORCPT ); Mon, 7 Mar 2022 12:20:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244442AbiCGRUa (ORCPT ); Mon, 7 Mar 2022 12:20:30 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2C90390FC8; Mon, 7 Mar 2022 09:19:34 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C11F31576; Mon, 7 Mar 2022 09:19:33 -0800 (PST) Received: from e121896.arm.com (unknown [10.57.41.31]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 09FCD3FA45; Mon, 7 Mar 2022 09:19:31 -0800 (PST) From: James Clark To: acme@kernel.org, linux-perf-users@vger.kernel.org, anshuman.khandual@arm.com Cc: german.gomez@arm.com, leo.yan@linaro.com, James Clark , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-kernel@vger.kernel.org Subject: [PATCH 4/4] perf script: Output branch sample type Date: Mon, 7 Mar 2022 17:19:17 +0000 Message-Id: <20220307171917.2555829-5-james.clark@arm.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20220307171917.2555829-1-james.clark@arm.com> References: <20220307171917.2555829-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The type info is saved when using '-j save_type'. Output this in perf script so it can be accessed by other tools or for debugging. It's appended to the end of the list of fields so any existing tools that split on / and access fields via an index are not affected. Also output '-' instead of 'N/A' when the branch type isn't saved because / is used as a field separator. Entries before this change look like this: 0xaaaadb350838/0xaaaadb3507a4/P/-/-/0 And afterwards like this: 0xaaaadb350838/0xaaaadb3507a4/P/-/-/0/CALL or this if no type info is saved: 0x7fb57586df6b/0x7fb5758731f0/P/-/-/143/- Signed-off-by: James Clark --- tools/perf/builtin-script.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index fac2e9470926..5e4a262a6825 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -859,11 +859,12 @@ mispred_str(struct branch_entry *br) =20 static int print_bstack_flags(FILE *fp, struct branch_entry *br) { - return fprintf(fp, "/%c/%c/%c/%d ", + return fprintf(fp, "/%c/%c/%c/%d/%s ", mispred_str(br), br->flags.in_tx ? 'X' : '-', br->flags.abort ? 'A' : '-', - br->flags.cycles); + br->flags.cycles, + br->flags.type ? branch_type_name(br->flags.type) : "-"); } =20 static int perf_sample__fprintf_brstack(struct perf_sample *sample, --=20 2.28.0