block.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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(__entry->rwbs, rq->cmd_flags, blk_rq_bytes(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(__entry->rwbs, rq->cmd_flags, blk_rq_bytes(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. * @error: io error value
  172. *
  173. * This tracepoint indicates there is no further work to do on this
  174. * block IO operation @bio.
  175. */
  176. TRACE_EVENT(block_bio_complete,
  177. TP_PROTO(struct request_queue *q, struct bio *bio, int error),
  178. TP_ARGS(q, bio, error),
  179. TP_STRUCT__entry(
  180. __field( dev_t, dev )
  181. __field( sector_t, sector )
  182. __field( unsigned, nr_sector )
  183. __field( int, error )
  184. __array( char, rwbs, 6 )
  185. ),
  186. TP_fast_assign(
  187. __entry->dev = bio->bi_bdev->bd_dev;
  188. __entry->sector = bio->bi_sector;
  189. __entry->nr_sector = bio->bi_size >> 9;
  190. __entry->error = error;
  191. blk_fill_rwbs(__entry->rwbs, bio->bi_rw, bio->bi_size);
  192. ),
  193. TP_printk("%d,%d %s %llu + %u [%d]",
  194. MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
  195. (unsigned long long)__entry->sector,
  196. __entry->nr_sector, __entry->error)
  197. );
  198. DECLARE_EVENT_CLASS(block_bio,
  199. TP_PROTO(struct request_queue *q, struct bio *bio),
  200. TP_ARGS(q, bio),
  201. TP_STRUCT__entry(
  202. __field( dev_t, dev )
  203. __field( sector_t, sector )
  204. __field( unsigned int, nr_sector )
  205. __array( char, rwbs, 6 )
  206. __array( char, comm, TASK_COMM_LEN )
  207. ),
  208. TP_fast_assign(
  209. __entry->dev = bio->bi_bdev->bd_dev;
  210. __entry->sector = bio->bi_sector;
  211. __entry->nr_sector = bio->bi_size >> 9;
  212. blk_fill_rwbs(__entry->rwbs, bio->bi_rw, bio->bi_size);
  213. memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
  214. ),
  215. TP_printk("%d,%d %s %llu + %u [%s]",
  216. MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
  217. (unsigned long long)__entry->sector,
  218. __entry->nr_sector, __entry->comm)
  219. );
  220. /**
  221. * block_bio_backmerge - merging block operation to the end of an existing operation
  222. * @q: queue holding operation
  223. * @bio: new block operation to merge
  224. *
  225. * Merging block request @bio to the end of an existing block request
  226. * in queue @q.
  227. */
  228. DEFINE_EVENT(block_bio, block_bio_backmerge,
  229. TP_PROTO(struct request_queue *q, struct bio *bio),
  230. TP_ARGS(q, bio)
  231. );
  232. /**
  233. * block_bio_frontmerge - merging block operation to the beginning of an existing operation
  234. * @q: queue holding operation
  235. * @bio: new block operation to merge
  236. *
  237. * Merging block IO operation @bio to the beginning of an existing block
  238. * operation in queue @q.
  239. */
  240. DEFINE_EVENT(block_bio, block_bio_frontmerge,
  241. TP_PROTO(struct request_queue *q, struct bio *bio),
  242. TP_ARGS(q, bio)
  243. );
  244. /**
  245. * block_bio_queue - putting new block IO operation in queue
  246. * @q: queue holding operation
  247. * @bio: new block operation
  248. *
  249. * About to place the block IO operation @bio into queue @q.
  250. */
  251. DEFINE_EVENT(block_bio, block_bio_queue,
  252. TP_PROTO(struct request_queue *q, struct bio *bio),
  253. TP_ARGS(q, bio)
  254. );
  255. DECLARE_EVENT_CLASS(block_get_rq,
  256. TP_PROTO(struct request_queue *q, struct bio *bio, int rw),
  257. TP_ARGS(q, bio, rw),
  258. TP_STRUCT__entry(
  259. __field( dev_t, dev )
  260. __field( sector_t, sector )
  261. __field( unsigned int, nr_sector )
  262. __array( char, rwbs, 6 )
  263. __array( char, comm, TASK_COMM_LEN )
  264. ),
  265. TP_fast_assign(
  266. __entry->dev = bio ? bio->bi_bdev->bd_dev : 0;
  267. __entry->sector = bio ? bio->bi_sector : 0;
  268. __entry->nr_sector = bio ? bio->bi_size >> 9 : 0;
  269. blk_fill_rwbs(__entry->rwbs,
  270. bio ? bio->bi_rw : 0, __entry->nr_sector);
  271. memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
  272. ),
  273. TP_printk("%d,%d %s %llu + %u [%s]",
  274. MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
  275. (unsigned long long)__entry->sector,
  276. __entry->nr_sector, __entry->comm)
  277. );
  278. /**
  279. * block_getrq - get a free request entry in queue for block IO operations
  280. * @q: queue for operations
  281. * @bio: pending block IO operation
  282. * @rw: low bit indicates a read (%0) or a write (%1)
  283. *
  284. * A request struct for queue @q has been allocated to handle the
  285. * block IO operation @bio.
  286. */
  287. DEFINE_EVENT(block_get_rq, block_getrq,
  288. TP_PROTO(struct request_queue *q, struct bio *bio, int rw),
  289. TP_ARGS(q, bio, rw)
  290. );
  291. /**
  292. * block_sleeprq - waiting to get a free request entry in queue for block IO operation
  293. * @q: queue for operation
  294. * @bio: pending block IO operation
  295. * @rw: low bit indicates a read (%0) or a write (%1)
  296. *
  297. * In the case where a request struct cannot be provided for queue @q
  298. * the process needs to wait for an request struct to become
  299. * available. This tracepoint event is generated each time the
  300. * process goes to sleep waiting for request struct become available.
  301. */
  302. DEFINE_EVENT(block_get_rq, block_sleeprq,
  303. TP_PROTO(struct request_queue *q, struct bio *bio, int rw),
  304. TP_ARGS(q, bio, rw)
  305. );
  306. /**
  307. * block_plug - keep operations requests in request queue
  308. * @q: request queue to plug
  309. *
  310. * Plug the request queue @q. Do not allow block operation requests
  311. * to be sent to the device driver. Instead, accumulate requests in
  312. * the queue to improve throughput performance of the block device.
  313. */
  314. TRACE_EVENT(block_plug,
  315. TP_PROTO(struct request_queue *q),
  316. TP_ARGS(q),
  317. TP_STRUCT__entry(
  318. __array( char, comm, TASK_COMM_LEN )
  319. ),
  320. TP_fast_assign(
  321. memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
  322. ),
  323. TP_printk("[%s]", __entry->comm)
  324. );
  325. DECLARE_EVENT_CLASS(block_unplug,
  326. TP_PROTO(struct request_queue *q, unsigned int depth, bool explicit),
  327. TP_ARGS(q, depth, explicit),
  328. TP_STRUCT__entry(
  329. __field( int, nr_rq )
  330. __array( char, comm, TASK_COMM_LEN )
  331. ),
  332. TP_fast_assign(
  333. __entry->nr_rq = depth;
  334. memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
  335. ),
  336. TP_printk("[%s] %d", __entry->comm, __entry->nr_rq)
  337. );
  338. /**
  339. * block_unplug - release of operations requests in request queue
  340. * @q: request queue to unplug
  341. * @depth: number of requests just added to the queue
  342. * @explicit: whether this was an explicit unplug, or one from schedule()
  343. *
  344. * Unplug request queue @q because device driver is scheduled to work
  345. * on elements in the request queue.
  346. */
  347. DEFINE_EVENT(block_unplug, block_unplug,
  348. TP_PROTO(struct request_queue *q, unsigned int depth, bool explicit),
  349. TP_ARGS(q, depth, explicit)
  350. );
  351. /**
  352. * block_split - split a single bio struct into two bio structs
  353. * @q: queue containing the bio
  354. * @bio: block operation being split
  355. * @new_sector: The starting sector for the new bio
  356. *
  357. * The bio request @bio in request queue @q needs to be split into two
  358. * bio requests. The newly created @bio request starts at
  359. * @new_sector. This split may be required due to hardware limitation
  360. * such as operation crossing device boundaries in a RAID system.
  361. */
  362. TRACE_EVENT(block_split,
  363. TP_PROTO(struct request_queue *q, struct bio *bio,
  364. unsigned int new_sector),
  365. TP_ARGS(q, bio, new_sector),
  366. TP_STRUCT__entry(
  367. __field( dev_t, dev )
  368. __field( sector_t, sector )
  369. __field( sector_t, new_sector )
  370. __array( char, rwbs, 6 )
  371. __array( char, comm, TASK_COMM_LEN )
  372. ),
  373. TP_fast_assign(
  374. __entry->dev = bio->bi_bdev->bd_dev;
  375. __entry->sector = bio->bi_sector;
  376. __entry->new_sector = new_sector;
  377. blk_fill_rwbs(__entry->rwbs, bio->bi_rw, bio->bi_size);
  378. memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
  379. ),
  380. TP_printk("%d,%d %s %llu / %llu [%s]",
  381. MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
  382. (unsigned long long)__entry->sector,
  383. (unsigned long long)__entry->new_sector,
  384. __entry->comm)
  385. );
  386. /**
  387. * block_bio_remap - map request for a logical device to the raw device
  388. * @q: queue holding the operation
  389. * @bio: revised operation
  390. * @dev: device for the operation
  391. * @from: original sector for the operation
  392. *
  393. * An operation for a logical device has been mapped to the
  394. * raw block device.
  395. */
  396. TRACE_EVENT(block_bio_remap,
  397. TP_PROTO(struct request_queue *q, struct bio *bio, dev_t dev,
  398. sector_t from),
  399. TP_ARGS(q, bio, dev, from),
  400. TP_STRUCT__entry(
  401. __field( dev_t, dev )
  402. __field( sector_t, sector )
  403. __field( unsigned int, nr_sector )
  404. __field( dev_t, old_dev )
  405. __field( sector_t, old_sector )
  406. __array( char, rwbs, 6 )
  407. ),
  408. TP_fast_assign(
  409. __entry->dev = bio->bi_bdev->bd_dev;
  410. __entry->sector = bio->bi_sector;
  411. __entry->nr_sector = bio->bi_size >> 9;
  412. __entry->old_dev = dev;
  413. __entry->old_sector = from;
  414. blk_fill_rwbs(__entry->rwbs, bio->bi_rw, bio->bi_size);
  415. ),
  416. TP_printk("%d,%d %s %llu + %u <- (%d,%d) %llu",
  417. MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
  418. (unsigned long long)__entry->sector,
  419. __entry->nr_sector,
  420. MAJOR(__entry->old_dev), MINOR(__entry->old_dev),
  421. (unsigned long long)__entry->old_sector)
  422. );
  423. /**
  424. * block_rq_remap - map request for a block operation request
  425. * @q: queue holding the operation
  426. * @rq: block IO operation request
  427. * @dev: device for the operation
  428. * @from: original sector for the operation
  429. *
  430. * The block operation request @rq in @q has been remapped. The block
  431. * operation request @rq holds the current information and @from hold
  432. * the original sector.
  433. */
  434. TRACE_EVENT(block_rq_remap,
  435. TP_PROTO(struct request_queue *q, struct request *rq, dev_t dev,
  436. sector_t from),
  437. TP_ARGS(q, rq, dev, from),
  438. TP_STRUCT__entry(
  439. __field( dev_t, dev )
  440. __field( sector_t, sector )
  441. __field( unsigned int, nr_sector )
  442. __field( dev_t, old_dev )
  443. __field( sector_t, old_sector )
  444. __array( char, rwbs, 6 )
  445. ),
  446. TP_fast_assign(
  447. __entry->dev = disk_devt(rq->rq_disk);
  448. __entry->sector = blk_rq_pos(rq);
  449. __entry->nr_sector = blk_rq_sectors(rq);
  450. __entry->old_dev = dev;
  451. __entry->old_sector = from;
  452. blk_fill_rwbs(__entry->rwbs, rq->cmd_flags, blk_rq_bytes(rq));
  453. ),
  454. TP_printk("%d,%d %s %llu + %u <- (%d,%d) %llu",
  455. MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
  456. (unsigned long long)__entry->sector,
  457. __entry->nr_sector,
  458. MAJOR(__entry->old_dev), MINOR(__entry->old_dev),
  459. (unsigned long long)__entry->old_sector)
  460. );
  461. #endif /* _TRACE_BLOCK_H */
  462. /* This part must be outside protection */
  463. #include <trace/define_trace.h>