From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379493; b=ChOhFrvHGaf0MT1FNpC5YM4ohclVSh6THDkDdQs2XgItm/dtT5tT+JT/Dx84GZgLmhz9 EVOuYboeyzMIj267B7AF6S2J9wXDIAa+k7IO++70doGqgca0H44Ho+TRWSTQVSH9OWQqp VXFK77kHNfex5bsvbDqjsjg58dXIKxJ/spH7Og2/V3zVELdTUE9X0yZsEiIm9EMrP3C84 wDxSJ11oTb0W6LGKLP/SLgPMiC3gIPY/BsZdb+upbe6fpCQoCQNYKq76XPrtBGWSARoTS ZwbQ4eS1jUZC3gGqb6lP2hj+XeFvb5f7Dey11aKDjkQAH92Mj/xDqSsCGmeuBP1gZYA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379493; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=dZjxKQPema1wf/ojKNhke80AqnoivHDsk9w9qmGii84=; b=H3OXHVCLBNETWLarR3WvAK26Hrkv6Qi5yd6zTOZEHoNhwWIq6ywARkPFf7MADoLx4C0d 9mnFDKQ/2llwug2GU6IgXO7h06yjWSbBPzt8kwx70gKzKi7RHIr1F43lo3zoBhZHno3Hr 9yCL87aItCuTWHkMMx+YrNA62eyOq63iznPal5zRjT5EZ3wtZRONO9lHrkQ1utXVRlFu7 f8yn8Au83IiXyhkIvc+nsOofF3CjJGAMIP2PZcQQff5d5A9skb/zJe7WnHBNC8z/ihtFE xGcED8RkBkAQS0chjs7ScyjzgTsxtmbsBpLbH092pDoj7XEino3X8nhhctIk8RuxtHg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=X5dqzx+Q; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECBE6606A32F; Fri, 4 Dec 2026 10:18:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=X5dqzx+Q Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D6171F00934; Fri, 4 Dec 2026 10:18:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379492; bh=dZjxKQPema1wf/ojKNhke80AqnoivHDsk9w9qmGii84=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=X5dqzx+Qn4Cyd0hAsGeu803xgqT5B6rsrioh3IgO8xhOi+4qKxKO4KfhEAI58i4RA HYQuiwJHa+24pnekoiIr3WsEiN4XjpJVAEgbMwiF832CA8r1hzepGY9xuOD6W+IXe+ e9gtspJXFDqgonYyca+XBX8nL1dCGyJbpTeERlh0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jens Axboe , Sasha Levin Subject: [PATCH 6.6 0016/1167] io_uring: enable toggle of iowait usage when waiting on CQEs Date: Fri, 4 Dec 2026 18:50:43 +0900 Message-ID: <20261204100702.470278881@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jens Axboe Commit 07754bfd9aee59063f8549f6e4d455eae636ecc7 upstream. 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 account the sleeping task as being in iowait. If the kernel supports this feature, then it will be marked by having the IORING_FEAT_NO_IOWAIT feature flag set. As the kernel currently does not support separating the iowait accounting and CPU frequency boosting, the IORING_ENTER_NO_IOWAIT controls both of these at the same time. In the future, if those do end up being split, then it'd be possible to control them separately. However, it seems more likely that the kernel will decouple iowait and CPU frequency boosting anyway. [ 6.6: no struct ext_arg here. Pass the enter flags to io_cqring_wait() and keep the setting in struct io_wait_queue. Flag bits match upstream. ] Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- include/uapi/linux/io_uring.h | 2 ++ io_uring/io_uring.c | 16 ++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 333769bc6abf0..7c8c70859c944 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -466,6 +466,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 << 7) /* * Passed in for io_uring_setup(2). Copied back with updated info on success @@ -500,6 +501,7 @@ struct io_uring_params { #define IORING_FEAT_CQE_SKIP (1U << 11) #define IORING_FEAT_LINKED_FILE (1U << 12) #define IORING_FEAT_REG_REG_RING (1U << 13) +#define IORING_FEAT_NO_IOWAIT (1U << 17) /* * io_uring_register(2) opcodes and arguments diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 43860048d2bf3..b14651c187d4f 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -2520,6 +2520,7 @@ struct io_wait_queue { unsigned cq_tail; unsigned nr_timeouts; ktime_t timeout; + bool iowait; }; static inline bool io_has_work(struct io_ring_ctx *ctx) @@ -2601,7 +2602,7 @@ static inline 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 (iowq->iowait && current_pending_io()) current->in_iowait = 1; ret = 0; if (iowq->timeout == KTIME_MAX) @@ -2616,7 +2617,7 @@ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx, * 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. */ -static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, +static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags, const sigset_t __user *sig, size_t sigsz, struct __kernel_timespec __user *uts) { @@ -2638,6 +2639,7 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, iowq.wq.private = current; INIT_LIST_HEAD(&iowq.wq.entry); iowq.ctx = ctx; + iowq.iowait = !(flags & IORING_ENTER_NO_IOWAIT); iowq.nr_timeouts = atomic_read(&ctx->cq_timeouts); iowq.cq_tail = READ_ONCE(ctx->rings->cq.head) + min_events; iowq.timeout = KTIME_MAX; @@ -3828,7 +3830,8 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit, if (unlikely(flags & ~(IORING_ENTER_GETEVENTS | IORING_ENTER_SQ_WAKEUP | IORING_ENTER_SQ_WAIT | IORING_ENTER_EXT_ARG | - IORING_ENTER_REGISTERED_RING))) + IORING_ENTER_REGISTERED_RING | + IORING_ENTER_NO_IOWAIT))) return -EINVAL; /* @@ -3928,8 +3931,8 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit, if (likely(!ret2)) { min_complete = min(min_complete, ctx->cq_entries); - ret2 = io_cqring_wait(ctx, min_complete, sig, - argsz, ts); + ret2 = io_cqring_wait(ctx, min_complete, flags, + sig, argsz, ts); } } @@ -4211,7 +4214,8 @@ static __cold int io_uring_create(unsigned entries, struct io_uring_params *p, IORING_FEAT_POLL_32BITS | IORING_FEAT_SQPOLL_NONFIXED | IORING_FEAT_EXT_ARG | IORING_FEAT_NATIVE_WORKERS | IORING_FEAT_RSRC_TAGS | IORING_FEAT_CQE_SKIP | - IORING_FEAT_LINKED_FILE | IORING_FEAT_REG_REG_RING; + IORING_FEAT_LINKED_FILE | IORING_FEAT_REG_REG_RING | + IORING_FEAT_NO_IOWAIT; if (copy_to_user(params, p, sizeof(*p))) { ret = -EFAULT; -- 2.53.0