Skip to content

Commit 428f138

Browse files
committed
io_uring/napi: ensure napi polling is aborted when work is available
While testing io_uring NAPI with DEFER_TASKRUN, I ran into slowdowns and stalls in packet delivery. Turns out that while io_napi_busy_loop_should_end() aborts appropriately on regular task_work, it does not abort if we have local task_work pending. Move io_has_work() into the private io_uring.h header, and gate whether we should continue polling on that as well. This makes NAPI polling on send/receive work as designed with IORING_SETUP_DEFER_TASKRUN as well. Fixes: 8d0c12a ("io-uring: add napi busy poll support") Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 3fb1764 commit 428f138

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

io_uring/io_uring.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,6 @@
122122
#define IO_COMPL_BATCH 32
123123
#define IO_REQ_ALLOC_BATCH 8
124124

125-
enum {
126-
IO_CHECK_CQ_OVERFLOW_BIT,
127-
IO_CHECK_CQ_DROPPED_BIT,
128-
};
129-
130125
struct io_defer_entry {
131126
struct list_head list;
132127
struct io_kiocb *req;
@@ -2479,12 +2474,6 @@ int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
24792474
return ret;
24802475
}
24812476

2482-
static inline bool io_has_work(struct io_ring_ctx *ctx)
2483-
{
2484-
return test_bit(IO_CHECK_CQ_OVERFLOW_BIT, &ctx->check_cq) ||
2485-
!llist_empty(&ctx->work_llist);
2486-
}
2487-
24882477
static int io_wake_function(struct wait_queue_entry *curr, unsigned int mode,
24892478
int wake_flags, void *key)
24902479
{

io_uring/io_uring.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,4 +448,15 @@ static inline bool io_file_can_poll(struct io_kiocb *req)
448448
}
449449
return false;
450450
}
451+
452+
enum {
453+
IO_CHECK_CQ_OVERFLOW_BIT,
454+
IO_CHECK_CQ_DROPPED_BIT,
455+
};
456+
457+
static inline bool io_has_work(struct io_ring_ctx *ctx)
458+
{
459+
return test_bit(IO_CHECK_CQ_OVERFLOW_BIT, &ctx->check_cq) ||
460+
!llist_empty(&ctx->work_llist);
461+
}
451462
#endif

io_uring/napi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static bool io_napi_busy_loop_should_end(void *data,
122122

123123
if (signal_pending(current))
124124
return true;
125-
if (io_should_wake(iowq))
125+
if (io_should_wake(iowq) || io_has_work(iowq->ctx))
126126
return true;
127127
if (io_napi_busy_loop_timeout(start_time, iowq->napi_busy_poll_to))
128128
return true;

0 commit comments

Comments
 (0)