]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
block: add missing block_bio_complete() tracepoint
authorTejun Heo <tj@kernel.org>
Fri, 11 Jan 2013 21:06:33 +0000 (13:06 -0800)
committerJens Axboe <axboe@kernel.dk>
Mon, 14 Jan 2013 14:00:36 +0000 (15:00 +0100)
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>
block/blk-core.c
drivers/md/dm.c
drivers/md/raid5.c
fs/bio.c
include/linux/blktrace_api.h
include/trace/events/block.h
kernel/trace/blktrace.c

index aca5d82ff13c2fed7efa872a9d14d0077ad4374f..4f5aec708be6faced0dc54f0eb74c83a771f7bd5 100644 (file)
@@ -39,7 +39,6 @@
 
 EXPORT_TRACEPOINT_SYMBOL_GPL(block_bio_remap);
 EXPORT_TRACEPOINT_SYMBOL_GPL(block_rq_remap);
-EXPORT_TRACEPOINT_SYMBOL_GPL(block_bio_complete);
 EXPORT_TRACEPOINT_SYMBOL_GPL(block_unplug);
 
 DEFINE_IDA(blk_queue_ida);
index c72e4d5a96178c6a542442e2e66bd3da92473b50..650ec2866e342a5833dad8d62f82318de86d1d69 100644 (file)
@@ -627,7 +627,6 @@ static void dec_pending(struct dm_io *io, int error)
                        queue_io(md, bio);
                } else {
                        /* done with normal IO or empty flush */
-                       trace_block_bio_complete(md->queue, bio, io_error);
                        bio_endio(bio, io_error);
                }
        }
index 19d77a02663972c3daa9d74295c820d2bb85ba37..9ab506df42daf84c7ad4397552e958ec3fa9bddf 100644 (file)
@@ -184,8 +184,6 @@ static void return_io(struct bio *return_bi)
                return_bi = bi->bi_next;
                bi->bi_next = NULL;
                bi->bi_size = 0;
-               trace_block_bio_complete(bdev_get_queue(bi->bi_bdev),
-                                        bi, 0);
                bio_endio(bi, 0);
                bi = return_bi;
        }
@@ -3917,8 +3915,6 @@ static void raid5_align_endio(struct bio *bi, int error)
        rdev_dec_pending(rdev, conf->mddev);
 
        if (!error && uptodate) {
-               trace_block_bio_complete(bdev_get_queue(raid_bi->bi_bdev),
-                                        raid_bi, 0);
                bio_endio(raid_bi, 0);
                if (atomic_dec_and_test(&conf->active_aligned_reads))
                        wake_up(&conf->wait_for_stripe);
@@ -4377,8 +4373,6 @@ static void make_request(struct mddev *mddev, struct bio * bi)
                if ( rw == WRITE )
                        md_write_end(mddev);
 
-               trace_block_bio_complete(bdev_get_queue(bi->bi_bdev),
-                                        bi, 0);
                bio_endio(bi, 0);
        }
 }
@@ -4755,11 +4749,8 @@ static int  retry_aligned_read(struct r5conf *conf, struct bio *raid_bio)
                handled++;
        }
        remaining = raid5_dec_bi_active_stripes(raid_bio);
-       if (remaining == 0) {
-               trace_block_bio_complete(bdev_get_queue(raid_bio->bi_bdev),
-                                        raid_bio, 0);
+       if (remaining == 0)
                bio_endio(raid_bio, 0);
-       }
        if (atomic_dec_and_test(&conf->active_aligned_reads))
                wake_up(&conf->wait_for_stripe);
        return handled;
index b96fc6ce485595f0179bc909c807ae197258e671..bb5768f59b32e22fdcde250f0ae8b01eb6b69b48 100644 (file)
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -1428,6 +1428,8 @@ void bio_endio(struct bio *bio, int error)
        else if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
                error = -EIO;
 
+       trace_block_bio_complete(bio, error);
+
        if (bio->bi_end_io)
                bio->bi_end_io(bio, error);
 }
index 7c2e030e72f10542612ba34ce79b18f6b1b8ad06..0ea61e07a91c03053833faf3a4250e1f6023a10d 100644 (file)
@@ -12,6 +12,7 @@
 
 struct blk_trace {
        int trace_state;
+       bool rq_based;
        struct rchan *rchan;
        unsigned long __percpu *sequence;
        unsigned char __percpu *msg_data;
index 05c5e61f0a7ca23b03a6a965a375323ea2b37036..8a168db9a645c292085e28b94e7331563ed5e116 100644 (file)
@@ -206,7 +206,6 @@ TRACE_EVENT(block_bio_bounce,
 
 /**
  * block_bio_complete - completed all work on the block operation
- * @q: queue holding the block operation
  * @bio: block operation completed
  * @error: io error value
  *
@@ -215,9 +214,9 @@ TRACE_EVENT(block_bio_bounce,
  */
 TRACE_EVENT(block_bio_complete,
 
-       TP_PROTO(struct request_queue *q, struct bio *bio, int error),
+       TP_PROTO(struct bio *bio, int error),
 
-       TP_ARGS(q, bio, error),
+       TP_ARGS(bio, error),
 
        TP_STRUCT__entry(
                __field( dev_t,         dev             )
@@ -228,7 +227,8 @@ TRACE_EVENT(block_bio_complete,
        ),
 
        TP_fast_assign(
-               __entry->dev            = bio->bi_bdev->bd_dev;
+               __entry->dev            = bio->bi_bdev ?
+                                         bio->bi_bdev->bd_dev : 0;
                __entry->sector         = bio->bi_sector;
                __entry->nr_sector      = bio->bi_size >> 9;
                __entry->error          = error;
index c0bd0308741ca1a343a9cbc0b551b4a12438ddd7..190d98fbed2763271c221fba6a86c3f33eb7530c 100644 (file)
@@ -739,6 +739,12 @@ static void blk_add_trace_rq_complete(void *ignore,
                                      struct request_queue *q,
                                      struct request *rq)
 {
+       struct blk_trace *bt = q->blk_trace;
+
+       /* if control ever passes through here, it's a request based driver */
+       if (unlikely(bt && !bt->rq_based))
+               bt->rq_based = true;
+
        blk_add_trace_rq(q, rq, BLK_TA_COMPLETE);
 }
 
@@ -774,10 +780,24 @@ static void blk_add_trace_bio_bounce(void *ignore,
        blk_add_trace_bio(q, bio, BLK_TA_BOUNCE, 0);
 }
 
-static void blk_add_trace_bio_complete(void *ignore,
-                                      struct request_queue *q, struct bio *bio,
-                                      int error)
+static void blk_add_trace_bio_complete(void *ignore, struct bio *bio, int error)
 {
+       struct request_queue *q;
+       struct blk_trace *bt;
+
+       if (!bio->bi_bdev)
+               return;
+
+       q = bdev_get_queue(bio->bi_bdev);
+       bt = q->blk_trace;
+
+       /*
+        * Request based drivers will generate both rq and bio completions.
+        * Ignore bio ones.
+        */
+       if (likely(!bt) || bt->rq_based)
+               return;
+
        blk_add_trace_bio(q, bio, BLK_TA_COMPLETE, error);
 }