Skip to content

Commit 730106b

Browse files
Ravi BangoriaSasha Levin
authored andcommitted
perf/amd/ibs: Fix ->config to sample period calculation for OP PMU
[ Upstream commit 598bdf4 ] Instead of using standard perf_event_attr->freq=0 and ->sample_period fields, IBS event in 'sample period mode' can also be opened by setting period value directly in perf_event_attr->config in a MaxCnt bit-field format. IBS OP MaxCnt bits are defined as: (high bits) IbsOpCtl[26:20] = IbsOpMaxCnt[26:20] (low bits) IbsOpCtl[15:0] = IbsOpMaxCnt[19:4] Perf event sample period can be derived from MaxCnt bits as: sample_period = (high bits) | ((low_bits) << 4); However, current code just masks MaxCnt bits and shifts all of them, including high bits, which is incorrect. Fix it. Signed-off-by: Ravi Bangoria <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Namhyung Kim <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Sasha Levin <[email protected]>
1 parent 6fafd8d commit 730106b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

arch/x86/events/amd/ibs.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ static int perf_ibs_init(struct perf_event *event)
272272
{
273273
struct hw_perf_event *hwc = &event->hw;
274274
struct perf_ibs *perf_ibs;
275-
u64 max_cnt, config;
275+
u64 config;
276276
int ret;
277277

278278
perf_ibs = get_ibs_pmu(event->attr.type);
@@ -309,10 +309,19 @@ static int perf_ibs_init(struct perf_event *event)
309309
if (!hwc->sample_period)
310310
hwc->sample_period = 0x10;
311311
} else {
312-
max_cnt = config & perf_ibs->cnt_mask;
312+
u64 period = 0;
313+
314+
if (perf_ibs == &perf_ibs_op) {
315+
period = (config & IBS_OP_MAX_CNT) << 4;
316+
if (ibs_caps & IBS_CAPS_OPCNTEXT)
317+
period |= config & IBS_OP_MAX_CNT_EXT_MASK;
318+
} else {
319+
period = (config & IBS_FETCH_MAX_CNT) << 4;
320+
}
321+
313322
config &= ~perf_ibs->cnt_mask;
314-
event->attr.sample_period = max_cnt << 4;
315-
hwc->sample_period = event->attr.sample_period;
323+
event->attr.sample_period = period;
324+
hwc->sample_period = period;
316325
}
317326

318327
if (!hwc->sample_period)

0 commit comments

Comments
 (0)