All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Safonov <dima@arista.com>
To: linux-kernel@vger.kernel.org
Cc: 0x7f454c46@gmail.com, Dmitry Safonov <dima@arista.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	David Miller <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Hannes Frederic Sowa <hannes@stressinduktion.org>,
	Ingo Molnar <mingo@kernel.org>,
	"Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Paolo Abeni <pabeni@redhat.com>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Radu Rendec <rrendec@arista.com>, Rik van Riel <riel@redhat.com>,
	Stanislaw Gruszka <sgruszka@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Wanpeng Li <wanpeng.li@hotmail.com>
Subject: [RFC 2/2] softirq: Introduce mask for __do_softirq()
Date: Tue,  9 Jan 2018 13:36:23 +0000	[thread overview]
Message-ID: <20180109133623.10711-3-dima@arista.com> (raw)
In-Reply-To: <20180109133623.10711-1-dima@arista.com>

Warning: Not merge-ready, tested only on x86_64 & arm32.

For the reason of deferring net-softirqs till ksoftirqd run,
__do_softirq() needs to process softirqs with mask, depending
if it's called from ksoftirqd thread or on the context of
some task.

Signed-off-by: Dmitry Safonov <dima@arista.com>
---
 include/linux/interrupt.h |  8 ++++----
 kernel/softirq.c          | 41 ++++++++++++++++++++++-------------------
 2 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index 69c238210325..1e943959b31a 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -489,14 +489,14 @@ struct softirq_action
 };
 
 asmlinkage void do_softirq(void);
-asmlinkage void __do_softirq(void);
+asmlinkage void __do_softirq(__u32 mask);
 
 #ifdef __ARCH_HAS_DO_SOFTIRQ
-void do_softirq_own_stack(void);
+void do_softirq_own_stack(__u32 mask);
 #else
-static inline void do_softirq_own_stack(void)
+static inline void do_softirq_own_stack(__u32 mask)
 {
-	__do_softirq();
+	__do_softirq(mask);
 }
 #endif
 
diff --git a/kernel/softirq.c b/kernel/softirq.c
index ee48f194dcec..5459b079bf73 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -88,26 +88,26 @@ static bool ksoftirqd_running(void)
 	return tsk && (tsk->state == TASK_RUNNING);
 }
 
-static bool defer_softirq(void)
+#define DEFER_SOFTIRQS (NET_RX_SOFTIRQ | NET_TX_SOFTIRQ)
+
+/* Mask of softirqs that are pending to be processed on the current context. */
+static __u32 current_softirq_pending(void)
 {
 	__u32 pending = local_softirq_pending();
 
-	if (!pending)
-		return true;
-
 	if (ksoftirqd_running())
-		return true;
+		return 0;
 
 	/*
 	 * Defer net-rx softirqs to ksoftirqd processing as they may
 	 * make userspace starving cpu time.
 	 */
-	if (pending & (NET_RX_SOFTIRQ | NET_TX_SOFTIRQ)) {
+	if (pending & DEFER_SOFTIRQS)
 		wakeup_softirqd();
-		return true;
-	}
 
-	return false;
+	pending &= ~DEFER_SOFTIRQS;
+
+	return pending;
 }
 
 /*
@@ -261,7 +261,7 @@ static inline bool lockdep_softirq_start(void) { return false; }
 static inline void lockdep_softirq_end(bool in_hardirq) { }
 #endif
 
-asmlinkage __visible void __softirq_entry __do_softirq(void)
+asmlinkage __visible void __softirq_entry __do_softirq(__u32 mask)
 {
 	unsigned long end = jiffies + MAX_SOFTIRQ_TIME;
 	unsigned long old_flags = current->flags;
@@ -286,7 +286,8 @@ asmlinkage __visible void __softirq_entry __do_softirq(void)
 
 restart:
 	/* Reset the pending bitmask before enabling irqs */
-	set_softirq_pending(0);
+	set_softirq_pending(pending & ~mask);
+	pending &= mask;
 
 	local_irq_enable();
 
@@ -320,7 +321,7 @@ asmlinkage __visible void __softirq_entry __do_softirq(void)
 	local_irq_disable();
 
 	pending = local_softirq_pending();
