Skip to content

Commit

Permalink
io-uring: add sqpoll support for napi busy poll
Browse files Browse the repository at this point in the history
This adds the sqpoll support to the io-uring napi.

Signed-off-by: Stefan Roesch <shr@devkernel.io>
Suggested-by: Olivier Langlois <olivier@trillion01.com>
Link: https://lore.kernel.org/r/20230608163839.2891748-6-shr@devkernel.io
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Stefan Roesch authored and Jens Axboe committed Feb 9, 2024
1 parent 8d0c12a commit ff183d4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
24 changes: 24 additions & 0 deletions io_uring/napi.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,28 @@ void __io_napi_busy_loop(struct io_ring_ctx *ctx, struct io_wait_queue *iowq)
io_napi_blocking_busy_loop(ctx, iowq);
}

/*
* io_napi_sqpoll_busy_poll() - busy poll loop for sqpoll
* @ctx: pointer to io-uring context structure
*
* Splice of the napi list and execute the napi busy poll loop.
*/
int io_napi_sqpoll_busy_poll(struct io_ring_ctx *ctx)
{
LIST_HEAD(napi_list);
bool is_stale = false;

if (!READ_ONCE(ctx->napi_busy_poll_to))
return 0;
if (list_empty_careful(&ctx->napi_list))
return 0;

rcu_read_lock();
is_stale = __io_napi_do_busy_loop(ctx, NULL);
rcu_read_unlock();

io_napi_remove_stale(ctx, is_stale);
return 1;
}

#endif
6 changes: 5 additions & 1 deletion io_uring/napi.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void __io_napi_add(struct io_ring_ctx *ctx, struct socket *sock);
void __io_napi_adjust_timeout(struct io_ring_ctx *ctx,
struct io_wait_queue *iowq, struct timespec64 *ts);
void __io_napi_busy_loop(struct io_ring_ctx *ctx, struct io_wait_queue *iowq);
int io_napi_sqpoll_busy_poll(struct io_ring_ctx *ctx);

static inline bool io_napi(struct io_ring_ctx *ctx)
{
Expand Down Expand Up @@ -83,7 +84,10 @@ static inline void io_napi_busy_loop(struct io_ring_ctx *ctx,
struct io_wait_queue *iowq)
{
}

static inline int io_napi_sqpoll_busy_poll(struct io_ring_ctx *ctx)
{
return 0;
}
#endif /* CONFIG_NET_RX_BUSY_POLL */

#endif
4 changes: 4 additions & 0 deletions io_uring/sqpoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <uapi/linux/io_uring.h>

#include "io_uring.h"
#include "napi.h"
#include "sqpoll.h"

#define IORING_SQPOLL_CAP_ENTRIES_VALUE 8
Expand Down Expand Up @@ -194,6 +195,9 @@ static int __io_sq_thread(struct io_ring_ctx *ctx, bool cap_entries)
ret = io_submit_sqes(ctx, to_submit);
mutex_unlock(&ctx->uring_lock);

if (io_napi(ctx))
ret += io_napi_sqpoll_busy_poll(ctx);

if (to_submit && wq_has_sleeper(&ctx->sqo_sq_wait))
wake_up(&ctx->sqo_sq_wait);
if (creds)
Expand Down

0 comments on commit ff183d4

Please sign in to comment.