tools: Fix BCC bio tools with recent kernel change
authorHengqi Chen <chenhengqi@outlook.com>
Sat, 11 Dec 2021 09:36:17 +0000 (17:36 +0800)
committerHengqi Chen <chenhengqi@outlook.com>
Sat, 11 Dec 2021 09:36:17 +0000 (17:36 +0800)
Several BCC bio tools are broken due to kernel change ([0]).
blk_account_io_{start, done} were renamed to __blk_account_io_{start, done},
and the symbols gone from /proc/kallsyms. Fix them by checking symbol existence.

  [0]: https://github.com/torvalds/linux/commit/be6bfe36db1795babe9d92178a47b2e02193cb0f

Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
tools/biolatency.py
tools/biolatpcts.py
tools/biosnoop.py
tools/biotop.py

index 7fb5bd8113beefda282e42cd2d1929ee5eb91b1a..f4e2c9ea1b1690a6e204cffd1547b2ed31d4dfe9 100755 (executable)
@@ -168,13 +168,18 @@ if debug or args.ebpf:
 # load BPF program
 b = BPF(text=bpf_text)
 if args.queued:
-    b.attach_kprobe(event="blk_account_io_start", fn_name="trace_req_start")
+    if BPF.get_kprobe_functions(b'__blk_account_io_start'):
+        b.attach_kprobe(event="__blk_account_io_start", fn_name="trace_req_start")
+    else:
+        b.attach_kprobe(event="blk_account_io_start", fn_name="trace_req_start")
 else:
     if BPF.get_kprobe_functions(b'blk_start_request'):
         b.attach_kprobe(event="blk_start_request", fn_name="trace_req_start")
     b.attach_kprobe(event="blk_mq_start_request", fn_name="trace_req_start")
-b.attach_kprobe(event="blk_account_io_done",
-    fn_name="trace_req_done")
+if BPF.get_kprobe_functions(b'__blk_account_io_done'):
+    b.attach_kprobe(event="__blk_account_io_done", fn_name="trace_req_done")
+else:
+    b.attach_kprobe(event="blk_account_io_done", fn_name="trace_req_done")
 
 if not args.json:
     print("Tracing block device I/O... Hit Ctrl-C to end.")
@@ -277,4 +282,3 @@ while (1):
     countdown -= 1
     if exiting or countdown == 0:
         exit()
-
index 5ab8aa5fcf76b02d0ee06340755f83bfeed11d79..a2f595924ac1477cedca1955231fa00f5f68ba88 100755 (executable)
@@ -142,7 +142,10 @@ bpf_source = bpf_source.replace('__MAJOR__', str(major))
 bpf_source = bpf_source.replace('__MINOR__', str(minor))
 
 bpf = BPF(text=bpf_source)
-bpf.attach_kprobe(event="blk_account_io_done", fn_name="kprobe_blk_account_io_done")
+if BPF.get_kprobe_functions(b'__blk_account_io_done'):
+    bpf.attach_kprobe(event="__blk_account_io_done", fn_name="kprobe_blk_account_io_done")
+else:
+    bpf.attach_kprobe(event="blk_account_io_done", fn_name="kprobe_blk_account_io_done")
 
 # times are in usecs
 MSEC = 1000
index 333949b5c4290093f4469cb5698858a9ae2ace57..2b954ac98c0d223f84263f355474f50fd638ffd0 100755 (executable)
@@ -163,12 +163,17 @@ if debug or args.ebpf:
 
 # initialize BPF
 b = BPF(text=bpf_text)
-b.attach_kprobe(event="blk_account_io_start", fn_name="trace_pid_start")
+if BPF.get_kprobe_functions(b'__blk_account_io_start'):
+    b.attach_kprobe(event="__blk_account_io_start", fn_name="trace_pid_start")
+else:
+    b.attach_kprobe(event="blk_account_io_start", fn_name="trace_pid_start")
 if BPF.get_kprobe_functions(b'blk_start_request'):
     b.attach_kprobe(event="blk_start_request", fn_name="trace_req_start")
 b.attach_kprobe(event="blk_mq_start_request", fn_name="trace_req_start")
-b.attach_kprobe(event="blk_account_io_done",
-    fn_name="trace_req_completion")
+if BPF.get_kprobe_functions(b'__blk_account_io_done'):
+    b.attach_kprobe(event="__blk_account_io_done", fn_name="trace_req_completion")
+else:
+    b.attach_kprobe(event="blk_account_io_done", fn_name="trace_req_completion")
 
 # header
 print("%-11s %-14s %-6s %-7s %-1s %-10s %-7s" % ("TIME(s)", "COMM", "PID",
index 609f0ac45ee51e849efc96e9a52f3507aa9115ac..eac4dab990f569b83317c277ca1c2bfcf02c7f78 100755 (executable)
@@ -175,12 +175,17 @@ if args.ebpf:
     exit()
 
 b = BPF(text=bpf_text)
-b.attach_kprobe(event="blk_account_io_start", fn_name="trace_pid_start")
+if BPF.get_kprobe_functions(b'__blk_account_io_start'):
+    b.attach_kprobe(event="__blk_account_io_start", fn_name="trace_pid_start")
+else:
+    b.attach_kprobe(event="blk_account_io_start", fn_name="trace_pid_start")
 if BPF.get_kprobe_functions(b'blk_start_request'):
     b.attach_kprobe(event="blk_start_request", fn_name="trace_req_start")
 b.attach_kprobe(event="blk_mq_start_request", fn_name="trace_req_start")
-b.attach_kprobe(event="blk_account_io_done",
-    fn_name="trace_req_completion")
+if BPF.get_kprobe_functions(b'__blk_account_io_done'):
+    b.attach_kprobe(event="__blk_account_io_done", fn_name="trace_req_completion")
+else:
+    b.attach_kprobe(event="blk_account_io_done", fn_name="trace_req_completion")
 
 print('Tracing... Output every %d secs. Hit Ctrl-C to end' % interval)