block.h 16 KB

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