linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: introduce block_io_start/block_io_done tracepoints
@ 2022-10-14 10:01 Hengqi Chen
  2022-10-14 16:24 ` Francis Laniel
  0 siblings, 1 reply; 5+ messages in thread
From: Hengqi Chen @ 2022-10-14 10:01 UTC (permalink / raw)
  To: linux-block, axboe, rostedt; +Cc: hengqi.chen, flaniel

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
  [0]: https://github.com/iovisor/bcc/issues/3954
  [1]: https://github.com/iovisor/bcc/issues/4261

Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
---
 block/blk-mq.c               |  4 ++++
 include/trace/events/block.h | 27 ++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index c96c8c4f751b..3777f486a365 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -887,6 +887,8 @@ static void __blk_account_io_done(struct request *req, u64 now)
 
 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
@@ -917,6 +919,8 @@ static void __blk_account_io_start(struct request *rq)
 
 static inline void blk_account_io_start(struct request *req)
 {
+	trace_block_io_start(req);
+
 	if (blk_do_io_stat(req))
 		__blk_account_io_start(req);
 }
diff --git a/include/trace/events/block.h b/include/trace/events/block.h
index 7f4dfbdf12a6..65c4cb224736 100644
--- a/include/trace/events/block.h
+++ b/include/trace/events/block.h
@@ -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
@@ -556,4 +582,3 @@ TRACE_EVENT(block_rq_remap,
 
 /* This part must be outside protection */
 #include <trace/define_trace.h>
-
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] block: introduce block_io_start/block_io_done tracepoints
  2022-10-14 10:01 [PATCH] block: introduce block_io_start/block_io_done tracepoints Hengqi Chen
@ 2022-10-14 16:24 ` Francis Laniel
  0 siblings, 0 replies; 5+ messages in thread
From: Francis Laniel @ 2022-10-14 16:24 UTC (permalink / raw)
  To: linux-block, axboe, rostedt, Hengqi Chen; +Cc: hengqi.chen

Hi.


Le vendredi 14 octobre 2022, 12:01:11 CEST Hengqi Chen a écrit :
> 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.

Thank you for working on this, I was able to build a kernel with your patch 
and successfully tested it:
root@vm-amd64:~# uname -a
Linux vm-amd64 6.0.0-rc4-00001-g89f38605b66b #95 SMP PREEMPT_DYNAMIC Fri Oct 
14 18:03:58 CEST 2022 x86_64 GNU/Linux
root@vm-amd64:~# perf_5.10 record -e block:block_io_done -e 
block:block_io_start -a dd if=/dev/zero of=foo count=100
...
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.083 MB perf.data (1 samples) ]
root@vm-amd64:~# perf_5.10 script                                              
              dd   313 [000]   273.355898: block:block_io_start: 8,0 W 53248 
()>
         swapper     0 [000]   273.357048:  block:block_io_done: 8,0 W 0 () 
484>

So, I can offer you this:
Tested-by: Francis Laniel <flaniel@linux.microsoft.com>

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

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

> 
> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
> ---
>  block/blk-mq.c               |  4 ++++
>  include/trace/events/block.h | 27 ++++++++++++++++++++++++++-
>  2 files changed, 30 insertions(+), 1 deletion(-)
> 
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index c96c8c4f751b..3777f486a365 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -887,6 +887,8 @@ static void __blk_account_io_done(struct request *req,
> u64 now)
> 
>  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
> @@ -917,6 +919,8 @@ static void __blk_account_io_start(struct request *rq)
> 
>  static inline void blk_account_io_start(struct request *req)
>  {
> +	trace_block_io_start(req);
> +
>  	if (blk_do_io_stat(req))
>  		__blk_account_io_start(req);
>  }
> diff --git a/include/trace/events/block.h b/include/trace/events/block.h
> index 7f4dfbdf12a6..65c4cb224736 100644
> --- a/include/trace/events/block.h
> +++ b/include/trace/events/block.h
> @@ -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
> @@ -556,4 +582,3 @@ TRACE_EVENT(block_rq_remap,
> 
>  /* This part must be outside protection */
>  #include <trace/define_trace.h>
> -


Best regards.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] block: introduce block_io_start/block_io_done tracepoints
@ 2023-05-20  8:40 Hengqi Chen
  2023-05-21  3:51 ` Yonghong Song
  2023-05-24 14:16 ` Jens Axboe
  0 siblings, 2 replies; 5+ messages in thread
From: Hengqi Chen @ 2023-05-20  8:40 UTC (permalink / raw)
  To: linux-block
  Cc: axboe, rostedt, mhiramat, bpf, yhs, hengqi.chen, Francis Laniel

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

Tested-by: Francis Laniel <flaniel@linux.microsoft.com>
Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
---
 block/blk-mq.c               |  4 ++++
 include/trace/events/block.h | 26 ++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index f6dad0886a2f..faa1c7992876 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -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
diff --git a/include/trace/events/block.h b/include/trace/events/block.h
index 7f4dfbdf12a6..40e60c33cc6f 100644
--- a/include/trace/events/block.h
+++ b/include/trace/events/block.h
@@ -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
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] block: introduce block_io_start/block_io_done tracepoints
  2023-05-20  8:40 Hengqi Chen
@ 2023-05-21  3:51 ` Yonghong Song
  2023-05-24 14:16 ` Jens Axboe
  1 sibling, 0 replies; 5+ messages in thread
From: Yonghong Song @ 2023-05-21  3:51 UTC (permalink / raw)
  To: Hengqi Chen, linux-block; +Cc: axboe, rostedt, mhiramat, bpf, Francis Laniel



On 5/20/23 1:40 AM, Hengqi Chen wrote:
> 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
> 
> Tested-by: Francis Laniel <flaniel@linux.microsoft.com>
> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>

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.

Tested-by: Yonghong Song <yhs@fb.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] block: introduce block_io_start/block_io_done tracepoints
  2023-05-20  8:40 Hengqi Chen
  2023-05-21  3:51 ` Yonghong Song
@ 2023-05-24 14:16 ` Jens Axboe
  1 sibling, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2023-05-24 14:16 UTC (permalink / raw)
  To: linux-block, Hengqi Chen; +Cc: rostedt, mhiramat, bpf, yhs, Francis Laniel


On Sat, 20 May 2023 08:40:57 +0000, Hengqi Chen wrote:
> 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,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-05-24 14:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-14 10:01 [PATCH] block: introduce block_io_start/block_io_done tracepoints Hengqi Chen
2022-10-14 16:24 ` Francis Laniel
  -- strict thread matches above, loose matches on Subject: below --
2023-05-20  8:40 Hengqi Chen
2023-05-21  3:51 ` Yonghong Song
2023-05-24 14:16 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).