Skip to content

Commit 85846b2

Browse files
Kan LiangPeter Zijlstra
Kan Liang
authored and
Peter Zijlstra
committed
perf/x86: Add PERF_X86_EVENT_NEEDS_BRANCH_STACK flag
Currently, branch_sample_type !=0 is used to check whether a branch stack setup is required. But it doesn't check the sample type, unnecessary branch stack setup may be done for a counting event. E.g., perf record -e "{branch-instructions,branch-misses}:S" -j any Also, the event only with the new PERF_SAMPLE_BRANCH_COUNTERS branch sample type may not require a branch stack setup either. Add a new flag NEEDS_BRANCH_STACK to indicate whether the event requires a branch stack setup. Replace the needs_branch_stack() by checking the new flag. The counting event check is implemented here. The later patch will take the new PERF_SAMPLE_BRANCH_COUNTERS into account. Signed-off-by: Kan Liang <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 571d91d commit 85846b2

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

arch/x86/events/intel/core.c

+11-3
Original file line numberDiff line numberDiff line change
@@ -2527,9 +2527,14 @@ static void intel_pmu_assign_event(struct perf_event *event, int idx)
25272527
perf_report_aux_output_id(event, idx);
25282528
}
25292529

2530+
static __always_inline bool intel_pmu_needs_branch_stack(struct perf_event *event)
2531+
{
2532+
return event->hw.flags & PERF_X86_EVENT_NEEDS_BRANCH_STACK;
2533+
}
2534+
25302535
static void intel_pmu_del_event(struct perf_event *event)
25312536
{
2532-
if (needs_branch_stack(event))
2537+
if (intel_pmu_needs_branch_stack(event))
25332538
intel_pmu_lbr_del(event);
25342539
if (event->attr.precise_ip)
25352540
intel_pmu_pebs_del(event);
@@ -2820,7 +2825,7 @@ static void intel_pmu_add_event(struct perf_event *event)
28202825
{
28212826
if (event->attr.precise_ip)
28222827
intel_pmu_pebs_add(event);
2823-
if (needs_branch_stack(event))
2828+
if (intel_pmu_needs_branch_stack(event))
28242829
intel_pmu_lbr_add(event);
28252830
}
28262831

@@ -3897,7 +3902,10 @@ static int intel_pmu_hw_config(struct perf_event *event)
38973902
x86_pmu.pebs_aliases(event);
38983903
}
38993904

3900-
if (needs_branch_stack(event)) {
3905+
if (needs_branch_stack(event) && is_sampling_event(event))
3906+
event->hw.flags |= PERF_X86_EVENT_NEEDS_BRANCH_STACK;
3907+
3908+
if (intel_pmu_needs_branch_stack(event)) {
39013909
ret = intel_pmu_setup_lbr_filter(event);
39023910
if (ret)
39033911
return ret;

arch/x86/events/perf_event_flags.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ PERF_ARCH(TOPDOWN, 0x04000) /* Count Topdown slots/metrics events */
2020
PERF_ARCH(PEBS_STLAT, 0x08000) /* st+stlat data address sampling */
2121
PERF_ARCH(AMD_BRS, 0x10000) /* AMD Branch Sampling */
2222
PERF_ARCH(PEBS_LAT_HYBRID, 0x20000) /* ld and st lat for hybrid */
23+
PERF_ARCH(NEEDS_BRANCH_STACK, 0x40000) /* require branch stack setup */

0 commit comments

Comments
 (0)