Skip to content

Commit

Permalink
biosnoop.bt: handle Linux 5.17 block layer update
Browse files Browse the repository at this point in the history
The kernel upstream commit:

    torvalds/linux@f3fa33a

has removed the `rq_disk` field from `struct request`. Instead,
`->q->disk` should be used, so this is reflected in biosnoop.bt.

The old version of the tool (suitable for kernel <= 5.16) is backed up
in tools/old and used in the CI.
  • Loading branch information
viktormalik committed May 9, 2022
1 parent e05e7a4 commit 6233473
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,31 @@ jobs:
LLVM_VERSION: 9
RUN_ALL_TESTS: 1
RUNTIME_TEST_DISABLE: probe.kprobe_offset_fail_size
TOOLS_TEST_OLDVERSION: biosnoop.bt
BASE: focal
VENDOR_GTEST: ON
- NAME: LLVM 9 Release
TYPE: Release
LLVM_VERSION: 9
RUN_ALL_TESTS: 1
RUNTIME_TEST_DISABLE: probe.kprobe_offset_fail_size
TOOLS_TEST_OLDVERSION: biosnoop.bt
BASE: focal
VENDOR_GTEST: ON
- NAME: LLVM 10 Debug
TYPE: Debug
LLVM_VERSION: 10
RUN_ALL_TESTS: 1
RUNTIME_TEST_DISABLE: probe.kprobe_offset_fail_size
TOOLS_TEST_OLDVERSION: biosnoop.bt
BASE: focal
VENDOR_GTEST: ON
- NAME: LLVM 10 Release
TYPE: Release
LLVM_VERSION: 10
RUN_ALL_TESTS: 1
RUNTIME_TEST_DISABLE: probe.kprobe_offset_fail_size
TOOLS_TEST_OLDVERSION: biosnoop.bt
BASE: focal
VENDOR_GTEST: ON
- NAME: LLVM 10 Clang Debug
Expand All @@ -62,27 +66,31 @@ jobs:
CXX: clang++-10
RUN_ALL_TESTS: 1
RUNTIME_TEST_DISABLE: probe.kprobe_offset_fail_size
TOOLS_TEST_OLDVERSION: biosnoop.bt
BASE: focal
VENDOR_GTEST: ON
- NAME: LLVM 11 Debug
TYPE: Debug
LLVM_VERSION: 11
RUN_ALL_TESTS: 1
RUNTIME_TEST_DISABLE: probe.kprobe_offset_fail_size
TOOLS_TEST_OLDVERSION: biosnoop.bt
BASE: focal
VENDOR_GTEST: ON
- NAME: LLVM 11 Release
TYPE: Release
LLVM_VERSION: 11
RUN_ALL_TESTS: 1
RUNTIME_TEST_DISABLE: probe.kprobe_offset_fail_size
TOOLS_TEST_OLDVERSION: biosnoop.bt
BASE: focal
VENDOR_GTEST: ON
- NAME: LLVM 12 Release
TYPE: Release
LLVM_VERSION: 12
RUN_ALL_TESTS: 1
RUNTIME_TEST_DISABLE: probe.kprobe_offset_fail_size
TOOLS_TEST_OLDVERSION: biosnoop.bt
BASE: focal
VENDOR_GTEST: ON
- NAME: LLVM 13 Release
Expand All @@ -91,13 +99,15 @@ jobs:
RUN_ALL_TESTS: 1
RUNTIME_TEST_DISABLE: probe.kprobe_offset_fail_size
GTEST_FILTER: '-clang_parser.nested_struct_no_type'
TOOLS_TEST_OLDVERSION: biosnoop.bt
BASE: focal
VENDOR_GTEST: ON
- NAME: LLVM 12 Release + libbpf
TYPE: Release
LLVM_VERSION: 12
RUN_ALL_TESTS: 1
RUNTIME_TEST_DISABLE: probe.kprobe_offset_fail_size
TOOLS_TEST_OLDVERSION: biosnoop.bt
BASE: focal
VENDOR_GTEST: ON
BUILD_LIBBPF: ON
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/embedded.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
EMBED_USE_LLVM: ON
RUN_ALL_TESTS: 1
RUNTIME_TEST_DISABLE: builtin.cgroup,probe.kprobe_offset_fail_size
TOOLS_TEST_OLDVERSION: biosnoop.bt
BASE: bionic
DISTRO: ubuntu-glibc
VENDOR_GTEST: ON
Expand All @@ -30,6 +31,7 @@ jobs:
EMBED_USE_LLVM: ON
RUN_ALL_TESTS: 1
RUNTIME_TEST_DISABLE: builtin.cgroup,probe.kprobe_offset_fail_size,other.string compare map lookup
TOOLS_TEST_OLDVERSION: biosnoop.bt
BASE: xenial
DISTRO: ubuntu-glibc
CMAKE_EXTRA_FLAGS: "-DCMAKE_CXX_FLAGS='-include /usr/local/include/bcc/compat/linux/bpf.h -D__LINUX_BPF_H__'"
Expand All @@ -45,6 +47,7 @@ jobs:
RUN_ALL_TESTS: 1
RUNTIME_TEST_DISABLE: json-output.join_delim,other.string compare map lookup,probe.kprobe_offset_fail_size,probe.uprobe_library,usdt."usdt probes - attach to fully specified probe of child",usdt."usdt probes - all probes by wildcard and file with child",usdt."usdt probes - attach to probe by wildcard and file with child",usdt."usdt probes - attach to probes by wildcard file with child",usdt."usdt probes - attach to probe on multiple files by wildcard",usdt."usdt probes - attach to probe with probe builtin and args by file with child",usdt."usdt probes - list probes by pid in separate mountns",usdt."usdt sized arguments",usdt."usdt - list probes by file with wildcarded probe type",uprobe."uprobes - list probes by pid; uprobes only",uprobe."uprobes - list probes by pid in separate mount namespace",other.positional pointer arithmetics
TOOLS_TEST_DISABLE: gethostlatency.bt,threadsnoop.bt
TOOLS_TEST_OLDVERSION: biosnoop.bt
BASE: alpine
DISTRO: alpine
ALPINE_VERSION: 3.11
Expand All @@ -58,6 +61,7 @@ jobs:
RUN_ALL_TESTS: 1
RUNTIME_TEST_DISABLE: other.string compare map lookup,probe.kprobe_offset_fail_size,probe.uprobe_library,usdt."usdt probes - attach to fully specified probe of child",usdt."usdt probes - all probes by wildcard and file with child",usdt."usdt probes - attach to probe by wildcard and file with child",usdt."usdt probes - attach to probes by wildcard file with child",usdt."usdt probes - attach to probe on multiple files by wildcard",usdt."usdt probes - attach to probe with probe builtin and args by file with child",usdt."usdt probes - list probes by pid in separate mountns",usdt."usdt sized arguments",usdt."usdt - list probes by file with wildcarded probe type",uprobe."uprobes - list probes by pid; uprobes only",uprobe."uprobes - list probes by pid in separate mount namespace",other.positional pointer arithmetics
TOOLS_TEST_DISABLE: gethostlatency.bt,threadsnoop.bt
TOOLS_TEST_OLDVERSION: biosnoop.bt
BASE: alpine
DISTRO: alpine
ALPINE_VERSION: 3.11
Expand Down
2 changes: 1 addition & 1 deletion tools/biosnoop.bt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ kprobe:__blk_account_io_start
@start[arg0] = nsecs;
@iopid[arg0] = pid;
@iocomm[arg0] = comm;
@disk[arg0] = ((struct request *)arg0)->rq_disk->disk_name;
@disk[arg0] = ((struct request *)arg0)->q->disk->disk_name;
}

kprobe:blk_account_io_done,
Expand Down
56 changes: 56 additions & 0 deletions tools/old/biosnoop.bt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bpftrace
/*
* biosnoop.bt Block I/O tracing tool, showing per I/O latency.
* For Linux, uses bpftrace, eBPF.
*
* TODO: switch to block tracepoints. Add offset and size columns.
*
* This is a bpftrace version of the bcc tool of the same name.
*
* For Linux <= 5.16.
*
* 15-Nov-2017 Brendan Gregg Created this.
*/

#ifndef BPFTRACE_HAVE_BTF
#include <linux/blkdev.h>
#include <linux/blk-mq.h>
#endif

BEGIN
{
printf("%-12s %-7s %-16s %-6s %7s\n", "TIME(ms)", "DISK", "COMM", "PID", "LAT(ms)");
}

kprobe:blk_account_io_start,
kprobe:__blk_account_io_start
{
@start[arg0] = nsecs;
@iopid[arg0] = pid;
@iocomm[arg0] = comm;
@disk[arg0] = ((struct request *)arg0)->rq_disk->disk_name;
}

kprobe:blk_account_io_done,
kprobe:__blk_account_io_done
/@start[arg0] != 0 && @iopid[arg0] != 0 && @iocomm[arg0] != ""/

{
$now = nsecs;
printf("%-12u %-7s %-16s %-6d %7d\n",
elapsed / 1e6, @disk[arg0], @iocomm[arg0], @iopid[arg0],
($now - @start[arg0]) / 1e6);

delete(@start[arg0]);
delete(@iopid[arg0]);
delete(@iocomm[arg0]);
delete(@disk[arg0]);
}

END
{
clear(@start);
clear(@iopid);
clear(@iocomm);
clear(@disk);
}

0 comments on commit 6233473

Please sign in to comment.