Skip to content

Commit 6b608ea

Browse files
committed
io_uring: add io_local_work_pending()
JIRA: https://issues.redhat.com/browse/RHEL-105612 commit 40cfe55 Author: David Wei <dw@davidwei.uk> Date: Wed Nov 20 14:14:51 2024 -0800 io_uring: add io_local_work_pending() In preparation for adding a new llist of tw to retry due to hitting the tw limit, add a helper io_local_work_pending(). This function returns true if there is any local tw pending. For now it only checks ctx->work_llist. Signed-off-by: David Wei <dw@davidwei.uk> Reviewed-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/20241120221452.3762588-2-dw@davidwei.uk Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
1 parent 1dc173e commit 6b608ea

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

io_uring/io_uring.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ static void __cold io_move_task_work_from_local(struct io_ring_ctx *ctx)
12751275
static bool io_run_local_work_continue(struct io_ring_ctx *ctx, int events,
12761276
int min_events)
12771277
{
1278-
if (llist_empty(&ctx->work_llist))
1278+
if (!io_local_work_pending(ctx))
12791279
return false;
12801280
if (events < min_events)
12811281
return true;
@@ -1328,7 +1328,7 @@ static inline int io_run_local_work_locked(struct io_ring_ctx *ctx,
13281328
{
13291329
struct io_tw_state ts = {};
13301330

1331-
if (llist_empty(&ctx->work_llist))
1331+
if (!io_local_work_pending(ctx))
13321332
return 0;
13331333
return __io_run_local_work(ctx, &ts, min_events);
13341334
}
@@ -2345,7 +2345,7 @@ static int io_wake_function(struct wait_queue_entry *curr, unsigned int mode,
23452345

23462346
int io_run_task_work_sig(struct io_ring_ctx *ctx)
23472347
{
2348-
if (!llist_empty(&ctx->work_llist)) {
2348+
if (io_local_work_pending(ctx)) {
23492349
__set_current_state(TASK_RUNNING);
23502350
if (io_run_local_work(ctx, INT_MAX) > 0)
23512351
return 0;
@@ -2475,7 +2475,7 @@ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx,
24752475
{
24762476
if (unlikely(READ_ONCE(ctx->check_cq)))
24772477
return 1;
2478-
if (unlikely(!llist_empty(&ctx->work_llist)))
2478+
if (unlikely(io_local_work_pending(ctx)))
24792479
return 1;
24802480
if (unlikely(task_work_pending(current)))
24812481
return 1;
@@ -2509,7 +2509,7 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags,
25092509

25102510
if (!io_allowed_run_tw(ctx))
25112511
return -EEXIST;
2512-
if (!llist_empty(&ctx->work_llist))
2512+
if (io_local_work_pending(ctx))
25132513
io_run_local_work(ctx, min_events);
25142514
io_run_task_work();
25152515

@@ -2580,7 +2580,7 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags,
25802580
* If we got woken because of task_work being processed, run it
25812581
* now rather than let the caller do another wait loop.
25822582
*/
2583-
if (!llist_empty(&ctx->work_llist))
2583+
if (io_local_work_pending(ctx))
25842584
io_run_local_work(ctx, nr_wait);
25852585
io_run_task_work();
25862586

@@ -3174,7 +3174,7 @@ __cold void io_uring_cancel_generic(bool cancel_all, struct io_sq_data *sqd)
31743174
io_run_task_work();
31753175
io_uring_drop_tctx_refs(current);
31763176
xa_for_each(&tctx->xa, index, node) {
3177-
if (!llist_empty(&node->ctx->work_llist)) {
3177+
if (io_local_work_pending(node->ctx)) {
31783178
WARN_ON_ONCE(node->ctx->submitter_task &&
31793179
node->ctx->submitter_task != current);
31803180
goto end_wait;

io_uring/io_uring.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,14 @@ static inline int io_run_task_work(void)
347347
return ret;
348348
}
349349

350+
static inline bool io_local_work_pending(struct io_ring_ctx *ctx)
351+
{
352+
return !llist_empty(&ctx->work_llist);
353+
}
354+
350355
static inline bool io_task_work_pending(struct io_ring_ctx *ctx)
351356
{
352-
return task_work_pending(current) || !llist_empty(&ctx->work_llist);
357+
return task_work_pending(current) || io_local_work_pending(ctx);
353358
}
354359

355360
static inline void io_tw_lock(struct io_ring_ctx *ctx, struct io_tw_state *ts)
@@ -484,6 +489,6 @@ enum {
484489
static inline bool io_has_work(struct io_ring_ctx *ctx)
485490
{
486491
return test_bit(IO_CHECK_CQ_OVERFLOW_BIT, &ctx->check_cq) ||
487-
!llist_empty(&ctx->work_llist);
492+
io_local_work_pending(ctx);
488493
}
489494
#endif

0 commit comments

Comments
 (0)