[Patch v7 15/24] perf/x86/intel: Set PERF_EV_CAP_SIBLING for pure branch counter events
From: Dapeng Mi
Date: Tue Nov 17 2026 - 22:24:48 EST
A pure branch counter event (i.e. an event which only applies
PERF_SAMPLE_BRANCH_COUNTERS without requiring the branch stack itself)
doesn't set up the LBR on its own. It relies on being grouped with a
normal branch event, which configures the LBR for it. Such an event
cannot work standalone.
Set the PERF_EV_CAP_SIBLING flag for pure branch counter events, so
that the generic perf core schedules them out once the group leader is
removed from the group.
Opportunistically refine the code style.
Fixes: 33744916196b ("perf/x86/intel: Support branch counters logging")
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Signed-off-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
---
arch/x86/events/intel/core.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 84b134bb91ee..fd4de141ef28 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -5130,10 +5130,17 @@ static int intel_pmu_hw_config(struct perf_event *event)
* require any branch stack setup.
* Clear the bit to avoid unnecessary branch stack setup.
*/
- if (0 == (event->attr.branch_sample_type &
- ~(PERF_SAMPLE_BRANCH_PLM_ALL |
- PERF_SAMPLE_BRANCH_COUNTERS)))
- event->hw.flags &= ~PERF_X86_EVENT_NEEDS_BRANCH_STACK;
+ if (!(event->attr.branch_sample_type &
+ ~(PERF_SAMPLE_BRANCH_PLM_ALL | PERF_SAMPLE_BRANCH_COUNTERS))) {
+ event->hw.flags &= ~PERF_X86_EVENT_NEEDS_BRANCH_STACK;
+ /*
+ * A pure branch counter event doesn't set up the LBR
+ * itself. It must stay grouped with a normal branch
+ * event which configures the LBR for it. Otherwise,
+ * the LBR cannot be configured correctly.
+ */
+ event->event_caps |= PERF_EV_CAP_SIBLING;
+ }
/*
* Force the leader to be a LBR event. So LBRs can be reset
--
2.34.1