Blame SOURCES/bcc-0.20.0-tools-Fix-BCC-bio-tools-with-recent-kernel-change.patch

baabe4
From 59a4e7ea490f78ba289c1ba461bfe1fce9e7ef19 Mon Sep 17 00:00:00 2001
baabe4
From: Hengqi Chen <chenhengqi@outlook.com>
baabe4
Date: Sat, 11 Dec 2021 17:36:17 +0800
baabe4
Subject: [PATCH] tools: Fix BCC bio tools with recent kernel change
baabe4
baabe4
Several BCC bio tools are broken due to kernel change ([0]).
baabe4
blk_account_io_{start, done} were renamed to __blk_account_io_{start, done},
baabe4
and the symbols gone from /proc/kallsyms. Fix them by checking symbol existence.
baabe4
baabe4
  [0]: https://github.com/torvalds/linux/commit/be6bfe36db1795babe9d92178a47b2e02193cb0f
baabe4
baabe4
Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
baabe4
---
baabe4
 tools/biolatency.py | 12 ++++++++----
baabe4
 tools/biolatpcts.py |  5 ++++-
baabe4
 tools/biosnoop.py   | 11 ++++++++---
baabe4
 tools/biotop.py     | 11 ++++++++---
baabe4
 4 files changed, 28 insertions(+), 11 deletions(-)
baabe4
baabe4
diff --git a/tools/biolatency.py b/tools/biolatency.py
baabe4
index 0599609b..2e75a5de 100755
baabe4
--- a/tools/biolatency.py
baabe4
+++ b/tools/biolatency.py
baabe4
@@ -168,13 +168,18 @@ bpf_text = bpf_text.replace("STORE", store_str)
baabe4
 # load BPF program
baabe4
 b = BPF(text=bpf_text)
baabe4
 if args.queued:
baabe4
-    b.attach_kprobe(event="blk_account_io_start", fn_name="trace_req_start")
baabe4
+    if BPF.get_kprobe_functions(b'__blk_account_io_start'):
baabe4
+        b.attach_kprobe(event="__blk_account_io_start", fn_name="trace_req_start")
baabe4
+    else:
baabe4
+        b.attach_kprobe(event="blk_account_io_start", fn_name="trace_req_start")
baabe4
 else:
baabe4
     if BPF.get_kprobe_functions(b'blk_start_request'):
baabe4
         b.attach_kprobe(event="blk_start_request", fn_name="trace_req_start")
baabe4
     b.attach_kprobe(event="blk_mq_start_request", fn_name="trace_req_start")
baabe4
-b.attach_kprobe(event="blk_account_io_done",
baabe4
-    fn_name="trace_req_done")
baabe4
+if BPF.get_kprobe_functions(b'__blk_account_io_done'):
baabe4
+    b.attach_kprobe(event="__blk_account_io_done", fn_name="trace_req_done")
baabe4
+else:
baabe4
+    b.attach_kprobe(event="blk_account_io_done", fn_name="trace_req_done")
baabe4
 
baabe4
 if not args.json:
baabe4
     print("Tracing block device I/O... Hit Ctrl-C to end.")
baabe4
@@ -277,4 +282,3 @@ dist = b.get_table("dist")
baabe4
     countdown -= 1
baabe4
     if exiting or countdown == 0:
baabe4
         exit()
baabe4
-
baabe4
diff --git a/tools/biolatpcts.py b/tools/biolatpcts.py
baabe4
index 5ab8aa5f..a2f59592 100755
baabe4
--- a/tools/biolatpcts.py
baabe4
+++ b/tools/biolatpcts.py
baabe4
@@ -142,7 +142,10 @@ bpf_source = bpf_source.replace('__MAJOR__', str(major))
baabe4
 bpf_source = bpf_source.replace('__MINOR__', str(minor))
baabe4
 
baabe4
 bpf = BPF(text=bpf_source)
