Skip to content

libbpf-tools/offcputime: fix PID filters in PID namespaces - #5524

Open
usamoi wants to merge 1 commit into
iovisor:masterfrom
usamoi:offcputime-pid-filter
Open

libbpf-tools/offcputime: fix PID filters in PID namespaces#5524
usamoi wants to merge 1 commit into
iovisor:masterfrom
usamoi:offcputime-pid-filter

Conversation

@usamoi

@usamoi usamoi commented Jun 18, 2026

Copy link
Copy Markdown

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 *next in sched_switch.


Checklist

  • Commit prefix matches changed area (e.g., tools/toolname:, libbpf-tools/toolname:, src/cc:, docs:, build:, tests/python:)
  • Commit body explains why this change is needed

About AI Code Review: This project uses GitHub Copilot to assist with code review.
If a Copilot review is added, treat its feedback as you would any reviewer comment — you can
agree, disagree (with explanation), or ask questions. The maintainer makes all final decisions.

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
usamoi force-pushed the offcputime-pid-filter branch from dd0ca76 to 1bfac38 Compare June 18, 2026 18:07
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))) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

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