* [PATCH v3] perf/core: Fix ITRACE start suppression for inherited events
@ 2026-12-02 17:58 Leo Yan
2026-12-02 18:06 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Leo Yan @ 2026-12-02 17:58 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, James Clark
Cc: Ingo Molnar, linux-perf-users, linux-kernel, Sashiko AI, Leo Yan
ITRACE_START supplies the initial PID/TID for AUX trace decoding. For
inherited events, perf_log_itrace_start() checks the parent, but
perf_event_itrace_started() marks the child. If a child starts first,
the parent's flag stays clear and subsequent schedule-ins can emit
redundant records.
One option is to set PERF_ATTACH_ITRACE in the parent's attach_state.
The child holds its own context lock during schedule-in, so this update
could race with parent teardown and overwrite changes to other flags.
Taking the parent's lock as well would require nesting the two context
locks in a consistent order.
Use a separate bool on the event to record whether the PMU has reported
a trace start for it or any of its children. This lets subsequent
schedule-ins suppress ITRACE_START independently of event attachment.
On the tested x86-64 and arm64 builds, the bool fits in existing
padding, preserving sizeof(struct perf_event) and the offsets of all
existing members.
Reported-by: Sashiko AI <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/linux-perf-users/20260901164705.042781F000E9@smtp.kernel.org/
Fixes: 9a6694cfa239 ("perf/x86/intel/pt: Do not force sync packets on every schedule-in")
Signed-off-by: Leo Yan <leo.yan@arm.com>
---
Changes in v3:
- Added a new the bool flag to avoid race condition with parent.
- Link to v2: https://lore.kernel.org/r/20260929-perf_core_itrace_start_fix_inherit_event-v2-1-9361a946ed56@arm.com
Changes in v2:
- Changed setter to fetch parent event instead (James).
- Link to v1: https://lore.kernel.org/r/20260903-perf_core_itrace_start_fix_inherit_event-v1-1-6bff7e675af5@arm.com
---
include/linux/perf_event.h | 2 +-
kernel/events/core.c | 8 +++++---
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index b52348eca6ef10ffd5938968846846433bc7f02c..aa232d3ebb7c297b69362e31e5ce6e8218ee675b 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -728,7 +728,6 @@ struct swevent_hlist {
#define PERF_ATTACH_CHILD 0x0040
#define PERF_ATTACH_EXCLUSIVE 0x0080
#define PERF_ATTACH_CALLCHAIN 0x0100
-#define PERF_ATTACH_ITRACE 0x0200
struct bpf_prog;
struct perf_cgroup;
@@ -827,6 +826,7 @@ struct perf_event {
u16 header_size;
u16 id_header_size;
u16 read_size;
+ bool itrace_started;
struct hw_perf_event hw;
struct perf_event_context *ctx;
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4ab3919ac78e903685a8693e78762d8b165cba20..e9d24000828868dac3f99939555950ed3134d92a 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -10691,7 +10691,10 @@ void perf_event_text_poke(const void *addr, const void *old_bytes,
void perf_event_itrace_started(struct perf_event *event)
{
- WRITE_ONCE(event->attach_state, event->attach_state | PERF_ATTACH_ITRACE);
+ if (event->parent)
+ event = event->parent;
+
+ WRITE_ONCE(event->itrace_started, true);
}
EXPORT_SYMBOL_GPL(perf_event_itrace_started);
@@ -10710,7 +10713,7 @@ static void perf_log_itrace_start(struct perf_event *event)
event = event->parent;
if (!(event->pmu->capabilities & PERF_PMU_CAP_ITRACE) ||
- event->attach_state & PERF_ATTACH_ITRACE)
+ READ_ONCE(event->itrace_started))
return;
rec.pid = perf_event_pid(event, current);
@@ -14758,7 +14761,6 @@ perf_event_exit_event(struct perf_event *event,
*/
detach_flags |= DETACH_GROUP | DETACH_CHILD;
mutex_lock(&parent_event->child_mutex);
- /* PERF_ATTACH_ITRACE might be set concurrently */
attach_state = READ_ONCE(event->attach_state);
if (attach_state & PERF_ATTACH_CHILD)
---
base-commit: 693c2e04e3f1d4c59af236e1211b7b8cb165a790
change-id: 20260903-perf_core_itrace_start_fix_inherit_event-a8930d792899
Best regards,
--
Leo Yan <leo.yan@arm.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-02 18:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 17:58 [PATCH v3] perf/core: Fix ITRACE start suppression for inherited events Leo Yan
2026-12-02 18:06 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox