Skip to content

Commit 23b3628

Browse files
Xiaoguang Wangaxboe
authored andcommitted
io_uring: clear IORING_SQ_NEED_WAKEUP after executing task works
In io_sq_thread(), if there are task works to handle, current codes will skip schedule() and go on polling sq again, but forget to clear IORING_SQ_NEED_WAKEUP flag, fix this issue. Also add two helpers to set and clear IORING_SQ_NEED_WAKEUP flag, Signed-off-by: Xiaoguang Wang <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 5af1d13 commit 23b3628

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

fs/io_uring.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6344,6 +6344,21 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
63446344
return submitted;
63456345
}
63466346

6347+
static inline void io_ring_set_wakeup_flag(struct io_ring_ctx *ctx)
6348+
{
6349+
/* Tell userspace we may need a wakeup call */
6350+
spin_lock_irq(&ctx->completion_lock);
6351+
ctx->rings->sq_flags |= IORING_SQ_NEED_WAKEUP;
6352+
spin_unlock_irq(&ctx->completion_lock);
6353+
}
6354+
6355+
static inline void io_ring_clear_wakeup_flag(struct io_ring_ctx *ctx)
6356+
{
6357+
spin_lock_irq(&ctx->completion_lock);
6358+
ctx->rings->sq_flags &= ~IORING_SQ_NEED_WAKEUP;
6359+
spin_unlock_irq(&ctx->completion_lock);
6360+
}
6361+
63476362
static int io_sq_thread(void *data)
63486363
{
63496364
struct io_ring_ctx *ctx = data;
@@ -6417,10 +6432,7 @@ static int io_sq_thread(void *data)
64176432
continue;
64186433
}
64196434

6420-
/* Tell userspace we may need a wakeup call */
6421-
spin_lock_irq(&ctx->completion_lock);
6422-
ctx->rings->sq_flags |= IORING_SQ_NEED_WAKEUP;
6423-
spin_unlock_irq(&ctx->completion_lock);
6435+
io_ring_set_wakeup_flag(ctx);
64246436

64256437
to_submit = io_sqring_entries(ctx);
64266438
if (!to_submit || ret == -EBUSY) {
@@ -6430,24 +6442,21 @@ static int io_sq_thread(void *data)
64306442
}
64316443
if (io_run_task_work()) {
64326444
finish_wait(&ctx->sqo_wait, &wait);
6445+
io_ring_clear_wakeup_flag(ctx);
64336446
continue;
64346447
}
64356448
if (signal_pending(current))
64366449
flush_signals(current);
64376450
schedule();
64386451
finish_wait(&ctx->sqo_wait, &wait);
64396452

6440-
spin_lock_irq(&ctx->completion_lock);
6441-
ctx->rings->sq_flags &= ~IORING_SQ_NEED_WAKEUP;
6442-
spin_unlock_irq(&ctx->completion_lock);
6453+
io_ring_clear_wakeup_flag(ctx);
64436454
ret = 0;
64446455
continue;
64456456
}
64466457
finish_wait(&ctx->sqo_wait, &wait);
64476458

6448-
spin_lock_irq(&ctx->completion_lock);
6449-
ctx->rings->sq_flags &= ~IORING_SQ_NEED_WAKEUP;
6450-
spin_unlock_irq(&ctx->completion_lock);
6459+
io_ring_clear_wakeup_flag(ctx);
64516460
}
64526461

64536462
mutex_lock(&ctx->uring_lock);

0 commit comments

Comments
 (0)