1 /* SPDX-License-Identifier: GPL-2.0 */
3 #define TRACE_SYSTEM io_uring
5 #if !defined(_TRACE_IO_URING_H) || defined(TRACE_HEADER_MULTI_READ)
6 #define _TRACE_IO_URING_H
8 #include <linux/tracepoint.h>
9 #include <uapi/linux/io_uring.h>
10 #include <linux/io_uring_types.h>
11 #include <linux/io_uring.h>
16 * io_uring_create - called after a new io_uring context was prepared
18 * @fd: corresponding file descriptor
19 * @ctx: pointer to a ring context structure
20 * @sq_entries: actual SQ size
21 * @cq_entries: actual CQ size
22 * @flags: SQ ring flags, provided to io_uring_setup(2)
24 * Allows to trace io_uring creation and provide pointer to a context, that can
25 * be used later to find correlated events.
27 TRACE_EVENT(io_uring_create,
29 TP_PROTO(int fd, void *ctx, u32 sq_entries, u32 cq_entries, u32 flags),
31 TP_ARGS(fd, ctx, sq_entries, cq_entries, flags),
35 __field( void *, ctx )
36 __field( u32, sq_entries )
37 __field( u32, cq_entries )
44 __entry->sq_entries = sq_entries;
45 __entry->cq_entries = cq_entries;
46 __entry->flags = flags;
49 TP_printk("ring %p, fd %d sq size %d, cq size %d, flags 0x%x",
50 __entry->ctx, __entry->fd, __entry->sq_entries,
51 __entry->cq_entries, __entry->flags)
55 * io_uring_register - called after a buffer/file/eventfd was successfully
56 * registered for a ring
58 * @ctx: pointer to a ring context structure
59 * @opcode: describes which operation to perform
60 * @nr_user_files: number of registered files
61 * @nr_user_bufs: number of registered buffers
64 * Allows to trace fixed files/buffers, that could be registered to
65 * avoid an overhead of getting references to them for every operation. This
66 * event, together with io_uring_file_get, can provide a full picture of how
67 * much overhead one can reduce via fixing.
69 TRACE_EVENT(io_uring_register,
71 TP_PROTO(void *ctx, unsigned opcode, unsigned nr_files,
72 unsigned nr_bufs, long ret),
74 TP_ARGS(ctx, opcode, nr_files, nr_bufs, ret),
77 __field( void *, ctx )
78 __field( unsigned, opcode )
79 __field( unsigned, nr_files)
80 __field( unsigned, nr_bufs )
86 __entry->opcode = opcode;
87 __entry->nr_files = nr_files;
88 __entry->nr_bufs = nr_bufs;
92 TP_printk("ring %p, opcode %d, nr_user_files %d, nr_user_bufs %d, "
94 __entry->ctx, __entry->opcode, __entry->nr_files,
95 __entry->nr_bufs, __entry->ret)
99 * io_uring_file_get - called before getting references to an SQE file
101 * @req: pointer to a submitted request
102 * @fd: SQE file descriptor
104 * Allows to trace out how often an SQE file reference is obtained, which can
105 * help figuring out if it makes sense to use fixed files, or check that fixed
106 * files are used correctly.
108 TRACE_EVENT(io_uring_file_get,
110 TP_PROTO(struct io_kiocb *req, int fd),
115 __field( void *, ctx )
116 __field( void *, req )
117 __field( u64, user_data )
122 __entry->ctx = req->ctx;
124 __entry->user_data = req->cqe.user_data;
128 TP_printk("ring %p, req %p, user_data 0x%llx, fd %d",
129 __entry->ctx, __entry->req, __entry->user_data, __entry->fd)
133 * io_uring_queue_async_work - called before submitting a new async work
135 * @req: pointer to a submitted request
136 * @rw: type of workqueue, hashed or normal
138 * Allows to trace asynchronous work submission.
140 TRACE_EVENT(io_uring_queue_async_work,
142 TP_PROTO(struct io_kiocb *req, int rw),
147 __field( void *, ctx )
148 __field( void *, req )
149 __field( u64, user_data )
150 __field( u8, opcode )
151 __field( unsigned int, flags )
152 __field( struct io_wq_work *, work )
155 __string( op_str, io_uring_get_opcode(req->opcode) )
159 __entry->ctx = req->ctx;
161 __entry->user_data = req->cqe.user_data;
162 __entry->flags = req->flags;
163 __entry->opcode = req->opcode;
164 __entry->work = &req->work;
167 __assign_str(op_str, io_uring_get_opcode(req->opcode));
170 TP_printk("ring %p, request %p, user_data 0x%llx, opcode %s, flags 0x%x, %s queue, work %p",
171 __entry->ctx, __entry->req, __entry->user_data,
173 __entry->flags, __entry->rw ? "hashed" : "normal", __entry->work)
177 * io_uring_defer - called when an io_uring request is deferred
179 * @req: pointer to a deferred request
181 * Allows to track deferred requests, to get an insight about what requests are
182 * not started immediately.
184 TRACE_EVENT(io_uring_defer,
186 TP_PROTO(struct io_kiocb *req),
191 __field( void *, ctx )
192 __field( void *, req )
193 __field( unsigned long long, data )
194 __field( u8, opcode )
196 __string( op_str, io_uring_get_opcode(req->opcode) )
200 __entry->ctx = req->ctx;
202 __entry->data = req->cqe.user_data;
203 __entry->opcode = req->opcode;
205 __assign_str(op_str, io_uring_get_opcode(req->opcode));
208 TP_printk("ring %p, request %p, user_data 0x%llx, opcode %s",
209 __entry->ctx, __entry->req, __entry->data,
214 * io_uring_link - called before the io_uring request added into link_list of
217 * @req: pointer to a linked request
218 * @target_req: pointer to a previous request, that would contain @req
220 * Allows to track linked requests, to understand dependencies between requests
221 * and how does it influence their execution flow.
223 TRACE_EVENT(io_uring_link,
225 TP_PROTO(struct io_kiocb *req, struct io_kiocb *target_req),
227 TP_ARGS(req, target_req),
230 __field( void *, ctx )
231 __field( void *, req )
232 __field( void *, target_req )
236 __entry->ctx = req->ctx;
238 __entry->target_req = target_req;
241 TP_printk("ring %p, request %p linked after %p",
242 __entry->ctx, __entry->req, __entry->target_req)
246 * io_uring_cqring_wait - called before start waiting for an available CQE
248 * @ctx: pointer to a ring context structure
249 * @min_events: minimal number of events to wait for
251 * Allows to track waiting for CQE, so that we can e.g. troubleshoot
252 * situations, when an application wants to wait for an event, that never
255 TRACE_EVENT(io_uring_cqring_wait,
257 TP_PROTO(void *ctx, int min_events),
259 TP_ARGS(ctx, min_events),
262 __field( void *, ctx )
263 __field( int, min_events )
268 __entry->min_events = min_events;
271 TP_printk("ring %p, min_events %d", __entry->ctx, __entry->min_events)
275 * io_uring_fail_link - called before failing a linked request
277 * @req: request, which links were cancelled
278 * @link: cancelled link
280 * Allows to track linked requests cancellation, to see not only that some work
281 * was cancelled, but also which request was the reason.
283 TRACE_EVENT(io_uring_fail_link,
285 TP_PROTO(struct io_kiocb *req, struct io_kiocb *link),
290 __field( void *, ctx )
291 __field( void *, req )
292 __field( unsigned long long, user_data )
293 __field( u8, opcode )
294 __field( void *, link )
296 __string( op_str, io_uring_get_opcode(req->opcode) )
300 __entry->ctx = req->ctx;
302 __entry->user_data = req->cqe.user_data;
303 __entry->opcode = req->opcode;
304 __entry->link = link;
306 __assign_str(op_str, io_uring_get_opcode(req->opcode));
309 TP_printk("ring %p, request %p, user_data 0x%llx, opcode %s, link %p",
310 __entry->ctx, __entry->req, __entry->user_data,
311 __get_str(op_str), __entry->link)
315 * io_uring_complete - called when completing an SQE
317 * @ctx: pointer to a ring context structure
318 * @req: pointer to a submitted request
319 * @user_data: user data associated with the request
320 * @res: result of the request
321 * @cflags: completion flags
322 * @extra1: extra 64-bit data for CQE32
323 * @extra2: extra 64-bit data for CQE32
326 TRACE_EVENT(io_uring_complete,
328 TP_PROTO(void *ctx, void *req, u64 user_data, int res, unsigned cflags,
329 u64 extra1, u64 extra2),
331 TP_ARGS(ctx, req, user_data, res, cflags, extra1, extra2),
334 __field( void *, ctx )
335 __field( void *, req )
336 __field( u64, user_data )
338 __field( unsigned, cflags )
339 __field( u64, extra1 )
340 __field( u64, extra2 )
346 __entry->user_data = user_data;
348 __entry->cflags = cflags;
349 __entry->extra1 = extra1;
350 __entry->extra2 = extra2;
353 TP_printk("ring %p, req %p, user_data 0x%llx, result %d, cflags 0x%x "
354 "extra1 %llu extra2 %llu ",
355 __entry->ctx, __entry->req,
357 __entry->res, __entry->cflags,
358 (unsigned long long) __entry->extra1,
359 (unsigned long long) __entry->extra2)
363 * io_uring_submit_sqe - called before submitting one SQE
365 * @req: pointer to a submitted request
366 * @force_nonblock: whether a context blocking or not
368 * Allows to track SQE submitting, to understand what was the source of it, SQ
369 * thread or io_uring_enter call.
371 TRACE_EVENT(io_uring_submit_sqe,
373 TP_PROTO(struct io_kiocb *req, bool force_nonblock),
375 TP_ARGS(req, force_nonblock),
378 __field( void *, ctx )
379 __field( void *, req )
380 __field( unsigned long long, user_data )
381 __field( u8, opcode )
382 __field( u32, flags )
383 __field( bool, force_nonblock )
384 __field( bool, sq_thread )
386 __string( op_str, io_uring_get_opcode(req->opcode) )
390 __entry->ctx = req->ctx;
392 __entry->user_data = req->cqe.user_data;
393 __entry->opcode = req->opcode;
394 __entry->flags = req->flags;
395 __entry->force_nonblock = force_nonblock;
396 __entry->sq_thread = req->ctx->flags & IORING_SETUP_SQPOLL;
398 __assign_str(op_str, io_uring_get_opcode(req->opcode));
401 TP_printk("ring %p, req %p, user_data 0x%llx, opcode %s, flags 0x%x, "
402 "non block %d, sq_thread %d", __entry->ctx, __entry->req,
403 __entry->user_data, __get_str(op_str),
404 __entry->flags, __entry->force_nonblock, __entry->sq_thread)
408 * io_uring_poll_arm - called after arming a poll wait if successful
410 * @req: pointer to the armed request
411 * @mask: request poll events mask
412 * @events: registered events of interest
414 * Allows to track which fds are waiting for and what are the events of
417 TRACE_EVENT(io_uring_poll_arm,
419 TP_PROTO(struct io_kiocb *req, int mask, int events),
421 TP_ARGS(req, mask, events),
424 __field( void *, ctx )
425 __field( void *, req )
426 __field( unsigned long long, user_data )
427 __field( u8, opcode )
429 __field( int, events )
431 __string( op_str, io_uring_get_opcode(req->opcode) )
435 __entry->ctx = req->ctx;
437 __entry->user_data = req->cqe.user_data;
438 __entry->opcode = req->opcode;
439 __entry->mask = mask;
440 __entry->events = events;
442 __assign_str(op_str, io_uring_get_opcode(req->opcode));
445 TP_printk("ring %p, req %p, user_data 0x%llx, opcode %s, mask 0x%x, events 0x%x",
446 __entry->ctx, __entry->req, __entry->user_data,
448 __entry->mask, __entry->events)
452 * io_uring_task_add - called after adding a task
454 * @req: pointer to request
455 * @mask: request poll events mask
458 TRACE_EVENT(io_uring_task_add,
460 TP_PROTO(struct io_kiocb *req, int mask),
465 __field( void *, ctx )
466 __field( void *, req )
467 __field( unsigned long long, user_data )
468 __field( u8, opcode )
471 __string( op_str, io_uring_get_opcode(req->opcode) )
475 __entry->ctx = req->ctx;
477 __entry->user_data = req->cqe.user_data;
478 __entry->opcode = req->opcode;
479 __entry->mask = mask;
481 __assign_str(op_str, io_uring_get_opcode(req->opcode));
484 TP_printk("ring %p, req %p, user_data 0x%llx, opcode %s, mask %x",
485 __entry->ctx, __entry->req, __entry->user_data,
491 * io_uring_req_failed - called when an sqe is errored dring submission
493 * @sqe: pointer to the io_uring_sqe that failed
494 * @req: pointer to request
495 * @error: error it failed with
497 * Allows easier diagnosing of malformed requests in production systems.
499 TRACE_EVENT(io_uring_req_failed,
501 TP_PROTO(const struct io_uring_sqe *sqe, struct io_kiocb *req, int error),
503 TP_ARGS(sqe, req, error),
506 __field( void *, ctx )
507 __field( void *, req )
508 __field( unsigned long long, user_data )
509 __field( u8, opcode )
511 __field( u8, ioprio )
515 __field( u32, op_flags )
516 __field( u16, buf_index )
517 __field( u16, personality )
518 __field( u32, file_index )
520 __field( u64, addr3 )
521 __field( int, error )
523 __string( op_str, io_uring_get_opcode(sqe->opcode) )
527 __entry->ctx = req->ctx;
529 __entry->user_data = sqe->user_data;
530 __entry->opcode = sqe->opcode;
531 __entry->flags = sqe->flags;
532 __entry->ioprio = sqe->ioprio;
533 __entry->off = sqe->off;
534 __entry->addr = sqe->addr;
535 __entry->len = sqe->len;
536 __entry->op_flags = sqe->poll32_events;
537 __entry->buf_index = sqe->buf_index;
538 __entry->personality = sqe->personality;
539 __entry->file_index = sqe->file_index;
540 __entry->pad1 = sqe->__pad2[0];
541 __entry->addr3 = sqe->addr3;
542 __entry->error = error;
544 __assign_str(op_str, io_uring_get_opcode(sqe->opcode));
547 TP_printk("ring %p, req %p, user_data 0x%llx, "
548 "opcode %s, flags 0x%x, prio=%d, off=%llu, addr=%llu, "
549 "len=%u, rw_flags=0x%x, buf_index=%d, "
550 "personality=%d, file_index=%d, pad=0x%llx, addr3=%llx, "
552 __entry->ctx, __entry->req, __entry->user_data,
554 __entry->flags, __entry->ioprio,
555 (unsigned long long)__entry->off,
556 (unsigned long long) __entry->addr, __entry->len,
558 __entry->buf_index, __entry->personality, __entry->file_index,
559 (unsigned long long) __entry->pad1,
560 (unsigned long long) __entry->addr3, __entry->error)
565 * io_uring_cqe_overflow - a CQE overflowed
567 * @ctx: pointer to a ring context structure
568 * @user_data: user data associated with the request
571 * @ocqe: pointer to the overflow cqe (if available)
574 TRACE_EVENT(io_uring_cqe_overflow,
576 TP_PROTO(void *ctx, unsigned long long user_data, s32 res, u32 cflags,
579 TP_ARGS(ctx, user_data, res, cflags, ocqe),
582 __field( void *, ctx )
583 __field( unsigned long long, user_data )
585 __field( u32, cflags )
586 __field( void *, ocqe )
591 __entry->user_data = user_data;
593 __entry->cflags = cflags;
594 __entry->ocqe = ocqe;
597 TP_printk("ring %p, user_data 0x%llx, res %d, flags %x, "
599 __entry->ctx, __entry->user_data, __entry->res,
600 __entry->cflags, __entry->ocqe)
604 * io_uring_task_work_run - ran task work
606 * @tctx: pointer to a io_uring_task
607 * @count: how many functions it ran
608 * @loops: how many loops it ran
611 TRACE_EVENT(io_uring_task_work_run,
613 TP_PROTO(void *tctx, unsigned int count, unsigned int loops),
615 TP_ARGS(tctx, count, loops),
618 __field( void *, tctx )
619 __field( unsigned int, count )
620 __field( unsigned int, loops )
624 __entry->tctx = tctx;
625 __entry->count = count;
626 __entry->loops = loops;
629 TP_printk("tctx %p, count %u, loops %u",
630 __entry->tctx, __entry->count, __entry->loops)
633 #endif /* _TRACE_IO_URING_H */
635 /* This part must be outside protection */
636 #include <trace/define_trace.h>