perf/core: Flush PMU internal buffers for per-CPU events
authorKan Liang <kan.liang@linux.intel.com>
Mon, 30 Nov 2020 19:38:40 +0000 (11:38 -0800)
committerIngo Molnar <mingo@kernel.org>
Sat, 6 Mar 2021 11:52:39 +0000 (12:52 +0100)
commita5398bffc01fe044848c5024e5e867e407f239b8
tree4024bf63256a99173f8c38e49de68debed41657e
parenta38fd8748464831584a19438cbb3082b5a2dab15
perf/core: Flush PMU internal buffers for per-CPU events

Sometimes the PMU internal buffers have to be flushed for per-CPU events
during a context switch, e.g., large PEBS. Otherwise, the perf tool may
report samples in locations that do not belong to the process where the
samples are processed in, because PEBS does not tag samples with PID/TID.

The current code only flush the buffers for a per-task event. It doesn't
check a per-CPU event.

Add a new event state flag, PERF_ATTACH_SCHED_CB, to indicate that the
PMU internal buffers have to be flushed for this event during a context
switch.

Add sched_cb_entry and perf_sched_cb_usages back to track the PMU/cpuctx
which is required to be flushed.

Only need to invoke the sched_task() for per-CPU events in this patch.
The per-task events have been handled in perf_event_context_sched_in/out
already.

Fixes: 9c964efa4330 ("perf/x86/intel: Drain the PEBS buffer during context switches")
Reported-by: Gabriel Marin <gmx@google.com>
Originally-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lkml.kernel.org/r/20201130193842.10569-1-kan.liang@linux.intel.com
include/linux/perf_event.h
kernel/events/core.c