Skip to content

Commit 9f354a7

Browse files
Kan LiangPeter Zijlstra
authored andcommitted
perf/x86/intel/lbr: Add a function pointer for LBR reset
The method to reset Architectural LBRs is different from previous model-specific LBR. Perf has to implement a different function. A function pointer is introduced for LBR reset. The enum of LBR_FORMAT_* is also moved to perf_event.h. Perf should initialize the corresponding functions at boot time, and avoid checking lbr_format at run time. The current 64-bit LBR reset 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 bd657aa commit 9f354a7

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

arch/x86/events/intel/core.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3978,6 +3978,8 @@ static __initconst const struct x86_pmu core_pmu = {
39783978
.cpu_dead = intel_pmu_cpu_dead,
39793979

39803980
.check_period = intel_pmu_check_period,
3981+
3982+
.lbr_reset = intel_pmu_lbr_reset_64,
39813983
};
39823984

39833985
static __initconst const struct x86_pmu intel_pmu = {
@@ -4023,6 +4025,8 @@ static __initconst const struct x86_pmu intel_pmu = {
40234025
.check_period = intel_pmu_check_period,
40244026

40254027
.aux_output_match = intel_pmu_aux_output_match,
4028+
4029+
.lbr_reset = intel_pmu_lbr_reset_64,
40264030
};
40274031

40284032
static __init void intel_clovertown_quirk(void)
@@ -4649,6 +4653,9 @@ __init int intel_pmu_init(void)
46494653
x86_pmu.intel_cap.capabilities = capabilities;
46504654
}
46514655

4656+
if (x86_pmu.intel_cap.lbr_format == LBR_FORMAT_32)
4657+
x86_pmu.lbr_reset = intel_pmu_lbr_reset_32;
4658+
46524659
intel_ds_init();
46534660

46544661
x86_add_quirk(intel_arch_events_quirk); /* Install first, so it runs last */

arch/x86/events/intel/lbr.c

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,6 @@
88

99
#include "../perf_event.h"
1010

11-
enum {
12-
LBR_FORMAT_32 = 0x00,
13-
LBR_FORMAT_LIP = 0x01,
14-
LBR_FORMAT_EIP = 0x02,
15-
LBR_FORMAT_EIP_FLAGS = 0x03,
16-
LBR_FORMAT_EIP_FLAGS2 = 0x04,
17-
LBR_FORMAT_INFO = 0x05,
18-
LBR_FORMAT_TIME = 0x06,
19-
LBR_FORMAT_MAX_KNOWN = LBR_FORMAT_TIME,
20-
};
21-
2211
static const enum {
2312
LBR_EIP_FLAGS = 1,
2413
LBR_TSX = 2,
@@ -194,15 +183,15 @@ static void __intel_pmu_lbr_disable(void)
194183
wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctl);
195184
}
196185

197-
static void intel_pmu_lbr_reset_32(void)
186+
void intel_pmu_lbr_reset_32(void)
198187
{
199188
int i;
200189

201190
for (i = 0; i < x86_pmu.lbr_nr; i++)
202191
wrmsrl(x86_pmu.lbr_from + i, 0);
203192
}
204193

205-
static void intel_pmu_lbr_reset_64(void)
194+
void intel_pmu_lbr_reset_64(void)
206195
{
207196
int i;
208197

@@ -221,10 +210,7 @@ void intel_pmu_lbr_reset(void)
221210
if (!x86_pmu.lbr_nr)
222211
return;
223212

224-
if (x86_pmu.intel_cap.lbr_format == LBR_FORMAT_32)
225-
intel_pmu_lbr_reset_32();
226-
else
227-
intel_pmu_lbr_reset_64();
213+
x86_pmu.lbr_reset();
228214

229215
cpuc->last_task_ctx = NULL;
230216
cpuc->last_log_id = 0;

arch/x86/events/perf_event.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,17 @@ struct intel_excl_cntrs {
179179
struct x86_perf_task_context;
180180
#define MAX_LBR_ENTRIES 32
181181

182+
enum {
183+
LBR_FORMAT_32 = 0x00,
184+
LBR_FORMAT_LIP = 0x01,
185+
LBR_FORMAT_EIP = 0x02,
186+
LBR_FORMAT_EIP_FLAGS = 0x03,
187+
LBR_FORMAT_EIP_FLAGS2 = 0x04,
188+
LBR_FORMAT_INFO = 0x05,
189+
LBR_FORMAT_TIME = 0x06,
190+
LBR_FORMAT_MAX_KNOWN = LBR_FORMAT_TIME,
191+
};
192+
182193
enum {
183194
X86_PERF_KFREE_SHARED = 0,
184195
X86_PERF_KFREE_EXCL = 1,
@@ -682,6 +693,8 @@ struct x86_pmu {
682693
bool lbr_double_abort; /* duplicated lbr aborts */
683694
bool lbr_pt_coexist; /* (LBR|BTS) may coexist with PT */
684695

696+
void (*lbr_reset)(void);
697+
685698
/*
686699
* Intel PT/LBR/BTS are exclusive
687700
*/
@@ -1058,6 +1071,10 @@ u64 lbr_from_signext_quirk_wr(u64 val);
10581071

10591072
void intel_pmu_lbr_reset(void);
10601073

1074+
void intel_pmu_lbr_reset_32(void);
1075+
1076+
void intel_pmu_lbr_reset_64(void);
1077+
10611078
void intel_pmu_lbr_add(struct perf_event *event);
10621079

10631080
void intel_pmu_lbr_del(struct perf_event *event);

0 commit comments

Comments
 (0)