[PATCH v1 02/13] perf off-cpu: Fix swapped PID and TID in direct off_cpu_dump() samples
From: Ian Rogers
Date: Mon Nov 23 2026 - 02:19:36 EST
__set_offcpu_sample() unpacks the first u64 of an off-cpu raw sample as
p32[0] = data->pid (process TGID) and p32[1] = data->tid (thread PID),
matching off_cpu_write() which packs (u64)key.pid << 32 | key.tgid on
little-endian hosts (and kernel BPF matches host endianness). However,
off_cpu_dump() packed (u64)key->tgid << 32 | key->pid, swapping PID and
TID for multi-threaded direct off-cpu samples exceeding the threshold.
Pack (u64)key->pid << 32 | key->tgid to match off_cpu_write() and
__set_offcpu_sample().
Fixes: d6948f2af24e ("perf record --off-cpu: Dump off-cpu samples in BPF")
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/bpf_skel/off_cpu.bpf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/util/bpf_skel/off_cpu.bpf.c b/tools/perf/util/bpf_skel/off_cpu.bpf.c
index 72763bb8d1de..eeb2cb8ac0d8 100644
--- a/tools/perf/util/bpf_skel/off_cpu.bpf.c
+++ b/tools/perf/util/bpf_skel/off_cpu.bpf.c
@@ -236,7 +236,7 @@ static int off_cpu_dump(void *ctx, struct offcpu_data *data, struct offcpu_key *
{
int n = 0, len = 0;
- data->array[n++] = (u64)key->tgid << 32 | key->pid;
+ data->array[n++] = (u64)key->pid << 32 | key->tgid;
data->array[n++] = delta;
/* data->array[n] is callchain->nr (updated later) */
--
2.56.1.750.gf70dc682cf-goog