Skip to content

Commit cc37e52

Browse files
Stephane EranianPeter Zijlstra
authored andcommitted
perf/x86/amd: Make Zen3 branch sampling opt-in
Add a kernel config option CONFIG_PERF_EVENTS_AMD_BRS to make the support for AMD Zen3 Branch Sampling (BRS) an opt-in compile time option. Signed-off-by: Stephane Eranian <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ba2fe75 commit cc37e52

File tree

3 files changed

+49
-11
lines changed

3 files changed

+49
-11
lines changed

arch/x86/events/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,12 @@ config PERF_EVENTS_AMD_UNCORE
4444

4545
To compile this driver as a module, choose M here: the
4646
module will be called 'amd-uncore'.
47+
48+
config PERF_EVENTS_AMD_BRS
49+
depends on PERF_EVENTS && CPU_SUP_AMD
50+
bool "AMD Zen3 Branch Sampling support"
51+
help
52+
Enable AMD Zen3 branch sampling support (BRS) which samples up to
53+
16 consecutive taken branches in registers.
54+
4755
endmenu

arch/x86/events/amd/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
obj-$(CONFIG_CPU_SUP_AMD) += core.o brs.o
2+
obj-$(CONFIG_CPU_SUP_AMD) += core.o
3+
obj-$(CONFIG_PERF_EVENTS_AMD_BRS) += brs.o
34
obj-$(CONFIG_PERF_EVENTS_AMD_POWER) += power.o
45
obj-$(CONFIG_X86_LOCAL_APIC) += ibs.o
56
obj-$(CONFIG_PERF_EVENTS_AMD_UNCORE) += amd-uncore.o

arch/x86/events/perf_event.h

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,8 @@ static inline bool fixed_counter_disabled(int i, struct pmu *pmu)
12181218
#ifdef CONFIG_CPU_SUP_AMD
12191219

12201220
int amd_pmu_init(void);
1221+
1222+
#ifdef CONFIG_PERF_EVENTS_AMD_BRS
12211223
int amd_brs_init(void);
12221224
void amd_brs_disable(void);
12231225
void amd_brs_enable(void);
@@ -1252,25 +1254,52 @@ static inline void amd_pmu_brs_del(struct perf_event *event)
12521254

12531255
void amd_pmu_brs_sched_task(struct perf_event_context *ctx, bool sched_in);
12541256

1255-
/*
1256-
* check if BRS is activated on the CPU
1257-
* active defined as it has non-zero users and DBG_EXT_CFG.BRSEN=1
1258-
*/
1259-
static inline bool amd_brs_active(void)
1257+
static inline s64 amd_brs_adjust_period(s64 period)
12601258
{
1261-
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
1259+
if (period > x86_pmu.lbr_nr)
1260+
return period - x86_pmu.lbr_nr;
12621261

1263-
return cpuc->brs_active;
1262+
return period;
1263+
}
1264+
#else
1265+
static inline int amd_brs_init(void)
1266+
{
1267+
return 0;
12641268
}
1269+
static inline void amd_brs_disable(void) {}
1270+
static inline void amd_brs_enable(void) {}
1271+
static inline void amd_brs_drain(void) {}
1272+
static inline void amd_brs_lopwr_init(void) {}
1273+
static inline void amd_brs_disable_all(void) {}
1274+
static inline int amd_brs_setup_filter(struct perf_event *event)
1275+
{
1276+
return 0;
1277+
}
1278+
static inline void amd_brs_reset(void) {}
12651279

1266-
static inline s64 amd_brs_adjust_period(s64 period)
1280+
static inline void amd_pmu_brs_add(struct perf_event *event)
12671281
{
1268-
if (period > x86_pmu.lbr_nr)
1269-
return period - x86_pmu.lbr_nr;
1282+
}
1283+
1284+
static inline void amd_pmu_brs_del(struct perf_event *event)
1285+
{
1286+
}
1287+
1288+
static inline void amd_pmu_brs_sched_task(struct perf_event_context *ctx, bool sched_in)
1289+
{
1290+
}
12701291

1292+
static inline s64 amd_brs_adjust_period(s64 period)
1293+
{
12711294
return period;
12721295
}
12731296

1297+
static inline void amd_brs_enable_all(void)
1298+
{
1299+
}
1300+
1301+
#endif
1302+
12741303
#else /* CONFIG_CPU_SUP_AMD */
12751304

12761305
static inline int amd_pmu_init(void)

0 commit comments

Comments
 (0)