Skip to content

Commit 312be9f

Browse files
Kan LiangIngo Molnar
authored andcommitted
perf/x86/intel/ds: Don't clear ->pebs_data_cfg for the last PEBS event
The MSR_PEBS_DATA_CFG MSR register is used to configure which data groups should be generated into a PEBS record, and it's shared among all counters. If there are different configurations among counters, perf combines all the configurations. The first perf command as below requires a complete PEBS record (including memory info, GPRs, XMMs, and LBRs). The second perf command only requires a basic group. However, after the second perf command is running, the MSR_PEBS_DATA_CFG register is cleared. Only a basic group is generated in a PEBS record, which is wrong. The required information for the first perf command is missed. $ perf record --intr-regs=AX,SP,XMM0 -a -C 8 -b -W -d -c 100000003 -o /dev/null -e cpu/event=0xd0,umask=0x81/upp & $ sleep 5 $ perf record --per-thread -c 1 -e cycles:pp --no-timestamp --no-tid taskset -c 8 ./noploop 1000 The first PEBS event is a system-wide PEBS event. The second PEBS event is a per-thread event. When the thread is scheduled out, the intel_pmu_pebs_del() function is invoked to update the PEBS state. Since the system-wide event is still available, the cpuc->n_pebs is 1. The cpuc->pebs_data_cfg is cleared. The data configuration for the system-wide PEBS event is lost. The (cpuc->n_pebs == 1) check was introduced in commit: b6a32f0 ("perf/x86: Fix PEBS threshold initialization") At that time, it indeed didn't hurt whether the state was updated during the removal, because only the threshold is updated. The calculation of the threshold takes the last PEBS event into account. However, since commit: b752ea0 ("perf/x86/intel/ds: Flush PEBS DS when changing PEBS_DATA_CFG") we delay the threshold update, and clear the PEBS data config, which triggers the bug. The PEBS data config update scope should not be shrunk during removal. [ mingo: Improved the changelog & comments. ] Fixes: b752ea0 ("perf/x86/intel/ds: Flush PEBS DS when changing PEBS_DATA_CFG") Reported-by: Stephane Eranian <[email protected]> Signed-off-by: Kan Liang <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected]
1 parent 39cd87c commit 312be9f

File tree

1 file changed

+4
-4
lines changed
  • arch/x86/events/intel

1 file changed

+4
-4
lines changed

arch/x86/events/intel/ds.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,11 +1237,11 @@ pebs_update_state(bool needed_cb, struct cpu_hw_events *cpuc,
12371237
struct pmu *pmu = event->pmu;
12381238

12391239
/*
1240-
* Make sure we get updated with the first PEBS
1241-
* event. It will trigger also during removal, but
1242-
* that does not hurt:
1240+
* Make sure we get updated with the first PEBS event.
1241+
* During removal, ->pebs_data_cfg is still valid for
1242+
* the last PEBS event. Don't clear it.
12431243
*/
1244-
if (cpuc->n_pebs == 1)
1244+
if ((cpuc->n_pebs == 1) && add)
12451245
cpuc->pebs_data_cfg = PEBS_UPDATE_DS_SW;
12461246

12471247
if (needed_cb != pebs_needs_sched_cb(cpuc)) {

0 commit comments

Comments
 (0)