Skip to content

Commit c301b1d

Browse files
Kan LiangPeter Zijlstra
authored andcommitted
perf/x86/intel/lbr: Add a function pointer for LBR read
The method to read Architectural LBRs is different from previous model-specific LBR. Perf has to implement a different function. A function pointer for LBR read is introduced. Perf should initialize the corresponding function at boot time, and avoid checking lbr_format at run time. The current 64-bit LBR read function is set as default. 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 9f354a7 commit c301b1d

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

arch/x86/events/intel/core.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3980,6 +3980,7 @@ static __initconst const struct x86_pmu core_pmu = {
39803980
.check_period = intel_pmu_check_period,
39813981

39823982
.lbr_reset = intel_pmu_lbr_reset_64,
3983+
.lbr_read = intel_pmu_lbr_read_64,
39833984
};
39843985

39853986
static __initconst const struct x86_pmu intel_pmu = {
@@ -4027,6 +4028,7 @@ static __initconst const struct x86_pmu intel_pmu = {
40274028
.aux_output_match = intel_pmu_aux_output_match,
40284029

40294030
.lbr_reset = intel_pmu_lbr_reset_64,
4031+
.lbr_read = intel_pmu_lbr_read_64,
40304032
};
40314033

40324034
static __init void intel_clovertown_quirk(void)
@@ -4653,8 +4655,10 @@ __init int intel_pmu_init(void)
46534655
x86_pmu.intel_cap.capabilities = capabilities;
46544656
}
46554657

4656-
if (x86_pmu.intel_cap.lbr_format == LBR_FORMAT_32)
4658+
if (x86_pmu.intel_cap.lbr_format == LBR_FORMAT_32) {
46574659
x86_pmu.lbr_reset = intel_pmu_lbr_reset_32;
4660+
x86_pmu.lbr_read = intel_pmu_lbr_read_32;
4661+
}
46584662

46594663
intel_ds_init();
46604664

arch/x86/events/intel/lbr.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ void intel_pmu_lbr_disable_all(void)
562562
__intel_pmu_lbr_disable();
563563
}
564564

565-
static void intel_pmu_lbr_read_32(struct cpu_hw_events *cpuc)
565+
void intel_pmu_lbr_read_32(struct cpu_hw_events *cpuc)
566566
{
567567
unsigned long mask = x86_pmu.lbr_nr - 1;
568568
u64 tos = intel_pmu_lbr_tos();
@@ -599,7 +599,7 @@ static void intel_pmu_lbr_read_32(struct cpu_hw_events *cpuc)
599599
* is the same as the linear address, allowing us to merge the LIP and EIP
600600
* LBR formats.
601601
*/
602-
static void intel_pmu_lbr_read_64(struct cpu_hw_events *cpuc)
602+
void intel_pmu_lbr_read_64(struct cpu_hw_events *cpuc)
603603
{
604604
bool need_info = false, call_stack = false;
605605
unsigned long mask = x86_pmu.lbr_nr - 1;
@@ -704,10 +704,7 @@ void intel_pmu_lbr_read(void)
704704
cpuc->lbr_users == cpuc->lbr_pebs_users)
705705
return;
706706

707-
if (x86_pmu.intel_cap.lbr_format == LBR_FORMAT_32)
708-
intel_pmu_lbr_read_32(cpuc);
709-
else
710-
intel_pmu_lbr_read_64(cpuc);
707+
x86_pmu.lbr_read(cpuc);
711708

712709
intel_pmu_lbr_filter(cpuc);
713710
}

arch/x86/events/perf_event.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ struct x86_pmu {
694694
bool lbr_pt_coexist; /* (LBR|BTS) may coexist with PT */
695695

696696
void (*lbr_reset)(void);
697+
void (*lbr_read)(struct cpu_hw_events *cpuc);
697698

698699
/*
699700
* Intel PT/LBR/BTS are exclusive
@@ -1085,6 +1086,10 @@ void intel_pmu_lbr_disable_all(void);
10851086

10861087
void intel_pmu_lbr_read(void);
10871088

1089+
void intel_pmu_lbr_read_32(struct cpu_hw_events *cpuc);
1090+
1091+
void intel_pmu_lbr_read_64(struct cpu_hw_events *cpuc);
1092+
10881093
void intel_pmu_lbr_init_core(void);
10891094

10901095
void intel_pmu_lbr_init_nhm(void);

0 commit comments

Comments
 (0)