io_uring: enable toggle of iowait usage when waiting on CQEs
Jens Axboe
maintainerPATCH 1/1 io_uring: enable toggle of iowait usage when waiting on CQEs
By default, io_uring marks a waiting task as being in iowait, if it's sleeping waiting on events and there are pending requests. This isn't necessarily always useful, and may be confusing on non-storage setups where iowait isn't expected. It can also cause extra power usage, by preventing the CPU from entering lower sleep states.
This adds a new enter flag, IORING_ENTER_NO_IOWAIT. If set, then io_uring will not mark the sleeping task as being in iowait.
---
This is easily paired with an io_uring_set_iowait(ring, bool) on the liburing side, which can add it to its internal flags. Might be worth adding a FEAT flag for this too, so a caller knows if it'll be honored or not. Can also be detected by an EINVAL return on the first io_uring_enter(2) call with the flag set, but that's a bit more cumbersome.
include/uapi/linux/io_uring.h +1 -0
@@ -546,6 +546,7 @@ struct io_cqring_offsets {#define IORING_ENTER_REGISTERED_RING (1U << 4)#define IORING_ENTER_ABS_TIMER (1U << 5)#define IORING_ENTER_EXT_ARG_REG (1U << 6) +#define IORING_ENTER_NO_IOWAIT (1U << 7)/* * Passed in for io_uring_setup(2). Copied back with updated info on success
io_uring/io_uring.c +18 -12
@@ -2483,8 +2483,18 @@ static int io_cqring_schedule_timeout(struct io_wait_queue *iowq,return READ_ONCE (iowq->hit_timeout) ? -ETIME :0 ; } +struct ext_arg { +size_t argsz; +struct timespec64 ts; +const sigset_t __user *sig; +ktime_t min_time; +bool ts_set; +bool iowait; +}; +static int __io_cqring_wait_schedule (struct io_ring_ctx *ctx,struct io_wait_queue *iowq, +struct ext_arg *ext_arg,ktime_t start_time) {int ret =0 ;
@@ -2494,7 +2504,7 @@ static int __io_cqring_wait_schedule(struct io_ring_ctx *ctx,* can take into account that the task is waiting for IO - turns out * to be important for low QD IO. */ -if (current_pending_io ()) +if (ext_arg->iowait &¤t_pending_io ()) current->in_iowait =1 ;if (iowq->timeout !=KTIME_MAX || iowq->min_timeout) ret =io_cqring_schedule_timeout (iowq, ctx->clockid, start_time);
@@ -2507,6 +2517,7 @@ static int __io_cqring_wait_schedule(struct io_ring_ctx *ctx,/* If this returns > 0, the caller should retry */ static inline int io_cqring_wait_schedule (struct io_ring_ctx *ctx,struct io_wait_queue *iowq, +struct ext_arg *ext_arg,ktime_t start_time) {if (unlikely (READ_ONCE (ctx->check_cq)))
@@ -2520,17 +2531,9 @@ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx,if (unlikely (io_should_wake (iowq)))return 0 ; -return __io_cqring_wait_schedule (ctx, iowq, start_time); +return __io_cqring_wait_schedule (ctx, iowq, ext_arg, start_time); } -struct ext_arg { -size_t argsz; -struct timespec64 ts; -const sigset_t __user *sig; -ktime_t min_time; -bool ts_set; -}; -/* * Wait until events become available, if we don't already have some. The * application must reap them itself, as they reside on the shared cq ring.
@@ -2608,7 +2611,7 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags, TASK_INTERRUPTIBLE); } - ret =io_cqring_wait_schedule (ctx, &iowq, start_time); + ret =io_cqring_wait_schedule (ctx, &iowq, ext_arg, start_time);__set_current_state (TASK_RUNNING );atomic_set (&ctx->cq_wait_nr,IO_CQ_WAKE_INIT );
@@ -3265,6 +3268,8 @@ static int io_get_ext_arg(struct io_ring_ctx *ctx, unsigned flags,const struct io_uring_getevents_arg __user *uarg = argp;struct io_uring_getevents_arg arg; + ext_arg->iowait = !(flags &IORING_ENTER_NO_IOWAIT ); +/* * If EXT_ARG isn't set, then we have no timespec and the argp pointer * is just a pointer to the sigset_t.
@@ -3342,7 +3347,8 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,IORING_ENTER_SQ_WAIT |IORING_ENTER_EXT_ARG |IORING_ENTER_REGISTERED_RING |IORING_ENTER_ABS_TIMER | - IORING_ENTER_EXT_ARG_REG))) +IORING_ENTER_EXT_ARG_REG | + IORING_ENTER_NO_IOWAIT))) return -EINVAL;/*
Signature · 1 line
Jens Axboe