Skip to contentSkip to conversation

block: introduce block_io_start/block_io_done tracepoints

PATCH Applied Hengqi Chen 3 participants 3 messages May 20, 2023 – May 24, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: introduce block_io_start/block_io_done tracepoints

Currently, several BCC ([0]) tools (biosnoop/biostacks/biotop) use kprobes to blk_account_io_start/blk_account_io_done to implement their functionalities. This is fragile because the target kernel functions may be renamed ([1]) or inlined ([2]). So introduces two new tracepoints for such use cases.

[0]: https://github.com/iovisor/bcc
[1]: https://github.com/iovisor/bcc/issues/3954
[2]: https://github.com/iovisor/bcc/issues/4261

---
 block/blk-mq.c               |  4 ++++
 include/trace/events/block.h | 26 ++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)
block/blk-mq.c +4 -0
index f6dad0886a2f..faa1c7992876 100644
@@ -957,6 +957,8 @@ EXPORT_SYMBOL_GPL(blk_update_request);
 
 static inline void blk_account_io_done(struct request *req, u64 now)
 {
+	trace_block_io_done(req);
+
 	/*
 	 * Account IO completion.  flush_rq isn't accounted as a
 	 * normal IO on queueing nor completion.  Accounting the
@@ -976,6 +978,8 @@ static inline void blk_account_io_done(struct request *req, u64 now)
 
 static inline void blk_account_io_start(struct request *req)
 {
+	trace_block_io_start(req);
+
 	if (blk_do_io_stat(req)) {
 		/*
 		 * All non-passthrough requests are created from a bio with one
include/trace/events/block.h +26 -0
index 7f4dfbdf12a6..40e60c33cc6f 100644
@@ -245,6 +245,32 @@ DEFINE_EVENT(block_rq, block_rq_merge,
 	TP_ARGS(rq)
 );
 
+/**
+ * block_io_start - insert a request for execution
+ * @rq: block IO operation request
+ *
+ * Called when block operation request @rq is queued for execution
+ */
+DEFINE_EVENT(block_rq, block_io_start,
+
+	TP_PROTO(struct request *rq),
+
+	TP_ARGS(rq)
+);
+
+/**
+ * block_io_done - block IO operation request completed
+ * @rq: block IO operation request
+ *
+ * Called when block operation request @rq is completed
+ */
+DEFINE_EVENT(block_rq, block_io_done,
+
+	TP_PROTO(struct request *rq),
+
+	TP_ARGS(rq)
+);
+
 /**
  * block_bio_complete - completed all work on the block operation
  * @q: queue holding the block operation
Signature · 1 line
2.34.1
Tested-by on v1 1/1
#1 lore raw
Quoted 6 lines · Hengqi Chen

Currently, several BCC ([0]) tools (biosnoop/biostacks/biotop) use kprobes to blk_account_io_start/blk_account_io_done to implement their functionalities. This is fragile because the target kernel functions may be renamed ([1]) or inlined ([2]). So introduces two new tracepoints for such use cases.

Quoted 6 lines
   [0]: https://github.com/iovisor/bcc
   [1]: https://github.com/iovisor/bcc/issues/3954
   [2]: https://github.com/iovisor/bcc/issues/4261

I tested with my local VM, enabled the tracepoint and did see the trace_pipe printout nicely. If the patch is accepted, we will enhance related bcc-tools/libbpf-tools with these tracepoints so they can continue to work with newer kernels.

maintainer Applied
#2 lore raw
In reply to Hengqi Chen
Quoted 11 lines · Hengqi Chen

Currently, several BCC ([0]) tools (biosnoop/biostacks/biotop) use kprobes to blk_account_io_start/blk_account_io_done to implement their functionalities. This is fragile because the target kernel functions may be renamed ([1]) or inlined ([2]). So introduces two new tracepoints for such use cases.

[0]: https://github.com/iovisor/bcc
[1]: https://github.com/iovisor/bcc/issues/3954
[2]: https://github.com/iovisor/bcc/issues/4261

[...]

Applied, thanks!

[1/1] block: introduce block_io_start/block_io_done tracepoints

      commit: 03fcc599757cd74dbcf1a5977f9c6497a6798587

Best regards,

Signature · 1 line
Jens Axboe