Skip to content

Commit 4a263bf

Browse files
Kan LiangPeter Zijlstra
authored andcommitted
perf/x86/intel: Don't extend the pseudo-encoding to GP counters
The INST_RETIRED.PREC_DIST event (0x0100) doesn't count on SPR. perf stat -e cpu/event=0xc0,umask=0x0/,cpu/event=0x0,umask=0x1/ -C0 Performance counter stats for 'CPU(s) 0': 607,246 cpu/event=0xc0,umask=0x0/ 0 cpu/event=0x0,umask=0x1/ The encoding for INST_RETIRED.PREC_DIST is pseudo-encoding, which doesn't work on the generic counters. However, current perf extends its mask to the generic counters. The pseudo event-code for a fixed counter must be 0x00. Check and avoid extending the mask for the fixed counter event which using the pseudo-encoding, e.g., ref-cycles and PREC_DIST event. With the patch, perf stat -e cpu/event=0xc0,umask=0x0/,cpu/event=0x0,umask=0x1/ -C0 Performance counter stats for 'CPU(s) 0': 583,184 cpu/event=0xc0,umask=0x0/ 583,048 cpu/event=0x0,umask=0x1/ Fixes: 2de71ee ("perf/x86/intel: Fix ICL/SPR INST_RETIRED.PREC_DIST encodings") Signed-off-by: Kan Liang <kan.liang@linux.intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/1648482543-14923-1-git-send-email-kan.liang@linux.intel.com
1 parent e3265a4 commit 4a263bf

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

arch/x86/events/intel/core.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5536,7 +5536,11 @@ static void intel_pmu_check_event_constraints(struct event_constraint *event_con
55365536
/* Disabled fixed counters which are not in CPUID */
55375537
c->idxmsk64 &= intel_ctrl;
55385538

5539-
if (c->idxmsk64 != INTEL_PMC_MSK_FIXED_REF_CYCLES)
5539+
/*
5540+
* Don't extend the pseudo-encoding to the
5541+
* generic counters
5542+
*/
5543+
if (!use_fixed_pseudo_encoding(c->code))
55405544
c->idxmsk64 |= (1ULL << num_counters) - 1;
55415545
}
55425546
c->idxmsk64 &=

arch/x86/include/asm/perf_event.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ struct x86_pmu_capability {
241241
#define INTEL_PMC_IDX_FIXED_SLOTS (INTEL_PMC_IDX_FIXED + 3)
242242
#define INTEL_PMC_MSK_FIXED_SLOTS (1ULL << INTEL_PMC_IDX_FIXED_SLOTS)
243243

244+
static inline bool use_fixed_pseudo_encoding(u64 code)
245+
{
246+
return !(code & 0xff);
247+
}
248+
244249
/*
245250
* We model BTS tracing as another fixed-mode PMC.
246251
*

0 commit comments

Comments
 (0)