io_uring: add set of tracing events
Subsystems (4)
RFC v2 1/1 io_uring: add set of tracing events
To trace io_uring activity one can get an information from workqueue and io trace events, but looks like some parts could be hard to identify via this approach. Making what happens inside io_uring more transparent is important to be able to reason about many aspects of it, hence introduce the set of tracing events.
All such events could be roughly divided into two categories:
* those, that are helping to understand correctness (from both kernel and an application point of view). E.g. a ring creation, file registration, or waiting for available CQE. Proposed approach is to get a pointer to an original structure of interest (ring context, or request), and then find relevant events. io_uring_queue_async_work also exposes a pointer to work_struct, to be able to track down corresponding workqueue events.
* those, that provide performance related information. Mostly it's about events that change the flow of requests, e.g. whether an async work was queued, or delayed due to some dependencies. Another important case is how io_uring optimizations (e.g. registered files) are utilized.
---
v1: add io_uring_link trace event
v2: Extend io_uring events, to include not only io_uring_link, but other
events to cover important parts of the functionality
fs/io_uring.c | 19 ++ include/Kbuild | 1 + include/trace/events/io_uring.h | 372 ++++++++++++++++++++++++++++++++ 3 files changed, 392 insertions(+) create mode 100644 include/trace/events/io_uring.h
fs/io_uring.c +19 -0
@@ -71,6 +71,9 @@#include <linux/sizes.h> #include <linux/hugetlb.h> +#define CREATE_TRACE_POINTS +#include <trace/events/io_uring.h> +#include <uapi/linux/io_uring.h> #include "internal.h"
@@ -483,6 +486,7 @@ static inline void io_queue_async_work(struct io_ring_ctx *ctx, } } +trace_io_uring_queue_async_work (ctx, rw, req, &req->work, req->flags);queue_work (ctx->sqo_wq[rw], &req->work); }
@@ -707,6 +711,7 @@ static void io_fail_links(struct io_kiocb *req) {struct io_kiocb *link; +trace_io_uring_fail_links (req);while (!list_empty (&req->link_list)) { link = list_first_entry(&req->link_list, struct io_kiocb, list);list_del (&link->list);
@@ -1292,6 +1297,7 @@ static ssize_t io_import_iovec(struct io_ring_ctx *ctx, int rw, iovec, iter);#endif +trace_io_uring_import_iovec (ctx, buf);return import_iovec (rw, buf, sqe_len,UIO_FASTIOV , iovec, iter); }
@@ -2021,6 +2027,7 @@ static int io_req_defer(struct io_ring_ctx *ctx, struct io_kiocb *req, req->submit.sqe = sqe_copy;INIT_WORK (&req->work, io_sq_wq_submit_work); +trace_io_uring_defer (ctx, req, false);list_add_tail (&req->list, &ctx->defer_list);spin_unlock_irq (&ctx->completion_lock);return -EIOCBQUEUED ;
@@ -2327,6 +2334,7 @@ static int io_req_set_file(struct io_ring_ctx *ctx, const struct sqe_submit *s, }else {if (s->needs_fixed_file)return -EBADF ; +trace_io_uring_file_get (ctx, fd); req->file =io_file_get (state, fd);if (unlikely (!req->file))return -EBADF ;
@@ -2357,6 +2365,8 @@ static int __io_queue_sqe(struct io_ring_ctx *ctx, struct io_kiocb *req,INIT_WORK (&req->work, io_sq_wq_submit_work);io_queue_async_work (ctx, req); } +else +trace_io_uring_add_to_prev (ctx, req);/* * Queued up for async execution, worker will release
@@ -2430,6 +2440,7 @@ static int io_queue_link_head(struct io_ring_ctx *ctx, struct io_kiocb *req,/* Insert shadow req to defer_list, blocking next IOs */ spin_lock_irq (&ctx->completion_lock); +trace_io_uring_defer (ctx, shadow, true);list_add_tail (&shadow->list, &ctx->defer_list);spin_unlock_irq (&ctx->completion_lock);
@@ -2488,6 +2499,7 @@ static void io_submit_sqe(struct io_ring_ctx *ctx, struct sqe_submit *s, s->sqe = sqe_copy;memcpy (&req->submit, s,sizeof (*s)); +trace_io_uring_link (ctx, req, prev);list_add_tail (&req->list, &prev->link_list); }else if (s->sqe->flags &IOSQE_IO_LINK ) { req->flags |=REQ_F_LINK ;
@@ -2626,6 +2638,7 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, struct sqe_submit *sqes, sqes[i].has_user = has_user; sqes[i].needs_lock = true; sqes[i].needs_fixed_file = true; +trace_io_uring_submit_sqe (ctx, true, true);io_submit_sqe (ctx, &sqes[i], statep, &link, true); submitted++; }
@@ -2824,6 +2837,7 @@ static int io_ring_submit(struct io_ring_ctx *ctx, unsigned int to_submit,if (block_for_last && submit == to_submit) force_nonblock = false; +trace_io_uring_submit_sqe (ctx, force_nonblock, false);io_submit_sqe (ctx, &s, statep, &link, force_nonblock); }io_commit_sqring (ctx);
@@ -2906,6 +2920,7 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, ret =0 ; iowq.nr_timeouts =atomic_read (&ctx->cq_timeouts); +trace_io_uring_cqring_wait (ctx, min_events); do { prepare_to_wait_exclusive(&ctx->wait, &iowq.wq, TASK_INTERRUPTIBLE);
@@ -4057,6 +4072,7 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p) p->cq_off.cqes = offsetof(struct io_rings , cqes); p->features =IORING_FEAT_SINGLE_MMAP ; +trace_io_uring_create (ret, ctx, p->sq_entries, p->cq_entries, p->flags);return ret; err:io_ring_ctx_wait_and_kill (ctx);
@@ -4194,6 +4210,9 @@ SYSCALL_DEFINE4(io_uring_register, unsigned int, fd, unsigned int, opcode,mutex_lock (&ctx->uring_lock); ret =__io_uring_register (ctx, opcode, arg, nr_args);mutex_unlock (&ctx->uring_lock); +if (ret >=0 ) +trace_io_uring_register (ctx, opcode, ctx->nr_user_files, + ctx->nr_user_bufs, ctx->cq_ev_fd !=NULL ); out_fput:fdput (f);return ret;
include/Kbuild +1 -0
@@ -1028,6 +1028,7 @@ header-test- += trace/events/fsi_master_gpio.h header-test- += trace/events/huge_memory.h header-test- += trace/events/ib_mad.h header-test- += trace/events/ib_umad.h +header-test- += trace/events/io_uring.h header-test- += trace/events/iscsi.h header-test- += trace/events/jbd2.h header-test- += trace/events/kvm.h
include/trace/events/io_uring.h new file +372 -0
372 lines not on this page · raw message
Signature · 1 line
2.21.0
Quoted 24 lines · Dmitrii Dolgov
To trace
io_uringactivity one can get an information from workqueue and io trace events, but looks like some parts could be hard to identify via this approach. Making what happens insideio_uringmore transparent is important to be able to reason about many aspects of it, hence introduce the set of tracing events.All such events could be roughly divided into two categories:
* those, that are helping to understand correctness (from both kernel and an application point of view). E.g. a ring creation, file registration, or waiting for available CQE. Proposed approach is to get a pointer to an original structure of interest (ring context, or request), and then find relevant events.
io_uring_queue_async_workalso exposes a pointer towork_struct, to be able to track down corresponding workqueue events.* those, that provide performance related information. Mostly it's about events that change the flow of requests, e.g. whether an async work was queued, or delayed due to some dependencies. Another important case is how
io_uringoptimizations (e.g. registered files) are utilized.
Quoted 5 lines
Signed-off-by Dmitrii Dolgov <[email protected]>---
v1: addio_uring_linktrace event
v2: Extendio_uringevents, to include not onlyio_uring_link, but other
events to cover important parts of the functionality
To clarify, I refer to this one [1] as v1. Would be glad to get any feedback.
Jens Axboe
maintainerQuoted 16 lines · Dmitrii Dolgov
To trace
io_uringactivity one can get an information from workqueue and io trace events, but looks like some parts could be hard to identify via this approach. Making what happens insideio_uringmore transparent is important to be able to reason about many aspects of it, hence introduce the set of tracing events.All such events could be roughly divided into two categories:
* those, that are helping to understand correctness (from both kernel and an application point of view). E.g. a ring creation, file registration, or waiting for available CQE. Proposed approach is to get a pointer to an original structure of interest (ring context, or request), and then find relevant events.
io_uring_queue_async_workalso exposes a pointer towork_struct, to be able to track down corresponding workqueue events.
Quoted 5 lines
* those, that provide performance related information. Mostly it's about events that change the flow of requests, e.g. whether an async work was queued, or delayed due to some dependencies. Another important case is how
io_uringoptimizations (e.g. registered files) are utilized.
I like this in general, a few questions below.
Quoted 23 lines
fs/io_uring.c +4
-0@@ -71,6 +71,9 @@#include <linux/sizes.h> #include <linux/hugetlb.h> +#define CREATE_TRACE_POINTS +#include <trace/events/io_uring.h> +#include <uapi/linux/io_uring.h> #include "internal.h" @@ -483,6 +486,7 @@ static inline void io_queue_async_work(struct io_ring_ctx *ctx, } } +trace_io_uring_queue_async_work (ctx, rw, req, &req->work, req->flags);queue_work (ctx->sqo_wq[rw], &req->work); }
fs/io_uring.c static void io_fail_links(struct io_kiocb *req) · line 717
Quoted 7 lines
fs/io_uring.c +1
-0@@ -707,6 +711,7 @@ static void io_fail_links(struct io_kiocb *req) {struct io_kiocb *link; +trace_io_uring_fail_links (req);while (!list_empty (&req->link_list)) { link = list_first_entry(&req->link_list, struct io_kiocb, list);list_del (&link->list);
Doesn't look like you have completion events, which makes it hard to tell which dependants got killed when failing the links. Maybe a good thing to add?
fs/io_uring.c static ssize_t io_import_iovec(struct io_ring_ctx *ctx, int rw, · line 1303
Quoted 8 lines
fs/io_uring.c +1
-0@@ -1292,6 +1297,7 @@ static ssize_t io_import_iovec(struct io_ring_ctx *ctx, int rw, iovec, iter);#endif +trace_io_uring_import_iovec (ctx, buf);return import_iovec (rw, buf, sqe_len,UIO_FASTIOV , iovec, iter); }
Not sure I see much merrit in this trace event.
Quoted 17 lines
fs/io_uring.c +2
-0@@ -2021,6 +2027,7 @@ static int io_req_defer(struct io_ring_ctx *ctx, struct io_kiocb *req, req->submit.sqe = sqe_copy;INIT_WORK (&req->work, io_sq_wq_submit_work); +trace_io_uring_defer (ctx, req, false);list_add_tail (&req->list, &ctx->defer_list);spin_unlock_irq (&ctx->completion_lock);return -EIOCBQUEUED ;@@ -2327,6 +2334,7 @@ static int io_req_set_file(struct io_ring_ctx *ctx, const struct sqe_submit *s, }else {if (s->needs_fixed_file)return -EBADF ; +trace_io_uring_file_get (ctx, fd); req->file =io_file_get (state, fd);if (unlikely (!req->file))return -EBADF ;
fs/io_uring.c static int __io_queue_sqe(struct io_ring_ctx *ctx, struct io_kiocb *req, · line 2372
Quoted 8 lines
fs/io_uring.c +2
-0@@ -2357,6 +2365,8 @@ static int __io_queue_sqe(struct io_ring_ctx *ctx, struct io_kiocb *req,INIT_WORK (&req->work, io_sq_wq_submit_work);io_queue_async_work (ctx, req); } +else +trace_io_uring_add_to_prev (ctx, req);/* * Queued up for async execution, worker will release
Maybe put this one in io_add_to_prev_work()? Probably just using the 'ret' as part of the trace, to avoid a branch for this?
Failing that, the style is off a bit, should be:
} else {
trace_io_uring_add_to_prev(ctx, req);
}fs/io_uring.c SYSCALL_DEFINE4(io_uring_register, unsigned int, fd, unsigned int, opcode, · line 4215
Quoted 7 lines
fs/io_uring.c +3
-0@@ -4194,6 +4210,9 @@ SYSCALL_DEFINE4(io_uring_register, unsigned int, fd, unsigned int, opcode,mutex_lock (&ctx->uring_lock); ret =__io_uring_register (ctx, opcode, arg, nr_args);mutex_unlock (&ctx->uring_lock); +if (ret >=0 ) +trace_io_uring_register (ctx, opcode, ctx->nr_user_files, + ctx->nr_user_bufs, ctx->cq_ev_fd !=NULL );
Just trace 'ret' as well?
fs/io_uring.c SYSCALL_DEFINE4(io_uring_register, unsigned int, fd, unsigned int, opcode,
Quoted 7 lines
fs/io_uring.c +7
-0+* io_uring_add_to_prev - called after a request was added into a previously +* submitted work +* +* @ctx: pointer to a ring context structure +* @req: pointer to a request, added to a previous +* +* Allows to track merged work, to figure out how oftern requests are piggy
often
Signature · 1 line
Jens Axboe
Quoted 28 lines · Jens Axboe
Quoted 27 lines
fs/io_uring.c +4
-0@@ -71,6 +71,9 @@#include <linux/sizes.h> #include <linux/hugetlb.h> +#define CREATE_TRACE_POINTS +#include <trace/events/io_uring.h> +#include <uapi/linux/io_uring.h> #include "internal.h" @@ -483,6 +486,7 @@ static inline void io_queue_async_work(struct io_ring_ctx *ctx, } } +trace_io_uring_queue_async_work (ctx, rw, req, &req->work, req->flags);queue_work (ctx->sqo_wq[rw], &req->work); }@@ -707,6 +711,7 @@ static void io_fail_links(struct io_kiocb *req) {struct io_kiocb *link;
Quoted 8 lines
fs/io_uring.c static void io_fail_links(struct io_kiocb *req) · line 717
Quoted 4 lines
fs/io_uring.c +1
-0+trace_io_uring_fail_links (req);while (!list_empty (&req->link_list)) { link = list_first_entry(&req->link_list, struct io_kiocb, list);list_del (&link->list);Doesn't look like you have completion events, which makes it hard to tell which dependants got killed when failing the links. Maybe a good thing to add?
Do you mean an event like "this dependant got killed due to failing a link". Yes, sounds useful.
Quoted 10 lines
fs/io_uring.c static ssize_t io_import_iovec(struct io_ring_ctx *ctx, int rw, · line 1303
Quoted 8 lines
fs/io_uring.c +1
-0@@ -1292,6 +1297,7 @@ static ssize_t io_import_iovec(struct io_ring_ctx *ctx, int rw, iovec, iter);#endif +trace_io_uring_import_iovec (ctx, buf);return import_iovec (rw, buf, sqe_len,UIO_FASTIOV , iovec, iter); }Not sure I see much merrit in this trace event.
Yep. The original idea was to somehow expose the information about "not using" ctx->user_bufs, but after playing around with this events, I see that this one called more often as I thought, and probably just confusing.
Quoted 23 lines
Quoted 23 lines
fs/io_uring.c +4
-0@@ -2021,6 +2027,7 @@ static int io_req_defer(struct io_ring_ctx *ctx, struct io_kiocb *req, req->submit.sqe = sqe_copy;INIT_WORK (&req->work, io_sq_wq_submit_work); +trace_io_uring_defer (ctx, req, false);list_add_tail (&req->list, &ctx->defer_list);spin_unlock_irq (&ctx->completion_lock);return -EIOCBQUEUED ;@@ -2327,6 +2334,7 @@ static int io_req_set_file(struct io_ring_ctx *ctx, const struct sqe_submit *s, }else {if (s->needs_fixed_file)return -EBADF ; +trace_io_uring_file_get (ctx, fd); req->file =io_file_get (state, fd);if (unlikely (!req->file))return -EBADF ;@@ -2357,6 +2365,8 @@ static int __io_queue_sqe(struct io_ring_ctx *ctx, struct io_kiocb *req,INIT_WORK (&req->work, io_sq_wq_submit_work);io_queue_async_work (ctx, req); } +else +trace_io_uring_add_to_prev (ctx, req);
Quoted 5 lines
fs/io_uring.c static int __io_queue_sqe(struct io_ring_ctx *ctx, struct io_kiocb *req, · line 2372
Quoted 2 lines
fs/io_uring.c +0
-0/* * Queued up for async execution, worker will release Maybe put this one in
io_add_to_prev_work()? Probably just using the 'ret' as part of the trace, to avoid a branch for this?
I thought about this, but then there will be no pointer to the context, and it would be harder to figure out to what exactly this event corresponds to.
On the other hand we can track down the pointer to req, and then everything should be clear. It involved a bit more efforts to analyze, but probably it acceptable. So, I will indeed it move into io_add_to_prev_work.
Quoted 23 lines
Failing that, the style is off a bit, should be:
} else { trace_io_uring_add_to_prev(ctx, req); }fs/io_uring.c SYSCALL_DEFINE4(io_uring_register, unsigned int, fd, unsigned int, opcode, · line 4215
Quoted 7 lines
fs/io_uring.c +3
-0@@ -4194,6 +4210,9 @@ SYSCALL_DEFINE4(io_uring_register, unsigned int, fd, unsigned int, opcode,mutex_lock (&ctx->uring_lock); ret =__io_uring_register (ctx, opcode, arg, nr_args);mutex_unlock (&ctx->uring_lock); +if (ret >=0 ) +trace_io_uring_register (ctx, opcode, ctx->nr_user_files, + ctx->nr_user_bufs, ctx->cq_ev_fd !=NULL );Just trace 'ret' as well?
fs/io_uring.c SYSCALL_DEFINE4(io_uring_register, unsigned int, fd, unsigned int, opcode,
Quoted 7 lines
fs/io_uring.c +7
-0+* io_uring_add_to_prev - called after a request was added into a previously +* submitted work +* +* @ctx: pointer to a ring context structure +* @req: pointer to a request, added to a previous +* +* Allows to track merged work, to figure out how oftern requests are piggy
Quoted 1 line
often
Sure, will fix both typo and 'ret' tracing. Thanks for the comments!