Skip to content

Commit 3a366e6

Browse files
htejunaxboe
authored andcommitted
block: add missing block_bio_complete() tracepoint
bio completion didn't kick block_bio_complete TP. Only dm was explicitly triggering the TP on IO completion. This makes block_bio_complete TP useless for tracers which want to know about bios, and all other bio based drivers skip generating blktrace completion events. This patch makes all bio completions via bio_endio() generate block_bio_complete TP. * Explicit trace_block_bio_complete() invocation removed from dm and the trace point is unexported. * @rq dropped from trace_block_bio_complete(). bios may fly around w/o queue associated. Verifying and accessing the assocaited queue belongs to TP probes. * blktrace now gets both request and bio completions. Make it ignore bio completions if request completion path is happening. This makes all bio based drivers generate blktrace completion events properly and makes the block_bio_complete TP actually useful. v2: With this change, block_bio_complete TP could be invoked on sg commands which have bio's with %NULL bi_bdev. Update TP assignment code to check whether bio->bi_bdev is %NULL before dereferencing. Signed-off-by: Tejun Heo <tj@kernel.org> Original-patch-by: Namhyung Kim <namhyung@gmail.com> Cc: Tejun Heo <tj@kernel.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Alasdair Kergon <agk@redhat.com> Cc: dm-devel@redhat.com Cc: Neil Brown <neilb@suse.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent ac9a197 commit 3a366e6

7 files changed

Lines changed: 31 additions & 19 deletions

File tree

‎block/blk-core.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939

4040
EXPORT_TRACEPOINT_SYMBOL_GPL(block_bio_remap);
4141
EXPORT_TRACEPOINT_SYMBOL_GPL(block_rq_remap);
42-
EXPORT_TRACEPOINT_SYMBOL_GPL(block_bio_complete);
4342
EXPORT_TRACEPOINT_SYMBOL_GPL(block_unplug);
4443

4544
DEFINE_IDA(blk_queue_ida);

‎drivers/md/dm.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,6 @@ static void dec_pending(struct dm_io *io, int error)
627627
queue_io(md, bio);
628628
} else {
629629
/* done with normal IO or empty flush */
630-
trace_block_bio_complete(md->queue, bio, io_error);
631630
bio_endio(bio, io_error);
632631
}
633632
}

‎drivers/md/raid5.c‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ static void return_io(struct bio *return_bi)
184184
return_bi = bi->bi_next;
185185
bi->bi_next = NULL;
186186
bi->bi_size = 0;
187-
trace_block_bio_complete(bdev_get_queue(bi->bi_bdev),
188-
bi, 0);
189187
bio_endio(bi, 0);
190188
bi = return_bi;
191189
}
@@ -3917,8 +3915,6 @@ static void raid5_align_endio(struct bio *bi, int error)
39173915
rdev_dec_pending(rdev, conf->mddev);
39183916

39193917
if (!error && uptodate) {
3920-
trace_block_bio_complete(bdev_get_queue(raid_bi->bi_bdev),
3921-
raid_bi, 0);
39223918
bio_endio(raid_bi, 0);
39233919
if (atomic_dec_and_test(&conf->active_aligned_reads))
39243920
wake_up(&conf->wait_for_stripe);
@@ -4377,8 +4373,6 @@ static void make_request(struct mddev *mddev, struct bio * bi)
43774373
if ( rw == WRITE )
43784374
md_write_end(mddev);
43794375

4380-
trace_block_bio_complete(bdev_get_queue(bi->bi_bdev),
4381-
bi, 0);
43824376
bio_endio(bi, 0);
43834377
}
43844378
}
@@ -4755,11 +4749,8 @@ static int retry_aligned_read(struct r5conf *conf, struct bio *raid_bio)
47554749
handled++;
47564750
}
47574751
remaining = raid5_dec_bi_active_stripes(raid_bio);
4758-
if (remaining == 0) {
4759-
trace_block_bio_complete(bdev_get_queue(raid_bio->bi_bdev),
4760-
raid_bio, 0);
4752+
if (remaining == 0)
47614753
bio_endio(raid_bio, 0);
4762-
}
47634754
if (atomic_dec_and_test(&conf->active_aligned_reads))
47644755
wake_up(&conf->wait_for_stripe);
47654756
return handled;

‎fs/bio.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,8 @@ void bio_endio(struct bio *bio, int error)
14281428
else if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
14291429
error = -EIO;
14301430

1431+
trace_block_bio_complete(bio, error);
1432+
14311433
if (bio->bi_end_io)
14321434
bio->bi_end_io(bio, error);
14331435
}

‎include/linux/blktrace_api.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
struct blk_trace {
1414
int trace_state;
15+
bool rq_based;
1516
struct rchan *rchan;
1617
unsigned long __percpu *sequence;
1718
unsigned char __percpu *msg_data;

‎include/trace/events/block.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ TRACE_EVENT(block_bio_bounce,
206206

207207
/**
208208
* block_bio_complete - completed all work on the block operation
209-
* @q: queue holding the block operation
210209
* @bio: block operation completed
211210
* @error: io error value
212211
*
@@ -215,9 +214,9 @@ TRACE_EVENT(block_bio_bounce,
215214
*/
216215
TRACE_EVENT(block_bio_complete,
217216

218-
TP_PROTO(struct request_queue *q, struct bio *bio, int error),
217+
TP_PROTO(struct bio *bio, int error),
219218

220-
TP_ARGS(q, bio, error),
219+
TP_ARGS(bio, error),
221220

222221
TP_STRUCT__entry(
223222
__field( dev_t, dev )
@@ -228,7 +227,8 @@ TRACE_EVENT(block_bio_complete,
228227
),
229228

230229
TP_fast_assign(
231-
__entry->dev = bio->bi_bdev->bd_dev;
230+
__entry->dev = bio->bi_bdev ?
231+
bio->bi_bdev->bd_dev : 0;
232232
__entry->sector = bio->bi_sector;
233233
__entry->nr_sector = bio->bi_size >> 9;
234234
__entry->error = error;

‎kernel/trace/blktrace.c‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,12 @@ static void blk_add_trace_rq_complete(void *ignore,
739739
struct request_queue *q,
740740
struct request *rq)
741741
{
742+
struct blk_trace *bt = q->blk_trace;
743+
744+
/* if control ever passes through here, it's a request based driver */
745+
if (unlikely(bt && !bt->rq_based))
746+
bt->rq_based = true;
747+
742748
blk_add_trace_rq(q, rq, BLK_TA_COMPLETE);
743749
}
744750

@@ -774,10 +780,24 @@ static void blk_add_trace_bio_bounce(void *ignore,
774780
blk_add_trace_bio(q, bio, BLK_TA_BOUNCE, 0);
775781
}
776782

777-
static void blk_add_trace_bio_complete(void *ignore,
778-
struct request_queue *q, struct bio *bio,
779-
int error)
783+
static void blk_add_trace_bio_complete(void *ignore, struct bio *bio, int error)
780784
{
785+
struct request_queue *q;
786+
struct blk_trace *bt;
787+
788+
if (!bio->bi_bdev)
789+
return;
790+
791+
q = bdev_get_queue(bio->bi_bdev);
792+
bt = q->blk_trace;
793+
794+
/*
795+
* Request based drivers will generate both rq and bio completions.
796+
* Ignore bio ones.
797+
*/
798+
if (likely(!bt) || bt->rq_based)
799+
return;
800+
781801
blk_add_trace_bio(q, bio, BLK_TA_COMPLETE, error);
782802
}
783803

0 commit comments

Comments
 (0)