1 /* SPDX-License-Identifier: GPL-2.0 */
3 #define TRACE_SYSTEM block
5 #if !defined(_TRACE_BLOCK_H) || defined(TRACE_HEADER_MULTI_READ)
8 #include <linux/blktrace_api.h>
9 #include <linux/blkdev.h>
10 #include <linux/buffer_head.h>
11 #include <linux/tracepoint.h>
15 DECLARE_EVENT_CLASS(block_buffer,
17 TP_PROTO(struct buffer_head *bh),
23 __field( sector_t, sector )
24 __field( size_t, size )
28 __entry->dev = bh->b_bdev->bd_dev;
29 __entry->sector = bh->b_blocknr;
30 __entry->size = bh->b_size;
33 TP_printk("%d,%d sector=%llu size=%zu",
34 MAJOR(__entry->dev), MINOR(__entry->dev),
35 (unsigned long long)__entry->sector, __entry->size
40 * block_touch_buffer - mark a buffer accessed
41 * @bh: buffer_head being touched
43 * Called from touch_buffer().
45 DEFINE_EVENT(block_buffer, block_touch_buffer,
47 TP_PROTO(struct buffer_head *bh),
53 * block_dirty_buffer - mark a buffer dirty
54 * @bh: buffer_head being dirtied
56 * Called from mark_buffer_dirty().
58 DEFINE_EVENT(block_buffer, block_dirty_buffer,
60 TP_PROTO(struct buffer_head *bh),
66 * block_rq_requeue - place block IO request back on a queue
67 * @rq: block IO operation request
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.
73 TRACE_EVENT(block_rq_requeue,
75 TP_PROTO(struct request *rq),
81 __field( sector_t, sector )
82 __field( unsigned int, nr_sector )
83 __array( char, rwbs, RWBS_LEN )
84 __dynamic_array( char, cmd, 1 )
88 __entry->dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0;
89 __entry->sector = blk_rq_trace_sector(rq);
90 __entry->nr_sector = blk_rq_trace_nr_sectors(rq);
92 blk_fill_rwbs(__entry->rwbs, rq->cmd_flags, blk_rq_bytes(rq));
93 __get_str(cmd)[0] = '\0';
96 TP_printk("%d,%d %s (%s) %llu + %u [%d]",
97 MAJOR(__entry->dev), MINOR(__entry->dev),
98 __entry->rwbs, __get_str(cmd),
99 (unsigned long long)__entry->sector,
100 __entry->nr_sector, 0)
104 * block_rq_complete - block IO operation completed by device driver
105 * @rq: block operations request
106 * @error: status code
107 * @nr_bytes: number of completed bytes
109 * The block_rq_complete tracepoint event indicates that some portion
110 * of operation request has been completed by the device driver. If
111 * the @rq->bio is %NULL, then there is absolutely no additional work to
112 * do for the request. If @rq->bio is non-NULL then there is
113 * additional work required to complete the request.
115 TRACE_EVENT(block_rq_complete,
117 TP_PROTO(struct request *rq, int error, unsigned int nr_bytes),
119 TP_ARGS(rq, error, nr_bytes),
122 __field( dev_t, dev )
123 __field( sector_t, sector )
124 __field( unsigned int, nr_sector )
125 __field( int, error )
126 __array( char, rwbs, RWBS_LEN )
127 __dynamic_array( char, cmd, 1 )
131 __entry->dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0;
132 __entry->sector = blk_rq_pos(rq);
133 __entry->nr_sector = nr_bytes >> 9;
134 __entry->error = error;
136 blk_fill_rwbs(__entry->rwbs, rq->cmd_flags, nr_bytes);
137 __get_str(cmd)[0] = '\0';
140 TP_printk("%d,%d %s (%s) %llu + %u [%d]",
141 MAJOR(__entry->dev), MINOR(__entry->dev),
142 __entry->rwbs, __get_str(cmd),
143 (unsigned long long)__entry->sector,
144 __entry->nr_sector, __entry->error)
147 DECLARE_EVENT_CLASS(block_rq,
149 TP_PROTO(struct request *rq),
154 __field( dev_t, dev )
155 __field( sector_t, sector )
156 __field( unsigned int, nr_sector )
157 __field( unsigned int, bytes )
158 __array( char, rwbs, RWBS_LEN )
159 __array( char, comm, TASK_COMM_LEN )
160 __dynamic_array( char, cmd, 1 )
164 __entry->dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0;
165 __entry->sector = blk_rq_trace_sector(rq);
166 __entry->nr_sector = blk_rq_trace_nr_sectors(rq);
167 __entry->bytes = blk_rq_bytes(rq);
169 blk_fill_rwbs(__entry->rwbs, rq->cmd_flags, blk_rq_bytes(rq));
170 __get_str(cmd)[0] = '\0';
171 memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
174 TP_printk("%d,%d %s %u (%s) %llu + %u [%s]",
175 MAJOR(__entry->dev), MINOR(__entry->dev),
176 __entry->rwbs, __entry->bytes, __get_str(cmd),
177 (unsigned long long)__entry->sector,
178 __entry->nr_sector, __entry->comm)
182 * block_rq_insert - insert block operation request into queue
183 * @rq: block IO operation request
185 * Called immediately before block operation request @rq is inserted
186 * into queue @q. The fields in the operation request @rq struct can
187 * be examined to determine which device and sectors the pending
188 * operation would access.
190 DEFINE_EVENT(block_rq, block_rq_insert,
192 TP_PROTO(struct request *rq),
198 * block_rq_issue - issue pending block IO request operation to device driver
199 * @rq: block IO operation operation request
201 * Called when block operation request @rq from queue @q is sent to a
202 * device driver for processing.
204 DEFINE_EVENT(block_rq, block_rq_issue,
206 TP_PROTO(struct request *rq),
212 * block_rq_merge - merge request with another one in the elevator
213 * @rq: block IO operation operation request
215 * Called when block operation request @rq from queue @q is merged to another
216 * request queued in the elevator.
218 DEFINE_EVENT(block_rq, block_rq_merge,
220 TP_PROTO(struct request *rq),
226 * block_bio_bounce - used bounce buffer when processing block operation
227 * @q: queue holding the block operation
228 * @bio: block operation
230 * A bounce buffer was used to handle the block operation @bio in @q.
231 * This occurs when hardware limitations prevent a direct transfer of
232 * data between the @bio data memory area and the IO device. Use of a
233 * bounce buffer requires extra copying of data and decreases
236 TRACE_EVENT(block_bio_bounce,
238 TP_PROTO(struct request_queue *q, struct bio *bio),
243 __field( dev_t, dev )
244 __field( sector_t, sector )
245 __field( unsigned int, nr_sector )
246 __array( char, rwbs, RWBS_LEN )
247 __array( char, comm, TASK_COMM_LEN )
251 __entry->dev = bio_dev(bio);
252 __entry->sector = bio->bi_iter.bi_sector;
253 __entry->nr_sector = bio_sectors(bio);
254 blk_fill_rwbs(__entry->rwbs, bio->bi_opf, bio->bi_iter.bi_size);
255 memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
258 TP_printk("%d,%d %s %llu + %u [%s]",
259 MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
260 (unsigned long long)__entry->sector,
261 __entry->nr_sector, __entry->comm)
265 * block_bio_complete - completed all work on the block operation
266 * @q: queue holding the block operation
267 * @bio: block operation completed
269 * This tracepoint indicates there is no further work to do on this
270 * block IO operation @bio.
272 TRACE_EVENT(block_bio_complete,
274 TP_PROTO(struct request_queue *q, struct bio *bio),
279 __field( dev_t, dev )
280 __field( sector_t, sector )
281 __field( unsigned, nr_sector )
282 __field( int, error )
283 __array( char, rwbs, RWBS_LEN)
287 __entry->dev = bio_dev(bio);
288 __entry->sector = bio->bi_iter.bi_sector;
289 __entry->nr_sector = bio_sectors(bio);
290 __entry->error = blk_status_to_errno(bio->bi_status);
291 blk_fill_rwbs(__entry->rwbs, bio->bi_opf, bio->bi_iter.bi_size);
294 TP_printk("%d,%d %s %llu + %u [%d]",
295 MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
296 (unsigned long long)__entry->sector,
297 __entry->nr_sector, __entry->error)
300 DECLARE_EVENT_CLASS(block_bio_merge,
302 TP_PROTO(struct request_queue *q, struct request *rq, struct bio *bio),
307 __field( dev_t, dev )
308 __field( sector_t, sector )
309 __field( unsigned int, nr_sector )
310 __array( char, rwbs, RWBS_LEN )
311 __array( char, comm, TASK_COMM_LEN )
315 __entry->dev = bio_dev(bio);
316 __entry->sector = bio->bi_iter.bi_sector;
317 __entry->nr_sector = bio_sectors(bio);
318 blk_fill_rwbs(__entry->rwbs, bio->bi_opf, bio->bi_iter.bi_size);
319 memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
322 TP_printk("%d,%d %s %llu + %u [%s]",
323 MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
324 (unsigned long long)__entry->sector,
325 __entry->nr_sector, __entry->comm)
329 * block_bio_backmerge - merging block operation to the end of an existing operation
330 * @q: queue holding operation
331 * @rq: request bio is being merged into
332 * @bio: new block operation to merge
334 * Merging block request @bio to the end of an existing block request
337 DEFINE_EVENT(block_bio_merge, block_bio_backmerge,
339 TP_PROTO(struct request_queue *q, struct request *rq, struct bio *bio),
345 * block_bio_frontmerge - merging block operation to the beginning of an existing operation
346 * @q: queue holding operation
347 * @rq: request bio is being merged into
348 * @bio: new block operation to merge
350 * Merging block IO operation @bio to the beginning of an existing block
351 * operation in queue @q.
353 DEFINE_EVENT(block_bio_merge, block_bio_frontmerge,
355 TP_PROTO(struct request_queue *q, struct request *rq, struct bio *bio),
361 * block_bio_queue - putting new block IO operation in queue
362 * @q: queue holding operation
363 * @bio: new block operation
365 * About to place the block IO operation @bio into queue @q.
367 TRACE_EVENT(block_bio_queue,
369 TP_PROTO(struct request_queue *q, struct bio *bio),
374 __field( dev_t, dev )
375 __field( sector_t, sector )
376 __field( unsigned int, nr_sector )
377 __array( char, rwbs, RWBS_LEN )
378 __array( char, comm, TASK_COMM_LEN )
382 __entry->dev = bio_dev(bio);
383 __entry->sector = bio->bi_iter.bi_sector;
384 __entry->nr_sector = bio_sectors(bio);
385 blk_fill_rwbs(__entry->rwbs, bio->bi_opf, bio->bi_iter.bi_size);
386 memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
389 TP_printk("%d,%d %s %llu + %u [%s]",
390 MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
391 (unsigned long long)__entry->sector,
392 __entry->nr_sector, __entry->comm)
395 DECLARE_EVENT_CLASS(block_get_rq,
397 TP_PROTO(struct request_queue *q, struct bio *bio, int rw),
402 __field( dev_t, dev )
403 __field( sector_t, sector )
404 __field( unsigned int, nr_sector )
405 __array( char, rwbs, RWBS_LEN )
406 __array( char, comm, TASK_COMM_LEN )
410 __entry->dev = bio ? bio_dev(bio) : 0;
411 __entry->sector = bio ? bio->bi_iter.bi_sector : 0;
412 __entry->nr_sector = bio ? bio_sectors(bio) : 0;
413 blk_fill_rwbs(__entry->rwbs,
414 bio ? bio->bi_opf : 0, __entry->nr_sector);
415 memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
418 TP_printk("%d,%d %s %llu + %u [%s]",
419 MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
420 (unsigned long long)__entry->sector,
421 __entry->nr_sector, __entry->comm)
425 * block_getrq - get a free request entry in queue for block IO operations
426 * @q: queue for operations
427 * @bio: pending block IO operation (can be %NULL)
428 * @rw: low bit indicates a read (%0) or a write (%1)
430 * A request struct for queue @q has been allocated to handle the
431 * block IO operation @bio.
433 DEFINE_EVENT(block_get_rq, block_getrq,
435 TP_PROTO(struct request_queue *q, struct bio *bio, int rw),
441 * block_sleeprq - waiting to get a free request entry in queue for block IO operation
442 * @q: queue for operation
443 * @bio: pending block IO operation (can be %NULL)
444 * @rw: low bit indicates a read (%0) or a write (%1)
446 * In the case where a request struct cannot be provided for queue @q
447 * the process needs to wait for an request struct to become
448 * available. This tracepoint event is generated each time the
449 * process goes to sleep waiting for request struct become available.
451 DEFINE_EVENT(block_get_rq, block_sleeprq,
453 TP_PROTO(struct request_queue *q, struct bio *bio, int rw),
459 * block_plug - keep operations requests in request queue
460 * @q: request queue to plug
462 * Plug the request queue @q. Do not allow block operation requests
463 * to be sent to the device driver. Instead, accumulate requests in
464 * the queue to improve throughput performance of the block device.
466 TRACE_EVENT(block_plug,
468 TP_PROTO(struct request_queue *q),
473 __array( char, comm, TASK_COMM_LEN )
477 memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
480 TP_printk("[%s]", __entry->comm)
483 DECLARE_EVENT_CLASS(block_unplug,
485 TP_PROTO(struct request_queue *q, unsigned int depth, bool explicit),
487 TP_ARGS(q, depth, explicit),
490 __field( int, nr_rq )
491 __array( char, comm, TASK_COMM_LEN )
495 __entry->nr_rq = depth;
496 memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
499 TP_printk("[%s] %d", __entry->comm, __entry->nr_rq)
503 * block_unplug - release of operations requests in request queue
504 * @q: request queue to unplug
505 * @depth: number of requests just added to the queue
506 * @explicit: whether this was an explicit unplug, or one from schedule()
508 * Unplug request queue @q because device driver is scheduled to work
509 * on elements in the request queue.
511 DEFINE_EVENT(block_unplug, block_unplug,
513 TP_PROTO(struct request_queue *q, unsigned int depth, bool explicit),
515 TP_ARGS(q, depth, explicit)
519 * block_split - split a single bio struct into two bio structs
520 * @q: queue containing the bio
521 * @bio: block operation being split
522 * @new_sector: The starting sector for the new bio
524 * The bio request @bio in request queue @q needs to be split into two
525 * bio requests. The newly created @bio request starts at
526 * @new_sector. This split may be required due to hardware limitation
527 * such as operation crossing device boundaries in a RAID system.
529 TRACE_EVENT(block_split,
531 TP_PROTO(struct request_queue *q, struct bio *bio,
532 unsigned int new_sector),
534 TP_ARGS(q, bio, new_sector),
537 __field( dev_t, dev )
538 __field( sector_t, sector )
539 __field( sector_t, new_sector )
540 __array( char, rwbs, RWBS_LEN )
541 __array( char, comm, TASK_COMM_LEN )
545 __entry->dev = bio_dev(bio);
546 __entry->sector = bio->bi_iter.bi_sector;
547 __entry->new_sector = new_sector;
548 blk_fill_rwbs(__entry->rwbs, bio->bi_opf, bio->bi_iter.bi_size);
549 memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
552 TP_printk("%d,%d %s %llu / %llu [%s]",
553 MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
554 (unsigned long long)__entry->sector,
555 (unsigned long long)__entry->new_sector,
560 * block_bio_remap - map request for a logical device to the raw device
561 * @q: queue holding the operation
562 * @bio: revised operation
563 * @dev: device for the operation
564 * @from: original sector for the operation
566 * An operation for a logical device has been mapped to the
569 TRACE_EVENT(block_bio_remap,
571 TP_PROTO(struct request_queue *q, struct bio *bio, dev_t dev,
574 TP_ARGS(q, bio, dev, from),
577 __field( dev_t, dev )
578 __field( sector_t, sector )
579 __field( unsigned int, nr_sector )
580 __field( dev_t, old_dev )
581 __field( sector_t, old_sector )
582 __array( char, rwbs, RWBS_LEN)
586 __entry->dev = bio_dev(bio);
587 __entry->sector = bio->bi_iter.bi_sector;
588 __entry->nr_sector = bio_sectors(bio);
589 __entry->old_dev = dev;
590 __entry->old_sector = from;
591 blk_fill_rwbs(__entry->rwbs, bio->bi_opf, bio->bi_iter.bi_size);
594 TP_printk("%d,%d %s %llu + %u <- (%d,%d) %llu",
595 MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
596 (unsigned long long)__entry->sector,
598 MAJOR(__entry->old_dev), MINOR(__entry->old_dev),
599 (unsigned long long)__entry->old_sector)
603 * block_rq_remap - map request for a block operation request
604 * @rq: block IO operation request
605 * @dev: device for the operation
606 * @from: original sector for the operation
608 * The block operation request @rq in @q has been remapped. The block
609 * operation request @rq holds the current information and @from hold
610 * the original sector.
612 TRACE_EVENT(block_rq_remap,
614 TP_PROTO(struct request *rq, dev_t dev, sector_t from),
616 TP_ARGS(rq, dev, from),
619 __field( dev_t, dev )
620 __field( sector_t, sector )
621 __field( unsigned int, nr_sector )
622 __field( dev_t, old_dev )
623 __field( sector_t, old_sector )
624 __field( unsigned int, nr_bios )
625 __array( char, rwbs, RWBS_LEN)
629 __entry->dev = disk_devt(rq->rq_disk);
630 __entry->sector = blk_rq_pos(rq);
631 __entry->nr_sector = blk_rq_sectors(rq);
632 __entry->old_dev = dev;
633 __entry->old_sector = from;
634 __entry->nr_bios = blk_rq_count_bios(rq);
635 blk_fill_rwbs(__entry->rwbs, rq->cmd_flags, blk_rq_bytes(rq));
638 TP_printk("%d,%d %s %llu + %u <- (%d,%d) %llu %u",
639 MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
640 (unsigned long long)__entry->sector,
642 MAJOR(__entry->old_dev), MINOR(__entry->old_dev),
643 (unsigned long long)__entry->old_sector, __entry->nr_bios)
646 #endif /* _TRACE_BLOCK_H */
648 /* This part must be outside protection */
649 #include <trace/define_trace.h>