1/* SPDX-License-Identifier: GPL-2.0 */
2#undef TRACE_SYSTEM
3#define TRACE_SYSTEM block
4
5#if !defined(_TRACE_BLOCK_H) || defined(TRACE_HEADER_MULTI_READ)
6#define _TRACE_BLOCK_H
7
8#include <linux/blktrace_api.h>
9#include <linux/blkdev.h>
10#include <linux/buffer_head.h>
11#include <linux/tracepoint.h>
12
13#define RWBS_LEN	8
14
15DECLARE_EVENT_CLASS(block_buffer,
16
17	TP_PROTO(struct buffer_head *bh),
18
19	TP_ARGS(bh),
20
21	TP_STRUCT__entry (
22		__field(  dev_t,	dev			)
23		__field(  sector_t,	sector			)
24		__field(  size_t,	size			)
25	),
26
27	TP_fast_assign(
28		__entry->dev		= bh->b_bdev->bd_dev;
29		__entry->sector		= bh->b_blocknr;
30		__entry->size		= bh->b_size;
31	),
32
33	TP_printk("%d,%d sector=%llu size=%zu",
34		MAJOR(__entry->dev), MINOR(__entry->dev),
35		(unsigned long long)__entry->sector, __entry->size
36	)
37);
38
39/**
40 * block_touch_buffer - mark a buffer accessed
41 * @bh: buffer_head being touched
42 *
43 * Called from touch_buffer().
44 */
45DEFINE_EVENT(block_buffer, block_touch_buffer,
46
47	TP_PROTO(struct buffer_head *bh),
48
49	TP_ARGS(bh)
50);
51
52/**
53 * block_dirty_buffer - mark a buffer dirty
54 * @bh: buffer_head being dirtied
55 *
56 * Called from mark_buffer_dirty().
57 */
58DEFINE_EVENT(block_buffer, block_dirty_buffer,
59
60	TP_PROTO(struct buffer_head *bh),
61
62	TP_ARGS(bh)
63);
64
65/**
66 * block_rq_requeue - place block IO request back on a queue
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 */
73TRACE_EVENT(block_rq_requeue,
74
75	TP_PROTO(struct request *rq),
76
77	TP_ARGS(rq),
78
79	TP_STRUCT__entry(
80		__field(  dev_t,	dev			)
81		__field(  sector_t,	sector			)
82		__field(  unsigned int,	nr_sector		)
83		__array(  char,		rwbs,	RWBS_LEN	)
84		__dynamic_array( char,	cmd,	1		)
85	),
86
87	TP_fast_assign(
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);
91
92		blk_fill_rwbs(__entry->rwbs, rq->cmd_flags, blk_rq_bytes(rq));
93		__get_str(cmd)[0] = '\0';
94	),
95
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)
101);
102
103/**
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
108 *
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.
114 */
115TRACE_EVENT(block_rq_complete,
116
117	TP_PROTO(struct request *rq, int error, unsigned int nr_bytes),
118
119	TP_ARGS(rq, error, nr_bytes),
120
121	TP_STRUCT__entry(
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		)
128	),
129
130	TP_fast_assign(
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;
135
136		blk_fill_rwbs(__entry->rwbs, rq->cmd_flags, nr_bytes);
137		__get_str(cmd)[0] = '\0';
138	),
139
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)
145);
146
147DECLARE_EVENT_CLASS(block_rq,
148
149	TP_PROTO(struct request *rq),
150
151	TP_ARGS(rq),
152
153	TP_STRUCT__entry(
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		)
161	),
162
163	TP_fast_assign(
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);
168
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);
172	),
173
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)
179);
180
181/**
182 * block_rq_insert - insert block operation request into queue
183 * @rq: block IO operation request
184 *
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.
189 */
190DEFINE_EVENT(block_rq, block_rq_insert,
191
192	TP_PROTO(struct request *rq),
193
194	TP_ARGS(rq)
195);
196
197/**
198 * block_rq_issue - issue pending block IO request operation to device driver
199 * @rq: block IO operation operation request
200 *
201 * Called when block operation request @rq from queue @q is sent to a
202 * device driver for processing.
203 */
204DEFINE_EVENT(block_rq, block_rq_issue,
205
206	TP_PROTO(struct request *rq),
207
208	TP_ARGS(rq)
209);
210
211/**
212 * block_rq_merge - merge request with another one in the elevator
213 * @rq: block IO operation operation request
214 *
215 * Called when block operation request @rq from queue @q is merged to another
216 * request queued in the elevator.
217 */
218DEFINE_EVENT(block_rq, block_rq_merge,
219
220	TP_PROTO(struct request *rq),
221
222	TP_ARGS(rq)
223);
224
225/**
226 * block_bio_bounce - used bounce buffer when processing block operation
227 * @q: queue holding the block operation
228 * @bio: block operation
229 *
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
234 * performance.
235 */
236TRACE_EVENT(block_bio_bounce,
237
238	TP_PROTO(struct request_queue *q, struct bio *bio),
239
240	TP_ARGS(q, bio),
241
242	TP_STRUCT__entry(
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	)
248	),
249
250	TP_fast_assign(
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);
256	),
257
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)
262);
263
264/**
265 * block_bio_complete - completed all work on the block operation
266 * @q: queue holding the block operation
267 * @bio: block operation completed
268 *
269 * This tracepoint indicates there is no further work to do on this
270 * block IO operation @bio.
271 */
272TRACE_EVENT(block_bio_complete,
273
274	TP_PROTO(struct request_queue *q, struct bio *bio),
275
276	TP_ARGS(q, bio),
277
278	TP_STRUCT__entry(
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)
284	),
285
286	TP_fast_assign(
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);
292	),
293
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)
298);
299
300DECLARE_EVENT_CLASS(block_bio_merge,
301
302	TP_PROTO(struct request_queue *q, struct request *rq, struct bio *bio),
303
304	TP_ARGS(q, rq, bio),
305
306	TP_STRUCT__entry(
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	)
312	),
313
314	TP_fast_assign(
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);
320	),
321
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)
326);
327
328/**
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
333 *
334 * Merging block request @bio to the end of an existing block request
335 * in queue @q.
336 */
337DEFINE_EVENT(block_bio_merge, block_bio_backmerge,
338
339	TP_PROTO(struct request_queue *q, struct request *rq, struct bio *bio),
340
341	TP_ARGS(q, rq, bio)
342);
343
344/**
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
349 *
350 * Merging block IO operation @bio to the beginning of an existing block
351 * operation in queue @q.
352 */
353DEFINE_EVENT(block_bio_merge, block_bio_frontmerge,
354
355	TP_PROTO(struct request_queue *q, struct request *rq, struct bio *bio),
356
357	TP_ARGS(q, rq, bio)
358);
359
360/**
361 * block_bio_queue - putting new block IO operation in queue
362 * @q: queue holding operation
363 * @bio: new block operation
364 *
365 * About to place the block IO operation @bio into queue @q.
366 */
367TRACE_EVENT(block_bio_queue,
368
369	TP_PROTO(struct request_queue *q, struct bio *bio),
370
371	TP_ARGS(q, bio),
372
373	TP_STRUCT__entry(
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	)
379	),
380
381	TP_fast_assign(
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);
387	),
388
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)
393);
394
395DECLARE_EVENT_CLASS(block_get_rq,
396
397	TP_PROTO(struct request_queue *q, struct bio *bio, int rw),
398
399	TP_ARGS(q, bio, rw),
400
401	TP_STRUCT__entry(
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	)
407        ),
408
409	TP_fast_assign(
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);
416        ),
417
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)
422);
423
424/**
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)
429 *
430 * A request struct for queue @q has been allocated to handle the
431 * block IO operation @bio.
432 */
433DEFINE_EVENT(block_get_rq, block_getrq,
434
435	TP_PROTO(struct request_queue *q, struct bio *bio, int rw),
436
437	TP_ARGS(q, bio, rw)
438);
439
440/**
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)
445 *
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.
450 */
451DEFINE_EVENT(block_get_rq, block_sleeprq,
452
453	TP_PROTO(struct request_queue *q, struct bio *bio, int rw),
454
455	TP_ARGS(q, bio, rw)
456);
457
458/**
459 * block_plug - keep operations requests in request queue
460 * @q: request queue to plug
461 *
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.
465 */
466TRACE_EVENT(block_plug,
467
468	TP_PROTO(struct request_queue *q),
469
470	TP_ARGS(q),
471
472	TP_STRUCT__entry(
473		__array( char,		comm,	TASK_COMM_LEN	)
474	),
475
476	TP_fast_assign(
477		memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
478	),
479
480	TP_printk("[%s]", __entry->comm)
481);
482
483DECLARE_EVENT_CLASS(block_unplug,
484
485	TP_PROTO(struct request_queue *q, unsigned int depth, bool explicit),
486
487	TP_ARGS(q, depth, explicit),
488
489	TP_STRUCT__entry(
490		__field( int,		nr_rq			)
491		__array( char,		comm,	TASK_COMM_LEN	)
492	),
493
494	TP_fast_assign(
495		__entry->nr_rq = depth;
496		memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
497	),
498
499	TP_printk("[%s] %d", __entry->comm, __entry->nr_rq)
500);
501
502/**
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()
507 *
508 * Unplug request queue @q because device driver is scheduled to work
509 * on elements in the request queue.
510 */
511DEFINE_EVENT(block_unplug, block_unplug,
512
513	TP_PROTO(struct request_queue *q, unsigned int depth, bool explicit),
514
515	TP_ARGS(q, depth, explicit)
516);
517
518/**
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
523 *
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.
528 */
529TRACE_EVENT(block_split,
530
531	TP_PROTO(struct request_queue *q, struct bio *bio,
532		 unsigned int new_sector),
533
534	TP_ARGS(q, bio, new_sector),
535
536	TP_STRUCT__entry(
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	)
542	),
543
544	TP_fast_assign(
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);
550	),
551
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,
556		  __entry->comm)
557);
558
559/**
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
565 *
566 * An operation for a logical device has been mapped to the
567 * raw block device.
568 */
569TRACE_EVENT(block_bio_remap,
570
571	TP_PROTO(struct request_queue *q, struct bio *bio, dev_t dev,
572		 sector_t from),
573
574	TP_ARGS(q, bio, dev, from),
575
576	TP_STRUCT__entry(
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)
583	),
584
585	TP_fast_assign(
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);
592	),
593
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,
597		  __entry->nr_sector,
598		  MAJOR(__entry->old_dev), MINOR(__entry->old_dev),
599		  (unsigned long long)__entry->old_sector)
600);
601
602/**
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
607 *
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.
611 */
612TRACE_EVENT(block_rq_remap,
613
614	TP_PROTO(struct request *rq, dev_t dev, sector_t from),
615
616	TP_ARGS(rq, dev, from),
617
618	TP_STRUCT__entry(
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)
626	),
627
628	TP_fast_assign(
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));
636	),
637
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,
641		  __entry->nr_sector,
642		  MAJOR(__entry->old_dev), MINOR(__entry->old_dev),
643		  (unsigned long long)__entry->old_sector, __entry->nr_bios)
644);
645
646#endif /* _TRACE_BLOCK_H */
647
648/* This part must be outside protection */
649#include <trace/define_trace.h>
650
651