Skip to content

Commit 0d23dc3

Browse files
Peter Zijlstra (Intel)bonzini
authored andcommitted
x86/perf/core: Add pebs_capable to store valid PEBS_COUNTER_MASK value
The value of pebs_counter_mask will be accessed frequently for repeated use in the intel_guest_get_msrs(). So it can be optimized instead of endlessly mucking about with branches. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Message-Id: <20220411101946.20262-7-likexu@tencent.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 2c98552 commit 0d23dc3

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

arch/x86/events/intel/core.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2932,10 +2932,7 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status)
29322932
* counters from the GLOBAL_STATUS mask and we always process PEBS
29332933
* events via drain_pebs().
29342934
*/
2935-
if (x86_pmu.flags & PMU_FL_PEBS_ALL)
2936-
status &= ~cpuc->pebs_enabled;
2937-
else
2938-
status &= ~(cpuc->pebs_enabled & PEBS_COUNTER_MASK);
2935+
status &= ~(cpuc->pebs_enabled & x86_pmu.pebs_capable);
29392936

29402937
/*
29412938
* PEBS overflow sets bit 62 in the global status register
@@ -3981,10 +3978,7 @@ static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr, void *data)
39813978
arr[0].msr = MSR_CORE_PERF_GLOBAL_CTRL;
39823979
arr[0].host = intel_ctrl & ~cpuc->intel_ctrl_guest_mask;
39833980
arr[0].guest = intel_ctrl & ~cpuc->intel_ctrl_host_mask;
3984-
if (x86_pmu.flags & PMU_FL_PEBS_ALL)
3985-
arr[0].guest &= ~cpuc->pebs_enabled;
3986-
else
3987-
arr[0].guest &= ~(cpuc->pebs_enabled & PEBS_COUNTER_MASK);
3981+
arr[0].guest &= ~(cpuc->pebs_enabled & x86_pmu.pebs_capable);
39883982
*nr = 1;
39893983

39903984
if (x86_pmu.pebs && x86_pmu.pebs_no_isolation) {
@@ -5692,6 +5686,7 @@ __init int intel_pmu_init(void)
56925686
x86_pmu.events_mask_len = eax.split.mask_length;
56935687

56945688
x86_pmu.max_pebs_events = min_t(unsigned, MAX_PEBS_EVENTS, x86_pmu.num_counters);
5689+
x86_pmu.pebs_capable = PEBS_COUNTER_MASK;
56955690

56965691
/*
56975692
* Quirk: v2 perfmon does not report fixed-purpose events, so
@@ -5876,6 +5871,7 @@ __init int intel_pmu_init(void)
58765871
x86_pmu.pebs_aliases = NULL;
58775872
x86_pmu.pebs_prec_dist = true;
58785873
x86_pmu.lbr_pt_coexist = true;
5874+
x86_pmu.pebs_capable = ~0ULL;
58795875
x86_pmu.flags |= PMU_FL_HAS_RSP_1;
58805876
x86_pmu.flags |= PMU_FL_PEBS_ALL;
58815877
x86_pmu.get_event_constraints = glp_get_event_constraints;
@@ -6233,6 +6229,7 @@ __init int intel_pmu_init(void)
62336229
x86_pmu.pebs_aliases = NULL;
62346230
x86_pmu.pebs_prec_dist = true;
62356231
x86_pmu.pebs_block = true;
6232+
x86_pmu.pebs_capable = ~0ULL;
62366233
x86_pmu.flags |= PMU_FL_HAS_RSP_1;
62376234
x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
62386235
x86_pmu.flags |= PMU_FL_PEBS_ALL;
@@ -6278,6 +6275,7 @@ __init int intel_pmu_init(void)
62786275
x86_pmu.pebs_aliases = NULL;
62796276
x86_pmu.pebs_prec_dist = true;
62806277
x86_pmu.pebs_block = true;
6278+
x86_pmu.pebs_capable = ~0ULL;
62816279
x86_pmu.flags |= PMU_FL_HAS_RSP_1;
62826280
x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
62836281
x86_pmu.flags |= PMU_FL_PEBS_ALL;

arch/x86/events/perf_event.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,7 @@ struct x86_pmu {
828828
void (*pebs_aliases)(struct perf_event *event);
829829
unsigned long large_pebs_flags;
830830
u64 rtm_abort_event;
831+
u64 pebs_capable;
831832

832833
/*
833834
* Intel LBR

0 commit comments

Comments
 (0)