Skip to content

Commit 48b77ad

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: cleanup tracing
A couple tweaks to the tracing code: - trace the request size for all requests - trace request sector and nr_sectors only for fs requests, enforced by helpers - drop SCSI CDB tracing - we have SCSI tracing for this and are going to me the CDB out of the generic struct request soon. With this the tracing code stops to know about BLOCK_PC requests entirely, it's just FS vs passthrough requests now, where the latter includes any driver-private requests. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 6d247d7 commit 48b77ad

File tree

3 files changed

+24
-60
lines changed

3 files changed

+24
-60
lines changed

include/linux/blktrace_api.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,16 @@ struct compat_blk_user_trace_setup {
110110

111111
#endif
112112

113-
#if defined(CONFIG_EVENT_TRACING) && defined(CONFIG_BLOCK)
113+
extern void blk_fill_rwbs(char *rwbs, unsigned int op, int bytes);
114114

115-
static inline int blk_cmd_buf_len(struct request *rq)
115+
static inline sector_t blk_rq_trace_sector(struct request *rq)
116116
{
117-
return (rq->cmd_type == REQ_TYPE_BLOCK_PC) ? rq->cmd_len * 3 : 1;
117+
return (rq->cmd_type != REQ_TYPE_FS) ? 0 : blk_rq_pos(rq);
118118
}
119119

120-
extern void blk_dump_cmd(char *buf, struct request *rq);
121-
extern void blk_fill_rwbs(char *rwbs, unsigned int op, int bytes);
122-
123-
#endif /* CONFIG_EVENT_TRACING && CONFIG_BLOCK */
120+
static inline unsigned int blk_rq_trace_nr_sectors(struct request *rq)
121+
{
122+
return (rq->cmd_type != REQ_TYPE_FS) ? 0 : blk_rq_sectors(rq);
123+
}
124124

125125
#endif

include/trace/events/block.h

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,17 @@ DECLARE_EVENT_CLASS(block_rq_with_error,
7373
__field( unsigned int, nr_sector )
7474
__field( int, errors )
7575
__array( char, rwbs, RWBS_LEN )
76-
__dynamic_array( char, cmd, blk_cmd_buf_len(rq) )
76+
__dynamic_array( char, cmd, 1 )
7777
),
7878

7979
TP_fast_assign(
8080
__entry->dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0;
81-
__entry->sector = (rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
82-
0 : blk_rq_pos(rq);
83-
__entry->nr_sector = (rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
84-
0 : blk_rq_sectors(rq);
81+
__entry->sector = blk_rq_trace_sector(rq);
82+
__entry->nr_sector = blk_rq_trace_nr_sectors(rq);
8583
__entry->errors = rq->errors;
8684

8785
blk_fill_rwbs(__entry->rwbs, rq->cmd_flags, blk_rq_bytes(rq));
88-
blk_dump_cmd(__get_str(cmd), rq);
86+
__get_str(cmd)[0] = '\0';
8987
),
9088

9189
TP_printk("%d,%d %s (%s) %llu + %u [%d]",
@@ -153,7 +151,7 @@ TRACE_EVENT(block_rq_complete,
153151
__field( unsigned int, nr_sector )
154152
__field( int, errors )
155153
__array( char, rwbs, RWBS_LEN )
156-
__dynamic_array( char, cmd, blk_cmd_buf_len(rq) )
154+
__dynamic_array( char, cmd, 1 )
157155
),
158156

159157
TP_fast_assign(
@@ -163,7 +161,7 @@ TRACE_EVENT(block_rq_complete,
163161
__entry->errors = rq->errors;
164162

165163
blk_fill_rwbs(__entry->rwbs, rq->cmd_flags, nr_bytes);
166-
blk_dump_cmd(__get_str(cmd), rq);
164+
__get_str(cmd)[0] = '\0';
167165
),
168166

169167
TP_printk("%d,%d %s (%s) %llu + %u [%d]",
@@ -186,20 +184,17 @@ DECLARE_EVENT_CLASS(block_rq,
186184
__field( unsigned int, bytes )
187185
__array( char, rwbs, RWBS_LEN )
188186
__array( char, comm, TASK_COMM_LEN )
189-
__dynamic_array( char, cmd, blk_cmd_buf_len(rq) )
187+
__dynamic_array( char, cmd, 1 )
190188
),
191189

192190
TP_fast_assign(
193191
__entry->dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0;
194-
__entry->sector = (rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
195-
0 : blk_rq_pos(rq);
196-
__entry->nr_sector = (rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
197-
0 : blk_rq_sectors(rq);
198-
__entry->bytes = (rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
199-
blk_rq_bytes(rq) : 0;
192+
__entry->sector = blk_rq_trace_sector(rq);
193+
__entry->nr_sector = blk_rq_trace_nr_sectors(rq);
194+
__entry->bytes = blk_rq_bytes(rq);
200195

201196
blk_fill_rwbs(__entry->rwbs, rq->cmd_flags, blk_rq_bytes(rq));
202-
blk_dump_cmd(__get_str(cmd), rq);
197+
__get_str(cmd)[0] = '\0';
203198
memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
204199
),
205200

kernel/trace/blktrace.c

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -712,15 +712,13 @@ static void blk_add_trace_rq(struct request_queue *q, struct request *rq,
712712
if (likely(!bt))
713713
return;
714714

715-
if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
715+
if (rq->cmd_type != REQ_TYPE_FS)
716716
what |= BLK_TC_ACT(BLK_TC_PC);
717-
__blk_add_trace(bt, 0, nr_bytes, req_op(rq), rq->cmd_flags,
718-
what, rq->errors, rq->cmd_len, rq->cmd);
719-
} else {
717+
else
720718
what |= BLK_TC_ACT(BLK_TC_FS);
721-
__blk_add_trace(bt, blk_rq_pos(rq), nr_bytes, req_op(rq),
722-
rq->cmd_flags, what, rq->errors, 0, NULL);
723-
}
719+
720+
__blk_add_trace(bt, blk_rq_trace_sector(rq), nr_bytes, req_op(rq),
721+
rq->cmd_flags, what, rq->errors, 0, NULL);
724722
}
725723

726724
static void blk_add_trace_rq_abort(void *ignore,
@@ -972,11 +970,7 @@ void blk_add_driver_data(struct request_queue *q,
972970
if (likely(!bt))
973971
return;
974972

975-
if (rq->cmd_type == REQ_TYPE_BLOCK_PC)
976-
__blk_add_trace(bt, 0, blk_rq_bytes(rq), 0, 0,
977-
BLK_TA_DRV_DATA, rq->errors, len, data);
978-
else
979-
__blk_add_trace(bt, blk_rq_pos(rq), blk_rq_bytes(rq), 0, 0,
973+
__blk_add_trace(bt, blk_rq_trace_sector(rq), blk_rq_bytes(rq), 0, 0,
980974
BLK_TA_DRV_DATA, rq->errors, len, data);
981975
}
982976
EXPORT_SYMBOL_GPL(blk_add_driver_data);
@@ -1752,31 +1746,6 @@ void blk_trace_remove_sysfs(struct device *dev)
17521746

17531747
#ifdef CONFIG_EVENT_TRACING
17541748

1755-
void blk_dump_cmd(char *buf, struct request *rq)
1756-
{
1757-
int i, end;
1758-
int len = rq->cmd_len;
1759-
unsigned char *cmd = rq->cmd;
1760-
1761-
if (rq->cmd_type != REQ_TYPE_BLOCK_PC) {
1762-
buf[0] = '\0';
1763-
return;
1764-
}
1765-
1766-
for (end = len - 1; end >= 0; end--)
1767-
if (cmd[end])
1768-
break;
1769-
end++;
1770-
1771-
for (i = 0; i < len; i++) {
1772-
buf += sprintf(buf, "%s%02x", i == 0 ? "" : " ", cmd[i]);
1773-
if (i == end && end != len - 1) {
1774-
sprintf(buf, " ..");
1775-
break;
1776-
}
1777-
}
1778-
}
1779-
17801749
void blk_fill_rwbs(char *rwbs, unsigned int op, int bytes)
17811750
{
17821751
int i = 0;

0 commit comments

Comments
 (0)