bcc/tools: Fix renaming of the state field of task_struct
Kernel commit 2f064a59a1 ("sched: Change task_struct::state") changes
the name of task_struct::state to task_struct::__state, which breaks
several bcc tools. Fix this issue by checking field existence in vmlinux
BTF. Since this change was intruduce in kernel v5.14, we should have
BTF support. Closes #3658 .
Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
diff --git a/tools/runqlat.py b/tools/runqlat.py
index a5c261a..9edd7be 100755
--- a/tools/runqlat.py
+++ b/tools/runqlat.py
@@ -156,7 +156,7 @@
u32 pid, tgid;
// ivcsw: treat like an enqueue event and store timestamp
- if (prev->state == TASK_RUNNING) {
+ if (prev->STATE_FIELD == TASK_RUNNING) {
tgid = prev->tgid;
pid = prev->pid;
if (!(FILTER || pid == 0)) {
@@ -210,7 +210,7 @@
u32 pid, tgid;
// ivcsw: treat like an enqueue event and store timestamp
- if (prev->state == TASK_RUNNING) {
+ if (prev->STATE_FIELD == TASK_RUNNING) {
tgid = prev->tgid;
pid = prev->pid;
if (!(FILTER || pid == 0)) {
@@ -248,6 +248,10 @@
bpf_text += bpf_text_kprobe
# code substitutions
+if BPF.kernel_struct_has_field(b'task_struct', b'__state') == 1:
+ bpf_text = bpf_text.replace('STATE_FIELD', '__state')
+else:
+ bpf_text = bpf_text.replace('STATE_FIELD', 'state')
if args.pid:
# pid from userspace point of view is thread group from kernel pov
bpf_text = bpf_text.replace('FILTER', 'tgid != %s' % args.pid)