Skip to content

Commit 0a8eda9

Browse files
rouminggregkh
authored andcommitted
blktrace: fix accounting of partially completed requests
commit af5040d upstream. trace_block_rq_complete does not take into account that request can be partially completed, so we can get the following incorrect output of blkparser: C R 232 + 240 [0] C R 240 + 232 [0] C R 248 + 224 [0] C R 256 + 216 [0] but should be: C R 232 + 8 [0] C R 240 + 8 [0] C R 248 + 8 [0] C R 256 + 8 [0] Also, the whole output summary statistics of completed requests and final throughput will be incorrect. This patch takes into account real completion size of the request and fixes wrong completion accounting. Signed-off-by: Roman Pen <r.peniaev@gmail.com> CC: Steven Rostedt <rostedt@goodmis.org> CC: Frederic Weisbecker <fweisbec@gmail.com> CC: Ingo Molnar <mingo@redhat.com> CC: linux-kernel@vger.kernel.org Signed-off-by: Jens Axboe <axboe@fb.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7a6f558 commit 0a8eda9

3 files changed

Lines changed: 42 additions & 13 deletions

File tree

‎block/blk-core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2353,7 +2353,7 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
23532353
if (!req->bio)
23542354
return false;
23552355

2356-
trace_block_rq_complete(req->q, req);
2356+
trace_block_rq_complete(req->q, req, nr_bytes);
23572357

23582358
/*
23592359
* For fs requests, rq is just carrier of independent bio's

‎include/trace/events/block.h‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,45 @@ DEFINE_EVENT(block_rq_with_error, block_rq_requeue,
132132
* block_rq_complete - block IO operation completed by device driver
133133
* @q: queue containing the block operation request
134134
* @rq: block operations request
135+
* @nr_bytes: number of completed bytes
135136
*
136137
* The block_rq_complete tracepoint event indicates that some portion
137138
* of operation request has been completed by the device driver. If
138139
* the @rq->bio is %NULL, then there is absolutely no additional work to
139140
* do for the request. If @rq->bio is non-NULL then there is
140141
* additional work required to complete the request.
141142
*/
142-
DEFINE_EVENT(block_rq_with_error, block_rq_complete,
143+
TRACE_EVENT(block_rq_complete,
143144

144-
TP_PROTO(struct request_queue *q, struct request *rq),
145+
TP_PROTO(struct request_queue *q, struct request *rq,
146+
unsigned int nr_bytes),
145147

146-
TP_ARGS(q, rq)
148+
TP_ARGS(q, rq, nr_bytes),
149+
150+
TP_STRUCT__entry(
151+
__field( dev_t, dev )
152+
__field( sector_t, sector )
153+
__field( unsigned int, nr_sector )
154+
__field( int, errors )
155+
__array( char, rwbs, RWBS_LEN )
156+
__dynamic_array( char, cmd, blk_cmd_buf_len(rq) )
157+
),
158+
159+
TP_fast_assign(
160+
__entry->dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0;
161+
__entry->sector = blk_rq_pos(rq);
162+
__entry->nr_sector = nr_bytes >> 9;
163+
__entry->errors = rq->errors;
164+
165+
blk_fill_rwbs(__entry->rwbs, rq->cmd_flags, nr_bytes);
166+
blk_dump_cmd(__get_str(cmd), rq);
167+
),
168+
169+
TP_printk("%d,%d %s (%s) %llu + %u [%d]",
170+
MAJOR(__entry->dev), MINOR(__entry->dev),
171+
__entry->rwbs, __get_str(cmd),
172+
(unsigned long long)__entry->sector,
173+
__entry->nr_sector, __entry->errors)
147174
);
148175

149176
DECLARE_EVENT_CLASS(block_rq,

‎kernel/trace/blktrace.c‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -702,14 +702,15 @@ void blk_trace_shutdown(struct request_queue *q)
702702
* blk_add_trace_rq - Add a trace for a request oriented action
703703
* @q: queue the io is for
704704
* @rq: the source request
705+
* @nr_bytes: number of completed bytes
705706
* @what: the action
706707
*
707708
* Description:
708709
* Records an action against a request. Will log the bio offset + size.
709710
*
710711
**/
711712
static void blk_add_trace_rq(struct request_queue *q, struct request *rq,
712-
u32 what)
713+
unsigned int nr_bytes, u32 what)
713714
{
714715
struct blk_trace *bt = q->blk_trace;
715716

@@ -718,45 +719,46 @@ static void blk_add_trace_rq(struct request_queue *q, struct request *rq,
718719

719720
if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
720721
what |= BLK_TC_ACT(BLK_TC_PC);
721-
__blk_add_trace(bt, 0, blk_rq_bytes(rq), rq->cmd_flags,
722+
__blk_add_trace(bt, 0, nr_bytes, rq->cmd_flags,
722723
what, rq->errors, rq->cmd_len, rq->cmd);
723724
} else {
724725
what |= BLK_TC_ACT(BLK_TC_FS);
725-
__blk_add_trace(bt, blk_rq_pos(rq), blk_rq_bytes(rq),
726+
__blk_add_trace(bt, blk_rq_pos(rq), nr_bytes,
726727
rq->cmd_flags, what, rq->errors, 0, NULL);
727728
}
728729
}
729730

730731
static void blk_add_trace_rq_abort(void *ignore,
731732
struct request_queue *q, struct request *rq)
732733
{
733-
blk_add_trace_rq(q, rq, BLK_TA_ABORT);
734+
blk_add_trace_rq(q, rq, blk_rq_bytes(rq), BLK_TA_ABORT);
734735
}
735736

736737
static void blk_add_trace_rq_insert(void *ignore,
737738
struct request_queue *q, struct request *rq)
738739
{
739-
blk_add_trace_rq(q, rq, BLK_TA_INSERT);
740+
blk_add_trace_rq(q, rq, blk_rq_bytes(rq), BLK_TA_INSERT);
740741
}
741742

742743
static void blk_add_trace_rq_issue(void *ignore,
743744
struct request_queue *q, struct request *rq)
744745
{
745-
blk_add_trace_rq(q, rq, BLK_TA_ISSUE);
746+
blk_add_trace_rq(q, rq, blk_rq_bytes(rq), BLK_TA_ISSUE);
746747
}
747748

748749
static void blk_add_trace_rq_requeue(void *ignore,
749750
struct request_queue *q,
750751
struct request *rq)
751752
{
752-
blk_add_trace_rq(q, rq, BLK_TA_REQUEUE);
753+
blk_add_trace_rq(q, rq, blk_rq_bytes(rq), BLK_TA_REQUEUE);
753754
}
754755

755756
static void blk_add_trace_rq_complete(void *ignore,
756757
struct request_queue *q,
757-
struct request *rq)
758+
struct request *rq,
759+
unsigned int nr_bytes)
758760
{
759-
blk_add_trace_rq(q, rq, BLK_TA_COMPLETE);
761+
blk_add_trace_rq(q, rq, nr_bytes, BLK_TA_COMPLETE);
760762
}
761763

762764
/**

0 commit comments

Comments
 (0)