block.h 15 KB

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