Skip to content

Commit 750750e

Browse files
author
Ming Lei
committed
io_uring: add io_local_work_pending()
JIRA: https://issues.redhat.com/browse/RHEL-106845 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: Ming Lei <ming.lei@redhat.com>
1 parent fd550a2 commit 750750e

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
@@ -1269,7 +1269,7 @@ static void __cold io_move_task_work_from_local(struct io_ring_ctx *ctx)
12691269
static bool io_run_local_work_continue(struct io_ring_ctx *ctx, int events,
12701270
int min_events)
12711271
{
1272-
if (llist_empty(&ctx->work_llist))
1272+
if (!io_local_work_pending(ctx))
12731273
return false;
12741274
if (events < min_events)
12751275
return true;
@@ -1322,7 +1322,7 @@ static inline int io_run_local_work_locked(struct io_ring_ctx *ctx,
13221322
{
13231323
struct io_tw_state ts = {};
13241324

1325-
if (llist_empty(&ctx->work_llist))
1325+
if (!io_local_work_pending(ctx))
13261326
return 0;
13271327
return __io_run_local_work(ctx, &ts, min_events);
13281328
}
@@ -2339,7 +2339,7 @@ static int io_wake_function(struct wait_queue_entry *curr, unsigned int mode,
23392339

23402340
int io_run_task_work_sig(struct io_ring_ctx *ctx)
23412341
{
2342-
if (!llist_empty(&ctx->work_llist)) {
2342+
if (io_local_work_pending(ctx)) {
23432343
__set_current_state(TASK_RUNNING);
23442344
if (io_run_local_work(ctx, INT_MAX) > 0)
23452345
return 0;
@@ -2470,7 +2470,7 @@ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx,
24702470
{
24712471
if (unlikely(READ_ONCE(ctx->check_cq)))
24722472
return 1;
2473-
if (unlikely(!llist_empty(&ctx->work_llist)))
2473+
if (unlikely(io_local_work_pending(ctx)))
24742474
return 1;
24752475
if (unlikely(task_work_pending(current)))
24762476
return 1;
@@ -2504,7 +2504,7 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags,
25042504

25052505
if (!io_allowed_run_tw(ctx))
25062506
return -EEXIST;
2507-
if (!llist_empty(&ctx->work_llist))
2507+
if (io_local_work_pending(ctx))
25082508
io_run_local_work(ctx, min_events);
25092509
io_run_task_work();
25102510

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

@@ -3169,7 +3169,7 @@ __cold void io_uring_cancel_generic(bool cancel_all, struct io_sq_data *sqd)
31693169
io_run_task_work();
31703170
io_uring_drop_tctx_refs(current);
31713171
xa_for_each(&tctx->xa, index, node) {
3172-
if (!llist_empty(&node->ctx->work_llist)) {
3172+
if (io_local_work_pending(node->ctx)) {
31733173
WARN_ON_ONCE(node->ctx->submitter_task &&
31743174
node->ctx->submitter_task != current);
31753175
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)