Blame SOURCES/bpftrace-0.13.1-biosnoop.bt-handle-Linux-5.17-block-layer-update.patch

bd8a9c
From bcb8903067ce7a45b67ad0d5cabf83154b56d5ab Mon Sep 17 00:00:00 2001
bd8a9c
From: Viktor Malik <viktor.malik@gmail.com>
bd8a9c
Date: Mon, 9 May 2022 07:58:46 +0200
bd8a9c
Subject: [PATCH 10/10] biosnoop.bt: handle Linux 5.17 block layer update
bd8a9c
bd8a9c
The kernel upstream commit:
bd8a9c
bd8a9c
    https://github.com/torvalds/linux/commit/f3fa33acca9f0058157214800f68b10d8e71ab7a
bd8a9c
bd8a9c
has removed the `rq_disk` field from `struct request`. Instead,
bd8a9c
`->q->disk` should be used, so this is reflected in biosnoop.bt.
bd8a9c
bd8a9c
The old version of the tool (suitable for kernel <= 5.16) is backed up
bd8a9c
in tools/old and used in the CI.
bd8a9c
---
bd8a9c
 tools/biosnoop.bt     |  2 +-
bd8a9c
 tools/old/biosnoop.bt | 56 +++++++++++++++++++++++++++++++++++++++++++
bd8a9c
 2 files changed, 57 insertions(+), 1 deletion(-)
bd8a9c
 create mode 100755 tools/old/biosnoop.bt
bd8a9c
bd8a9c
diff --git a/tools/biosnoop.bt b/tools/biosnoop.bt
bd8a9c
index 33ad75de..c00ef428 100755
bd8a9c
--- a/tools/biosnoop.bt
bd8a9c
+++ b/tools/biosnoop.bt
bd8a9c
@@ -25,7 +25,7 @@ kprobe:__blk_account_io_start
bd8a9c
 	@start[arg0] = nsecs;
bd8a9c
 	@iopid[arg0] = pid;
bd8a9c
 	@iocomm[arg0] = comm;
bd8a9c
-	@disk[arg0] = ((struct request *)arg0)->rq_disk->disk_name;
bd8a9c
+	@disk[arg0] = ((struct request *)arg0)->q->disk->disk_name;
bd8a9c
 }
bd8a9c
 
bd8a9c
 kprobe:blk_account_io_done,
bd8a9c
diff --git a/tools/old/biosnoop.bt b/tools/old/biosnoop.bt
bd8a9c
new file mode 100755
bd8a9c
index 00000000..1a99643a
bd8a9c
--- /dev/null
bd8a9c
+++ b/tools/old/biosnoop.bt
bd8a9c
@@ -0,0 +1,56 @@
bd8a9c
+#!/usr/bin/env bpftrace
bd8a9c
+/*
bd8a9c
+ * biosnoop.bt   Block I/O tracing tool, showing per I/O latency.
bd8a9c
+ *               For Linux, uses bpftrace, eBPF.
bd8a9c
+ *
bd8a9c
+ * TODO: switch to block tracepoints. Add offset and size columns.
bd8a9c
+ *
bd8a9c
+ * This is a bpftrace version of the bcc tool of the same name.
bd8a9c
+ *
bd8a9c
+ * For Linux <= 5.16.
bd8a9c
+ *
bd8a9c
+ * 15-Nov-2017	Brendan Gregg	Created this.
bd8a9c
+ */
bd8a9c
+
bd8a9c
+#ifndef BPFTRACE_HAVE_BTF
bd8a9c
+#include <linux/blkdev.h>
bd8a9c
+#include <linux/blk-mq.h>
bd8a9c
+#endif
bd8a9c
+
bd8a9c
+BEGIN
bd8a9c
+{
bd8a9c
+	printf("%-12s %-7s %-16s %-6s %7s\n", "TIME(ms)", "DISK", "COMM", "PID", "LAT(ms)");
bd8a9c
+}
bd8a9c
+
bd8a9c
+kprobe:blk_account_io_start,
bd8a9c
+kprobe:__blk_account_io_start
bd8a9c
+{
bd8a9c
+	@start[arg0] = nsecs;
bd8a9c
+	@iopid[arg0] = pid;
bd8a9c
+	@iocomm[arg0] = comm;
bd8a9c
+	@disk[arg0] = ((struct request *)arg0)->rq_disk->disk_name;
bd8a9c
+}
bd8a9c
+
bd8a9c
+kprobe:blk_account_io_done,
bd8a9c
+kprobe:__blk_account_io_done
bd8a9c
+/@start[arg0] != 0 && @iopid[arg0] != 0 && @iocomm[arg0] != ""/
bd8a9c
+
bd8a9c
+{
bd8a9c
+	$now = nsecs;
bd8a9c
+	printf("%-12u %-7s %-16s %-6d %7d\n",
bd8a9c
+	    elapsed / 1e6, @disk[arg0], @iocomm[arg0], @iopid[arg0],
bd8a9c
+	    ($now - @start[arg0]) / 1e6);
bd8a9c
+
bd8a9c
+	delete(@start[arg0]);
bd8a9c
+	delete(@iopid[arg0]);
bd8a9c
+	delete(@iocomm[arg0]);
bd8a9c
+	delete(@disk[arg0]);
bd8a9c
+}
bd8a9c
+
bd8a9c
+END
bd8a9c
+{
bd8a9c
+	clear(@start);
bd8a9c
+	clear(@iopid);
bd8a9c
+	clear(@iocomm);
bd8a9c
+	clear(@disk);
bd8a9c
+}
bd8a9c
-- 
bd8a9c
2.35.3
bd8a9c