Skip to content

Commit d381099

Browse files
isilenceaxboe
authored andcommitted
io_uring: clean up local tw add-wait sync
Kill a smp_mb__after_atomic() right before wake_up, it's useless, and add a comment explaining implicit barriers from cmpxchg and synchronsation around ->cq_wait_nr with the waiter. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/3007f3c2d53c72b61de56919ef56b53158b8276f.1705438669.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent dc12d17 commit d381099

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

io_uring/io_uring.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,14 @@ static inline void io_req_local_work_add(struct io_kiocb *req, unsigned flags)
13321332
} while (!try_cmpxchg(&ctx->work_llist.first, &first,
13331333
&req->io_task_work.node));
13341334

1335+
/*
1336+
* cmpxchg implies a full barrier, which pairs with the barrier
1337+
* in set_current_state() on the io_cqring_wait() side. It's used
1338+
* to ensure that either we see updated ->cq_wait_nr, or waiters
1339+
* going to sleep will observe the work added to the list, which
1340+
* is similar to the wait/wawke task state sync.
1341+
*/
1342+
13351343
if (!first) {
13361344
if (ctx->flags & IORING_SETUP_TASKRUN_FLAG)
13371345
atomic_or(IORING_SQ_TASKRUN, &ctx->rings->sq_flags);
@@ -1346,8 +1354,6 @@ static inline void io_req_local_work_add(struct io_kiocb *req, unsigned flags)
13461354
/* either not enough or the previous add has already woken it up */
13471355
if (nr_wait > nr_tw || nr_tw_prev >= nr_wait)
13481356
return;
1349-
/* pairs with set_current_state() in io_cqring_wait() */
1350-
smp_mb__after_atomic();
13511357
wake_up_state(ctx->submitter_task, TASK_INTERRUPTIBLE);
13521358
}
13531359

0 commit comments

Comments
 (0)