io_uring.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #undef TRACE_SYSTEM
  3. #define TRACE_SYSTEM io_uring
  4. #if !defined(_TRACE_IO_URING_H) || defined(TRACE_HEADER_MULTI_READ)
  5. #define _TRACE_IO_URING_H
  6. #include <linux/tracepoint.h>
  7. #include <uapi/linux/io_uring.h>
  8. #include <linux/io_uring_types.h>
  9. #include <linux/io_uring.h>
  10. struct io_wq_work;
  11. /**
  12. * io_uring_create - called after a new io_uring context was prepared
  13. *
  14. * @fd: corresponding file descriptor
  15. * @ctx: pointer to a ring context structure
  16. * @sq_entries: actual SQ size
  17. * @cq_entries: actual CQ size
  18. * @flags: SQ ring flags, provided to io_uring_setup(2)
  19. *
  20. * Allows to trace io_uring creation and provide pointer to a context, that can
  21. * be used later to find correlated events.
  22. */
  23. TRACE_EVENT(io_uring_create,
  24. TP_PROTO(int fd, void *ctx, u32 sq_entries, u32 cq_entries, u32 flags),
  25. TP_ARGS(fd, ctx, sq_entries, cq_entries, flags),
  26. TP_STRUCT__entry (
  27. __field( int, fd )
  28. __field( void *, ctx )
  29. __field( u32, sq_entries )
  30. __field( u32, cq_entries )
  31. __field( u32, flags )
  32. ),
  33. TP_fast_assign(
  34. __entry->fd = fd;
  35. __entry->ctx = ctx;
  36. __entry->sq_entries = sq_entries;
  37. __entry->cq_entries = cq_entries;
  38. __entry->flags = flags;
  39. ),
  40. TP_printk("ring %p, fd %d sq size %d, cq size %d, flags 0x%x",
  41. __entry->ctx, __entry->fd, __entry->sq_entries,
  42. __entry->cq_entries, __entry->flags)
  43. );
  44. /**
  45. * io_uring_register - called after a buffer/file/eventfd was successfully
  46. * registered for a ring
  47. *
  48. * @ctx: pointer to a ring context structure
  49. * @opcode: describes which operation to perform
  50. * @nr_user_files: number of registered files
  51. * @nr_user_bufs: number of registered buffers
  52. * @ret: return code
  53. *
  54. * Allows to trace fixed files/buffers, that could be registered to
  55. * avoid an overhead of getting references to them for every operation. This
  56. * event, together with io_uring_file_get, can provide a full picture of how
  57. * much overhead one can reduce via fixing.
  58. */
  59. TRACE_EVENT(io_uring_register,
  60. TP_PROTO(void *ctx, unsigned opcode, unsigned nr_files,
  61. unsigned nr_bufs, long ret),
  62. TP_ARGS(ctx, opcode, nr_files, nr_bufs, ret),
  63. TP_STRUCT__entry (
  64. __field( void *, ctx )
  65. __field( unsigned, opcode )
  66. __field( unsigned, nr_files)
  67. __field( unsigned, nr_bufs )
  68. __field( long, ret )
  69. ),
  70. TP_fast_assign(
  71. __entry->ctx = ctx;
  72. __entry->opcode = opcode;
  73. __entry->nr_files = nr_files;
  74. __entry->nr_bufs = nr_bufs;
  75. __entry->ret = ret;
  76. ),
  77. TP_printk("ring %p, opcode %d, nr_user_files %d, nr_user_bufs %d, "
  78. "ret %ld",
  79. __entry->ctx, __entry->opcode, __entry->nr_files,
  80. __entry->nr_bufs, __entry->ret)
  81. );
  82. /**
  83. * io_uring_file_get - called before getting references to an SQE file
  84. *
  85. * @req: pointer to a submitted request
  86. * @fd: SQE file descriptor
  87. *
  88. * Allows to trace out how often an SQE file reference is obtained, which can
  89. * help figuring out if it makes sense to use fixed files, or check that fixed
  90. * files are used correctly.
  91. */
  92. TRACE_EVENT(io_uring_file_get,
  93. TP_PROTO(struct io_kiocb *req, int fd),
  94. TP_ARGS(req, fd),
  95. TP_STRUCT__entry (
  96. __field( void *, ctx )
  97. __field( void *, req )
  98. __field( u64, user_data )
  99. __field( int, fd )
  100. ),
  101. TP_fast_assign(
  102. __entry->ctx = req->ctx;
  103. __entry->req = req;
  104. __entry->user_data = req->cqe.user_data;
  105. __entry->fd = fd;
  106. ),
  107. TP_printk("ring %p, req %p, user_data 0x%llx, fd %d",
  108. __entry->ctx, __entry->req, __entry->user_data, __entry->fd)
  109. );
  110. /**
  111. * io_uring_queue_async_work - called before submitting a new async work
  112. *
  113. * @req: pointer to a submitted request
  114. * @rw: type of workqueue, hashed or normal
  115. *
  116. * Allows to trace asynchronous work submission.
  117. */
  118. TRACE_EVENT(io_uring_queue_async_work,
  119. TP_PROTO(struct io_kiocb *req, int rw),
  120. TP_ARGS(req, rw),
  121. TP_STRUCT__entry (
  122. __field( void *, ctx )
  123. __field( void *, req )
  124. __field( u64, user_data )
  125. __field( u8, opcode )
  126. __field( unsigned long long, flags )
  127. __field( struct io_wq_work *, work )
  128. __field( int, rw )
  129. __string( op_str, io_uring_get_opcode(req->opcode) )
  130. ),
  131. TP_fast_assign(
  132. __entry->ctx = req->ctx;
  133. __entry->req = req;
  134. __entry->user_data = req->cqe.user_data;
  135. __entry->flags = (__force unsigned long long) req->flags;
  136. __entry->opcode = req->opcode;
  137. __entry->work = &req->work;
  138. __entry->rw = rw;
  139. __assign_str(op_str);
  140. ),
  141. TP_printk("ring %p, request %p, user_data 0x%llx, opcode %s, flags 0x%llx, %s queue, work %p",
  142. __entry->ctx, __entry->req, __entry->user_data,
  143. __get_str(op_str), __entry->flags,
  144. __entry->rw ? "hashed" : "normal", __entry->work)
  145. );
  146. /**
  147. * io_uring_defer - called when an io_uring request is deferred
  148. *
  149. * @req: pointer to a deferred request
  150. *
  151. * Allows to track deferred requests, to get an insight about what requests are
  152. * not started immediately.
  153. */
  154. TRACE_EVENT(io_uring_defer,
  155. TP_PROTO(struct io_kiocb *req),
  156. TP_ARGS(req),
  157. TP_STRUCT__entry (
  158. __field( void *, ctx )
  159. __field( void *, req )
  160. __field( unsigned long long, data )
  161. __field( u8, opcode )
  162. __string( op_str, io_uring_get_opcode(req->opcode) )
  163. ),
  164. TP_fast_assign(
  165. __entry->ctx = req->ctx;
  166. __entry->req = req;
  167. __entry->data = req->cqe.user_data;
  168. __entry->opcode = req->opcode;
  169. __assign_str(op_str);
  170. ),
  171. TP_printk("ring %p, request %p, user_data 0x%llx, opcode %s",
  172. __entry->ctx, __entry->req, __entry->data,
  173. __get_str(op_str))
  174. );
  175. /**
  176. * io_uring_link - called before the io_uring request added into link_list of
  177. * another request
  178. *
  179. * @req: pointer to a linked request
  180. * @target_req: pointer to a previous request, that would contain @req
  181. *
  182. * Allows to track linked requests, to understand dependencies between requests
  183. * and how does it influence their execution flow.
  184. */
  185. TRACE_EVENT(io_uring_link,
  186. TP_PROTO(struct io_kiocb *req, struct io_kiocb *target_req),
  187. TP_ARGS(req, target_req),
  188. TP_STRUCT__entry (
  189. __field( void *, ctx )
  190. __field( void *, req )
  191. __field( void *, target_req )
  192. ),
  193. TP_fast_assign(
  194. __entry->ctx = req->ctx;
  195. __entry->req = req;
  196. __entry->target_req = target_req;
  197. ),
  198. TP_printk("ring %p, request %p linked after %p",
  199. __entry->ctx, __entry->req, __entry->target_req)
  200. );
  201. /**
  202. * io_uring_cqring_wait - called before start waiting for an available CQE
  203. *
  204. * @ctx: pointer to a ring context structure
  205. * @min_events: minimal number of events to wait for
  206. *
  207. * Allows to track waiting for CQE, so that we can e.g. troubleshoot
  208. * situations, when an application wants to wait for an event, that never
  209. * comes.
  210. */
  211. TRACE_EVENT(io_uring_cqring_wait,
  212. TP_PROTO(void *ctx, int min_events),
  213. TP_ARGS(ctx, min_events),
  214. TP_STRUCT__entry (
  215. __field( void *, ctx )
  216. __field( int, min_events )
  217. ),
  218. TP_fast_assign(
  219. __entry->ctx = ctx;
  220. __entry->min_events = min_events;
  221. ),
  222. TP_printk("ring %p, min_events %d", __entry->ctx, __entry->min_events)
  223. );
  224. /**
  225. * io_uring_fail_link - called before failing a linked request
  226. *
  227. * @req: request, which links were cancelled
  228. * @link: cancelled link
  229. *
  230. * Allows to track linked requests cancellation, to see not only that some work
  231. * was cancelled, but also which request was the reason.
  232. */
  233. TRACE_EVENT(io_uring_fail_link,
  234. TP_PROTO(struct io_kiocb *req, struct io_kiocb *link),
  235. TP_ARGS(req, link),
  236. TP_STRUCT__entry (
  237. __field( void *, ctx )
  238. __field( void *, req )
  239. __field( unsigned long long, user_data )
  240. __field( u8, opcode )
  241. __field( void *, link )
  242. __string( op_str, io_uring_get_opcode(req->opcode) )
  243. ),
  244. TP_fast_assign(
  245. __entry->ctx = req->ctx;
  246. __entry->req = req;
  247. __entry->user_data = req->cqe.user_data;
  248. __entry->opcode = req->opcode;
  249. __entry->link = link;
  250. __assign_str(op_str);
  251. ),
  252. TP_printk("ring %p, request %p, user_data 0x%llx, opcode %s, link %p",
  253. __entry->ctx, __entry->req, __entry->user_data,
  254. __get_str(op_str), __entry->link)
  255. );
  256. /**
  257. * io_uring_complete - called when completing an SQE
  258. *
  259. * @ctx: pointer to a ring context structure
  260. * @req: pointer to a submitted request
  261. * @user_data: user data associated with the request
  262. * @res: result of the request
  263. * @cflags: completion flags
  264. * @extra1: extra 64-bit data for CQE32
  265. * @extra2: extra 64-bit data for CQE32
  266. *
  267. */
  268. TRACE_EVENT(io_uring_complete,
  269. TP_PROTO(void *ctx, void *req, u64 user_data, int res, unsigned cflags,
  270. u64 extra1, u64 extra2),
  271. TP_ARGS(ctx, req, user_data, res, cflags, extra1, extra2),
  272. TP_STRUCT__entry (
  273. __field( void *, ctx )
  274. __field( void *, req )
  275. __field( u64, user_data )
  276. __field( int, res )
  277. __field( unsigned, cflags )
  278. __field( u64, extra1 )
  279. __field( u64, extra2 )
  280. ),
  281. TP_fast_assign(
  282. __entry->ctx = ctx;
  283. __entry->req = req;
  284. __entry->user_data = user_data;
  285. __entry->res = res;
  286. __entry->cflags = cflags;
  287. __entry->extra1 = extra1;
  288. __entry->extra2 = extra2;
  289. ),
  290. TP_printk("ring %p, req %p, user_data 0x%llx, result %d, cflags 0x%x "
  291. "extra1 %llu extra2 %llu ",
  292. __entry->ctx, __entry->req,
  293. __entry->user_data,
  294. __entry->res, __entry->cflags,
  295. (unsigned long long) __entry->extra1,
  296. (unsigned long long) __entry->extra2)
  297. );
  298. /**
  299. * io_uring_submit_req - called before submitting a request
  300. *
  301. * @req: pointer to a submitted request
  302. *
  303. * Allows to track SQE submitting, to understand what was the source of it, SQ
  304. * thread or io_uring_enter call.
  305. */
  306. TRACE_EVENT(io_uring_submit_req,
  307. TP_PROTO(struct io_kiocb *req),
  308. TP_ARGS(req),
  309. TP_STRUCT__entry (
  310. __field( void *, ctx )
  311. __field( void *, req )
  312. __field( unsigned long long, user_data )
  313. __field( u8, opcode )
  314. __field( unsigned long long, flags )
  315. __field( bool, sq_thread )
  316. __string( op_str, io_uring_get_opcode(req->opcode) )
  317. ),
  318. TP_fast_assign(
  319. __entry->ctx = req->ctx;
  320. __entry->req = req;
  321. __entry->user_data = req->cqe.user_data;
  322. __entry->opcode = req->opcode;
  323. __entry->flags = (__force unsigned long long) req->flags;
  324. __entry->sq_thread = req->ctx->flags & IORING_SETUP_SQPOLL;
  325. __assign_str(op_str);
  326. ),
  327. TP_printk("ring %p, req %p, user_data 0x%llx, opcode %s, flags 0x%llx, "
  328. "sq_thread %d", __entry->ctx, __entry->req,
  329. __entry->user_data, __get_str(op_str), __entry->flags,
  330. __entry->sq_thread)
  331. );
  332. /*
  333. * io_uring_poll_arm - called after arming a poll wait if successful
  334. *
  335. * @req: pointer to the armed request
  336. * @mask: request poll events mask
  337. * @events: registered events of interest
  338. *
  339. * Allows to track which fds are waiting for and what are the events of
  340. * interest.
  341. */
  342. TRACE_EVENT(io_uring_poll_arm,
  343. TP_PROTO(struct io_kiocb *req, int mask, int events),
  344. TP_ARGS(req, mask, events),
  345. TP_STRUCT__entry (
  346. __field( void *, ctx )
  347. __field( void *, req )
  348. __field( unsigned long long, user_data )
  349. __field( u8, opcode )
  350. __field( int, mask )
  351. __field( int, events )
  352. __string( op_str, io_uring_get_opcode(req->opcode) )
  353. ),
  354. TP_fast_assign(
  355. __entry->ctx = req->ctx;
  356. __entry->req = req;
  357. __entry->user_data = req->cqe.user_data;
  358. __entry->opcode = req->opcode;
  359. __entry->mask = mask;
  360. __entry->events = events;
  361. __assign_str(op_str);
  362. ),
  363. TP_printk("ring %p, req %p, user_data 0x%llx, opcode %s, mask 0x%x, events 0x%x",
  364. __entry->ctx, __entry->req, __entry->user_data,
  365. __get_str(op_str),
  366. __entry->mask, __entry->events)
  367. );
  368. /*
  369. * io_uring_task_add - called after adding a task
  370. *
  371. * @req: pointer to request
  372. * @mask: request poll events mask
  373. *
  374. */
  375. TRACE_EVENT(io_uring_task_add,
  376. TP_PROTO(struct io_kiocb *req, int mask),
  377. TP_ARGS(req, mask),
  378. TP_STRUCT__entry (
  379. __field( void *, ctx )
  380. __field( void *, req )
  381. __field( unsigned long long, user_data )
  382. __field( u8, opcode )
  383. __field( int, mask )
  384. __string( op_str, io_uring_get_opcode(req->opcode) )
  385. ),
  386. TP_fast_assign(
  387. __entry->ctx = req->ctx;
  388. __entry->req = req;
  389. __entry->user_data = req->cqe.user_data;
  390. __entry->opcode = req->opcode;
  391. __entry->mask = mask;
  392. __assign_str(op_str);
  393. ),
  394. TP_printk("ring %p, req %p, user_data 0x%llx, opcode %s, mask %x",
  395. __entry->ctx, __entry->req, __entry->user_data,
  396. __get_str(op_str),
  397. __entry->mask)
  398. );
  399. /*
  400. * io_uring_req_failed - called when an sqe is errored dring submission
  401. *
  402. * @sqe: pointer to the io_uring_sqe that failed
  403. * @req: pointer to request
  404. * @error: error it failed with
  405. *
  406. * Allows easier diagnosing of malformed requests in production systems.
  407. */
  408. TRACE_EVENT(io_uring_req_failed,
  409. TP_PROTO(const struct io_uring_sqe *sqe, struct io_kiocb *req, int error),
  410. TP_ARGS(sqe, req, error),
  411. TP_STRUCT__entry (
  412. __field( void *, ctx )
  413. __field( void *, req )
  414. __field( unsigned long long, user_data )
  415. __field( u8, opcode )
  416. __field( u8, flags )
  417. __field( u8, ioprio )
  418. __field( u64, off )
  419. __field( u64, addr )
  420. __field( u32, len )
  421. __field( u32, op_flags )
  422. __field( u16, buf_index )
  423. __field( u16, personality )
  424. __field( u32, file_index )
  425. __field( u64, pad1 )
  426. __field( u64, addr3 )
  427. __field( int, error )
  428. __string( op_str, io_uring_get_opcode(sqe->opcode) )
  429. ),
  430. TP_fast_assign(
  431. __entry->ctx = req->ctx;
  432. __entry->req = req;
  433. __entry->user_data = sqe->user_data;
  434. __entry->opcode = sqe->opcode;
  435. __entry->flags = sqe->flags;
  436. __entry->ioprio = sqe->ioprio;
  437. __entry->off = sqe->off;
  438. __entry->addr = sqe->addr;
  439. __entry->len = sqe->len;
  440. __entry->op_flags = sqe->poll32_events;
  441. __entry->buf_index = sqe->buf_index;
  442. __entry->personality = sqe->personality;
  443. __entry->file_index = sqe->file_index;
  444. __entry->pad1 = sqe->__pad2[0];
  445. __entry->addr3 = sqe->addr3;
  446. __entry->error = error;
  447. __assign_str(op_str);
  448. ),
  449. TP_printk("ring %p, req %p, user_data 0x%llx, "
  450. "opcode %s, flags 0x%x, prio=%d, off=%llu, addr=%llu, "
  451. "len=%u, rw_flags=0x%x, buf_index=%d, "
  452. "personality=%d, file_index=%d, pad=0x%llx, addr3=%llx, "
  453. "error=%d",
  454. __entry->ctx, __entry->req, __entry->user_data,
  455. __get_str(op_str),
  456. __entry->flags, __entry->ioprio,
  457. (unsigned long long)__entry->off,
  458. (unsigned long long) __entry->addr, __entry->len,
  459. __entry->op_flags,
  460. __entry->buf_index, __entry->personality, __entry->file_index,
  461. (unsigned long long) __entry->pad1,
  462. (unsigned long long) __entry->addr3, __entry->error)
  463. );
  464. /*
  465. * io_uring_cqe_overflow - a CQE overflowed
  466. *
  467. * @ctx: pointer to a ring context structure
  468. * @user_data: user data associated with the request
  469. * @res: CQE result
  470. * @cflags: CQE flags
  471. * @ocqe: pointer to the overflow cqe (if available)
  472. *
  473. */
  474. TRACE_EVENT(io_uring_cqe_overflow,
  475. TP_PROTO(void *ctx, unsigned long long user_data, s32 res, u32 cflags,
  476. void *ocqe),
  477. TP_ARGS(ctx, user_data, res, cflags, ocqe),
  478. TP_STRUCT__entry (
  479. __field( void *, ctx )
  480. __field( unsigned long long, user_data )
  481. __field( s32, res )
  482. __field( u32, cflags )
  483. __field( void *, ocqe )
  484. ),
  485. TP_fast_assign(
  486. __entry->ctx = ctx;
  487. __entry->user_data = user_data;
  488. __entry->res = res;
  489. __entry->cflags = cflags;
  490. __entry->ocqe = ocqe;
  491. ),
  492. TP_printk("ring %p, user_data 0x%llx, res %d, cflags 0x%x, "
  493. "overflow_cqe %p",
  494. __entry->ctx, __entry->user_data, __entry->res,
  495. __entry->cflags, __entry->ocqe)
  496. );
  497. /*
  498. * io_uring_task_work_run - ran task work
  499. *
  500. * @tctx: pointer to a io_uring_task
  501. * @count: how many functions it ran
  502. *
  503. */
  504. TRACE_EVENT(io_uring_task_work_run,
  505. TP_PROTO(void *tctx, unsigned int count),
  506. TP_ARGS(tctx, count),
  507. TP_STRUCT__entry (
  508. __field( void *, tctx )
  509. __field( unsigned int, count )
  510. ),
  511. TP_fast_assign(
  512. __entry->tctx = tctx;
  513. __entry->count = count;
  514. ),
  515. TP_printk("tctx %p, count %u", __entry->tctx, __entry->count)
  516. );
  517. TRACE_EVENT(io_uring_short_write,
  518. TP_PROTO(void *ctx, u64 fpos, u64 wanted, u64 got),
  519. TP_ARGS(ctx, fpos, wanted, got),
  520. TP_STRUCT__entry(
  521. __field(void *, ctx)
  522. __field(u64, fpos)
  523. __field(u64, wanted)
  524. __field(u64, got)
  525. ),
  526. TP_fast_assign(
  527. __entry->ctx = ctx;
  528. __entry->fpos = fpos;
  529. __entry->wanted = wanted;
  530. __entry->got = got;
  531. ),
  532. TP_printk("ring %p, fpos %lld, wanted %lld, got %lld",
  533. __entry->ctx, __entry->fpos,
  534. __entry->wanted, __entry->got)
  535. );
  536. /*
  537. * io_uring_local_work_run - ran ring local task work
  538. *
  539. * @tctx: pointer to a io_uring_ctx
  540. * @count: how many functions it ran
  541. * @loops: how many loops it ran
  542. *
  543. */
  544. TRACE_EVENT(io_uring_local_work_run,
  545. TP_PROTO(void *ctx, int count, unsigned int loops),
  546. TP_ARGS(ctx, count, loops),
  547. TP_STRUCT__entry (
  548. __field(void *, ctx )
  549. __field(int, count )
  550. __field(unsigned int, loops )
  551. ),
  552. TP_fast_assign(
  553. __entry->ctx = ctx;
  554. __entry->count = count;
  555. __entry->loops = loops;
  556. ),
  557. TP_printk("ring %p, count %d, loops %u", __entry->ctx, __entry->count, __entry->loops)
  558. );
  559. #endif /* _TRACE_IO_URING_H */
  560. /* This part must be outside protection */
  561. #include <trace/define_trace.h>