Skip to content

Commit

Permalink
tools/runqlat.py:get the pid namespace by following task_active_pid_ns()
Browse files Browse the repository at this point in the history
Simliar fix as commit bced75a

Signed-off-by: Li Chengyuan [email protected]
  • Loading branch information
ChengyuanLiCY authored and yonghong-song committed Oct 27, 2021
1 parent bced75a commit c73d7d8
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion tools/runqlat.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#include <linux/sched.h>
#include <linux/nsproxy.h>
#include <linux/pid_namespace.h>
#include <linux/init_task.h>
typedef struct pid_key {
u64 id; // work around
Expand All @@ -96,6 +97,45 @@
start.update(&pid, &ts);
return 0;
}
static __always_inline unsigned int pid_namespace(struct task_struct *task)
{
/* pids[] was removed from task_struct since commit 2c4704756cab7cfa031ada4dab361562f0e357c0
* Using the macro INIT_PID_LINK as a conditional judgment.
*/
#ifdef INIT_PID_LINK
struct pid_link pids;
unsigned int level;
struct upid upid;
struct ns_common ns;
/* get the pid namespace by following task_active_pid_ns(),
* pid->numbers[pid->level].ns
*/
bpf_probe_read_kernel(&pids, sizeof(pids), &task->pids[PIDTYPE_PID]);
bpf_probe_read_kernel(&level, sizeof(level), &pids.pid->level);
bpf_probe_read_kernel(&upid, sizeof(upid), &pids.pid->numbers[level]);
bpf_probe_read_kernel(&ns, sizeof(ns), &upid.ns->ns);
return ns.inum;
#else
struct pid *pid;
unsigned int level;
struct upid upid;
struct ns_common ns;
/* get the pid namespace by following task_active_pid_ns(),
* pid->numbers[pid->level].ns
*/
bpf_probe_read_kernel(&pid, sizeof(pid), &task->thread_pid);
bpf_probe_read_kernel(&level, sizeof(level), &pid->level);
bpf_probe_read_kernel(&upid, sizeof(upid), &pid->numbers[level]);
bpf_probe_read_kernel(&ns, sizeof(ns), &upid.ns->ns);
return ns.inum;
#endif
}
"""

bpf_text_kprobe = """
Expand Down Expand Up @@ -235,7 +275,7 @@
bpf_text = bpf_text.replace('STORAGE',
'BPF_HISTOGRAM(dist, pidns_key_t);')
bpf_text = bpf_text.replace('STORE', 'pidns_key_t key = ' +
'{.id = prev->nsproxy->pid_ns_for_children->ns.inum, ' +
'{.id = pid_namespace(prev), ' +
'.slot = bpf_log2l(delta)}; dist.atomic_increment(key);')
else:
section = ""
Expand Down

0 comments on commit c73d7d8

Please sign in to comment.