All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Roesch <shr@devkernel.io>
To: io-uring@vger.kernel.org, kernel-team@fb.com
Cc: shr@devkernel.io, axboe@kernel.dk, ammarfaizi2@gnuweeb.org,
	Olivier Langlois <olivier@trillion01.com>
Subject: [PATCH v8 5/7] io-uring: add sqpoll support for napi busy poll
Date: Thu,  9 Feb 2023 15:01:42 -0800	[thread overview]
Message-ID: <20230209230144.465620-6-shr@devkernel.io> (raw)
In-Reply-To: <20230209230144.465620-1-shr@devkernel.io>

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>
---
 io_uring/napi.c   | 25 +++++++++++++++++++++++++
 io_uring/napi.h   |  2 ++
 io_uring/sqpoll.c |  4 ++++
 3 files changed, 31 insertions(+)

diff --git a/io_uring/napi.c b/io_uring/napi.c
index c9e2afae382d..038957b46a0e 100644
--- a/io_uring/napi.c
+++ b/io_uring/napi.c
@@ -278,4 +278,29 @@ void io_napi_end_busy_loop(struct io_ring_ctx *ctx, struct io_wait_queue *iowq,
 		io_napi_merge_lists(ctx, napi_list);
 }
 
+/*
+ * io_napi_sqpoll_busy_poll() - busy poll loop for sqpoll
+ * @ctx: pointer to io-uring context structure
+ * @napi_list: pointer to head of napi list
+ *
+ * Splice of the napi list and execute the napi busy poll loop.
+ */
+int io_napi_sqpoll_busy_poll(struct io_ring_ctx *ctx, struct list_head *napi_list)
+{
+	int ret = 0;
+
+	spin_lock(&ctx->napi_lock);
+	list_splice_init(&ctx->napi_list, napi_list);
+	spin_unlock(&ctx->napi_lock);
+
+	if (!list_empty(napi_list) &&
+	    READ_ONCE(ctx->napi_busy_poll_to) > 0 &&
+	    io_napi_busy_loop(napi_list, ctx->napi_prefer_busy_poll)) {
+		io_napi_merge_lists(ctx, napi_list);
+		ret = 1;
+	}
+
+	return ret;
+}
+
 #endif
diff --git a/io_uring/napi.h b/io_uring/napi.h
index 0672592cfb79..23a6df32805f 100644
--- a/io_uring/napi.h
+++ b/io_uring/napi.h
@@ -23,6 +23,7 @@ void io_napi_adjust_busy_loop_timeout(struct io_ring_ctx *ctx,
 			struct timespec64 *ts);
 void io_napi_end_busy_loop(struct io_ring_ctx *ctx, struct io_wait_queue *iowq,
 			struct list_head *napi_list);
+int io_napi_sqpoll_busy_poll(struct io_ring_ctx *ctx, struct list_head *napi_list);
 
 #else
 
@@ -43,6 +44,7 @@ static inline void io_napi_add(struct io_kiocb *req)
 #define io_napi_setup_busy_loop(ctx, iowq, napi_list) do {} while (0)
 #define io_napi_adjust_busy_loop_timeout(ctx, iowq, napi_list, ts) do {} while (0)
 #define io_napi_end_busy_loop(ctx, iowq, napi_list) do {} while (0)
+#define io_napi_sqpoll_busy_poll(ctx, napi_list) (0)
 
 #endif
 
diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c
index 0119d3f1a556..90fdbd87434a 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
@@ -168,6 +169,7 @@ static int __io_sq_thread(struct io_ring_ctx *ctx, bool cap_entries)
 {
 	unsigned int to_submit;
 	int ret = 0;
+	NAPI_LIST_HEAD(local_napi_list);
 
 	to_submit = io_sqring_entries(ctx);
 	/* if we're handling multiple rings, cap submit size for fairness */
@@ -193,6 +195,8 @@ 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);
 
+		ret += io_napi_sqpoll_busy_poll(ctx, &local_napi_list);
+
 		if (to_submit && wq_has_sleeper(&ctx->sqo_sq_wait))
 			wake_up(&ctx->sqo_sq_wait);
 		if (creds)
-- 
2.30.2


  parent reply	other threads:[~2023-02-09 23:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-09 23:01 [PATCH v8 0/7] io_uring: add napi busy polling support Stefan Roesch
2023-02-09 23:01 ` [PATCH v8 1/7] io-uring: move io_wait_queue definition to header file Stefan Roesch
2023-02-09 23:01 ` [PATCH v8 2/7] io-uring: add napi fields to io_ring_ctx Stefan Roesch
2023-02-09 23:01 ` [PATCH v8 3/7] io-uring: add busy poll timeout, prefer busy poll to io_wait_queue Stefan Roesch
2023-02-09 23:01 ` [PATCH v8 4/7] io-uring: add napi busy poll support Stefan Roesch
2023-02-10  0:00   ` Jens Axboe
2023-02-15 17:22     ` Stefan Roesch
2023-02-09 23:01 ` Stefan Roesch [this message]
2023-02-10  0:14   ` [PATCH v8 5/7] io-uring: add sqpoll support for napi busy poll Jens Axboe
2023-02-09 23:01 ` [PATCH v8 6/7] io_uring: add api to set / get napi configuration Stefan Roesch
2023-02-10  0:02   ` Jens Axboe
2023-02-09 23:01 ` [PATCH v8 7/7] " Stefan Roesch
2023-02-10  0:02   ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230209230144.465620-6-shr@devkernel.io \
    --to=shr@devkernel.io \
    --cc=ammarfaizi2@gnuweeb.org \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    --cc=kernel-team@fb.com \
    --cc=olivier@trillion01.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.