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.h>
15 * io_uring_create - called after a new io_uring context was prepared
17 * @fd: corresponding file descriptor
18 * @ctx: pointer to a ring context structure
19 * @sq_entries: actual SQ size
20 * @cq_entries: actual CQ size
21 * @flags: SQ ring flags, provided to io_uring_setup(2)
23 * Allows to trace io_uring creation and provide pointer to a context, that can
24 * be used later to find correlated events.
26 TRACE_EVENT(io_uring_create,
28 TP_PROTO(int fd, void *ctx, u32 sq_entries, u32 cq_entries, u32 flags),
30 TP_ARGS(fd, ctx, sq_entries, cq_entries, flags),
34 __field( void *, ctx )
35 __field( u32, sq_entries )
36 __field( u32, cq_entries )
43 __entry->sq_entries = sq_entries;
44 __entry->cq_entries = cq_entries;
45 __entry->flags = flags;
48 TP_printk("ring %p, fd %d sq size %d, cq size %d, flags 0x%x",
49 __entry->ctx, __entry->fd, __entry->sq_entries,
50 __entry->cq_entries, __entry->flags)
54 * io_uring_register - called after a buffer/file/eventfd was successfully
55 * registered for a ring
57 * @ctx: pointer to a ring context structure
58 * @opcode: describes which operation to perform
59 * @nr_user_files: number of registered files
60 * @nr_user_bufs: number of registered buffers
63 * Allows to trace fixed files/buffers, that could be registered to
64 * avoid an overhead of getting references to them for every operation. This
65 * event, together with io_uring_file_get, can provide a full picture of how
66 * much overhead one can reduce via fixing.
68 TRACE_EVENT(io_uring_register,
70 TP_PROTO(void *ctx, unsigned opcode, unsigned nr_files,
71 unsigned nr_bufs, long ret),
73 TP_ARGS(ctx, opcode, nr_files, nr_bufs, ret),
76 __field( void *, ctx )
77 __field( unsigned, opcode )
78 __field( unsigned, nr_files)
79 __field( unsigned, nr_bufs )
85 __entry->opcode = opcode;
86 __entry->nr_files = nr_files;
87 __entry->nr_bufs = nr_bufs;
91 TP_printk("ring %p, opcode %d, nr_user_files %d, nr_user_bufs %d, "
93 __entry->ctx, __entry->opcode, __entry->nr_files,
94 __entry->nr_bufs, __entry->ret)
98 * io_uring_file_get - called before getting references to an SQE file
100 * @ctx: pointer to a ring context structure
101 * @req: pointer to a submitted request
102 * @user_data: user data associated with the request
103 * @fd: SQE file descriptor
105 * Allows to trace out how often an SQE file reference is obtained, which can
106 * help figuring out if it makes sense to use fixed files, or check that fixed
107 * files are used correctly.
109 TRACE_EVENT(io_uring_file_get,
111 TP_PROTO(void *ctx, void *req, unsigned long long user_data, int fd),
113 TP_ARGS(ctx, req, user_data, fd),
116 __field( void *, ctx )
117 __field( void *, req )
118 __field( u64, user_data )
125 __entry->user_data = user_data;
129 TP_printk("ring %p, req %p, user_data 0x%llx, fd %d",
130 __entry->ctx, __entry->req, __entry->user_data, __entry->fd)
134 * io_uring_queue_async_work - called before submitting a new async work
136 * @ctx: pointer to a ring context structure
137 * @req: pointer to a submitted request
138 * @user_data: user data associated with the request
139 * @opcode: opcode of request
140 * @flags request flags
141 * @work: pointer to a submitted io_wq_work
142 * @rw: type of workqueue, hashed or normal
144 * Allows to trace asynchronous work submission.
146 TRACE_EVENT(io_uring_queue_async_work,
148 TP_PROTO(void *ctx, void * req, unsigned long long user_data, u8 opcode,
149 unsigned int flags, struct io_wq_work *work, int rw),
151 TP_ARGS(ctx, req, user_data, opcode, flags, work, rw),
154 __field( void *, ctx )
155 __field( void *, req )
156 __field( u64, user_data )
157 __field( u8, opcode )
158 __field( unsigned int, flags )
159 __field( struct io_wq_work *, work )
162 __string( op_str, io_uring_get_opcode(opcode) )
168 __entry->user_data = user_data;
169 __entry->flags = flags;
170 __entry->opcode = opcode;
171 __entry->work = work;
174 __assign_str(op_str, io_uring_get_opcode(opcode));
177 TP_printk("ring %p, request %p, user_data 0x%llx, opcode %s, flags 0x%x, %s queue, work %p",
178 __entry->ctx, __entry->req, __entry->user_data,
180 __entry->flags, __entry->rw ? "hashed" : "normal", __entry->work)
184 * io_uring_defer - called when an io_uring request is deferred
186 * @ctx: pointer to a ring context structure
187 * @req: pointer to a deferred request
188 * @user_data: user data associated with the request
189 * @opcode: opcode of request
191 * Allows to track deferred requests, to get an insight about what requests are
192 * not started immediately.
194 TRACE_EVENT(io_uring_defer,
196 TP_PROTO(void *ctx, void *req, unsigned long long user_data, u8 opcode),
198 TP_ARGS(ctx, req, user_data, opcode),
201 __field( void *, ctx )
202 __field( void *, req )
203 __field( unsigned long long, data )
204 __field( u8, opcode )
206 __string( op_str, io_uring_get_opcode(opcode) )
212 __entry->data = user_data;
213 __entry->opcode = opcode;
215 __assign_str(op_str, io_uring_get_opcode(opcode));
218 TP_printk("ring %p, request %p, user_data 0x%llx, opcode %s",
219 __entry->ctx, __entry->req, __entry->data,
224 * io_uring_link - called before the io_uring request added into link_list of
227 * @ctx: pointer to a ring context structure
228 * @req: pointer to a linked request
229 * @target_req: pointer to a previous request, that would contain @req
231 * Allows to track linked requests, to understand dependencies between requests
232 * and how does it influence their execution flow.
234 TRACE_EVENT(io_uring_link,
236 TP_PROTO(void *ctx, void *req, void *target_req),
238 TP_ARGS(ctx, req, target_req),
241 __field( void *, ctx )
242 __field( void *, req )
243 __field( void *, target_req )
249 __entry->target_req = target_req;
252 TP_printk("ring %p, request %p linked after %p",
253 __entry->ctx, __entry->req, __entry->target_req)
257 * io_uring_cqring_wait - called before start waiting for an available CQE
259 * @ctx: pointer to a ring context structure
260 * @min_events: minimal number of events to wait for
262 * Allows to track waiting for CQE, so that we can e.g. troubleshoot
263 * situations, when an application wants to wait for an event, that never
266 TRACE_EVENT(io_uring_cqring_wait,
268 TP_PROTO(void *ctx, int min_events),
270 TP_ARGS(ctx, min_events),
273 __field( void *, ctx )
274 __field( int, min_events )
279 __entry->min_events = min_events;
282 TP_printk("ring %p, min_events %d", __entry->ctx, __entry->min_events)
286 * io_uring_fail_link - called before failing a linked request
288 * @ctx: pointer to a ring context structure
289 * @req: request, which links were cancelled
290 * @user_data: user data associated with the request
291 * @opcode: opcode of request
292 * @link: cancelled link
294 * Allows to track linked requests cancellation, to see not only that some work
295 * was cancelled, but also which request was the reason.
297 TRACE_EVENT(io_uring_fail_link,
299 TP_PROTO(void *ctx, void *req, unsigned long long user_data, u8 opcode, void *link),
301 TP_ARGS(ctx, req, user_data, opcode, link),
304 __field( void *, ctx )
305 __field( void *, req )
306 __field( unsigned long long, user_data )
307 __field( u8, opcode )
308 __field( void *, link )
310 __string( op_str, io_uring_get_opcode(opcode) )
316 __entry->user_data = user_data;
317 __entry->opcode = opcode;
318 __entry->link = link;
320 __assign_str(op_str, io_uring_get_opcode(opcode));
323 TP_printk("ring %p, request %p, user_data 0x%llx, opcode %s, link %p",
324 __entry->ctx, __entry->req, __entry->user_data,
325 __get_str(op_str), __entry->link)
329 * io_uring_complete - called when completing an SQE
331 * @ctx: pointer to a ring context structure
332 * @req: pointer to a submitted request
333 * @user_data: user data associated with the request
334 * @res: result of the request
335 * @cflags: completion flags
336 * @extra1: extra 64-bit data for CQE32
337 * @extra2: extra 64-bit data for CQE32
340 TRACE_EVENT(io_uring_complete,
342 TP_PROTO(void *ctx, void *req, u64 user_data, int res, unsigned cflags,
343 u64 extra1, u64 extra2),
345 TP_ARGS(ctx, req, user_data, res, cflags, extra1, extra2),
348 __field( void *, ctx )
349 __field( void *, req )
350 __field( u64, user_data )
352 __field( unsigned, cflags )
353 __field( u64, extra1 )
354 __field( u64, extra2 )
360 __entry->user_data = user_data;
362 __entry->cflags = cflags;
363 __entry->extra1 = extra1;
364 __entry->extra2 = extra2;
367 TP_printk("ring %p, req %p, user_data 0x%llx, result %d, cflags 0x%x "
368 "extra1 %llu extra2 %llu ",
369 __entry->ctx, __entry->req,
371 __entry->res, __entry->cflags,
372 (unsigned long long) __entry->extra1,
373 (unsigned long long) __entry->extra2)
377 * io_uring_submit_sqe - called before submitting one SQE
379 * @ctx: pointer to a ring context structure
380 * @req: pointer to a submitted request
381 * @user_data: user data associated with the request
382 * @opcode: opcode of request
383 * @flags request flags
384 * @force_nonblock: whether a context blocking or not
385 * @sq_thread: true if sq_thread has submitted this SQE
387 * Allows to track SQE submitting, to understand what was the source of it, SQ
388 * thread or io_uring_enter call.
390 TRACE_EVENT(io_uring_submit_sqe,
392 TP_PROTO(void *ctx, void *req, unsigned long long user_data, u8 opcode, u32 flags,
393 bool force_nonblock, bool sq_thread),
395 TP_ARGS(ctx, req, user_data, opcode, flags, force_nonblock, sq_thread),
398 __field( void *, ctx )
399 __field( void *, req )
400 __field( unsigned long long, user_data )
401 __field( u8, opcode )
402 __field( u32, flags )
403 __field( bool, force_nonblock )
404 __field( bool, sq_thread )
406 __string( op_str, io_uring_get_opcode(opcode) )
412 __entry->user_data = user_data;
413 __entry->opcode = opcode;
414 __entry->flags = flags;
415 __entry->force_nonblock = force_nonblock;
416 __entry->sq_thread = sq_thread;
418 __assign_str(op_str, io_uring_get_opcode(opcode));
421 TP_printk("ring %p, req %p, user_data 0x%llx, opcode %s, flags 0x%x, "
422 "non block %d, sq_thread %d", __entry->ctx, __entry->req,
423 __entry->user_data, __get_str(op_str),
424 __entry->flags, __entry->force_nonblock, __entry->sq_thread)
428 * io_uring_poll_arm - called after arming a poll wait if successful
430 * @ctx: pointer to a ring context structure
431 * @req: pointer to the armed request
432 * @user_data: user data associated with the request
433 * @opcode: opcode of request
434 * @mask: request poll events mask
435 * @events: registered events of interest
437 * Allows to track which fds are waiting for and what are the events of
440 TRACE_EVENT(io_uring_poll_arm,
442 TP_PROTO(void *ctx, void *req, u64 user_data, u8 opcode,
443 int mask, int events),
445 TP_ARGS(ctx, req, user_data, opcode, mask, events),
448 __field( void *, ctx )
449 __field( void *, req )
450 __field( unsigned long long, user_data )
451 __field( u8, opcode )
453 __field( int, events )
455 __string( op_str, io_uring_get_opcode(opcode) )
461 __entry->user_data = user_data;
462 __entry->opcode = opcode;
463 __entry->mask = mask;
464 __entry->events = events;
466 __assign_str(op_str, io_uring_get_opcode(opcode));
469 TP_printk("ring %p, req %p, user_data 0x%llx, opcode %s, mask 0x%x, events 0x%x",
470 __entry->ctx, __entry->req, __entry->user_data,
472 __entry->mask, __entry->events)
476 * io_uring_task_add - called after adding a task
478 * @ctx: pointer to a ring context structure
479 * @req: pointer to request
480 * @user_data: user data associated with the request
481 * @opcode: opcode of request
482 * @mask: request poll events mask
485 TRACE_EVENT(io_uring_task_add,
487 TP_PROTO(void *ctx, void *req, unsigned long long user_data, u8 opcode, int mask),
489 TP_ARGS(ctx, req, user_data, opcode, mask),
492 __field( void *, ctx )
493 __field( void *, req )
494 __field( unsigned long long, user_data )
495 __field( u8, opcode )
498 __string( op_str, io_uring_get_opcode(opcode) )
504 __entry->user_data = user_data;
505 __entry->opcode = opcode;
506 __entry->mask = mask;
508 __assign_str(op_str, io_uring_get_opcode(opcode));
511 TP_printk("ring %p, req %p, user_data 0x%llx, opcode %s, mask %x",
512 __entry->ctx, __entry->req, __entry->user_data,
518 * io_uring_req_failed - called when an sqe is errored dring submission
520 * @sqe: pointer to the io_uring_sqe that failed
521 * @ctx: pointer to a ring context structure
522 * @req: pointer to request
523 * @error: error it failed with
525 * Allows easier diagnosing of malformed requests in production systems.
527 TRACE_EVENT(io_uring_req_failed,
529 TP_PROTO(const struct io_uring_sqe *sqe, void *ctx, void *req, int error),
531 TP_ARGS(sqe, ctx, req, error),
534 __field( void *, ctx )
535 __field( void *, req )
536 __field( unsigned long long, user_data )
537 __field( u8, opcode )
539 __field( u8, ioprio )
543 __field( u32, op_flags )
544 __field( u16, buf_index )
545 __field( u16, personality )
546 __field( u32, file_index )
548 __field( u64, addr3 )
549 __field( int, error )
551 __string( op_str, io_uring_get_opcode(sqe->opcode) )
557 __entry->user_data = sqe->user_data;
558 __entry->opcode = sqe->opcode;
559 __entry->flags = sqe->flags;
560 __entry->ioprio = sqe->ioprio;
561 __entry->off = sqe->off;
562 __entry->addr = sqe->addr;
563 __entry->len = sqe->len;
564 __entry->op_flags = sqe->poll32_events;
565 __entry->buf_index = sqe->buf_index;
566 __entry->personality = sqe->personality;
567 __entry->file_index = sqe->file_index;
568 __entry->pad1 = sqe->__pad2[0];
569 __entry->addr3 = sqe->addr3;
570 __entry->error = error;
572 __assign_str(op_str, io_uring_get_opcode(sqe->opcode));
575 TP_printk("ring %p, req %p, user_data 0x%llx, "
576 "opcode %s, flags 0x%x, prio=%d, off=%llu, addr=%llu, "
577 "len=%u, rw_flags=0x%x, buf_index=%d, "
578 "personality=%d, file_index=%d, pad=0x%llx, addr3=%llx, "
580 __entry->ctx, __entry->req, __entry->user_data,
582 __entry->flags, __entry->ioprio,
583 (unsigned long long)__entry->off,
584 (unsigned long long) __entry->addr, __entry->len,
586 __entry->buf_index, __entry->personality, __entry->file_index,
587 (unsigned long long) __entry->pad1,
588 (unsigned long long) __entry->addr3, __entry->error)
593 * io_uring_cqe_overflow - a CQE overflowed
595 * @ctx: pointer to a ring context structure
596 * @user_data: user data associated with the request
599 * @ocqe: pointer to the overflow cqe (if available)
602 TRACE_EVENT(io_uring_cqe_overflow,
604 TP_PROTO(void *ctx, unsigned long long user_data, s32 res, u32 cflags,
607 TP_ARGS(ctx, user_data, res, cflags, ocqe),
610 __field( void *, ctx )
611 __field( unsigned long long, user_data )
613 __field( u32, cflags )
614 __field( void *, ocqe )
619 __entry->user_data = user_data;
621 __entry->cflags = cflags;
622 __entry->ocqe = ocqe;
625 TP_printk("ring %p, user_data 0x%llx, res %d, flags %x, "
627 __entry->ctx, __entry->user_data, __entry->res,
628 __entry->cflags, __entry->ocqe)
631 #endif /* _TRACE_IO_URING_H */
633 /* This part must be outside protection */
634 #include <trace/define_trace.h>