baabe4
-bpf.attach_kprobe(event="blk_account_io_done", fn_name="kprobe_blk_account_io_done")
baabe4
+if BPF.get_kprobe_functions(b'__blk_account_io_done'):
baabe4
+    bpf.attach_kprobe(event="__blk_account_io_done", fn_name="kprobe_blk_account_io_done")
baabe4
+else:
baabe4
+    bpf.attach_kprobe(event="blk_account_io_done", fn_name="kprobe_blk_account_io_done")
baabe4
 
baabe4
 # times are in usecs
baabe4
 MSEC = 1000
baabe4
diff --git a/tools/biosnoop.py b/tools/biosnoop.py
baabe4
index 333949b5..2b954ac9 100755
baabe4
--- a/tools/biosnoop.py
baabe4
+++ b/tools/biosnoop.py
baabe4
@@ -163,12 +163,17 @@ int trace_req_completion(struct pt_regs *ctx, struct request *req)
baabe4
 
baabe4
 # initialize BPF
baabe4
 b = BPF(text=bpf_text)
baabe4
-b.attach_kprobe(event="blk_account_io_start", fn_name="trace_pid_start")
baabe4
+if BPF.get_kprobe_functions(b'__blk_account_io_start'):
baabe4
+    b.attach_kprobe(event="__blk_account_io_start", fn_name="trace_pid_start")
baabe4
+else:
baabe4
+    b.attach_kprobe(event="blk_account_io_start", fn_name="trace_pid_start")
baabe4
 if BPF.get_kprobe_functions(b'blk_start_request'):
baabe4
     b.attach_kprobe(event="blk_start_request", fn_name="trace_req_start")
baabe4
 b.attach_kprobe(event="blk_mq_start_request", fn_name="trace_req_start")
baabe4
-b.attach_kprobe(event="blk_account_io_done",
baabe4
-    fn_name="trace_req_completion")
baabe4
+if BPF.get_kprobe_functions(b'__blk_account_io_done'):
baabe4
+    b.attach_kprobe(event="__blk_account_io_done", fn_name="trace_req_completion")
baabe4
+else:
baabe4
+    b.attach_kprobe(event="blk_account_io_done", fn_name="trace_req_completion")
baabe4
 
baabe4
 # header
baabe4
 print("%-11s %-14s %-6s %-7s %-1s %-10s %-7s" % ("TIME(s)", "COMM", "PID",
baabe4
diff --git a/tools/biotop.py b/tools/biotop.py
baabe4
index 596f0076..0ebfef0e 100755
baabe4
--- a/tools/biotop.py
baabe4
+++ b/tools/biotop.py
baabe4
@@ -180,12 +180,17 @@ int trace_req_completion(struct pt_regs *ctx, struct request *req)
baabe4
     exit()
baabe4
 
baabe4
 b = BPF(text=bpf_text)
baabe4
-b.attach_kprobe(event="blk_account_io_start", fn_name="trace_pid_start")
baabe4
+if BPF.get_kprobe_functions(b'__blk_account_io_start'):
baabe4
+    b.attach_kprobe(event="__blk_account_io_start", fn_name="trace_pid_start")
baabe4
+else:
baabe4
+    b.attach_kprobe(event="blk_account_io_start", fn_name="trace_pid_start")
baabe4
 if BPF.get_kprobe_functions(b'blk_start_request'):
baabe4
     b.attach_kprobe(event="blk_start_request", fn_name="trace_req_start")
baabe4
 b.attach_kprobe(event="blk_mq_start_request", fn_name="trace_req_start")
baabe4
-b.attach_kprobe(event="blk_account_io_done",
baabe4
-    fn_name="trace_req_completion")
baabe4
+if BPF.get_kprobe_functions(b'__blk_account_io_done'):
baabe4
+    b.attach_kprobe(event="__blk_account_io_done", fn_name="trace_req_completion")
baabe4
+else:
baabe4
+    b.attach_kprobe(event="blk_account_io_done", fn_name="trace_req_completion")
baabe4
 
baabe4
 print('Tracing... Output every %d secs. Hit Ctrl-C to end' % interval)
baabe4
 
baabe4
-- 
baabe4
2.35.1
baabe4