libbpf-tools/offcputime: fix PID filters in PID namespaces - #5524
Open
usamoi wants to merge 1 commit into
Open
Conversation
usamoi
requested review from
brendangregg,
chenhengqi,
ekyooo and
yonghong-song
as code owners
June 18, 2026 13:39
In PID namespaces, the TGIDs and PIDs seen by users differ from the IDs seen by the kernel, causing the filters to fail. Fix this by using PID namespace TGIDs and PIDs for filtering and output.
usamoi
force-pushed
the
offcputime-pid-filter
branch
from
June 18, 2026 18:07
dd0ca76 to
1bfac38
Compare
ekyooo
reviewed
Jun 24, 2026
| struct bpf_pidns_info ns = {}; | ||
|
|
||
| if (use_pidns && BPF_CORE_READ(t, pid) != 0) { | ||
| if (!bpf_get_ns_current_pid_tgid(pidns_dev, pidns_ino, &ns, sizeof(ns))) { |
Collaborator
There was a problem hiding this comment.
Don't kernel thread fail the bpf_get_ns_current_pid_tgid namespace translation?
If so, wouldn't allow_record return false early and completely filter out all kernel threads?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In PID namespaces, the TGIDs and PIDs seen by users differ from the IDs seen by the kernel, causing the filters to fail. Fix this by using PID namespace TGIDs and PIDs for filtering and output.
Why this approach
PID namespace TGIDs and PIDs must be stored as value instead of key, because there isn't a helper function that returns PID namespace TGIDs and PIDs of
task_struct *nextinsched_switch.Checklist
tools/toolname:,libbpf-tools/toolname:,src/cc:,docs:,build:,tests/python:)