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 0x%x",
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
62 * Allows to trace fixed files/buffers, that could be registered to
63 * avoid an overhead of getting references to them for every operation. This
64 * event, together with io_uring_file_get, can provide a full picture of how
65 * much overhead one can reduce via fixing.
67 TRACE_EVENT(io_uring_register,
69 TP_PROTO(void *ctx, unsigned opcode, unsigned nr_files,
70 unsigned nr_bufs, long ret),
72 TP_ARGS(ctx, opcode, nr_files, nr_bufs, ret),
75 __field( void *, ctx )
76 __field( unsigned, opcode )
77 __field( unsigned, nr_files)
78 __field( unsigned, nr_bufs )
84 __entry->opcode = opcode;
85 __entry->nr_files = nr_files;
86 __entry->nr_bufs = nr_bufs;
90 TP_printk("ring %p, opcode %d, nr_user_files %d, nr_user_bufs %d, "
92 __entry->ctx, __entry->opcode, __entry->nr_files,
93 __entry->nr_bufs, __entry->ret)
97 * io_uring_file_get - called before getting references to an SQE file
99 * @ctx: pointer to a ring context structure
100 * @req: pointer to a submitted request
101 * @user_data: user data associated with the 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(void *ctx, void *req, unsigned long long user_data, int fd),
112 TP_ARGS(ctx, req, user_data, fd),
115 __field( void *, ctx )
116 __field( void *, req )
117 __field( u64, user_data )
124 __entry->user_data = 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 * @ctx: pointer to a ring context structure
136 * @req: pointer to a submitted request
137 * @user_data: user data associated with the request
138 * @opcode: opcode of request
139 * @flags request flags
140 * @work: pointer to a submitted io_wq_work
141 * @rw: type of workqueue, hashed or normal
143 * Allows to trace asynchronous work submission.
145 TRACE_EVENT(io_uring_queue_async_work,
147 TP_PROTO(void *ctx, void * req, unsigned long long user_data, u8 opcode,
148 unsigned int flags, struct io_wq_work *work, int rw),
150 TP_ARGS(ctx, req, user_data, flags, opcode, work, rw),
153 __field( void *, ctx )
154 __field( void *, req )
155 __field( u64, user_data )
156 __field( u8, opcode )
157 __field( unsigned int, flags )
158 __field( struct io_wq_work *, work )
165 __entry->user_data = user_data;
166 __entry->flags = flags;
167 __entry->opcode = opcode;
168 __entry->work = work;
172 TP_printk("ring %p, request %p, user_data 0x%llx, opcode %d, flags 0x%x, %s queue, work %p",
173 __entry->ctx, __entry->req, __entry->user_data, __entry->opcode,
174 __entry->flags, __entry->rw ? "hashed" : "normal", __entry->work)
178 * io_uring_defer - called when an io_uring request is deferred
180 * @ctx: pointer to a ring context structure
181 * @req: pointer to a deferred request
182 * @user_data: user data associated with the request
183 * @opcode: opcode of request
185 * Allows to track deferred requests, to get an insight about what requests are
186 * not started immediately.
188 TRACE_EVENT(io_uring_defer,
190 TP_PROTO(void *ctx, void *req, unsigned long long user_data, u8 opcode),
192 TP_ARGS(ctx, req, user_data, opcode),
195 __field( void *, ctx )
196 __field( void *, req )
197 __field( unsigned long long, data )
198 __field( u8, opcode )
204 __entry->data = user_data;
205 __entry->opcode = opcode;
208 TP_printk("ring %p, request %p, user_data 0x%llx, opcode %d",
209 __entry->ctx, __entry->req, __entry->data, __entry->opcode)
213 * io_uring_link - called before the io_uring request added into link_list of
216 * @ctx: pointer to a ring context structure
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(void *ctx, void *req, void *target_req),
227 TP_ARGS(ctx, req, target_req),
230 __field( void *, ctx )
231 __field( void *, req )
232 __field( void *, target_req )
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 * @ctx: pointer to a ring context structure
278 * @req: request, which links were cancelled
279 * @user_data: user data associated with the request
280 * @opcode: opcode of request
281 * @link: cancelled link
283 * Allows to track linked requests cancellation, to see not only that some work
284 * was cancelled, but also which request was the reason.
286 TRACE_EVENT(io_uring_fail_link,
288 TP_PROTO(void *ctx, void *req, unsigned long long user_data, u8 opcode, void *link),
290 TP_ARGS(ctx, req, user_data, opcode, link),
293 __field( void *, ctx )
294 __field( void *, req )
295 __field( unsigned long long, user_data )
296 __field( u8, opcode )
297 __field( void *, link )
303 __entry->user_data = user_data;
304 __entry->opcode = opcode;
305 __entry->link = link;
308 TP_printk("ring %p, request %p, user_data 0x%llx, opcode %d, link %p",
309 __entry->ctx, __entry->req, __entry->user_data, __entry->opcode,
314 * io_uring_complete - called when completing an SQE
316 * @ctx: pointer to a ring context structure
317 * @req: pointer to a submitted request
318 * @user_data: user data associated with the request
319 * @res: result of the request
320 * @cflags: completion flags
323 TRACE_EVENT(io_uring_complete,
325 TP_PROTO(void *ctx, void *req, u64 user_data, int res, unsigned cflags),
327 TP_ARGS(ctx, req, user_data, res, cflags),
330 __field( void *, ctx )
331 __field( void *, req )
332 __field( u64, user_data )
334 __field( unsigned, cflags )
340 __entry->user_data = user_data;
342 __entry->cflags = cflags;
345 TP_printk("ring %p, req %p, user_data 0x%llx, result %d, cflags 0x%x",
346 __entry->ctx, __entry->req,
348 __entry->res, __entry->cflags)
352 * io_uring_submit_sqe - called before submitting one SQE
354 * @ctx: pointer to a ring context structure
355 * @req: pointer to a submitted request
356 * @user_data: user data associated with the request
357 * @opcode: opcode of request
358 * @flags request flags
359 * @force_nonblock: whether a context blocking or not
360 * @sq_thread: true if sq_thread has submitted this SQE
362 * Allows to track SQE submitting, to understand what was the source of it, SQ
363 * thread or io_uring_enter call.
365 TRACE_EVENT(io_uring_submit_sqe,
367 TP_PROTO(void *ctx, void *req, unsigned long long user_data, u8 opcode, u32 flags,
368 bool force_nonblock, bool sq_thread),
370 TP_ARGS(ctx, req, user_data, opcode, flags, force_nonblock, sq_thread),
373 __field( void *, ctx )
374 __field( void *, req )
375 __field( unsigned long long, user_data )
376 __field( u8, opcode )
377 __field( u32, flags )
378 __field( bool, force_nonblock )
379 __field( bool, sq_thread )
385 __entry->user_data = user_data;
386 __entry->opcode = opcode;
387 __entry->flags = flags;
388 __entry->force_nonblock = force_nonblock;
389 __entry->sq_thread = sq_thread;
392 TP_printk("ring %p, req %p, user_data 0x%llx, opcode %d, flags 0x%x, "
393 "non block %d, sq_thread %d", __entry->ctx, __entry->req,
394 __entry->user_data, __entry->opcode,
395 __entry->flags, __entry->force_nonblock, __entry->sq_thread)
399 * io_uring_poll_arm - called after arming a poll wait if successful
401 * @ctx: pointer to a ring context structure
402 * @req: pointer to the armed request
403 * @user_data: user data associated with the request
404 * @opcode: opcode of request
405 * @mask: request poll events mask
406 * @events: registered events of interest
408 * Allows to track which fds are waiting for and what are the events of
411 TRACE_EVENT(io_uring_poll_arm,
413 TP_PROTO(void *ctx, void *req, u64 user_data, u8 opcode,
414 int mask, int events),
416 TP_ARGS(ctx, req, user_data, opcode, mask, events),
419 __field( void *, ctx )
420 __field( void *, req )
421 __field( unsigned long long, user_data )
422 __field( u8, opcode )
424 __field( int, events )
430 __entry->user_data = user_data;
431 __entry->opcode = opcode;
432 __entry->mask = mask;
433 __entry->events = events;
436 TP_printk("ring %p, req %p, user_data 0x%llx, opcode %d, mask 0x%x, events 0x%x",
437 __entry->ctx, __entry->req, __entry->user_data, __entry->opcode,
438 __entry->mask, __entry->events)
442 * io_uring_task_add - called after adding a task
444 * @ctx: pointer to a ring context structure
445 * @req: pointer to request
446 * @user_data: user data associated with the request
447 * @opcode: opcode of request
448 * @mask: request poll events mask
451 TRACE_EVENT(io_uring_task_add,
453 TP_PROTO(void *ctx, void *req, unsigned long long user_data, u8 opcode, int mask),
455 TP_ARGS(ctx, req, user_data, opcode, mask),
458 __field( void *, ctx )
459 __field( void *, req )
460 __field( unsigned long long, user_data )
461 __field( u8, opcode )
468 __entry->user_data = user_data;
469 __entry->opcode = opcode;
470 __entry->mask = mask;
473 TP_printk("ring %p, req %p, user_data 0x%llx, opcode %d, mask %x",
474 __entry->ctx, __entry->req, __entry->user_data, __entry->opcode,
479 * io_uring_req_failed - called when an sqe is errored dring submission
481 * @sqe: pointer to the io_uring_sqe that failed
482 * @ctx: pointer to a ring context structure
483 * @req: pointer to request
484 * @error: error it failed with
486 * Allows easier diagnosing of malformed requests in production systems.
488 TRACE_EVENT(io_uring_req_failed,
490 TP_PROTO(const struct io_uring_sqe *sqe, void *ctx, void *req, int error),
492 TP_ARGS(sqe, ctx, req, error),
495 __field( void *, ctx )
496 __field( void *, req )
497 __field( unsigned long long, user_data )
498 __field( u8, opcode )
500 __field( u8, ioprio )
504 __field( u32, op_flags )
505 __field( u16, buf_index )
506 __field( u16, personality )
507 __field( u32, file_index )
510 __field( int, error )
516 __entry->user_data = sqe->user_data;
517 __entry->opcode = sqe->opcode;
518 __entry->flags = sqe->flags;
519 __entry->ioprio = sqe->ioprio;
520 __entry->off = sqe->off;
521 __entry->addr = sqe->addr;
522 __entry->len = sqe->len;
523 __entry->op_flags = sqe->rw_flags;
524 __entry->buf_index = sqe->buf_index;
525 __entry->personality = sqe->personality;
526 __entry->file_index = sqe->file_index;
527 __entry->pad1 = sqe->__pad2[0];
528 __entry->pad2 = sqe->__pad2[1];
529 __entry->error = error;
532 TP_printk("ring %p, req %p, user_data 0x%llx, "
533 "op %d, flags 0x%x, prio=%d, off=%llu, addr=%llu, "
534 "len=%u, rw_flags=0x%x, buf_index=%d, "
535 "personality=%d, file_index=%d, pad=0x%llx/%llx, error=%d",
536 __entry->ctx, __entry->req, __entry->user_data,
537 __entry->opcode, __entry->flags, __entry->ioprio,
538 (unsigned long long)__entry->off,
539 (unsigned long long) __entry->addr, __entry->len,
541 __entry->buf_index, __entry->personality, __entry->file_index,
542 (unsigned long long) __entry->pad1,
543 (unsigned long long) __entry->pad2, __entry->error)
546 #endif /* _TRACE_IO_URING_H */
548 /* This part must be outside protection */
549 #include <trace/define_trace.h>