Skip to content

Commit 40cfe55

Browse files
spikehaxboe
authored andcommitted
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>
1 parent 2ae6bdb commit 40cfe55

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
@@ -1261,7 +1261,7 @@ static void __cold io_move_task_work_from_local(struct io_ring_ctx *ctx)
12611261
static bool io_run_local_work_continue(struct io_ring_ctx *ctx, int events,
12621262
int min_events)
12631263
{
1264-
if (llist_empty(&ctx->work_llist))
1264+
if (!io_local_work_pending(ctx))
12651265
return false;
12661266
if (events < min_events)
12671267
return true;
@@ -1314,7 +1314,7 @@ static inline int io_run_local_work_locked(struct io_ring_ctx *ctx,
13141314
{
13151315
struct io_tw_state ts = {};
13161316

1317-
if (llist_empty(&ctx->work_llist))
1317+
if (!io_local_work_pending(ctx))
13181318
return 0;
13191319
return __io_run_local_work(ctx, &ts, min_events);
13201320
}
@@ -2329,7 +2329,7 @@ static int io_wake_function(struct wait_queue_entry *curr, unsigned int mode,
23292329

23302330
int io_run_task_work_sig(struct io_ring_ctx *ctx)
23312331
{
2332-
if (!llist_empty(&ctx->work_llist)) {
2332+
if (io_local_work_pending(ctx)) {
23332333
__set_current_state(TASK_RUNNING);
23342334
if (io_run_local_work(ctx, INT_MAX) > 0)
23352335
return 0;
@@ -2459,7 +2459,7 @@ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx,
24592459
{
24602460
if (unlikely(READ_ONCE(ctx->check_cq)))
24612461
return 1;
2462-
if (unlikely(!llist_empty(&ctx->work_llist)))
2462+
if (unlikely(io_local_work_pending(ctx)))
24632463
return 1;
24642464
if (unlikely(task_work_pending(current)))
24652465
return 1;
@@ -2493,7 +2493,7 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags,
24932493

24942494
if (!io_allowed_run_tw(ctx))
24952495
return -EEXIST;
2496-
if (!llist_empty(&ctx->work_llist))
2496+
if (io_local_work_pending(ctx))
24972497
io_run_local_work(ctx, min_events);
24982498
io_run_task_work();
24992499

@@ -2564,7 +2564,7 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags,
25642564
* If we got woken because of task_work being processed, run it
25652565
* now rather than let the caller do another wait loop.
25662566
*/
2567-
if (!llist_empty(&ctx->work_llist))
2567+
if (io_local_work_pending(ctx))
25682568
io_run_local_work(ctx, nr_wait);
25692569
io_run_task_work();
25702570

@@ -3158,7 +3158,7 @@ __cold void io_uring_cancel_generic(bool cancel_all, struct io_sq_data *sqd)
31583158
io_run_task_work();
31593159
io_uring_drop_tctx_refs(current);
31603160
xa_for_each(&tctx->xa, index, node) {
3161-
if (!llist_empty(&node->ctx->work_llist)) {
3161+
if (io_local_work_pending(node->ctx)) {
31623162
WARN_ON_ONCE(node->ctx->submitter_task &&
31633163
node->ctx->submitter_task != current);
31643164
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)