blob: 048e2658d8952aea1358c3e7d9fcbc1a959fb467 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001#undef TRACE_SYSTEM
2#define TRACE_SYSTEM block
3
4#if !defined(_TRACE_BLOCK_H) || defined(TRACE_HEADER_MULTI_READ)
5#define _TRACE_BLOCK_H
6
7#include <linux/blktrace_api.h>
8#include <linux/blkdev.h>
9#include <linux/tracepoint.h>
10
11#define RWBS_LEN 8
12
13DECLARE_EVENT_CLASS(block_rq_with_error,
14
15 TP_PROTO(struct request_queue *q, struct request *rq),
16
17 TP_ARGS(q, rq),
18
19 TP_STRUCT__entry(
20 __field( dev_t, dev )
21 __field( sector_t, sector )
22 __field( unsigned int, nr_sector )
23 __field( int, errors )
24 __array( char, rwbs, RWBS_LEN )
25 __dynamic_array( char, cmd, blk_cmd_buf_len(rq) )
26 ),
27
28 TP_fast_assign(
29 __entry->dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0;
30 __entry->sector = (rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
31 0 : blk_rq_pos(rq);
32 __entry->nr_sector = (rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
33 0 : blk_rq_sectors(rq);
34 __entry->errors = rq->errors;
35
36 blk_fill_rwbs(__entry->rwbs, rq->cmd_flags, blk_rq_bytes(rq));
37 blk_dump_cmd(__get_str(cmd), rq);
38 ),
39
40 TP_printk("%d,%d %s (%s) %llu + %u [%d]",
41 MAJOR(__entry->dev), MINOR(__entry->dev),
42 __entry->rwbs, __get_str(cmd),
43 (unsigned long long)__entry->sector,
44 __entry->nr_sector, __entry->errors)
45);
46
47/**
48 * block_rq_abort - abort block operation request
49 * @q: queue containing the block operation request
50 * @rq: block IO operation request
51 *
52 * Called immediately after pending block IO operation request @rq in
53 * queue @q is aborted. The fields in the operation request @rq
54 * can be examined to determine which device and sectors the pending
55 * operation would access.
56 */
57DEFINE_EVENT(block_rq_with_error, block_rq_abort,
58
59 TP_PROTO(struct request_queue *q, struct request *rq),
60
61 TP_ARGS(q, rq)
62);
63
64/**
65 * block_rq_requeue - place block IO request back on a queue
66 * @q: queue holding operation
67 * @rq: block IO operation request
68 *
69 * The block operation request @rq is being placed back into queue
70 * @q. For some reason the request was not completed and needs to be
71 * put back in the queue.
72 */
73DEFINE_EVENT(block_rq_with_error, block_rq_requeue,
74
75 TP_PROTO(struct request_queue *q, struct request *rq),
76
77 TP_ARGS(q, rq)
78);
79
80/**
81 * block_rq_complete - block IO operation completed by device driver
82 * @q: queue containing the block operation request
83 * @rq: block operations request
84 * @nr_bytes: number of completed bytes
85 *
86 * The block_rq_complete tracepoint event indicates that some portion
87 * of operation request has been completed by the device driver. If
88 * the @rq->bio is %NULL, then there is absolutely no additional work to
89 * do for the request. If @rq->bio is non-NULL then there is
90 * additional work required to complete the request.
91 */
92TRACE_EVENT(block_rq_complete,
93
94 TP_PROTO(struct request_queue *q, struct request *rq,
95 unsigned int nr_bytes),
96
97 TP_ARGS(q, rq, nr_bytes),
98
99 TP_STRUCT__entry(
100 __field( dev_t, dev )
101 __field( sector_t, sector )
102 __field( unsigned int, nr_sector )
103 __field( int, errors )
104 __array( char, rwbs, RWBS_LEN )
105 __dynamic_array( char, cmd, blk_cmd_buf_len(rq) )
106 ),
107
108 TP_fast_assign(
109 __entry->dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0;
110 __entry->sector = blk_rq_pos(rq);
111 __entry->nr_sector = nr_bytes >> 9;
112 __entry->errors = rq->errors;
113
114 blk_fill_rwbs(__entry->rwbs, rq->cmd_flags, nr_bytes);
115 blk_dump_cmd(__get_str(cmd), rq);
116 ),
117
118 TP_printk("%d,%d %s (%s) %llu + %u [%d]",
119 MAJOR(__entry->dev), MINOR(__entry->dev),
120 __entry->rwbs, __get_str(cmd),
121 (unsigned long long)__entry->sector,
122 __entry->nr_sector, __entry->errors)
123);
124
125DECLARE_EVENT_CLASS(block_rq,
126
127 TP_PROTO(struct request_queue *q, struct request *rq),
128
129 TP_ARGS(q, rq),
130
131 TP_STRUCT__entry(
132 __field( dev_t, dev )
133 __field( sector_t, sector )
134 __field( unsigned int, nr_sector )
135 __field( unsigned int, bytes )
136 __array( char, rwbs, RWBS_LEN )
137 __array( char, comm, TASK_COMM_LEN )
138 __dynamic_array( char, cmd, blk_cmd_buf_len(rq) )
139 ),
140
141 TP_fast_assign(
142 __entry->dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0;
143 __entry->sector = (rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
144 0 : blk_rq_pos(rq);
145 __entry->nr_sector = (rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
146 0 : blk_rq_sectors(rq);
147 __entry->bytes = (rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
148 blk_rq_bytes(rq) : 0;
149
150 blk_fill_rwbs(__entry->rwbs, rq->cmd_flags, blk_rq_bytes(rq));
151 blk_dump_cmd(__get_str(cmd), rq);
152 memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
153 ),
154
155 TP_printk("%d,%d %s %u (%s) %llu + %u [%s]",
156 MAJOR(__entry->dev), MINOR(__entry->dev),
157 __entry->rwbs, __entry->bytes, __get_str(cmd),
158 (unsigned long long)__entry->sector,
159 __entry->nr_sector, __entry->comm)
160);
161
162/**
163 * block_rq_insert - insert block operation request into queue
164 * @q: target queue
165 * @rq: block IO operation request
166 *
167 * Called immediately before block operation request @rq is inserted
168 * into queue @q. The fields in the operation request @rq struct can
169 * be examined to determine which device and sectors the pending
170 * operation would access.
171 */
172DEFINE_EVENT(block_rq, block_rq_insert,
173
174 TP_PROTO(struct request_queue *q, struct request *rq),
175
176 TP_ARGS(q, rq)
177);
178
179/**
180 * block_rq_issue - issue pending block IO request operation to device driver
181 * @q: queue holding operation
182 * @rq: block IO operation operation request
183 *
184 * Called when block operation request @rq from queue @q is sent to a
185 * device driver for processing.
186 */
187DEFINE_EVENT(block_rq, block_rq_issue,
188
189 TP_PROTO(struct request_queue *q, struct request *rq),
190
191 TP_ARGS(q, rq)
192);
193
194/**
195 * block_bio_bounce - used bounce buffer when processing block operation
196 * @q: queue holding the block operation
197 * @bio: block operation
198 *
199 * A bounce buffer was used to handle the block operation @bio in @q.
200 * This occurs when hardware limitations prevent a direct transfer of
201 * data between the @bio data memory area and the IO device. Use of a
202 * bounce buffer requires extra copying of data and decreases
203 * performance.
204 */
205TRACE_EVENT(block_bio_bounce,
206
207 TP_PROTO(struct request_queue *q, struct bio *bio),
208
209 TP_ARGS(q, bio),
210
211 TP_STRUCT__entry(
212 __field( dev_t, dev )
213 __field( sector_t, sector )
214 __field( unsigned int, nr_sector )
215 __array( char, rwbs, RWBS_LEN )
216 __array( char, comm, TASK_COMM_LEN )
217 ),
218
219 TP_fast_assign(
220 __entry->dev = bio->bi_bdev ?
221 bio->bi_bdev->bd_dev : 0;
222 __entry->sector = bio->bi_sector;
223 __entry->nr_sector = bio->bi_size >> 9;
224 blk_fill_rwbs(__entry->rwbs, bio->bi_rw, bio->bi_size);
225 memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
226 ),
227
228 TP_printk("%d,%d %s %llu + %u [%s]",
229 MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
230 (unsigned long long)__entry->sector,
231 __entry->nr_sector, __entry->comm)
232);
233
234/**
235 * block_bio_complete - completed all work on the block operation
236 * @q: queue holding the block operation
237 * @bio: block operation completed
238 * @error: io error value
239 *
240 * This tracepoint indicates there is no further work to do on this
241 * block IO operation @bio.
242 */
243TRACE_EVENT(block_bio_complete,
244
245 TP_PROTO(struct request_queue *q, struct bio *bio, int error),
246
247 TP_ARGS(q, bio, error),
248
249 TP_STRUCT__entry(
250 __field( dev_t, dev )
251 __field( sector_t, sector )
252 __field( unsigned, nr_sector )
253 __field( int, error )
254 __array( char, rwbs, RWBS_LEN)
255 ),
256
257 TP_fast_assign(
258 __entry->dev = bio->bi_bdev->bd_dev;
259 __entry->sector = bio->bi_sector;
260 __entry->nr_sector = bio->bi_size >> 9;
261 __entry->error = error;
262 blk_fill_rwbs(__entry->rwbs, bio->bi_rw, bio->bi_size);
263 ),
264
265 TP_printk("%d,%d %s %llu + %u [%d]",
266 MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
267 (unsigned long long)__entry->sector,
268 __entry->nr_sector, __entry->error)
269);
270
271DECLARE_EVENT_CLASS(block_bio,
272
273 TP_PROTO(struct request_queue *q, struct bio *bio),
274
275 TP_ARGS(q, bio),
276
277 TP_STRUCT__entry(
278 __field( dev_t, dev )
279 __field( sector_t, sector )
280 __field( unsigned int, nr_sector )
281 __array( char, rwbs, RWBS_LEN )
282 __array( char, comm, TASK_COMM_LEN )
283 ),
284
285 TP_fast_assign(
286 __entry->dev = bio->bi_bdev->bd_dev;
287 __entry->sector = bio->bi_sector;
288 __entry->nr_sector = bio->bi_size >> 9;
289 blk_fill_rwbs(__entry->rwbs, bio->bi_rw, bio->bi_size);
290 memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
291 ),
292
293 TP_printk("%d,%d %s %llu + %u [%s]",
294 MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
295 (unsigned long long)__entry->sector,
296 __entry->nr_sector, __entry->comm)
297);
298
299/**
300 * block_bio_backmerge - merging block operation to the end of an existing operation
301 * @q: queue holding operation
302 * @bio: new block operation to merge
303 *
304 * Merging block request @bio to the end of an existing block request
305 * in queue @q.
306 */
307DEFINE_EVENT(block_bio, block_bio_backmerge,
308
309 TP_PROTO(struct request_queue *q, struct bio *bio),
310
311 TP_ARGS(q, bio)
312);
313
314/**
315 * block_bio_frontmerge - merging block operation to the beginning of an existing operation
316 * @q: queue holding operation
317 * @bio: new block operation to merge
318 *
319 * Merging block IO operation @bio to the beginning of an existing block
320 * operation in queue @q.
321 */
322DEFINE_EVENT(block_bio, block_bio_frontmerge,
323
324 TP_PROTO(struct request_queue *q, struct bio *bio),
325
326 TP_ARGS(q, bio)
327);
328
329/**
330 * block_bio_queue - putting new block IO operation in queue
331 * @q: queue holding operation
332 * @bio: new block operation
333 *
334 * About to place the block IO operation @bio into queue @q.
335 */
336DEFINE_EVENT(block_bio, block_bio_queue,
337
338 TP_PROTO(struct request_queue *q, struct bio *bio),
339
340 TP_ARGS(q, bio)
341);
342
343DECLARE_EVENT_CLASS(block_get_rq,
344
345 TP_PROTO(struct request_queue *q, struct bio *bio, int rw),
346
347 TP_ARGS(q, bio, rw),
348
349 TP_STRUCT__entry(
350 __field( dev_t, dev )
351 __field( sector_t, sector )
352 __field( unsigned int, nr_sector )
353 __array( char, rwbs, RWBS_LEN )
354 __array( char, comm, TASK_COMM_LEN )
355 ),
356
357 TP_fast_assign(
358 __entry->dev = bio ? bio->bi_bdev->bd_dev : 0;
359 __entry->sector = bio ? bio->bi_sector : 0;
360 __entry->nr_sector = bio ? bio->bi_size >> 9 : 0;
361 blk_fill_rwbs(__entry->rwbs,
362 bio ? bio->bi_rw : 0, __entry->nr_sector);
363 memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
364 ),
365
366 TP_printk("%d,%d %s %llu + %u [%s]",
367 MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
368 (unsigned long long)__entry->sector,
369 __entry->nr_sector, __entry->comm)
370);
371
372/**
373 * block_getrq - get a free request entry in queue for block IO operations
374 * @q: queue for operations
375 * @bio: pending block IO operation
376 * @rw: low bit indicates a read (%0) or a write (%1)
377 *
378 * A request struct for queue @q has been allocated to handle the
379 * block IO operation @bio.
380 */
381DEFINE_EVENT(block_get_rq, block_getrq,
382
383 TP_PROTO(struct request_queue *q, struct bio *bio, int rw),
384
385 TP_ARGS(q, bio, rw)
386);
387
388/**
389 * block_sleeprq - waiting to get a free request entry in queue for block IO operation
390 * @q: queue for operation
391 * @bio: pending block IO operation
392 * @rw: low bit indicates a read (%0) or a write (%1)
393 *
394 * In the case where a request struct cannot be provided for queue @q
395 * the process needs to wait for an request struct to become
396 * available. This tracepoint event is generated each time the
397 * process goes to sleep waiting for request struct become available.
398 */
399DEFINE_EVENT(block_get_rq, block_sleeprq,
400
401 TP_PROTO(struct request_queue *q, struct bio *bio, int rw),
402
403 TP_ARGS(q, bio, rw)
404);
405
406/**
407 * block_plug - keep operations requests in request queue
408 * @q: request queue to plug
409 *
410 * Plug the request queue @q. Do not allow block operation requests
411 * to be sent to the device driver. Instead, accumulate requests in
412 * the queue to improve throughput performance of the block device.
413 */
414TRACE_EVENT(block_plug,
415
416 TP_PROTO(struct request_queue *q),
417
418 TP_ARGS(q),
419
420 TP_STRUCT__entry(
421 __array( char, comm, TASK_COMM_LEN )
422 ),
423
424 TP_fast_assign(
425 memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
426 ),
427
428 TP_printk("[%s]", __entry->comm)
429);
430
431DECLARE_EVENT_CLASS(block_unplug,
432
433 TP_PROTO(struct request_queue *q, unsigned int depth, bool explicit),
434
435 TP_ARGS(q, depth, explicit),
436
437 TP_STRUCT__entry(
438 __field( int, nr_rq )
439 __array( char, comm, TASK_COMM_LEN )
440 ),
441
442 TP_fast_assign(
443 __entry->nr_rq = depth;
444 memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
445 ),
446
447 TP_printk("[%s] %d", __entry->comm, __entry->nr_rq)
448);
449
450/**
451 * block_unplug - release of operations requests in request queue
452 * @q: request queue to unplug
453 * @depth: number of requests just added to the queue
454 * @explicit: whether this was an explicit unplug, or one from schedule()
455 *
456 * Unplug request queue @q because device driver is scheduled to work
457 * on elements in the request queue.
458 */
459DEFINE_EVENT(block_unplug, block_unplug,
460
461 TP_PROTO(struct request_queue *q, unsigned int depth, bool explicit),
462
463 TP_ARGS(q, depth, explicit)
464);
465
466/**
467 * block_split - split a single bio struct into two bio structs
468 * @q: queue containing the bio
469 * @bio: block operation being split
470 * @new_sector: The starting sector for the new bio
471 *
472 * The bio request @bio in request queue @q needs to be split into two
473 * bio requests. The newly created @bio request starts at
474 * @new_sector. This split may be required due to hardware limitation
475 * such as operation crossing device boundaries in a RAID system.
476 */
477TRACE_EVENT(block_split,
478
479 TP_PROTO(struct request_queue *q, struct bio *bio,
480 unsigned int new_sector),
481
482 TP_ARGS(q, bio, new_sector),
483
484 TP_STRUCT__entry(
485 __field( dev_t, dev )
486 __field( sector_t, sector )
487 __field( sector_t, new_sector )
488 __array( char, rwbs, RWBS_LEN )
489 __array( char, comm, TASK_COMM_LEN )
490 ),
491
492 TP_fast_assign(
493 __entry->dev = bio->bi_bdev->bd_dev;
494 __entry->sector = bio->bi_sector;
495 __entry->new_sector = new_sector;
496 blk_fill_rwbs(__entry->rwbs, bio->bi_rw, bio->bi_size);
497 memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
498 ),
499
500 TP_printk("%d,%d %s %llu / %llu [%s]",
501 MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
502 (unsigned long long)__entry->sector,
503 (unsigned long long)__entry->new_sector,
504 __entry->comm)
505);
506
507/**
508 * block_bio_remap - map request for a logical device to the raw device
509 * @q: queue holding the operation
510 * @bio: revised operation
511 * @dev: device for the operation
512 * @from: original sector for the operation
513 *
514 * An operation for a logical device has been mapped to the
515 * raw block device.
516 */
517TRACE_EVENT(block_bio_remap,
518
519 TP_PROTO(struct request_queue *q, struct bio *bio, dev_t dev,
520 sector_t from),
521
522 TP_ARGS(q, bio, dev, from),
523
524 TP_STRUCT__entry(
525 __field( dev_t, dev )
526 __field( sector_t, sector )
527 __field( unsigned int, nr_sector )
528 __field( dev_t, old_dev )
529 __field( sector_t, old_sector )
530 __array( char, rwbs, RWBS_LEN)
531 ),
532
533 TP_fast_assign(
534 __entry->dev = bio->bi_bdev->bd_dev;
535 __entry->sector = bio->bi_sector;
536 __entry->nr_sector = bio->bi_size >> 9;
537 __entry->old_dev = dev;
538 __entry->old_sector = from;
539 blk_fill_rwbs(__entry->rwbs, bio->bi_rw, bio->bi_size);
540 ),
541
542 TP_printk("%d,%d %s %llu + %u <- (%d,%d) %llu",
543 MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
544 (unsigned long long)__entry->sector,
545 __entry->nr_sector,
546 MAJOR(__entry->old_dev), MINOR(__entry->old_dev),
547 (unsigned long long)__entry->old_sector)
548);
549
550/**
551 * block_rq_remap - map request for a block operation request
552 * @q: queue holding the operation
553 * @rq: block IO operation request
554 * @dev: device for the operation
555 * @from: original sector for the operation
556 *
557 * The block operation request @rq in @q has been remapped. The block
558 * operation request @rq holds the current information and @from hold
559 * the original sector.
560 */
561TRACE_EVENT(block_rq_remap,
562
563 TP_PROTO(struct request_queue *q, struct request *rq, dev_t dev,
564 sector_t from),
565
566 TP_ARGS(q, rq, dev, from),
567
568 TP_STRUCT__entry(
569 __field( dev_t, dev )
570 __field( sector_t, sector )
571 __field( unsigned int, nr_sector )
572 __field( dev_t, old_dev )
573 __field( sector_t, old_sector )
574 __array( char, rwbs, RWBS_LEN)
575 ),
576
577 TP_fast_assign(
578 __entry->dev = disk_devt(rq->rq_disk);
579 __entry->sector = blk_rq_pos(rq);
580 __entry->nr_sector = blk_rq_sectors(rq);
581 __entry->old_dev = dev;
582 __entry->old_sector = from;
583 blk_fill_rwbs(__entry->rwbs, rq->cmd_flags, blk_rq_bytes(rq));
584 ),
585
586 TP_printk("%d,%d %s %llu + %u <- (%d,%d) %llu",
587 MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
588 (unsigned long long)__entry->sector,
589 __entry->nr_sector,
590 MAJOR(__entry->old_dev), MINOR(__entry->old_dev),
591 (unsigned long long)__entry->old_sector)
592);
593
594#endif /* _TRACE_BLOCK_H */
595
596/* This part must be outside protection */
597#include <trace/define_trace.h>
598