block.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #undef TRACE_SYSTEM
  3. #define TRACE_SYSTEM block
  4. #if !defined(_TRACE_BLOCK_H) || defined(TRACE_HEADER_MULTI_READ)
  5. #define _TRACE_BLOCK_H
  6. #include <linux/blktrace_api.h>
  7. #include <linux/blkdev.h>
  8. #include <linux/buffer_head.h>
  9. #include <linux/tracepoint.h>
  10. #define RWBS_LEN 8
  11. DECLARE_EVENT_CLASS(block_buffer,
  12. TP_PROTO(struct buffer_head *bh),
  13. TP_ARGS(bh),
  14. TP_STRUCT__entry (
  15. __field( dev_t, dev )
  16. __field( sector_t, sector )
  17. __field( size_t, size )
  18. ),
  19. TP_fast_assign(
  20. __entry->dev = bh->b_bdev->bd_dev;
  21. __entry->sector = bh->b_blocknr;
  22. __entry->size = bh->b_size;
  23. ),
  24. TP_printk("%d,%d sector=%llu size=%zu",
  25. MAJOR(__entry->dev), MINOR(__entry->dev),
  26. (unsigned long long)__entry->sector, __entry->size
  27. )
  28. );
  29. /**
  30. * block_touch_buffer - mark a buffer accessed
  31. * @bh: buffer_head being touched
  32. *
  33. * Called from touch_buffer().
  34. */
  35. DEFINE_EVENT(block_buffer, block_touch_buffer,
  36. TP_PROTO(struct buffer_head *bh),
  37. TP_ARGS(bh)
  38. );
  39. /**
  40. * block_dirty_buffer - mark a buffer dirty
  41. * @bh: buffer_head being dirtied
  42. *
  43. * Called from mark_buffer_dirty().
  44. */
  45. DEFINE_EVENT(block_buffer, block_dirty_buffer,
  46. TP_PROTO(struct buffer_head *bh),
  47. TP_ARGS(bh)
  48. );
  49. /**
  50. * block_rq_requeue - place block IO request back on a queue
  51. * @rq: block IO operation request
  52. *
  53. * The block operation request @rq is being placed back into queue
  54. * @q. For some reason the request was not completed and needs to be
  55. * put back in the queue.
  56. */
  57. TRACE_EVENT(block_rq_requeue,
  58. TP_PROTO(struct request *rq),
  59. TP_ARGS(rq),
  60. TP_STRUCT__entry(
  61. __field( dev_t, dev )
  62. __field( sector_t, sector )
  63. __field( unsigned int, nr_sector )
  64. __array( char, rwbs, RWBS_LEN )
  65. __dynamic_array( char, cmd, 1 )
  66. ),
  67. TP_fast_assign(
  68. __entry->dev = rq->q->disk ? disk_devt(rq->q->disk) : 0;
  69. __entry->sector = blk_rq_trace_sector(rq);
  70. __entry->nr_sector = blk_rq_trace_nr_sectors(rq);
  71. blk_fill_rwbs(__entry->rwbs, rq->cmd_flags);
  72. __get_str(cmd)[0] = '\0';
  73. ),
  74. TP_printk("%d,%d %s (%s) %llu + %u [%d]",
  75. MAJOR(__entry->dev), MINOR(__entry->dev),
  76. __entry->rwbs, __get_str(cmd),
  77. (unsigned long long)__entry->sector,
  78. __entry->nr_sector, 0)
  79. );
  80. DECLARE_EVENT_CLASS(block_rq_completion,
  81. TP_PROTO(struct request *rq, blk_status_t error, unsigned int nr_bytes),
  82. TP_ARGS(rq, error, nr_bytes),
  83. TP_STRUCT__entry(
  84. __field( dev_t, dev )
  85. __field( sector_t, sector )
  86. __field( unsigned int, nr_sector )
  87. __field( int , error )
  88. __array( char, rwbs, RWBS_LEN )
  89. __dynamic_array( char, cmd, 1 )
  90. ),
  91. TP_fast_assign(
  92. __entry->dev = rq->q->disk ? disk_devt(rq->q->disk) : 0;
  93. __entry->sector = blk_rq_pos(rq);
  94. __entry->nr_sector = nr_bytes >> 9;
  95. __entry->error = blk_status_to_errno(error);
  96. blk_fill_rwbs(__entry->rwbs, rq->cmd_flags);
  97. __get_str(cmd)[0] = '\0';
  98. ),
  99. TP_printk("%d,%d %s (%s) %llu + %u [%d]",
  100. MAJOR(__entry->dev), MINOR(__entry->dev),
  101. __entry->rwbs, __get_str(cmd),
  102. (unsigned long long)__entry->sector,
  103. __entry->nr_sector, __entry->error)
  104. );
  105. /**
  106. * block_rq_complete - block IO operation completed by device driver
  107. * @rq: block operations request
  108. * @error: status code
  109. * @nr_bytes: number of completed bytes
  110. *
  111. * The block_rq_complete tracepoint event indicates that some portion
  112. * of operation request has been completed by the device driver. If
  113. * the @rq->bio is %NULL, then there is absolutely no additional work to
  114. * do for the request. If @rq->bio is non-NULL then there is
  115. * additional work required to complete the request.
  116. */
  117. DEFINE_EVENT(block_rq_completion, block_rq_complete,
  118. TP_PROTO(struct request *rq, blk_status_t error, unsigned int nr_bytes),
  119. TP_ARGS(rq, error, nr_bytes)
  120. );
  121. /**
  122. * block_rq_error - block IO operation error reported by device driver
  123. * @rq: block operations request
  124. * @error: status code
  125. * @nr_bytes: number of completed bytes
  126. *
  127. * The block_rq_error tracepoint event indicates that some portion
  128. * of operation request has failed as reported by the device driver.
  129. */
  130. DEFINE_EVENT(block_rq_completion, block_rq_error,
  131. TP_PROTO(struct request *rq, blk_status_t error, unsigned int nr_bytes),
  132. TP_ARGS(rq, error, nr_bytes)
  133. );
  134. DECLARE_EVENT_CLASS(block_rq,
  135. TP_PROTO(struct request *rq),
  136. TP_ARGS(rq),
  137. TP_STRUCT__entry(
  138. __field( dev_t, dev )
  139. __field( sector_t, sector )
  140. __field( unsigned int, nr_sector )
  141. __field( unsigned int, bytes )
  142. __array( char, rwbs, RWBS_LEN )
  143. __array( char, comm, TASK_COMM_LEN )
  144. __dynamic_array( char, cmd, 1 )
  145. ),
  146. TP_fast_assign(
  147. __entry->dev = rq->q->disk ? disk_devt(rq->q->disk) : 0;
  148. __entry->sector = blk_rq_trace_sector(rq);
  149. __entry->nr_sector = blk_rq_trace_nr_sectors(rq);
  150. __entry->bytes = blk_rq_bytes(rq);
  151. blk_fill_rwbs(__entry->rwbs, rq->cmd_flags);
  152. __get_str(cmd)[0] = '\0';
  153. memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
  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. * block_rq_insert - insert block operation request into queue
  163. * @rq: block IO operation request
  164. *
  165. * Called immediately before block operation request @rq is inserted
  166. * into queue @q. The fields in the operation request @rq struct can
  167. * be examined to determine which device and sectors the pending
  168. * operation would access.
  169. */
  170. DEFINE_EVENT(block_rq, block_rq_insert,
  171. TP_PROTO(struct request *rq),
  172. TP_ARGS(rq)
  173. );
  174. /**
  175. * block_rq_issue - issue pending block IO request operation to device driver
  176. * @rq: block IO operation request
  177. *
  178. * Called when block operation request @rq from queue @q is sent to a
  179. * device driver for processing.
  180. */
  181. DEFINE_EVENT(block_rq, block_rq_issue,
  182. TP_PROTO(struct request *rq),
  183. TP_ARGS(rq)
  184. );
  185. /**
  186. * block_rq_merge - merge request with another one in the elevator
  187. * @rq: block IO operation request
  188. *
  189. * Called when block operation request @rq from queue @q is merged to another
  190. * request queued in the elevator.
  191. */
  192. DEFINE_EVENT(block_rq, block_rq_merge,
  193. TP_PROTO(struct request *rq),
  194. TP_ARGS(rq)
  195. );
  196. /**
  197. * block_bio_complete - completed all work on the block operation
  198. * @q: queue holding the block operation
  199. * @bio: block operation completed
  200. *
  201. * This tracepoint indicates there is no further work to do on this
  202. * block IO operation @bio.
  203. */
  204. TRACE_EVENT(block_bio_complete,
  205. TP_PROTO(struct request_queue *q, struct bio *bio),
  206. TP_ARGS(q, bio),
  207. TP_STRUCT__entry(
  208. __field( dev_t, dev )
  209. __field( sector_t, sector )
  210. __field( unsigned, nr_sector )
  211. __field( int, error )
  212. __array( char, rwbs, RWBS_LEN)
  213. ),
  214. TP_fast_assign(
  215. __entry->dev = bio_dev(bio);
  216. __entry->sector = bio->bi_iter.bi_sector;
  217. __entry->nr_sector = bio_sectors(bio);
  218. __entry->error = blk_status_to_errno(bio->bi_status);
  219. blk_fill_rwbs(__entry->rwbs, bio->bi_opf);
  220. ),
  221. TP_printk("%d,%d %s %llu + %u [%d]",
  222. MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
  223. (unsigned long long)__entry->sector,
  224. __entry->nr_sector, __entry->error)
  225. );
  226. DECLARE_EVENT_CLASS(block_bio,
  227. TP_PROTO(struct bio *bio),
  228. TP_ARGS(bio),
  229. TP_STRUCT__entry(
  230. __field( dev_t, dev )
  231. __field( sector_t, sector )
  232. __field( unsigned int, nr_sector )
  233. __array( char, rwbs, RWBS_LEN )
  234. __array( char, comm, TASK_COMM_LEN )
  235. ),
  236. TP_fast_assign(
  237. __entry->dev = bio_dev(bio);
  238. __entry->sector = bio->bi_iter.bi_sector;
  239. __entry->nr_sector = bio_sectors(bio);
  240. blk_fill_rwbs(__entry->rwbs, bio->bi_opf);
  241. memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
  242. ),
  243. TP_printk("%d,%d %s %llu + %u [%s]",
  244. MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
  245. (unsigned long long)__entry->sector,
  246. __entry->nr_sector, __entry->comm)
  247. );
  248. /**
  249. * block_bio_bounce - used bounce buffer when processing block operation
  250. * @bio: block operation
  251. *
  252. * A bounce buffer was used to handle the block operation @bio in @q.
  253. * This occurs when hardware limitations prevent a direct transfer of
  254. * data between the @bio data memory area and the IO device. Use of a
  255. * bounce buffer requires extra copying of data and decreases
  256. * performance.
  257. */
  258. DEFINE_EVENT(block_bio, block_bio_bounce,
  259. TP_PROTO(struct bio *bio),
  260. TP_ARGS(bio)
  261. );
  262. /**
  263. * block_bio_backmerge - merging block operation to the end of an existing operation
  264. * @bio: new block operation to merge
  265. *
  266. * Merging block request @bio to the end of an existing block request.
  267. */
  268. DEFINE_EVENT(block_bio, block_bio_backmerge,
  269. TP_PROTO(struct bio *bio),
  270. TP_ARGS(bio)
  271. );
  272. /**
  273. * block_bio_frontmerge - merging block operation to the beginning of an existing operation
  274. * @bio: new block operation to merge
  275. *
  276. * Merging block IO operation @bio to the beginning of an existing block request.
  277. */
  278. DEFINE_EVENT(block_bio, block_bio_frontmerge,
  279. TP_PROTO(struct bio *bio),
  280. TP_ARGS(bio)
  281. );
  282. /**
  283. * block_bio_queue - putting new block IO operation in queue
  284. * @bio: new block operation
  285. *
  286. * About to place the block IO operation @bio into queue @q.
  287. */
  288. DEFINE_EVENT(block_bio, block_bio_queue,
  289. TP_PROTO(struct bio *bio),
  290. TP_ARGS(bio)
  291. );
  292. /**
  293. * block_getrq - get a free request entry in queue for block IO operations
  294. * @bio: pending block IO operation (can be %NULL)
  295. *
  296. * A request struct has been allocated to handle the block IO operation @bio.
  297. */
  298. DEFINE_EVENT(block_bio, block_getrq,
  299. TP_PROTO(struct bio *bio),
  300. TP_ARGS(bio)
  301. );
  302. /**
  303. * block_plug - keep operations requests in request queue
  304. * @q: request queue to plug
  305. *
  306. * Plug the request queue @q. Do not allow block operation requests
  307. * to be sent to the device driver. Instead, accumulate requests in
  308. * the queue to improve throughput performance of the block device.
  309. */
  310. TRACE_EVENT(block_plug,
  311. TP_PROTO(struct request_queue *q),
  312. TP_ARGS(q),
  313. TP_STRUCT__entry(
  314. __array( char, comm, TASK_COMM_LEN )
  315. ),
  316. TP_fast_assign(
  317. memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
  318. ),
  319. TP_printk("[%s]", __entry->comm)
  320. );
  321. DECLARE_EVENT_CLASS(block_unplug,
  322. TP_PROTO(struct request_queue *q, unsigned int depth, bool explicit),
  323. TP_ARGS(q, depth, explicit),
  324. TP_STRUCT__entry(
  325. __field( int, nr_rq )
  326. __array( char, comm, TASK_COMM_LEN )
  327. ),
  328. TP_fast_assign(
  329. __entry->nr_rq = depth;
  330. memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
  331. ),
  332. TP_printk("[%s] %d", __entry->comm, __entry->nr_rq)
  333. );
  334. /**
  335. * block_unplug - release of operations requests in request queue
  336. * @q: request queue to unplug
  337. * @depth: number of requests just added to the queue
  338. * @explicit: whether this was an explicit unplug, or one from schedule()
  339. *
  340. * Unplug request queue @q because device driver is scheduled to work
  341. * on elements in the request queue.
  342. */
  343. DEFINE_EVENT(block_unplug, block_unplug,
  344. TP_PROTO(struct request_queue *q, unsigned int depth, bool explicit),
  345. TP_ARGS(q, depth, explicit)
  346. );
  347. /**
  348. * block_split - split a single bio struct into two bio structs
  349. * @bio: block operation being split
  350. * @new_sector: The starting sector for the new bio
  351. *
  352. * The bio request @bio needs to be split into two bio requests. The newly
  353. * created @bio request starts at @new_sector. This split may be required due to
  354. * hardware limitations such as operation crossing device boundaries in a RAID
  355. * system.
  356. */
  357. TRACE_EVENT(block_split,
  358. TP_PROTO(struct bio *bio, unsigned int new_sector),
  359. TP_ARGS(bio, new_sector),
  360. TP_STRUCT__entry(
  361. __field( dev_t, dev )
  362. __field( sector_t, sector )
  363. __field( sector_t, new_sector )
  364. __array( char, rwbs, RWBS_LEN )
  365. __array( char, comm, TASK_COMM_LEN )
  366. ),
  367. TP_fast_assign(
  368. __entry->dev = bio_dev(bio);
  369. __entry->sector = bio->bi_iter.bi_sector;
  370. __entry->new_sector = new_sector;
  371. blk_fill_rwbs(__entry->rwbs, bio->bi_opf);
  372. memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
  373. ),
  374. TP_printk("%d,%d %s %llu / %llu [%s]",
  375. MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
  376. (unsigned long long)__entry->sector,
  377. (unsigned long long)__entry->new_sector,
  378. __entry->comm)
  379. );
  380. /**
  381. * block_bio_remap - map request for a logical device to the raw device
  382. * @bio: revised operation
  383. * @dev: original device for the operation
  384. * @from: original sector for the operation
  385. *
  386. * An operation for a logical device has been mapped to the
  387. * raw block device.
  388. */
  389. TRACE_EVENT(block_bio_remap,
  390. TP_PROTO(struct bio *bio, dev_t dev, sector_t from),
  391. TP_ARGS(bio, dev, from),
  392. TP_STRUCT__entry(
  393. __field( dev_t, dev )
  394. __field( sector_t, sector )
  395. __field( unsigned int, nr_sector )
  396. __field( dev_t, old_dev )
  397. __field( sector_t, old_sector )
  398. __array( char, rwbs, RWBS_LEN)
  399. ),
  400. TP_fast_assign(
  401. __entry->dev = bio_dev(bio);
  402. __entry->sector = bio->bi_iter.bi_sector;
  403. __entry->nr_sector = bio_sectors(bio);
  404. __entry->old_dev = dev;
  405. __entry->old_sector = from;
  406. blk_fill_rwbs(__entry->rwbs, bio->bi_opf);
  407. ),
  408. TP_printk("%d,%d %s %llu + %u <- (%d,%d) %llu",
  409. MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
  410. (unsigned long long)__entry->sector,
  411. __entry->nr_sector,
  412. MAJOR(__entry->old_dev), MINOR(__entry->old_dev),
  413. (unsigned long long)__entry->old_sector)
  414. );
  415. /**
  416. * block_rq_remap - map request for a block operation request
  417. * @rq: block IO operation request
  418. * @dev: device for the operation
  419. * @from: original sector for the operation
  420. *
  421. * The block operation request @rq in @q has been remapped. The block
  422. * operation request @rq holds the current information and @from hold
  423. * the original sector.
  424. */
  425. TRACE_EVENT(block_rq_remap,
  426. TP_PROTO(struct request *rq, dev_t dev, sector_t from),
  427. TP_ARGS(rq, dev, from),
  428. TP_STRUCT__entry(
  429. __field( dev_t, dev )
  430. __field( sector_t, sector )
  431. __field( unsigned int, nr_sector )
  432. __field( dev_t, old_dev )
  433. __field( sector_t, old_sector )
  434. __field( unsigned int, nr_bios )
  435. __array( char, rwbs, RWBS_LEN)
  436. ),
  437. TP_fast_assign(
  438. __entry->dev = disk_devt(rq->q->disk);
  439. __entry->sector = blk_rq_pos(rq);
  440. __entry->nr_sector = blk_rq_sectors(rq);
  441. __entry->old_dev = dev;
  442. __entry->old_sector = from;
  443. __entry->nr_bios = blk_rq_count_bios(rq);
  444. blk_fill_rwbs(__entry->rwbs, rq->cmd_flags);
  445. ),
  446. TP_printk("%d,%d %s %llu + %u <- (%d,%d) %llu %u",
  447. MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
  448. (unsigned long long)__entry->sector,
  449. __entry->nr_sector,
  450. MAJOR(__entry->old_dev), MINOR(__entry->old_dev),
  451. (unsigned long long)__entry->old_sector, __entry->nr_bios)
  452. );
  453. #endif /* _TRACE_BLOCK_H */
  454. /* This part must be outside protection */
  455. #include <trace/define_trace.h>