Update README.md for supported kernel
[lttng-modules.git] / instrumentation / events / lttng-module / block.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #undef TRACE_SYSTEM
3 #define TRACE_SYSTEM block
4
5 #if !defined(LTTNG_TRACE_BLOCK_H) || defined(TRACE_HEADER_MULTI_READ)
6 #define LTTNG_TRACE_BLOCK_H
7
8 #include <probes/lttng-tracepoint-event.h>
9 #include <linux/blktrace_api.h>
10 #include <linux/blkdev.h>
11 #include <linux/trace_seq.h>
12
13 #include <scsi/scsi_request.h>
14
15 #ifndef _TRACE_BLOCK_DEF_
16 #define _TRACE_BLOCK_DEF_
17
18 enum {
19 RWBS_FLAG_WRITE = (1 << 0),
20 RWBS_FLAG_DISCARD = (1 << 1),
21 RWBS_FLAG_READ = (1 << 2),
22 RWBS_FLAG_RAHEAD = (1 << 3),
23 RWBS_FLAG_BARRIER = (1 << 4),
24 RWBS_FLAG_SYNC = (1 << 5),
25 RWBS_FLAG_META = (1 << 6),
26 RWBS_FLAG_SECURE = (1 << 7),
27 RWBS_FLAG_FLUSH = (1 << 8),
28 RWBS_FLAG_FUA = (1 << 9),
29 RWBS_FLAG_PREFLUSH = (1 << 10),
30 };
31
32 #endif /* _TRACE_BLOCK_DEF_ */
33
34 LTTNG_TRACEPOINT_ENUM(block_rq_type,
35 TP_ENUM_VALUES(
36 ctf_enum_value("RWBS_FLAG_WRITE", RWBS_FLAG_WRITE)
37 ctf_enum_value("RWBS_FLAG_DISCARD", RWBS_FLAG_DISCARD)
38 ctf_enum_value("RWBS_FLAG_READ", RWBS_FLAG_READ)
39 ctf_enum_value("RWBS_FLAG_RAHEAD", RWBS_FLAG_RAHEAD)
40 ctf_enum_value("RWBS_FLAG_BARRIER", RWBS_FLAG_BARRIER)
41 ctf_enum_value("RWBS_FLAG_SYNC", RWBS_FLAG_SYNC)
42 ctf_enum_value("RWBS_FLAG_META", RWBS_FLAG_META)
43 ctf_enum_value("RWBS_FLAG_SECURE", RWBS_FLAG_SECURE)
44 ctf_enum_value("RWBS_FLAG_FLUSH", RWBS_FLAG_FLUSH)
45 ctf_enum_value("RWBS_FLAG_FUA", RWBS_FLAG_FUA)
46 ctf_enum_value("RWBS_FLAG_PREFLUSH", RWBS_FLAG_PREFLUSH)
47 )
48 )
49
50 #define lttng_req_op(rq) req_op(rq)
51 #define lttng_req_rw(rq) ((rq)->cmd_flags)
52 #define lttng_bio_op(bio) bio_op(bio)
53 #define lttng_bio_rw(bio) ((bio)->bi_opf)
54
55 #define blk_rwbs_ctf_integer(type, rwbs, op, rw, bytes) \
56 ctf_enum(block_rq_type, type, rwbs, \
57 (((op) == REQ_OP_WRITE || (op) == REQ_OP_WRITE_SAME) ? RWBS_FLAG_WRITE : \
58 ( (op) == REQ_OP_DISCARD ? RWBS_FLAG_DISCARD : \
59 ( (op) == REQ_OP_SECURE_ERASE ? (RWBS_FLAG_DISCARD | RWBS_FLAG_SECURE) : \
60 ( (op) == REQ_OP_FLUSH ? RWBS_FLAG_FLUSH : \
61 ( (op) == REQ_OP_READ ? RWBS_FLAG_READ : \
62 ( 0 )))))) \
63 | ((rw) & REQ_RAHEAD ? RWBS_FLAG_RAHEAD : 0) \
64 | ((rw) & REQ_SYNC ? RWBS_FLAG_SYNC : 0) \
65 | ((rw) & REQ_META ? RWBS_FLAG_META : 0) \
66 | ((rw) & REQ_PREFLUSH ? RWBS_FLAG_PREFLUSH : 0) \
67 | ((rw) & REQ_FUA ? RWBS_FLAG_FUA : 0))
68
69 LTTNG_TRACEPOINT_EVENT_CLASS(block_buffer,
70
71 TP_PROTO(struct buffer_head *bh),
72
73 TP_ARGS(bh),
74
75 TP_FIELDS (
76 ctf_integer(dev_t, dev, bh->b_bdev->bd_dev)
77 ctf_integer(sector_t, sector, bh->b_blocknr)
78 ctf_integer(size_t, size, bh->b_size)
79 )
80 )
81
82 /**
83 * block_touch_buffer - mark a buffer accessed
84 * @bh: buffer_head being touched
85 *
86 * Called from touch_buffer().
87 */
88 LTTNG_TRACEPOINT_EVENT_INSTANCE(block_buffer, block_touch_buffer,
89
90 TP_PROTO(struct buffer_head *bh),
91
92 TP_ARGS(bh)
93 )
94
95 /**
96 * block_dirty_buffer - mark a buffer dirty
97 * @bh: buffer_head being dirtied
98 *
99 * Called from mark_buffer_dirty().
100 */
101 LTTNG_TRACEPOINT_EVENT_INSTANCE(block_buffer, block_dirty_buffer,
102
103 TP_PROTO(struct buffer_head *bh),
104
105 TP_ARGS(bh)
106 )
107
108 /**
109 * block_rq_requeue - place block IO request back on a queue
110 * @q: queue holding operation
111 * @rq: block IO operation request
112 *
113 * The block operation request @rq is being placed back into queue
114 * @q. For some reason the request was not completed and needs to be
115 * put back in the queue.
116 */
117 LTTNG_TRACEPOINT_EVENT(block_rq_requeue,
118
119 TP_PROTO(struct request_queue *q, struct request *rq),
120
121 TP_ARGS(q, rq),
122
123 TP_FIELDS(
124 ctf_integer(dev_t, dev,
125 rq->rq_disk ? disk_devt(rq->rq_disk) : 0)
126 ctf_integer(sector_t, sector, blk_rq_trace_sector(rq))
127 ctf_integer(unsigned int, nr_sector, blk_rq_trace_nr_sectors(rq))
128 blk_rwbs_ctf_integer(unsigned int, rwbs,
129 lttng_req_op(rq), lttng_req_rw(rq), blk_rq_bytes(rq))
130 )
131 )
132
133 /**
134 * block_rq_complete - block IO operation completed by device driver
135 * @q: queue containing the block operation request
136 * @rq: block operations request
137 * @nr_bytes: number of completed bytes
138 *
139 * The block_rq_complete tracepoint event indicates that some portion
140 * of operation request has been completed by the device driver. If
141 * the @rq->bio is %NULL, then there is absolutely no additional work to
142 * do for the request. If @rq->bio is non-NULL then there is
143 * additional work required to complete the request.
144 */
145 LTTNG_TRACEPOINT_EVENT(block_rq_complete,
146
147 TP_PROTO(struct request *rq, int error, unsigned int nr_bytes),
148
149 TP_ARGS(rq, error, nr_bytes),
150
151 TP_FIELDS(
152 ctf_integer(dev_t, dev,
153 rq->rq_disk ? disk_devt(rq->rq_disk) : 0)
154 ctf_integer(sector_t, sector, blk_rq_pos(rq))
155 ctf_integer(unsigned int, nr_sector, nr_bytes >> 9)
156 ctf_integer(int, error, error)
157 blk_rwbs_ctf_integer(unsigned int, rwbs,
158 lttng_req_op(rq), lttng_req_rw(rq), nr_bytes)
159 )
160 )
161
162 LTTNG_TRACEPOINT_EVENT_CLASS(block_rq,
163
164 TP_PROTO(struct request_queue *q, struct request *rq),
165
166 TP_ARGS(q, rq),
167
168 TP_FIELDS(
169 ctf_integer(dev_t, dev,
170 rq->rq_disk ? disk_devt(rq->rq_disk) : 0)
171 ctf_integer(sector_t, sector, blk_rq_trace_sector(rq))
172 ctf_integer(unsigned int, nr_sector, blk_rq_trace_nr_sectors(rq))
173 ctf_integer(unsigned int, bytes, blk_rq_bytes(rq))
174 ctf_integer(pid_t, tid, current->pid)
175 blk_rwbs_ctf_integer(unsigned int, rwbs,
176 lttng_req_op(rq), lttng_req_rw(rq), blk_rq_bytes(rq))
177 ctf_array_text(char, comm, current->comm, TASK_COMM_LEN)
178 )
179 )
180
181 /**
182 * block_rq_insert - insert block operation request into queue
183 * @q: target queue
184 * @rq: block IO operation request
185 *
186 * Called immediately before block operation request @rq is inserted
187 * into queue @q. The fields in the operation request @rq struct can
188 * be examined to determine which device and sectors the pending
189 * operation would access.
190 */
191 LTTNG_TRACEPOINT_EVENT_INSTANCE(block_rq, block_rq_insert,
192
193 TP_PROTO(struct request_queue *q, struct request *rq),
194
195 TP_ARGS(q, rq)
196 )
197
198 /**
199 * block_rq_issue - issue pending block IO request operation to device driver
200 * @q: queue holding operation
201 * @rq: block IO operation operation request
202 *
203 * Called when block operation request @rq from queue @q is sent to a
204 * device driver for processing.
205 */
206 LTTNG_TRACEPOINT_EVENT_INSTANCE(block_rq, block_rq_issue,
207
208 TP_PROTO(struct request_queue *q, struct request *rq),
209
210 TP_ARGS(q, rq)
211 )
212
213 /**
214 * block_bio_bounce - used bounce buffer when processing block operation
215 * @q: queue holding the block operation
216 * @bio: block operation
217 *
218 * A bounce buffer was used to handle the block operation @bio in @q.
219 * This occurs when hardware limitations prevent a direct transfer of
220 * data between the @bio data memory area and the IO device. Use of a
221 * bounce buffer requires extra copying of data and decreases
222 * performance.
223 */
224 LTTNG_TRACEPOINT_EVENT(block_bio_bounce,
225
226 TP_PROTO(struct request_queue *q, struct bio *bio),
227
228 TP_ARGS(q, bio),
229
230 TP_FIELDS(
231 ctf_integer(dev_t, dev, bio_dev(bio))
232 ctf_integer(sector_t, sector, bio->bi_iter.bi_sector)
233 ctf_integer(unsigned int, nr_sector, bio_sectors(bio))
234 blk_rwbs_ctf_integer(unsigned int, rwbs,
235 lttng_bio_op(bio), lttng_bio_rw(bio),
236 bio->bi_iter.bi_size)
237 ctf_integer(pid_t, tid, current->pid)
238 ctf_array_text(char, comm, current->comm, TASK_COMM_LEN)
239 )
240 )
241
242 /**
243 * block_bio_complete - completed all work on the block operation
244 * @q: queue holding the block operation
245 * @bio: block operation completed
246 * @error: io error value
247 *
248 * This tracepoint indicates there is no further work to do on this
249 * block IO operation @bio.
250 */
251 LTTNG_TRACEPOINT_EVENT(block_bio_complete,
252
253 TP_PROTO(struct request_queue *q, struct bio *bio, int error),
254
255 TP_ARGS(q, bio, error),
256
257 TP_FIELDS(
258 ctf_integer(dev_t, dev, bio_dev(bio))
259 ctf_integer(sector_t, sector, bio->bi_iter.bi_sector)
260 ctf_integer(unsigned int, nr_sector, bio_sectors(bio))
261 ctf_integer(int, error, error)
262 blk_rwbs_ctf_integer(unsigned int, rwbs,
263 lttng_bio_op(bio), lttng_bio_rw(bio),
264 bio->bi_iter.bi_size)
265 )
266 )
267
268 LTTNG_TRACEPOINT_EVENT_CLASS(block_bio_merge,
269
270 TP_PROTO(struct request_queue *q, struct request *rq, struct bio *bio),
271
272 TP_ARGS(q, rq, bio),
273
274 TP_FIELDS(
275 ctf_integer(dev_t, dev, bio_dev(bio))
276 ctf_integer(sector_t, sector, bio->bi_iter.bi_sector)
277 ctf_integer(unsigned int, nr_sector, bio_sectors(bio))
278 blk_rwbs_ctf_integer(unsigned int, rwbs,
279 lttng_bio_op(bio), lttng_bio_rw(bio),
280 bio->bi_iter.bi_size)
281 ctf_integer(pid_t, tid, current->pid)
282 ctf_array_text(char, comm, current->comm, TASK_COMM_LEN)
283 )
284 )
285
286 /**
287 * block_bio_backmerge - merging block operation to the end of an existing operation
288 * @q: queue holding operation
289 * @bio: new block operation to merge
290 *
291 * Merging block request @bio to the end of an existing block request
292 * in queue @q.
293 */
294 LTTNG_TRACEPOINT_EVENT_INSTANCE(block_bio_merge, block_bio_backmerge,
295
296 TP_PROTO(struct request_queue *q, struct request *rq, struct bio *bio),
297
298 TP_ARGS(q, rq, bio)
299 )
300
301 /**
302 * block_bio_frontmerge - merging block operation to the beginning of an existing operation
303 * @q: queue holding operation
304 * @bio: new block operation to merge
305 *
306 * Merging block IO operation @bio to the beginning of an existing block
307 * operation in queue @q.
308 */
309 LTTNG_TRACEPOINT_EVENT_INSTANCE(block_bio_merge, block_bio_frontmerge,
310
311 TP_PROTO(struct request_queue *q, struct request *rq, struct bio *bio),
312
313 TP_ARGS(q, rq, bio)
314 )
315
316 /**
317 * block_bio_queue - putting new block IO operation in queue
318 * @q: queue holding operation
319 * @bio: new block operation
320 *
321 * About to place the block IO operation @bio into queue @q.
322 */
323 LTTNG_TRACEPOINT_EVENT(block_bio_queue,
324
325 TP_PROTO(struct request_queue *q, struct bio *bio),
326
327 TP_ARGS(q, bio),
328
329 TP_FIELDS(
330 ctf_integer(dev_t, dev, bio_dev(bio))
331 ctf_integer(sector_t, sector, bio->bi_iter.bi_sector)
332 ctf_integer(unsigned int, nr_sector, bio_sectors(bio))
333 blk_rwbs_ctf_integer(unsigned int, rwbs,
334 lttng_bio_op(bio), lttng_bio_rw(bio),
335 bio->bi_iter.bi_size)
336 ctf_integer(pid_t, tid, current->pid)
337 ctf_array_text(char, comm, current->comm, TASK_COMM_LEN)
338 )
339 )
340
341 LTTNG_TRACEPOINT_EVENT_CLASS(block_get_rq,
342
343 TP_PROTO(struct request_queue *q, struct bio *bio, int rw),
344
345 TP_ARGS(q, bio, rw),
346
347 TP_FIELDS(
348 ctf_integer(dev_t, dev, bio ? bio_dev(bio) : 0)
349 ctf_integer(sector_t, sector, bio ? bio->bi_iter.bi_sector : 0)
350 ctf_integer(unsigned int, nr_sector,
351 bio ? bio_sectors(bio) : 0)
352 blk_rwbs_ctf_integer(unsigned int, rwbs,
353 bio ? lttng_bio_op(bio) : 0,
354 bio ? lttng_bio_rw(bio) : 0,
355 bio ? bio->bi_iter.bi_size : 0)
356 ctf_integer(pid_t, tid, current->pid)
357 ctf_array_text(char, comm, current->comm, TASK_COMM_LEN)
358 )
359 )
360
361 /**
362 * block_getrq - get a free request entry in queue for block IO operations
363 * @q: queue for operations
364 * @bio: pending block IO operation (can be %NULL)
365 * @rw: low bit indicates a read (%0) or a write (%1)
366 *
367 * A request struct for queue @q has been allocated to handle the
368 * block IO operation @bio.
369 */
370 LTTNG_TRACEPOINT_EVENT_INSTANCE(block_get_rq, block_getrq,
371
372 TP_PROTO(struct request_queue *q, struct bio *bio, int rw),
373
374 TP_ARGS(q, bio, rw)
375 )
376
377 /**
378 * block_sleeprq - waiting to get a free request entry in queue for block IO operation
379 * @q: queue for operation
380 * @bio: pending block IO operation (can be %NULL)
381 * @rw: low bit indicates a read (%0) or a write (%1)
382 *
383 * In the case where a request struct cannot be provided for queue @q
384 * the process needs to wait for an request struct to become
385 * available. This tracepoint event is generated each time the
386 * process goes to sleep waiting for request struct become available.
387 */
388 LTTNG_TRACEPOINT_EVENT_INSTANCE(block_get_rq, block_sleeprq,
389
390 TP_PROTO(struct request_queue *q, struct bio *bio, int rw),
391
392 TP_ARGS(q, bio, rw)
393 )
394
395 /**
396 * block_plug - keep operations requests in request queue
397 * @q: request queue to plug
398 *
399 * Plug the request queue @q. Do not allow block operation requests
400 * to be sent to the device driver. Instead, accumulate requests in
401 * the queue to improve throughput performance of the block device.
402 */
403 LTTNG_TRACEPOINT_EVENT(block_plug,
404
405 TP_PROTO(struct request_queue *q),
406
407 TP_ARGS(q),
408
409 TP_FIELDS(
410 ctf_integer(pid_t, tid, current->pid)
411 ctf_array_text(char, comm, current->comm, TASK_COMM_LEN)
412 )
413 )
414
415 LTTNG_TRACEPOINT_EVENT_CLASS(block_unplug,
416
417 TP_PROTO(struct request_queue *q, unsigned int depth, bool explicit),
418
419 TP_ARGS(q, depth, explicit),
420
421 TP_FIELDS(
422 ctf_integer(int, nr_rq, depth)
423 ctf_integer(pid_t, tid, current->pid)
424 ctf_array_text(char, comm, current->comm, TASK_COMM_LEN)
425 )
426 )
427
428 /**
429 * block_unplug - release of operations requests in request queue
430 * @q: request queue to unplug
431 * @depth: number of requests just added to the queue
432 * @explicit: whether this was an explicit unplug, or one from schedule()
433 *
434 * Unplug request queue @q because device driver is scheduled to work
435 * on elements in the request queue.
436 */
437 LTTNG_TRACEPOINT_EVENT_INSTANCE(block_unplug, block_unplug,
438
439 TP_PROTO(struct request_queue *q, unsigned int depth, bool explicit),
440
441 TP_ARGS(q, depth, explicit)
442 )
443
444 /**
445 * block_split - split a single bio struct into two bio structs
446 * @q: queue containing the bio
447 * @bio: block operation being split
448 * @new_sector: The starting sector for the new bio
449 *
450 * The bio request @bio in request queue @q needs to be split into two
451 * bio requests. The newly created @bio request starts at
452 * @new_sector. This split may be required due to hardware limitation
453 * such as operation crossing device boundaries in a RAID system.
454 */
455 LTTNG_TRACEPOINT_EVENT(block_split,
456
457 TP_PROTO(struct request_queue *q, struct bio *bio,
458 unsigned int new_sector),
459
460 TP_ARGS(q, bio, new_sector),
461
462 TP_FIELDS(
463 ctf_integer(dev_t, dev, bio_dev(bio))
464 ctf_integer(sector_t, sector, bio->bi_iter.bi_sector)
465 blk_rwbs_ctf_integer(unsigned int, rwbs,
466 lttng_bio_op(bio), lttng_bio_rw(bio),
467 bio->bi_iter.bi_size)
468 ctf_integer(sector_t, new_sector, new_sector)
469 ctf_integer(pid_t, tid, current->pid)
470 ctf_array_text(char, comm, current->comm, TASK_COMM_LEN)
471 )
472 )
473
474 /**
475 * block_bio_remap - map request for a logical device to the raw device
476 * @q: queue holding the operation
477 * @bio: revised operation
478 * @dev: device for the operation
479 * @from: original sector for the operation
480 *
481 * An operation for a logical device has been mapped to the
482 * raw block device.
483 */
484 LTTNG_TRACEPOINT_EVENT(block_bio_remap,
485
486 TP_PROTO(struct request_queue *q, struct bio *bio, dev_t dev,
487 sector_t from),
488
489 TP_ARGS(q, bio, dev, from),
490
491 TP_FIELDS(
492 ctf_integer(dev_t, dev, bio_dev(bio))
493 ctf_integer(sector_t, sector, bio->bi_iter.bi_sector)
494 ctf_integer(unsigned int, nr_sector, bio_sectors(bio))
495 blk_rwbs_ctf_integer(unsigned int, rwbs,
496 lttng_bio_op(bio), lttng_bio_rw(bio),
497 bio->bi_iter.bi_size)
498 ctf_integer(dev_t, old_dev, dev)
499 ctf_integer(sector_t, old_sector, from)
500 )
501 )
502
503 /**
504 * block_rq_remap - map request for a block operation request
505 * @q: queue holding the operation
506 * @rq: block IO operation request
507 * @dev: device for the operation
508 * @from: original sector for the operation
509 *
510 * The block operation request @rq in @q has been remapped. The block
511 * operation request @rq holds the current information and @from hold
512 * the original sector.
513 */
514 LTTNG_TRACEPOINT_EVENT(block_rq_remap,
515
516 TP_PROTO(struct request_queue *q, struct request *rq, dev_t dev,
517 sector_t from),
518
519 TP_ARGS(q, rq, dev, from),
520
521 TP_FIELDS(
522 ctf_integer(dev_t, dev, disk_devt(rq->rq_disk))
523 ctf_integer(sector_t, sector, blk_rq_pos(rq))
524 ctf_integer(unsigned int, nr_sector, blk_rq_sectors(rq))
525 ctf_integer(dev_t, old_dev, dev)
526 ctf_integer(sector_t, old_sector, from)
527 blk_rwbs_ctf_integer(unsigned int, rwbs,
528 lttng_req_op(rq), lttng_req_rw(rq), blk_rq_bytes(rq))
529 )
530 )
531
532 #undef __print_rwbs_flags
533 #undef blk_fill_rwbs
534
535 #endif /* LTTNG_TRACE_BLOCK_H */
536
537 /* This part must be outside protection */
538 #include <probes/define_trace.h>
This page took 0.039386 seconds and 4 git commands to generate.