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