Skip to content

Commit

Permalink
tools: Fix BCC bio tools with recent kernel change
Browse files Browse the repository at this point in the history
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]: torvalds/linux@be6bfe3

Signed-off-by: Hengqi Chen <[email protected]>
  • Loading branch information
chenhengqi committed Dec 11, 2021
1 parent f32f772 commit 8c80b29
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
12 changes: 8 additions & 4 deletions tools/biolatency.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,18 @@
# 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.")
Expand Down Expand Up @@ -277,4 +282,3 @@ def flags_print(flags):
countdown -= 1
if exiting or countdown == 0:
exit()

5 changes: 4 additions & 1 deletion tools/biolatpcts.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@
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
Expand Down
11 changes: 8 additions & 3 deletions tools/biosnoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,17 @@

# 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",
Expand Down
11 changes: 8 additions & 3 deletions tools/biotop.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,17 @@
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)

Expand Down

0 comments on commit 8c80b29

Please sign in to comment.