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>
14 * io_uring_create - called after a new io_uring context was prepared
16 * @fd: corresponding file descriptor
17 * @ctx: pointer to a ring context structure
18 * @sq_entries: actual SQ size
19 * @cq_entries: actual CQ size
20 * @flags: SQ ring flags, provided to io_uring_setup(2)
22 * Allows to trace io_uring creation and provide pointer to a context, that can
23 * be used later to find correlated events.
25 TRACE_EVENT(io_uring_create,
27 TP_PROTO(int fd, void *ctx, u32 sq_entries, u32 cq_entries, u32 flags),
29 TP_ARGS(fd, ctx, sq_entries, cq_entries, flags),
33 __field( void *, ctx )
34 __field( u32, sq_entries )
35 __field( u32, cq_entries )
42 __entry->sq_entries = sq_entries;
43 __entry->cq_entries = cq_entries;
44 __entry->flags = flags;
47 TP_printk("ring %p, fd %d sq size %d, cq size %d, flags %d",
48 __entry->ctx, __entry->fd, __entry->sq_entries,
49 __entry->cq_entries, __entry->flags)
53 * io_uring_register - called after a buffer/file/eventfd was successfully
54 * registered for a ring
56 * @ctx: pointer to a ring context structure
57 * @opcode: describes which operation to perform
58 * @nr_user_files: number of registered files
59 * @nr_user_bufs: number of registered buffers
60 * @cq_ev_fd: whether eventfs registered or not
63 * Allows to trace fixed files/buffers/eventfds, 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, bool eventfd, long ret),
73 TP_ARGS(ctx, opcode, nr_files, nr_bufs, eventfd, ret),
76 __field( void *, ctx )
77 __field( unsigned, opcode )
78 __field( unsigned, nr_files )
79 __field( unsigned, nr_bufs )
80 __field( bool, eventfd )
86 __entry->opcode = opcode;
87 __entry->nr_files = nr_files;
88 __entry->nr_bufs = nr_bufs;
89 __entry->eventfd = eventfd;
93 TP_printk("ring %p, opcode %d, nr_user_files %d, nr_user_bufs %d, "
94 "eventfd %d, ret %ld",
95 __entry->ctx, __entry->opcode, __entry->nr_files,
96 __entry->nr_bufs, __entry->eventfd, __entry->ret)
100 * io_uring_file_get - called before getting references to an SQE file
102 * @ctx: pointer to a ring context structure
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, int fd),
116 __field( void *, ctx )
125 TP_printk("ring %p, fd %d", __entry->ctx, __entry->fd)
129 * io_uring_queue_async_work - called before submitting a new async work
131 * @ctx: pointer to a ring context structure
132 * @hashed: type of workqueue, hashed or normal
133 * @req: pointer to a submitted request
134 * @work: pointer to a submitted io_wq_work
136 * Allows to trace asynchronous work submission.
138 TRACE_EVENT(io_uring_queue_async_work,
140 TP_PROTO(void *ctx, int rw, void * req, struct io_wq_work *work,
143 TP_ARGS(ctx, rw, req, work, flags),
146 __field( void *, ctx )
148 __field( void *, req )
149 __field( struct io_wq_work *, work )
150 __field( unsigned int, flags )
157 __entry->work = work;
158 __entry->flags = flags;
161 TP_printk("ring %p, request %p, flags %d, %s queue, work %p",
162 __entry->ctx, __entry->req, __entry->flags,
163 __entry->rw ? "hashed" : "normal", __entry->work)
167 * io_uring_defer - called when an io_uring request is deferred
169 * @ctx: pointer to a ring context structure
170 * @req: pointer to a deferred request
171 * @user_data: user data associated with the request
173 * Allows to track deferred requests, to get an insight about what requests are
174 * not started immediately.
176 TRACE_EVENT(io_uring_defer,
178 TP_PROTO(void *ctx, void *req, unsigned long long user_data),
180 TP_ARGS(ctx, req, user_data),
183 __field( void *, ctx )
184 __field( void *, req )
185 __field( unsigned long long, data )
191 __entry->data = user_data;
194 TP_printk("ring %p, request %p user_data %llu", __entry->ctx,
195 __entry->req, __entry->data)
199 * io_uring_link - called before the io_uring request added into link_list of
202 * @ctx: pointer to a ring context structure
203 * @req: pointer to a linked request
204 * @target_req: pointer to a previous request, that would contain @req
206 * Allows to track linked requests, to understand dependencies between requests
207 * and how does it influence their execution flow.
209 TRACE_EVENT(io_uring_link,
211 TP_PROTO(void *ctx, void *req, void *target_req),
213 TP_ARGS(ctx, req, target_req),
216 __field( void *, ctx )
217 __field( void *, req )
218 __field( void *, target_req )
224 __entry->target_req = target_req;
227 TP_printk("ring %p, request %p linked after %p",
228 __entry->ctx, __entry->req, __entry->target_req)
232 * io_uring_cqring_wait - called before start waiting for an available CQE
234 * @ctx: pointer to a ring context structure
235 * @min_events: minimal number of events to wait for
237 * Allows to track waiting for CQE, so that we can e.g. troubleshoot
238 * situations, when an application wants to wait for an event, that never
241 TRACE_EVENT(io_uring_cqring_wait,
243 TP_PROTO(void *ctx, int min_events),
245 TP_ARGS(ctx, min_events),
248 __field( void *, ctx )
249 __field( int, min_events )
254 __entry->min_events = min_events;
257 TP_printk("ring %p, min_events %d", __entry->ctx, __entry->min_events)
261 * io_uring_fail_link - called before failing a linked request
263 * @req: request, which links were cancelled
264 * @link: cancelled link
266 * Allows to track linked requests cancellation, to see not only that some work
267 * was cancelled, but also which request was the reason.
269 TRACE_EVENT(io_uring_fail_link,
271 TP_PROTO(void *req, void *link),
276 __field( void *, req )
277 __field( void *, link )
282 __entry->link = link;
285 TP_printk("request %p, link %p", __entry->req, __entry->link)
289 * io_uring_complete - called when completing an SQE
291 * @ctx: pointer to a ring context structure
292 * @user_data: user data associated with the request
293 * @res: result of the request
294 * @cflags: completion flags
297 TRACE_EVENT(io_uring_complete,
299 TP_PROTO(void *ctx, u64 user_data, int res, unsigned cflags),
301 TP_ARGS(ctx, user_data, res, cflags),
304 __field( void *, ctx )
305 __field( u64, user_data )
307 __field( unsigned, cflags )
312 __entry->user_data = user_data;
314 __entry->cflags = cflags;
317 TP_printk("ring %p, user_data 0x%llx, result %d, cflags %x",
318 __entry->ctx, (unsigned long long)__entry->user_data,
319 __entry->res, __entry->cflags)
323 * io_uring_submit_sqe - called before submitting one SQE
325 * @ctx: pointer to a ring context structure
326 * @req: pointer to a submitted request
327 * @opcode: opcode of request
328 * @user_data: user data associated with the request
329 * @flags request flags
330 * @force_nonblock: whether a context blocking or not
331 * @sq_thread: true if sq_thread has submitted this SQE
333 * Allows to track SQE submitting, to understand what was the source of it, SQ
334 * thread or io_uring_enter call.
336 TRACE_EVENT(io_uring_submit_sqe,
338 TP_PROTO(void *ctx, void *req, u8 opcode, u64 user_data, u32 flags,
339 bool force_nonblock, bool sq_thread),
341 TP_ARGS(ctx, req, opcode, user_data, flags, force_nonblock, sq_thread),
344 __field( void *, ctx )
345 __field( void *, req )
346 __field( u8, opcode )
347 __field( u64, user_data )
348 __field( u32, flags )
349 __field( bool, force_nonblock )
350 __field( bool, sq_thread )
356 __entry->opcode = opcode;
357 __entry->user_data = user_data;
358 __entry->flags = flags;
359 __entry->force_nonblock = force_nonblock;
360 __entry->sq_thread = sq_thread;
363 TP_printk("ring %p, req %p, op %d, data 0x%llx, flags %u, "
364 "non block %d, sq_thread %d", __entry->ctx, __entry->req,
365 __entry->opcode, (unsigned long long)__entry->user_data,
366 __entry->flags, __entry->force_nonblock, __entry->sq_thread)
370 * io_uring_poll_arm - called after arming a poll wait if successful
372 * @ctx: pointer to a ring context structure
373 * @req: pointer to the armed request
374 * @opcode: opcode of request
375 * @user_data: user data associated with the request
376 * @mask: request poll events mask
377 * @events: registered events of interest
379 * Allows to track which fds are waiting for and what are the events of
382 TRACE_EVENT(io_uring_poll_arm,
384 TP_PROTO(void *ctx, void *req, u8 opcode, u64 user_data,
385 int mask, int events),
387 TP_ARGS(ctx, req, opcode, user_data, mask, events),
390 __field( void *, ctx )
391 __field( void *, req )
392 __field( u8, opcode )
393 __field( u64, user_data )
395 __field( int, events )
401 __entry->opcode = opcode;
402 __entry->user_data = user_data;
403 __entry->mask = mask;
404 __entry->events = events;
407 TP_printk("ring %p, req %p, op %d, data 0x%llx, mask 0x%x, events 0x%x",
408 __entry->ctx, __entry->req, __entry->opcode,
409 (unsigned long long) __entry->user_data,
410 __entry->mask, __entry->events)
413 TRACE_EVENT(io_uring_poll_wake,
415 TP_PROTO(void *ctx, u8 opcode, u64 user_data, int mask),
417 TP_ARGS(ctx, opcode, user_data, mask),
420 __field( void *, ctx )
421 __field( u8, opcode )
422 __field( u64, user_data )
428 __entry->opcode = opcode;
429 __entry->user_data = user_data;
430 __entry->mask = mask;
433 TP_printk("ring %p, op %d, data 0x%llx, mask 0x%x",
434 __entry->ctx, __entry->opcode,
435 (unsigned long long) __entry->user_data,
439 TRACE_EVENT(io_uring_task_add,
441 TP_PROTO(void *ctx, u8 opcode, u64 user_data, int mask),
443 TP_ARGS(ctx, opcode, user_data, mask),
446 __field( void *, ctx )
447 __field( u8, opcode )
448 __field( u64, user_data )
454 __entry->opcode = opcode;
455 __entry->user_data = user_data;
456 __entry->mask = mask;
459 TP_printk("ring %p, op %d, data 0x%llx, mask %x",
460 __entry->ctx, __entry->opcode,
461 (unsigned long long) __entry->user_data,
466 * io_uring_task_run - called when task_work_run() executes the poll events
467 * notification callbacks
469 * @ctx: pointer to a ring context structure
470 * @req: pointer to the armed request
471 * @opcode: opcode of request
472 * @user_data: user data associated with the request
474 * Allows to track when notified poll events are processed
476 TRACE_EVENT(io_uring_task_run,
478 TP_PROTO(void *ctx, void *req, u8 opcode, u64 user_data),
480 TP_ARGS(ctx, req, opcode, user_data),
483 __field( void *, ctx )
484 __field( void *, req )
485 __field( u8, opcode )
486 __field( u64, user_data )
492 __entry->opcode = opcode;
493 __entry->user_data = user_data;
496 TP_printk("ring %p, req %p, op %d, data 0x%llx",
497 __entry->ctx, __entry->req, __entry->opcode,
498 (unsigned long long) __entry->user_data)
502 * io_uring_req_failed - called when an sqe is errored dring submission
504 * @sqe: pointer to the io_uring_sqe that failed
505 * @error: error it failed with
507 * Allows easier diagnosing of malformed requests in production systems.
509 TRACE_EVENT(io_uring_req_failed,
511 TP_PROTO(const struct io_uring_sqe *sqe, int error),
516 __field( u8, opcode )
518 __field( u8, ioprio )
522 __field( u32, op_flags )
523 __field( u64, user_data )
524 __field( u16, buf_index )
525 __field( u16, personality )
526 __field( u32, file_index )
529 __field( int, error )
533 __entry->opcode = sqe->opcode;
534 __entry->flags = sqe->flags;
535 __entry->ioprio = sqe->ioprio;
536 __entry->off = sqe->off;
537 __entry->addr = sqe->addr;
538 __entry->len = sqe->len;
539 __entry->op_flags = sqe->rw_flags;
540 __entry->user_data = sqe->user_data;
541 __entry->buf_index = sqe->buf_index;
542 __entry->personality = sqe->personality;
543 __entry->file_index = sqe->file_index;
544 __entry->pad1 = sqe->__pad2[0];
545 __entry->pad2 = sqe->__pad2[1];
546 __entry->error = error;
549 TP_printk("op %d, flags=0x%x, prio=%d, off=%llu, addr=%llu, "
550 "len=%u, rw_flags=0x%x, user_data=0x%llx, buf_index=%d, "
551 "personality=%d, file_index=%d, pad=0x%llx/%llx, error=%d",
552 __entry->opcode, __entry->flags, __entry->ioprio,
553 (unsigned long long)__entry->off,
554 (unsigned long long) __entry->addr, __entry->len,
555 __entry->op_flags, (unsigned long long) __entry->user_data,
556 __entry->buf_index, __entry->personality, __entry->file_index,
557 (unsigned long long) __entry->pad1,
558 (unsigned long long) __entry->pad2, __entry->error)
561 #endif /* _TRACE_IO_URING_H */
563 /* This part must be outside protection */
564 #include <trace/define_trace.h>