Skip to content

Commit 3c27b0c

Browse files
author
Peter Zijlstra
committed
perf/x86/amd: Fix AMD BRS period adjustment
There's two problems with the current amd_brs_adjust_period() code: - it isn't in fact AMD specific and wil always adjust the period; - it adjusts the period, while it should only adjust the event count, resulting in repoting a short period. Fix this by using x86_pmu.limit_period, this makes it specific to the AMD BRS case and ensures only the event count is adjusted while the reported period is unmodified. Fixes: ba2fe75 ("perf/x86/amd: Add AMD branch sampling period adjustment") Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
1 parent bc469dd commit 3c27b0c

File tree

3 files changed

+13
-25
lines changed

3 files changed

+13
-25
lines changed

arch/x86/events/amd/core.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,18 @@ static void amd_pmu_sched_task(struct perf_event_context *ctx,
12551255
amd_pmu_brs_sched_task(ctx, sched_in);
12561256
}
12571257

1258+
static u64 amd_pmu_limit_period(struct perf_event *event, u64 left)
1259+
{
1260+
/*
1261+
* Decrease period by the depth of the BRS feature to get the last N
1262+
* taken branches and approximate the desired period
1263+
*/
1264+
if (has_branch_stack(event) && left > x86_pmu.lbr_nr)
1265+
left -= x86_pmu.lbr_nr;
1266+
1267+
return left;
1268+
}
1269+
12581270
static __initconst const struct x86_pmu amd_pmu = {
12591271
.name = "AMD",
12601272
.handle_irq = amd_pmu_handle_irq,
@@ -1415,6 +1427,7 @@ static int __init amd_core_pmu_init(void)
14151427
if (boot_cpu_data.x86 >= 0x19 && !amd_brs_init()) {
14161428
x86_pmu.get_event_constraints = amd_get_event_constraints_f19h;
14171429
x86_pmu.sched_task = amd_pmu_sched_task;
1430+
x86_pmu.limit_period = amd_pmu_limit_period;
14181431
/*
14191432
* put_event_constraints callback same as Fam17h, set above
14201433
*/

arch/x86/events/core.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,13 +1374,6 @@ int x86_perf_event_set_period(struct perf_event *event)
13741374
x86_pmu.set_topdown_event_period)
13751375
return x86_pmu.set_topdown_event_period(event);
13761376

1377-
/*
1378-
* decrease period by the depth of the BRS feature to get
1379-
* the last N taken branches and approximate the desired period
1380-
*/
1381-
if (has_branch_stack(event))
1382-
period = amd_brs_adjust_period(period);
1383-
13841377
/*
13851378
* If we are way outside a reasonable range then just skip forward:
13861379
*/

arch/x86/events/perf_event.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,14 +1254,6 @@ static inline void amd_pmu_brs_del(struct perf_event *event)
12541254
}
12551255

12561256
void amd_pmu_brs_sched_task(struct perf_event_context *ctx, bool sched_in);
1257-
1258-
static inline s64 amd_brs_adjust_period(s64 period)
1259-
{
1260-
if (period > x86_pmu.lbr_nr)
1261-
return period - x86_pmu.lbr_nr;
1262-
1263-
return period;
1264-
}
12651257
#else
12661258
static inline int amd_brs_init(void)
12671259
{
@@ -1290,11 +1282,6 @@ static inline void amd_pmu_brs_sched_task(struct perf_event_context *ctx, bool s
12901282
{
12911283
}
12921284

1293-
static inline s64 amd_brs_adjust_period(s64 period)
1294-
{
1295-
return period;
1296-
}
1297-
12981285
static inline void amd_brs_enable_all(void)
12991286
{
13001287
}
@@ -1324,11 +1311,6 @@ static inline void amd_brs_enable_all(void)
13241311
static inline void amd_brs_disable_all(void)
13251312
{
13261313
}
1327-
1328-
static inline s64 amd_brs_adjust_period(s64 period)
1329-
{
1330-
return period;
1331-
}
13321314
#endif /* CONFIG_CPU_SUP_AMD */
13331315

13341316
static inline int is_pebs_pt(struct perf_event *event)

0 commit comments

Comments
 (0)