public inbox for [email protected]
 help / color / mirror / Atom feed
From: Stefan Roesch <[email protected]>
To: [email protected], [email protected]
Cc: [email protected], [email protected], [email protected],
	[email protected], [email protected], [email protected]
Subject: [PATCH v14 3/8] net: split off _napi_busy_loop()
Date: Mon,  5 Jun 2023 14:20:04 -0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

This splits off the function _napi_busy_loop from the commonality of
napi_busy_loop() and napi_busy_loop_rcu().

Signed-off-by: Stefan Roesch <[email protected]>
---
 net/core/dev.c | 66 ++++++++++++++++++++++++--------------------------
 1 file changed, 31 insertions(+), 35 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index fcd4a6a70646..2a2d9bae1eb4 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -6214,39 +6214,10 @@ static inline void __napi_busy_poll(struct napi_busy_poll_ctx *ctx,
 	local_bh_enable();
 }
 
-/*
- * Warning: can exit without calling need_resched().
- */
-void napi_busy_loop_rcu(unsigned int napi_id,
-		    bool (*loop_end)(void *, unsigned long),
-		    void *loop_end_arg, bool prefer_busy_poll, u16 budget)
-{
-	unsigned long start_time = loop_end ? busy_loop_current_time() : 0;
-	struct napi_busy_poll_ctx ctx = {};
-
-	ctx.napi = napi_by_id(napi_id);
-	if (!ctx.napi)
-		return;
-
-	preempt_disable();
-	for (;;) {
-		__napi_busy_poll(&ctx, prefer_busy_poll, budget);
-
-		if (!loop_end || loop_end(loop_end_arg, start_time))
-			break;
-		if (unlikely(need_resched()))
-			break;
-
-		cpu_relax();
-	}
-	if (ctx.napi_poll)
-		busy_poll_stop(ctx.napi, ctx.have_poll_lock, prefer_busy_poll, budget);
-	preempt_enable();
-}
-
-void napi_busy_loop(unsigned int napi_id,
+static void _napi_busy_loop(unsigned int napi_id,
 		    bool (*loop_end)(void *, unsigned long),
-		    void *loop_end_arg, bool prefer_busy_poll, u16 budget)
+		    void *loop_end_arg, bool prefer_busy_poll, u16 budget,
+		    bool rcu)
 {
 	unsigned long start_time = loop_end ? busy_loop_current_time() : 0;
 	struct napi_busy_poll_ctx ctx = {};
@@ -6254,7 +6225,8 @@ void napi_busy_loop(unsigned int napi_id,
 restart:
 	ctx.napi_poll = NULL;
 
-	rcu_read_lock();
+	if (rcu)
+		rcu_read_lock();
 
 	ctx.napi = napi_by_id(napi_id);
 	if (!ctx.napi)
@@ -6268,8 +6240,12 @@ void napi_busy_loop(unsigned int napi_id,
 			break;
 
 		if (unlikely(need_resched())) {
+			if (rcu)
+				break;
+
 			if (ctx.napi_poll)
-				busy_poll_stop(ctx.napi, ctx.have_poll_lock, prefer_busy_poll, budget);
+				busy_poll_stop(ctx.napi, ctx.have_poll_lock,
+					       prefer_busy_poll, budget);
 			preempt_enable();
 			rcu_read_unlock();
 			cond_resched();
@@ -6283,7 +6259,27 @@ void napi_busy_loop(unsigned int napi_id,
 		busy_poll_stop(ctx.napi, ctx.have_poll_lock, prefer_busy_poll, budget);
 	preempt_enable();
 out:
-	rcu_read_unlock();
+	if (rcu)
+		rcu_read_unlock();
+}
+
+/*
+ * Warning: can exit without calling need_resched().
+ */
+void napi_busy_loop_rcu(unsigned int napi_id,
+		    bool (*loop_end)(void *, unsigned long),
+		    void *loop_end_arg, bool prefer_busy_poll, u16 budget)
+{
+	_napi_busy_loop(napi_id, loop_end, loop_end_arg, prefer_busy_poll,
+			budget, true);
+}
+
+void napi_busy_loop(unsigned int napi_id,
+		    bool (*loop_end)(void *, unsigned long),
+		    void *loop_end_arg, bool prefer_busy_poll, u16 budget)
+{
+	_napi_busy_loop(napi_id, loop_end, loop_end_arg, prefer_busy_poll,
+			budget, false);
 }
 EXPORT_SYMBOL(napi_busy_loop);
 
-- 
2.39.1


  parent reply	other threads:[~2023-06-05 21:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-05 21:20 [PATCH v14 0/8] io_uring: add napi busy polling support Stefan Roesch
2023-06-05 21:20 ` [PATCH v14 1/8] net: split off __napi_busy_poll from napi_busy_poll Stefan Roesch
2023-06-05 21:20 ` [PATCH v14 2/8] net: introduce napi_busy_loop_rcu() Stefan Roesch
2023-06-06 10:10   ` Simon Horman
2023-06-05 21:20 ` Stefan Roesch [this message]
2023-06-05 22:21   ` [PATCH v14 3/8] net: split off _napi_busy_loop() Jakub Kicinski
2023-06-05 21:20 ` [PATCH v14 4/8] io-uring: move io_wait_queue definition to header file Stefan Roesch
2023-06-05 21:20 ` [PATCH v14 5/8] io-uring: add napi busy poll support Stefan Roesch
2023-06-05 21:20 ` [PATCH v14 6/8] io-uring: add sqpoll support for napi busy poll Stefan Roesch
2023-06-05 21:20 ` [PATCH v14 7/8] io_uring: add register/unregister napi function Stefan Roesch
2023-06-05 21:20 ` [PATCH v14 8/8] io_uring: add prefer busy poll to register and unregister napi api Stefan Roesch

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 \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox