[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230518211751.3492982-6-shr@devkernel.io>
Date: Thu, 18 May 2023 14:17:49 -0700
From: Stefan Roesch <shr@...kernel.io>
To: io-uring@...r.kernel.org,
kernel-team@...com
Cc: shr@...kernel.io,
axboe@...nel.dk,
ammarfaizi2@...weeb.org,
netdev@...r.kernel.org,
kuba@...nel.org,
olivier@...llion01.com
Subject: [PATCH v13 5/7] io-uring: add sqpoll support for napi busy poll
This adds the sqpoll support to the io-uring napi.
Signed-off-by: Stefan Roesch <shr@...kernel.io>
Suggested-by: Olivier Langlois <olivier@...llion01.com>
---
io_uring/napi.c | 24 ++++++++++++++++++++++++
io_uring/napi.h | 2 ++
io_uring/sqpoll.c | 4 ++++
3 files changed, 30 insertions(+)
diff --git a/io_uring/napi.c b/io_uring/napi.c
index 54d66dd3119f..9aaeea51250f 100644
--- a/io_uring/napi.c
+++ b/io_uring/napi.c
@@ -257,4 +257,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
diff --git a/io_uring/napi.h b/io_uring/napi.h
index 1bdf8442081f..945d3c8c201d 100644
--- a/io_uring/napi.h
+++ b/io_uring/napi.h
@@ -17,6 +17,7 @@ void __io_napi_add(struct io_ring_ctx *ctx, struct file *file);
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)
{
@@ -77,6 +78,7 @@ static inline void io_napi_add(struct io_kiocb *req)
#define io_napi_adjust_timeout(ctx, iowq, ts) do {} while (0)
#define io_napi_busy_loop(ctx, iowq) do {} while (0)
+#define io_napi_sqpoll_busy_poll(ctx) do {} while (0)
#endif
diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c
index 9db4bc1f521a..0c8d53ef134a 100644
--- a/io_uring/sqpoll.c
+++ b/io_uring/sqpoll.c
@@ -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
@@ -193,6 +194,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)
--
2.39.1
Powered by blists - more mailing lists