-	if (pending) {
+	if (pending & mask) {
 		if (time_before(jiffies, end) && !need_resched() &&
 		    --max_restart)
 			goto restart;
@@ -338,14 +339,14 @@ asmlinkage __visible void __softirq_entry __do_softirq(void)
 asmlinkage __visible void do_softirq(void)
 {
 	unsigned long flags;
+	__u32 pending = current_softirq_pending();
 
-	if (in_interrupt())
+	if (in_interrupt() || !pending)
 		return;
 
 	local_irq_save(flags);
 
-	if (!defer_softirq())
-		do_softirq_own_stack();
+	do_softirq_own_stack(pending);
 
 	local_irq_restore(flags);
 }
@@ -371,7 +372,9 @@ void irq_enter(void)
 
 static inline void invoke_softirq(void)
 {
-	if (defer_softirq())
+	__u32 pending = current_softirq_pending();
+
+	if (!pending)
 		return;
 
 	if (!force_irqthreads) {
@@ -381,14 +384,14 @@ static inline void invoke_softirq(void)
 		 * it is the irq stack, because it should be near empty
 		 * at this stage.
 		 */
-		__do_softirq();
+		__do_softirq(pending);
 #else
 		/*
 		 * Otherwise, irq_exit() is called on the task stack that can
 		 * be potentially deep already. So call softirq in its own stack
 		 * to prevent from any overrun.
 		 */
-		do_softirq_own_stack();
+		do_softirq_own_stack(pending);
 #endif
 	} else {
 		wakeup_softirqd();
@@ -682,7 +685,7 @@ static void run_ksoftirqd(unsigned int cpu)
 		 * We can safely run softirq on inline stack, as we are not deep
 		 * in the task stack here.
 		 */
-		__do_softirq();
+		__do_softirq(~0);
 		local_irq_enable();
 		cond_resched_rcu_qs();
 		return;
-- 
2.13.6

      parent reply	other threads:[~2018-01-09 13:36 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-09 13:36 [RFC 0/2] Net softirq deferring to ksoftirqd Dmitry Safonov
2018-01-09 13:36 ` [RFC 1/2] softirq: Defer net rx/tx processing to ksoftirqd context Dmitry Safonov
2018-01-09 16:03   ` Frederic Weisbecker
2018-01-10 21:20     ` Dmitry Safonov
2018-01-09 18:02   ` Eric Dumazet
2018-01-10 21:48     ` Dmitry Safonov
2018-01-11  2:13       ` Linus Torvalds
2018-01-11  3:22         ` Frederic Weisbecker
2018-01-11  4:19           ` Linus Torvalds
2018-01-11  4:44             ` Frederic Weisbecker
2018-01-11 14:31               ` Dmitry Safonov
2018-01-11 16:20                 ` Eric Dumazet
2018-01-11 16:32                   ` Peter Zijlstra
2018-01-11 16:38                     ` David Miller
2018-01-11 16:43                       ` Peter Zijlstra
2018-01-11 18:48                     ` Linus Torvalds
2018-01-11 19:15                       ` Eric Dumazet
2018-01-11 19:43                         ` Linus Torvalds
2018-01-11 19:48                           ` Eric Dumazet
2018-01-11 20:03                             ` Linus Torvalds
2018-01-11 20:16                               ` Eric Dumazet
2018-01-11 20:22                                 ` Linus Torvalds
2018-01-11 20:34                                   ` Dmitry Safonov
2018-01-11 20:37                                     ` Eric Dumazet
2018-01-11 20:40                                     ` Linus Torvalds
2018-01-11 20:46                                       ` Dmitry Safonov
2018-01-11 20:53                                         ` Eric Dumazet
2018-01-11 21:13                                           ` Dmitry Safonov
2018-01-12  5:41                                             ` Frederic Weisbecker
2018-01-12  5:23                                   ` Mike Galbraith
2018-01-12 10:13                                     ` Peter Zijlstra
2018-01-12 17:26                                       ` Linus Torvalds
2018-01-12 17:44                                         ` Mike Galbraith
2018-01-12 17:51                                           ` Linus Torvalds
2018-01-12 18:15                                             ` Mike Galbraith
2018-01-12 18:44                                               ` Mike Galbraith
2018-01-17 20:30                                                 ` David Miller
2018-01-17 21:06                                                   ` Linus Torvalds
2018-01-17 21:49                                                     ` David Miller
2018-01-17 21:54                                                       ` Thomas Gleixner
2018-01-17 21:58                                                         ` Linus Torvalds
2018-01-17 22:00                                                           ` Thomas Gleixner
2018-01-17 22:02                                                             ` Eric Dumazet
2018-01-17 22:24                                                               ` David Miller
2018-01-17 22:54                                                                 ` Thomas Gleixner
2018-02-06 16:56                                                                 ` Sebastian Andrzej Siewior
2018-02-13 16:36                                                                   ` Thomas Gleixner
2018-01-17 21:54                                                       ` Linus Torvalds
2018-01-17 21:58                                                         ` Thomas Gleixner
2018-01-12 19:28                                             ` Thomas Gleixner
2018-01-12 19:53                                               ` Frederic Weisbecker
2018-01-12 14:58                                     ` Frederic Weisbecker
2018-01-12 15:15                                       ` Mike Galbraith
2018-01-12 17:00                                         ` Frederic Weisbecker
2018-01-12 18:08                                           ` Mike Galbraith
2018-01-12 17:24                                     ` Linus Torvalds
2018-01-09 13:36 ` Dmitry Safonov [this message]

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=20180109133623.10711-3-dima@arista.com \
    --to=dima@arista.com \
    --cc=0x7f454c46@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.levin@verizon.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=fweisbec@gmail.com \
    --cc=hannes@stressinduktion.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=pabeni@redhat.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=riel@redhat.com \
    --cc=rrendec@arista.com \
    --cc=sgruszka@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=wanpeng.li@hotmail.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.