Skip to content

Commit 7da9960

Browse files
Kan LiangPeter Zijlstra
authored andcommitted
perf/x86/intel/ds: Fix counter backwards of non-precise events counters-snapshotting
The counter backwards may be observed in the PMI handler when counters-snapshotting some non-precise events in the freq mode. For the non-precise events, it's possible the counters-snapshotting records a positive value for an overflowed PEBS event. Then the HW auto-reload mechanism reset the counter to 0 immediately. Because the pebs_event_reset is cleared in the freq mode, which doesn't set the PERF_X86_EVENT_AUTO_RELOAD. In the PMI handler, 0 will be read rather than the positive value recorded in the counters-snapshotting record. The counters-snapshotting case has to be specially handled. Since the event value has been updated when processing the counters-snapshotting record, only needs to set the new period for the counter via x86_pmu_set_period(). Fixes: e02e9b0 ("perf/x86/intel: Support PEBS counters snapshotting") Signed-off-by: Kan Liang <kan.liang@linux.intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/20250424134718.311934-6-kan.liang@linux.intel.com
1 parent e9988ad commit 7da9960

File tree

1 file changed

+19
-2
lines changed
  • arch/x86/events/intel

1 file changed

+19
-2
lines changed

arch/x86/events/intel/ds.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,8 +2379,25 @@ __intel_pmu_pebs_last_event(struct perf_event *event,
23792379
*/
23802380
intel_pmu_save_and_restart_reload(event, count);
23812381
}
2382-
} else
2383-
intel_pmu_save_and_restart(event);
2382+
} else {
2383+
/*
2384+
* For a non-precise event, it's possible the
2385+
* counters-snapshotting records a positive value for the
2386+
* overflowed event. Then the HW auto-reload mechanism
2387+
* reset the counter to 0 immediately, because the
2388+
* pebs_event_reset is cleared if the PERF_X86_EVENT_AUTO_RELOAD
2389+
* is not set. The counter backwards may be observed in a
2390+
* PMI handler.
2391+
*
2392+
* Since the event value has been updated when processing the
2393+
* counters-snapshotting record, only needs to set the new
2394+
* period for the counter.
2395+
*/
2396+
if (is_pebs_counter_event_group(event))
2397+
static_call(x86_pmu_set_period)(event);
2398+
else
2399+
intel_pmu_save_and_restart(event);
2400+
}
23842401
}
23852402

23862403
static __always_inline void

0 commit comments

Comments
 (0)