Skip to content

Commit 7f612a7

Browse files
Peter Zijlstra (Intel)ingomolnar
authored andcommitted
perf/x86: Fix full width counter, counter overflow
Lukasz reported that perf stat counters overflow handling is broken on KNL/SLM. Both these parts have full_width_write set, and that does indeed have a problem. In order to deal with counter wrap, we must sample the counter at at least half the counter period (see also the sampling theorem) such that we can unambiguously reconstruct the count. However commit: 069e0c3 ("perf/x86/intel: Support full width counting") sets the sampling interval to the full period, not half. Fixing that exposes another issue, in that we must not sign extend the delta value when we shift it right; the counter cannot have decremented after all. With both these issues fixed, counter overflow functions correctly again. Reported-by: Lukasz Odzioba <lukasz.odzioba@intel.com> Tested-by: Liang, Kan <kan.liang@intel.com> Tested-by: Odzioba, Lukasz <lukasz.odzioba@intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Vince Weaver <vincent.weaver@maine.edu> Cc: stable@vger.kernel.org Fixes: 069e0c3 ("perf/x86/intel: Support full width counting") Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 1dba23b commit 7f612a7

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

arch/x86/events/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ u64 x86_perf_event_update(struct perf_event *event)
6969
int shift = 64 - x86_pmu.cntval_bits;
7070
u64 prev_raw_count, new_raw_count;
7171
int idx = hwc->idx;
72-
s64 delta;
72+
u64 delta;
7373

7474
if (idx == INTEL_PMC_IDX_FIXED_BTS)
7575
return 0;

arch/x86/events/intel/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4034,7 +4034,7 @@ __init int intel_pmu_init(void)
40344034

40354035
/* Support full width counters using alternative MSR range */
40364036
if (x86_pmu.intel_cap.full_width_write) {
4037-
x86_pmu.max_period = x86_pmu.cntval_mask;
4037+
x86_pmu.max_period = x86_pmu.cntval_mask >> 1;
40384038
x86_pmu.perfctr = MSR_IA32_PMC0;
40394039
pr_cont("full-width counters, ");
40404040
}

0 commit comments

Comments
 (0)