Skip to content

Commit 5fb181c

Browse files
committed
Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf fixes from Thomas Gleixner: "Two fixes for perf x86 hardware implementations: - Restrict the period on Nehalem machines to prevent perf from hogging the CPU - Prevent the AMD IBS driver from overwriting the hardwre controlled and pre-seeded reserved bits (0-6) in the count register which caused a sample bias for dispatched micro-ops" * 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: perf/x86/amd/ibs: Fix sample bias for dispatched micro-ops perf/x86/intel: Restrict period on Nehalem
2 parents 5358e6e + 0f4cd76 commit 5fb181c

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

arch/x86/events/amd/ibs.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,10 +661,17 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs)
661661

662662
throttle = perf_event_overflow(event, &data, &regs);
663663
out:
664-
if (throttle)
664+
if (throttle) {
665665
perf_ibs_stop(event, 0);
666-
else
667-
perf_ibs_enable_event(perf_ibs, hwc, period >> 4);
666+
} else {
667+
period >>= 4;
668+
669+
if ((ibs_caps & IBS_CAPS_RDWROPCNT) &&
670+
(*config & IBS_OP_CNT_CTL))
671+
period |= *config & IBS_OP_CUR_CNT_RAND;
672+
673+
perf_ibs_enable_event(perf_ibs, hwc, period);
674+
}
668675

669676
perf_event_update_userpage(event);
670677

arch/x86/events/intel/core.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3572,6 +3572,11 @@ static u64 bdw_limit_period(struct perf_event *event, u64 left)
35723572
return left;
35733573
}
35743574

3575+
static u64 nhm_limit_period(struct perf_event *event, u64 left)
3576+
{
3577+
return max(left, 32ULL);
3578+
}
3579+
35753580
PMU_FORMAT_ATTR(event, "config:0-7" );
35763581
PMU_FORMAT_ATTR(umask, "config:8-15" );
35773582
PMU_FORMAT_ATTR(edge, "config:18" );
@@ -4606,6 +4611,7 @@ __init int intel_pmu_init(void)
46064611
x86_pmu.pebs_constraints = intel_nehalem_pebs_event_constraints;
46074612
x86_pmu.enable_all = intel_pmu_nhm_enable_all;
46084613
x86_pmu.extra_regs = intel_nehalem_extra_regs;
4614+
x86_pmu.limit_period = nhm_limit_period;
46094615

46104616
mem_attr = nhm_mem_events_attrs;
46114617

arch/x86/include/asm/perf_event.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,20 @@ struct pebs_lbr {
252252
#define IBSCTL_LVT_OFFSET_VALID (1ULL<<8)
253253
#define IBSCTL_LVT_OFFSET_MASK 0x0F
254254

255-
/* ibs fetch bits/masks */
255+
/* IBS fetch bits/masks */
256256
#define IBS_FETCH_RAND_EN (1ULL<<57)
257257
#define IBS_FETCH_VAL (1ULL<<49)
258258
#define IBS_FETCH_ENABLE (1ULL<<48)
259259
#define IBS_FETCH_CNT 0xFFFF0000ULL
260260
#define IBS_FETCH_MAX_CNT 0x0000FFFFULL
261261

262-
/* ibs op bits/masks */
263-
/* lower 4 bits of the current count are ignored: */
264-
#define IBS_OP_CUR_CNT (0xFFFF0ULL<<32)
262+
/*
263+
* IBS op bits/masks
264+
* The lower 7 bits of the current count are random bits
265+
* preloaded by hardware and ignored in software
266+
*/
267+
#define IBS_OP_CUR_CNT (0xFFF80ULL<<32)
268+
#define IBS_OP_CUR_CNT_RAND (0x0007FULL<<32)
265269
#define IBS_OP_CNT_CTL (1ULL<<19)
266270
#define IBS_OP_VAL (1ULL<<18)
267271
#define IBS_OP_ENABLE (1ULL<<17)

0 commit comments

Comments
 (0)