From: qianjun.kernel@gmail.com
To: tglx@linutronix.de, peterz@infradead.org, will@kernel.org,
luto@kernel.org, linux-kernel@vger.kernel.org
Cc: laoar.shao@gmail.com, qais.yousef@arm.com, urezki@gmail.com,
jun qian <qianjun.kernel@gmail.com>
Subject: [PATCH V7 2/4] softirq: Factor loop termination condition
Date: Tue, 15 Sep 2020 19:56:07 +0800 [thread overview]
Message-ID: <20200915115609.85106-3-qianjun.kernel@gmail.com> (raw)
In-Reply-To: <20200915115609.85106-1-qianjun.kernel@gmail.com>
From: jun qian <qianjun.kernel@gmail.com>
Add a function interface to end softirq process
Signed-off-by: jun qian <qianjun.kernel@gmail.com>
---
kernel/softirq.c | 44 +++++++++++++++++++++++++-------------------
1 file changed, 25 insertions(+), 19 deletions(-)
diff --git a/kernel/softirq.c b/kernel/softirq.c
index 0db77ab..5a627cd 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -198,22 +198,6 @@ void __local_bh_enable_ip(unsigned long ip, unsigned int cnt)
}
EXPORT_SYMBOL(__local_bh_enable_ip);
-/*
- * We restart softirq processing for at most MAX_SOFTIRQ_RESTART times,
- * but break the loop if need_resched() is set or after 2 ms.
- * The MAX_SOFTIRQ_TIME provides a nice upper bound in most cases, but in
- * certain cases, such as stop_machine(), jiffies may cease to
- * increment and so we need the MAX_SOFTIRQ_RESTART limit as
- * well to make sure we eventually return from this method.
- *
- * These limits have been established via experimentation.
- * The two things to balance is latency against fairness -
- * we want to handle softirqs as soon as possible, but they
- * should not be able to lock up the box.
- */
-#define MAX_SOFTIRQ_TIME (2 * NSEC_PER_MSEC)
-#define MAX_SOFTIRQ_RESTART 10
-
#ifdef CONFIG_TRACE_IRQFLAGS
/*
* When we run softirqs from irq_exit() and thus on the hardirq stack we need
@@ -247,11 +231,34 @@ static inline void lockdep_softirq_end(bool in_hardirq)
static inline void lockdep_softirq_end(bool in_hardirq) { }
#endif
+/*
+ * We restart softirq processing but break the loop if need_resched() is
+ * set or after 2 ms. The MAX_SOFTIRQ_RESTART guarantees a loop termination
+ * if sched_clock() were ever to stall.
+ *
+ * These limits have been established via experimentation. The two things
+ * to balance is latency against fairness - we want to handle softirqs as
+ * soon as possible, but they should not be able to lock up the box.
+ */
+#define MAX_SOFTIRQ_TIME (2 * NSEC_PER_MSEC)
+#define MAX_SOFTIRQ_RESTART 10
+
+static inline bool __softirq_needs_break(u64 start)
+{
+ if (need_resched())
+ return true;
+
+ if (sched_clock() - start >= MAX_SOFTIRQ_TIME)
+ return true;
+
+ return false;
+}
+
asmlinkage __visible void __softirq_entry __do_softirq(void)
{
u64 start = sched_clock();
unsigned long old_flags = current->flags;
- int max_restart = MAX_SOFTIRQ_RESTART;
+ unsigned int max_restart = MAX_SOFTIRQ_RESTART;
struct softirq_action *h;
bool in_hardirq;
__u32 pending;
@@ -308,8 +315,7 @@ asmlinkage __visible void __softirq_entry __do_softirq(void)
pending = local_softirq_pending();
if (pending) {
- if (sched_clock() - start < MAX_SOFTIRQ_TIME && !need_resched() &&
- --max_restart)
+ if (!__softirq_needs_break(start) && --max_restart)
goto restart;
wakeup_softirqd();
--
1.8.3.1
next prev parent reply other threads:[~2020-09-15 12:12 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-15 11:56 [PATCH V7 0/4] Softirq:avoid large sched delay from the pending softirqs qianjun.kernel
2020-09-15 11:56 ` [PATCH V7 1/4] softirq: Use sched_clock() based timeout qianjun.kernel
2020-09-24 8:34 ` Thomas Gleixner
2020-09-15 11:56 ` qianjun.kernel [this message]
2020-09-24 8:36 ` [PATCH V7 2/4] softirq: Factor loop termination condition Thomas Gleixner
2020-09-24 12:31 ` Thomas Gleixner
2020-09-15 11:56 ` [PATCH V7 3/4] softirq: Rewrite softirq processing loop qianjun.kernel
2020-09-15 11:56 ` [PATCH V7 4/4] softirq: Allow early break the " qianjun.kernel
2020-09-24 15:37 ` Thomas Gleixner
2020-09-24 23:08 ` Frederic Weisbecker
2020-09-24 23:10 ` Frederic Weisbecker
2020-09-25 22:37 ` Thomas Gleixner
2020-09-25 0:42 ` Frederic Weisbecker
2020-09-25 22:42 ` Thomas Gleixner
2020-09-26 12:22 ` Frederic Weisbecker
2020-09-28 10:51 ` jun qian
2020-09-29 11:44 ` Frederic Weisbecker
2020-10-09 15:01 ` Qais Yousef
2020-10-13 10:43 ` Frederic Weisbecker
2020-10-13 12:40 ` Qais Yousef
2020-09-26 2:00 ` jun qian
2020-09-27 1:05 ` [softirq] 56c21abbe6: will-it-scale.per_process_ops -9.1% regression kernel test robot
2020-09-28 9:20 ` [PATCH V7 4/4] softirq: Allow early break the softirq processing loop Peter Zijlstra
2020-09-28 11:15 ` jun qian
2020-09-28 9:22 ` Peter Zijlstra
2020-09-28 10:09 ` Thomas Gleixner
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=20200915115609.85106-3-qianjun.kernel@gmail.com \
--to=qianjun.kernel@gmail.com \
--cc=laoar.shao@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=peterz@infradead.org \
--cc=qais.yousef@arm.com \
--cc=tglx@linutronix.de \
--cc=urezki@gmail.com \
--cc=will@kernel.org \
/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