Skip to content

Commit

Permalink
block: introduce block_io_start/block_io_done tracepoints
Browse files Browse the repository at this point in the history
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 introduce two
new tracepoints for such use cases.

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

Tested-by: Francis Laniel <flaniel@linux.microsoft.com>
Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
Tested-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/r/20230520084057.1467003-1-hengqi.chen@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
chenhengqi authored and axboe committed May 24, 2023
1 parent a13bd91 commit 5a80bd0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions block/blk-mq.c
Expand Up @@ -962,6 +962,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
Expand All @@ -981,6 +983,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
Expand Down
26 changes: 26 additions & 0 deletions include/trace/events/block.h
Expand Up @@ -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
Expand Down

0 comments on commit 5a80bd0

Please sign in to comment.