block.h 15 KB

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