Skip to content

Commit 0140150

Browse files
Stephane Eraniangregkh
authored andcommitted
perf/x86/intel/uncore: Fix broken read_counter() for SNB IMC PMU
commit 11745ec upstream. Existing code was generating bogus counts for the SNB IMC bandwidth counters: $ perf stat -a -I 1000 -e uncore_imc/data_reads/,uncore_imc/data_writes/ 1.000327813 1,024.03 MiB uncore_imc/data_reads/ 1.000327813 20.73 MiB uncore_imc/data_writes/ 2.000580153 261,120.00 MiB uncore_imc/data_reads/ 2.000580153 23.28 MiB uncore_imc/data_writes/ The problem was introduced by commit: 07ce734 ("perf/x86/intel/uncore: Clean up client IMC") Where the read_counter callback was replace to point to the generic uncore_mmio_read_counter() function. The SNB IMC counters are freerunnig 32-bit counters laid out contiguously in MMIO. But uncore_mmio_read_counter() is using a readq() call to read from MMIO therefore reading 64-bit from MMIO. Although this is okay for the uncore_perf_event_update() function because it is shifting the value based on the actual counter width to compute a delta, it is not okay for the uncore_pmu_event_start() which is simply reading the counter and therefore priming the event->prev_count with a bogus value which is responsible for causing bogus deltas in the perf stat command above. The fix is to reintroduce the custom callback for read_counter for the SNB IMC PMU and use readl() instead of readq(). With the change the output of perf stat is back to normal: $ perf stat -a -I 1000 -e uncore_imc/data_reads/,uncore_imc/data_writes/ 1.000120987 296.94 MiB uncore_imc/data_reads/ 1.000120987 138.42 MiB uncore_imc/data_writes/ 2.000403144 175.91 MiB uncore_imc/data_reads/ 2.000403144 68.50 MiB uncore_imc/data_writes/ Fixes: 07ce734 ("perf/x86/intel/uncore: Clean up client IMC") Signed-off-by: Stephane Eranian <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Kan Liang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d31fdd5 commit 0140150

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

arch/x86/events/intel/uncore_snb.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,22 @@ int snb_pci2phy_map_init(int devid)
575575
return 0;
576576
}
577577

578+
static u64 snb_uncore_imc_read_counter(struct intel_uncore_box *box, struct perf_event *event)
579+
{
580+
struct hw_perf_event *hwc = &event->hw;
581+
582+
/*
583+
* SNB IMC counters are 32-bit and are laid out back to back
584+
* in MMIO space. Therefore we must use a 32-bit accessor function
585+
* using readq() from uncore_mmio_read_counter() causes problems
586+
* because it is reading 64-bit at a time. This is okay for the
587+
* uncore_perf_event_update() function because it drops the upper
588+
* 32-bits but not okay for plain uncore_read_counter() as invoked
589+
* in uncore_pmu_event_start().
590+
*/
591+
return (u64)readl(box->io_addr + hwc->event_base);
592+
}
593+
578594
static struct pmu snb_uncore_imc_pmu = {
579595
.task_ctx_nr = perf_invalid_context,
580596
.event_init = snb_uncore_imc_event_init,
@@ -594,7 +610,7 @@ static struct intel_uncore_ops snb_uncore_imc_ops = {
594610
.disable_event = snb_uncore_imc_disable_event,
595611
.enable_event = snb_uncore_imc_enable_event,
596612
.hw_config = snb_uncore_imc_hw_config,
597-
.read_counter = uncore_mmio_read_counter,
613+
.read_counter = snb_uncore_imc_read_counter,
598614
};
599615

600616
static struct intel_uncore_type snb_uncore_imc = {

0 commit comments

Comments
 (0)