Add io_uring_iowait_toggle()
PATCH v2 1/1 Add io_uring_iowait_toggle()
Add io_uring_iowait_toggle() helper function for the userspace liburing side of IORING_ENTER_NO_IOWAIT flag added in io_uring for 6.12.
This function toggles whether a ring sets in_iowait when waiting for completions. This is useful when waiting for multiple batched completions using e.g. io_uring_submit_and_wait_timeout() and userspace treats iowait time as CPU utilization.
It works by keeping an internal flag INT_FLAG_NO_IOWAIT, which if set will set IORING_ENTER_NO_IOWAIT on every io_uring_enter().
Manpages are added/modified, a unit test is included, and io_uring.h is synced with the kernel side.
Signed-off-by David Wei <[email protected]>
---
v2:
- edit manpages
--- man/io_uring_enter.2 | 6 ++ man/io_uring_iowait_toggle.3 | 52 ++++++++++ src/include/liburing.h | 1 + src/include/liburing/io_uring.h | 2 + src/int_flags.h | 1 + src/liburing.map | 2 + src/queue.c | 2 + src/setup.c | 12 +++ test/Makefile | 1 + test/no-iowait.c | 162 ++++++++++++++++++++++++++++++++ 10 files changed, 241 insertions(+) create mode 100644 man/io_uring_iowait_toggle.3 create mode 100644 test/no-iowait.c
man/io_uring_enter.2 +6 -0
@@ -104,6 +104,12 @@ If the ring file descriptor has been registered through use of then setting this flag will tell the kernel that the .I ring_fd passed in is the registered ring offset rather than a normal file descriptor. +.TP +.B IORING_ENTER_NO_IOWAIT +If this flag is set, then waiting on events will not be accounted as iowait for +the task if +.BR io_uring_enter (2) +results in waiting. .PP .PP
man/io_uring_iowait_toggle.3 new file +52 -0
52 lines not on this page · raw message
src/include/liburing.h +1 -0
@@ -243,6 +243,7 @@ int io_uring_unregister_napi(struct io_uring *ring, struct io_uring_napi *napi);int io_uring_get_events (struct io_uring *ring);int io_uring_submit_and_get_events (struct io_uring *ring); +int io_uring_iowait_toggle (struct io_uring *ring,bool enabled);/* * io_uring syscalls.
src/include/liburing/io_uring.h +2 -0
@@ -504,6 +504,7 @@ struct io_cqring_offsets {#define IORING_ENTER_SQ_WAIT (1U << 2)#define IORING_ENTER_EXT_ARG (1U << 3)#define IORING_ENTER_REGISTERED_RING (1U << 4) +#define IORING_ENTER_NO_IOWAIT (1U << 6)/* * Passed in for io_uring_setup(2). Copied back with updated info on success
@@ -539,6 +540,7 @@ struct io_uring_params {#define IORING_FEAT_LINKED_FILE (1U << 12)#define IORING_FEAT_REG_REG_RING (1U << 13)#define IORING_FEAT_RECVSEND_BUNDLE (1U << 14) +#define IORING_FEAT_IOWAIT_TOGGLE (1U << 15)/* * io_uring_register(2) opcodes and arguments
src/int_flags.h +1 -0
@@ -6,6 +6,7 @@ enum {INT_FLAG_REG_RING =1 ,INT_FLAG_REG_REG_RING =2 ,INT_FLAG_APP_MEM =4 , + INT_FLAG_NO_IOWAIT = 8, };#endif
src/liburing.map +2 -0
@@ -97,4 +97,6 @@ LIBURING_2.7 { } LIBURING_2.6; LIBURING_2.8 { + global: + io_uring_iowait_toggle; } LIBURING_2.7;
src/queue.c +2 -0
@@ -110,6 +110,8 @@ static int _io_uring_get_cqe(struct io_uring *ring,if (ring->int_flags &INT_FLAG_REG_RING ) flags |=IORING_ENTER_REGISTERED_RING ; +if (ring->int_flags &INT_FLAG_NO_IOWAIT ) + flags |=IORING_ENTER_NO_IOWAIT ; ret =__sys_io_uring_enter2 (ring->enter_ring_fd, data->submit, data->wait_nr, flags, data->arg, data->sz);
src/setup.c +12 -0
@@ -687,3 +687,15 @@ int io_uring_free_buf_ring(struct io_uring *ring, struct io_uring_buf_ring *br,__sys_munmap (br, nentries *sizeof (struct io_uring_buf ));return 0 ; } + +int io_uring_iowait_toggle (struct io_uring *ring,bool enabled) +{ +if (!(ring->features &IORING_FEAT_IOWAIT_TOGGLE )) +return -EOPNOTSUPP ; + +if (enabled) + ring->int_flags &= ~INT_FLAG_NO_IOWAIT ; +else + ring->int_flags |=INT_FLAG_NO_IOWAIT ; +return 0 ; +}
test/Makefile +1 -0
@@ -125,6 +125,7 @@ test_srcs := \ msg-ring-flags.c \ msg-ring-overflow.c \ multicqes_drain.c \ + no-iowait.c \ no-mmap-inval.c \ nolibc.c \ nop-all-sizes.c \
test/no-iowait.c new file +162 -0
162 lines not on this page · raw message
Signature · 1 line
2.43.5