public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: io-uring@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 3/3] io_uring: add IORING_CQE_F_POLLED flag
Date: Fri, 11 Jul 2025 17:59:25 -0600	[thread overview]
Message-ID: <20250712000344.1579663-4-axboe@kernel.dk> (raw)
In-Reply-To: <20250712000344.1579663-1-axboe@kernel.dk>

If IORING_CQE_F_POLLED is set in cqe->flags for a completion, then that
request had to go through the poll machinery before it could be
completed. For a read/recv type operation, that meant the fd/socket was
originally empty when the request was submitted. For a write/send type
operation, it means that the socket/pipe/file was full when the initial
attempt was made to execute it. This can be used for backpressure
signaling, sending back information to the application on the state of
the file or socket.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 include/uapi/linux/io_uring.h | 6 ++++++
 io_uring/io_uring.c           | 3 +++
 io_uring/io_uring.h           | 2 ++
 3 files changed, 11 insertions(+)

diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
index b8a0e70ee2fd..7f2613ee9a5b 100644
--- a/include/uapi/linux/io_uring.h
+++ b/include/uapi/linux/io_uring.h
@@ -483,12 +483,18 @@ struct io_uring_cqe {
  *			other provided buffer type, all completions with a
  *			buffer passed back is automatically returned to the
  *			application.
+ * IORING_CQE_F_POLLED	If set, the operation was completed after being through
+ *			the poll machinery. For a write/send, this meant the
+ *			socket was full when the operation was attempted. For
+ *			a read operation, the socket/fd was empty when it was
+ *			initially attempted.
  */
 #define IORING_CQE_F_BUFFER		(1U << 0)
 #define IORING_CQE_F_MORE		(1U << 1)
 #define IORING_CQE_F_SOCK_NONEMPTY	(1U << 2)
 #define IORING_CQE_F_NOTIF		(1U << 3)
 #define IORING_CQE_F_BUF_MORE		(1U << 4)
+#define IORING_CQE_F_POLLED		(1U << 5)
 
 #define IORING_CQE_BUFFER_SHIFT		16
 
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 4ef69dd58734..292ac416dfbe 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -891,6 +891,9 @@ bool io_req_post_cqe(struct io_kiocb *req, s32 res, u32 cflags)
 	struct io_ring_ctx *ctx = req->ctx;
 	bool posted;
 
+	if (req->flags & REQ_F_POLL_WAKE)
+		cflags |= IORING_CQE_F_POLLED;
+
 	/*
 	 * If multishot has already posted deferred completions, ensure that
 	 * those are flushed first before posting this one. If not, CQEs
diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index dc17162e7af1..d837e02d26b2 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -235,6 +235,8 @@ static inline void req_set_fail(struct io_kiocb *req)
 
 static inline void io_req_set_res(struct io_kiocb *req, s32 res, u32 cflags)
 {
+	if (req->flags & REQ_F_POLL_WAKE)
+		cflags |= IORING_CQE_F_POLLED;
 	req->cqe.res = res;
 	req->cqe.flags = cflags;
 }
-- 
2.50.0


  parent reply	other threads:[~2025-07-12  0:03 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <[PATCHSET 0/3] Add support for IORING_CQE_F_POLLED>
2025-07-11 23:59 ` Jens Axboe
2025-07-11 23:59   ` [PATCH 1/3] io_uring/poll: cleanup apoll freeing Jens Axboe
2025-07-11 23:59   ` [PATCH 2/3] io_uring/poll: flag request as having gone through poll wake machinery Jens Axboe
2025-07-12 11:39     ` Pavel Begunkov
2025-07-12 20:59       ` Jens Axboe
2025-07-14  9:26         ` Pavel Begunkov
2025-07-14 14:54           ` Jens Axboe
2025-07-14 15:45             ` Pavel Begunkov
2025-07-14 17:51               ` Jens Axboe
2025-07-18 10:20                 ` Pavel Begunkov
2025-07-11 23:59   ` Jens Axboe [this message]
2025-07-12 11:34     ` [PATCH 3/3] io_uring: add IORING_CQE_F_POLLED flag Pavel Begunkov
2025-07-12 14:49       ` Pavel Begunkov
2025-07-12 21:02         ` Jens Axboe
2025-07-12 23:05           ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250712000344.1579663-4-axboe@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox