Skip to contentSkip to conversation

io_uring: use lockless_cq flag in io_req_complete_post()

PATCH Applied Caleb Sander Mateos 3 participants 4 messages Feb 12, 2025 – Feb 18, 2025 io_uring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 io_uring: use lockless_cq flag in io_req_complete_post()

io_uring_create() computes ctx->lockless_cq as:
ctx->task_complete || (ctx->flags & IORING_SETUP_IOPOLL)

So use it to simplify that expression in io_req_complete_post().

---
 io_uring/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
io_uring/io_uring.c +1 -1
index ec98a0ec6f34..0bd94599df81 100644
@@ -897,11 +897,11 @@ static void io_req_complete_post(struct io_kiocb *req, unsigned issue_flags)
 
 	/*
 	 * Handle special CQ sync cases via task_work. DEFER_TASKRUN requires
 	 * the submitter task context, IOPOLL protects with uring_lock.
 	 */
-	if (ctx->task_complete || (ctx->flags & IORING_SETUP_IOPOLL)) {
+	if (ctx->lockless_cq) {
 		req->io_task_work.func = io_req_task_complete;
 		io_req_task_work_add(req);
 		return;
 	}
 
Signature · 1 line
2.45.2
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 28 lines

-----Original Message-----
From: Caleb Sander Mateos <[email protected]>
Sent: Wednesday, February 12, 2025 8:51 AM
To: Jens Axboe <[email protected]>; Pavel Begunkov <[email protected]>
Cc: Caleb Sander Mateos <[email protected]>; io- [email protected]; [email protected]
Subject: [PATCH] io_uring: use lockless_cq flag in io_req_complete_post()

io_uring_create() computes ctx->lockless_cq as:
ctx->task_complete || (ctx->flags & IORING_SETUP_IOPOLL)

So use it to simplify that expression in io_req_complete_post().

---
 io_uring/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
io_uring/io_uring.c index renamed from io_uring/io_uring.c +0 -0

ec98a0ec6f34..0bd94599df81 100644

io_uring/io_uring.c +0 -0
@@ -897,11 +897,11 @@ static void io_req_complete_post(struct io_kiocb
 *req, unsigned issue_flags)
 
 	/*
 	 * Handle special CQ sync cases via task_work. DEFER_TASKRUN

requires

io_uring/io_uring.c static void io_req_complete_post(struct io_kiocb *req, unsigned issue_flags) · line 902

Quoted 4 lines
io_uring/io_uring.c +1 -1
 	 * the submitter task context, IOPOLL protects with uring_lock.
 	 */
-	if (ctx->task_complete || (ctx->flags & IORING_SETUP_IOPOLL)) {
+	if (ctx->lockless_cq) {

When the completion_lock is not held, the req completion event needs to be handled through the task_work mechanism, so this modification makes sense to me.

Quoted 8 lines
io_uring/io_uring.c +0 -1
 		req->io_task_work.func = io_req_task_complete;
 		io_req_task_work_add(req);
 		return;
 	}
 
--

2.45.2

---
Li Zetao

#2 lore raw
In reply to Caleb Sander Mateos

Hi Jens,
Gentle ping on this patch that Li Zetao reviewed last week. Do you think the comment should be removed/reworded to match the new if condition?

Thanks,
Caleb

Quoted 31 lines · Caleb Sander Mateos

io_uring_create() computes ctx->lockless_cq as:
ctx->task_complete || (ctx->flags & IORING_SETUP_IOPOLL)

So use it to simplify that expression in io_req_complete_post().

---
 io_uring/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
io_uring/io_uring.c +1 -2
index ec98a0ec6f34..0bd94599df81 100644
@@ -897,11 +897,11 @@ static void io_req_complete_post(struct io_kiocb *req, unsigned issue_flags)
 
        /*
         * Handle special CQ sync cases via task_work. DEFER_TASKRUN requires
         * the submitter task context, IOPOLL protects with uring_lock.
         */
-       if (ctx->task_complete || (ctx->flags & IORING_SETUP_IOPOLL)) {
+       if (ctx->lockless_cq) {
                req->io_task_work.func = io_req_task_complete;
                io_req_task_work_add(req);
                return;
        }
 
--

2.45.2

maintainer Applied
#3 lore raw
In reply to Caleb Sander Mateos
Quoted 6 lines · Caleb Sander Mateos

io_uring_create() computes ctx->lockless_cq as:
ctx->task_complete || (ctx->flags & IORING_SETUP_IOPOLL)

So use it to simplify that expression in io_req_complete_post().

Applied, thanks!

[1/1] io_uring: use lockless_cq flag in io_req_complete_post()

      commit: 62aa9805d123165102273eb277f776aaca908e0e

Best regards,

Signature · 1 line
Jens Axboe