From: Andrii Nakryiko <andrii@kernel.org>
To: linux-perf-users@vger.kernel.org, peterz@infradead.org,
kan.liang@linux.intel.com
Cc: x86@kernel.org, mingo@redhat.com, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org, acme@kernel.org, kernel-team@meta.com,
Andrii Nakryiko <andrii@kernel.org>,
stable@vger.kernel.org
Subject: [PATCH] perf/x86: fix wrong assumption that LBR is only useful for sampling events
Date: Thu, 5 Sep 2024 11:00:55 -0700 [thread overview]
Message-ID: <20240905180055.1221620-1-andrii@kernel.org> (raw)
It's incorrect to assume that LBR can/should only be used with sampling
events. BPF subsystem provides bpf_get_branch_snapshot() BPF helper,
which expects a properly setup and activated perf event which allows
kernel to capture LBR data.
For instance, retsnoop tool ([0]) makes an extensive use of this
functionality and sets up perf event as follows:
struct perf_event_attr attr;
memset(&attr, 0, sizeof(attr));
attr.size = sizeof(attr);
attr.type = PERF_TYPE_HARDWARE;
attr.config = PERF_COUNT_HW_CPU_CYCLES;
attr.sample_type = PERF_SAMPLE_BRANCH_STACK;
attr.branch_sample_type = PERF_SAMPLE_BRANCH_KERNEL;
Commit referenced in Fixes tag broke this setup by making invalid assumption
that LBR is useful only for sampling events. Remove that assumption.
Note, earlier we removed a similar assumption on AMD side of LBR support,
see [1] for details.
[0] https://github.com/anakryiko/retsnoop
[1] 9794563d4d05 ("perf/x86/amd: Don't reject non-sampling events with configured LBR")
Cc: stable@vger.kernel.org # 6.8+
Fixes: 85846b27072d ("perf/x86: Add PERF_X86_EVENT_NEEDS_BRANCH_STACK flag")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
arch/x86/events/intel/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 9e519d8a810a..f82a342b8852 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -3972,7 +3972,7 @@ static int intel_pmu_hw_config(struct perf_event *event)
x86_pmu.pebs_aliases(event);
}
- if (needs_branch_stack(event) && is_sampling_event(event))
+ if (needs_branch_stack(event))
event->hw.flags |= PERF_X86_EVENT_NEEDS_BRANCH_STACK;
if (branch_sample_counters(event)) {
--
2.43.5
next reply other threads:[~2024-09-05 18:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-05 18:00 Andrii Nakryiko [this message]
2024-09-05 19:20 ` [PATCH] perf/x86: fix wrong assumption that LBR is only useful for sampling events Liang, Kan
2024-09-05 20:22 ` Andrii Nakryiko
2024-09-05 20:29 ` Liang, Kan
2024-09-05 20:33 ` Andrii Nakryiko
2024-09-09 16:02 ` Liang, Kan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240905180055.1221620-1-andrii@kernel.org \
--to=andrii@kernel.org \
--cc=acme@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=stable@vger.kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).