Skip to content

Fix get_cpu_id() to return actual CPU core instead of hardcoded 0#5

Merged
cong-or merged 1 commit into
cong-or:mainfrom
TickTockBent:fix/ebpf-cpu-id
Mar 18, 2026
Merged

Fix get_cpu_id() to return actual CPU core instead of hardcoded 0#5
cong-or merged 1 commit into
cong-or:mainfrom
TickTockBent:fix/ebpf-cpu-id

Conversation

@TickTockBent
Copy link
Copy Markdown
Contributor

What

get_cpu_id() in the eBPF program was stubbed to always return 0, with a comment saying aya-ebpf doesn't expose bpf_get_smp_processor_id yet. It actually does. The bindings re-export it through pub use gen::* in the helpers module, but it's #[doc(hidden)] so it never shows up in the docs. Easy to miss.

Impact

Every trace event has been reporting cpu_id: 0 regardless of which core the sample was taken on. The TUI doesn't display per-CPU data, so this was invisible there. But the Chrome Trace JSON export includes cpu_id in the args for both BEGIN and END events, and that data was wrong.

This is the same calling convention as bpf_get_current_pid_tgid (helper #14) and bpf_ktime_get_ns (helper #5), both already used in the same file. Helper #8 has been available since Linux 3.18, well below hud's 5.8+ requirement.

Change

3 lines in hud-ebpf/src/main.rs. Add the import, replace the stub with the real call.

-- mass cargo-culting since mass '09

get_cpu_id() was stubbed to always return 0 because aya-ebpf didn't
appear to expose bpf_get_smp_processor_id. Turns out it does, via the
re-exported bindings (helper #8), it's just #[doc(hidden)] so it
doesn't show up in the generated docs.

Every exported trace event was reporting cpu_id: 0 regardless of which
core the sample was actually taken on. The TUI doesn't render per-CPU
data so nobody noticed, but the Chrome Trace JSON was silently wrong.

// ticktockbent
@cong-or
Copy link
Copy Markdown
Owner

cong-or commented Mar 18, 2026

Thanks @TickTockBent !

@cong-or cong-or merged commit 4953120 into cong-or:main Mar 18, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants