bpftrace/SOURCES/bpftrace-0.13.1-biosnoop.bt...

99 lines
2.5 KiB
Diff

From bcb8903067ce7a45b67ad0d5cabf83154b56d5ab Mon Sep 17 00:00:00 2001
From: Viktor Malik <viktor.malik@gmail.com>
Date: Mon, 9 May 2022 07:58:46 +0200
Subject: [PATCH 10/10] biosnoop.bt: handle Linux 5.17 block layer update
The kernel upstream commit:
https://github.com/torvalds/linux/commit/f3fa33acca9f0058157214800f68b10d8e71ab7a
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.
---
tools/biosnoop.bt | 2 +-
tools/old/biosnoop.bt | 56 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 57 insertions(+), 1 deletion(-)
create mode 100755 tools/old/biosnoop.bt
diff --git a/tools/biosnoop.bt b/tools/biosnoop.bt
index 33ad75de..c00ef428 100755
--- a/tools/biosnoop.bt
+++ b/tools/biosnoop.bt
@@ -25,7 +25,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,
diff --git a/tools/old/biosnoop.bt b/tools/old/biosnoop.bt
new file mode 100755
index 00000000..1a99643a
--- /dev/null
+++ b/tools/old/biosnoop.bt
@@ -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);
+}
--
2.35.3