Skip to content

Commit f605cfc

Browse files
Kan LiangIngo Molnar
authored andcommitted
perf/x86/intel: Fix large period handling on Broadwell CPUs
Large fixed period values could be truncated on Broadwell, for example: perf record -e cycles -c 10000000000 Here the fixed period is 0x2540BE400, but the period which finally applied is 0x540BE400 - which is wrong. The reason is that x86_pmu::limit_period() uses an u32 parameter, so the high 32 bits of 'period' get truncated. This bug was introduced in: commit 294fe0f ("perf/x86/intel: Add INST_RETIRED.ALL workarounds") It's safe to use u64 instead of u32: - Although the 'left' is s64, the value of 'left' must be positive when calling limit_period(). - bdw_limit_period() only modifies the lowest 6 bits, it doesn't touch the higher 32 bits. Signed-off-by: Kan Liang <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Vince Weaver <[email protected]> Fixes: 294fe0f ("perf/x86/intel: Add INST_RETIRED.ALL workarounds") Link: http://lkml.kernel.org/r/[email protected] [ Rewrote unacceptably bad changelog. ] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 3f986ee commit f605cfc

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

arch/x86/events/intel/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3188,7 +3188,7 @@ glp_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
31883188
* Therefore the effective (average) period matches the requested period,
31893189
* despite coarser hardware granularity.
31903190
*/
3191-
static unsigned bdw_limit_period(struct perf_event *event, unsigned left)
3191+
static u64 bdw_limit_period(struct perf_event *event, u64 left)
31923192
{
31933193
if ((event->hw.config & INTEL_ARCH_EVENT_MASK) ==
31943194
X86_CONFIG(.event=0xc0, .umask=0x01)) {

arch/x86/events/perf_event.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ struct x86_pmu {
557557
struct x86_pmu_quirk *quirks;
558558
int perfctr_second_write;
559559
bool late_ack;
560-
unsigned (*limit_period)(struct perf_event *event, unsigned l);
560+
u64 (*limit_period)(struct perf_event *event, u64 l);
561561

562562
/*
563563
* sysfs attrs

0 commit comments

Comments
 (0)