--- /dev/null
+From 7a490187f22b4bfae7ef752edbe3fb13017ca11c Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Mon, 1 Jun 2026 13:07:52 -0300
+Subject: perf sample: Add file_offset field to struct perf_sample
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit 7a490187f22b4bfae7ef752edbe3fb13017ca11c upstream.
+
+Add a file_offset field to struct perf_sample so that event processing
+callbacks can report the byte offset of the problematic event in
+perf.data, letting users cross-reference with 'perf report -D' output.
+
+Set sample.file_offset in perf_session__deliver_event(), which is the
+common entry point for both file mode (mmap'd offset) and pipe mode
+(running byte counter from __perf_session__process_pipe_events).
+
+The assignment is placed after evsel__parse_sample(), which zeroes
+the struct via memset.
+
+Preserve file_offset through the deferred callchain delivery path by
+storing it in struct deferred_event and restoring it after
+evlist__parse_sample() in both evlist__deliver_deferred_callchain()
+and session__flush_deferred_samples().
+
+Subsequent patches will use this field in skip/stop warning messages.
+
+Reviewed-by: Ian Rogers <irogers@google.com>
+Assisted-by: Claude:claude-opus-4.6
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/perf/util/sample.h | 2 ++
+ tools/perf/util/session.c | 5 +++++
+ 2 files changed, 7 insertions(+)
+
+--- a/tools/perf/util/sample.h
++++ b/tools/perf/util/sample.h
+@@ -158,6 +158,8 @@ struct perf_sample {
+ u64 code_page_size;
+ /** @cgroup: The sample event PERF_SAMPLE_CGROUP value. */
+ u64 cgroup;
++ /** @file_offset: Byte offset of this event in the perf.data file. */
++ u64 file_offset;
+ /** @flags: Extra flag data from auxiliary events like intel-pt. */
+ u32 flags;
+ /** @machine_pid: The guest machine pid derived from the sample id. */
+--- a/tools/perf/util/session.c
++++ b/tools/perf/util/session.c
+@@ -1352,6 +1352,7 @@ static int evlist__deliver_sample(struct
+ struct deferred_event {
+ struct list_head list;
+ union perf_event *event;
++ u64 file_offset;
+ };
+
+ /*
+@@ -1387,6 +1388,7 @@ static int evlist__deliver_deferred_call
+ perf_sample__exit(&orig_sample);
+ break;
+ }
++ orig_sample.file_offset = de->file_offset;
+
+ if (sample->tid != orig_sample.tid) {
+ perf_sample__exit(&orig_sample);
+@@ -1435,6 +1437,7 @@ static int session__flush_deferred_sampl
+ perf_sample__exit(&sample);
+ break;
+ }
++ sample.file_offset = de->file_offset;
+
+ sample.evsel = evlist__id2evsel(evlist, sample.id);
+ ret = evlist__deliver_sample(evlist, tool, de->event,
+@@ -1496,6 +1499,7 @@ static int machines__deliver_event(struc
+ return -ENOMEM;
+ }
+ memcpy(de->event, event, sz);
++ de->file_offset = sample->file_offset;
+ list_add_tail(&de->list, &evlist->deferred_samples);
+ return 0;
+ }
+@@ -1589,6 +1593,7 @@ static int perf_session__deliver_event(s
+ ret = 0;
+ goto out;
+ }
++ sample.file_offset = file_offset;
+
+ ret = machines__deliver_event(&session->machines, session->evlist,
+ event, &sample, tool, file_offset, file_path);
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
- tools/perf/builtin-sched.c | 8 +++++++-
+ tools/perf/builtin-sched.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
-diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
-index fc8ae0342dd6c2..9ea3416f30ac6d 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
-@@ -2904,7 +2904,13 @@ static int timehist_sched_change_event(const struct perf_tool *tool,
+@@ -2904,7 +2904,13 @@ static int timehist_sched_change_event(c
t = ptime->end;
}
+ * whose priv is thread_runtime, not idle_thread_runtime — the cast
+ * below would read past the allocation.
+ */
-+ if (!sched->idle_hist || is_idle_sample(sample)) {
++ if (!sched->idle_hist || is_idle_sample(sample, evsel)) {
if (!cpu_list || (sample->cpu < MAX_NR_CPUS &&
test_bit(sample->cpu, cpu_bitmap)))
timehist_update_runtime_stats(tr, t, tprev);
---
-2.53.0
-