From: Thomas Gleixner <tglx@linutronix.de>
To: Jakub Kicinski <kuba@kernel.org>, peterz@infradead.org
Cc: jstultz@google.com, edumazet@google.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>
Subject: Re: [PATCH 2/3] softirq: avoid spurious stalls due to need_resched()
Date: Fri, 03 Mar 2023 14:30:46 +0100 [thread overview]
Message-ID: <87r0u6j721.ffs@tglx> (raw)
In-Reply-To: <20221222221244.1290833-3-kuba@kernel.org>
Jakub!
On Thu, Dec 22 2022 at 14:12, Jakub Kicinski wrote:
> DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
> +static DEFINE_PER_CPU(unsigned long, overload_limit);
>
> const char * const softirq_to_name[NR_SOFTIRQS] = {
> "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "IRQ_POLL",
> @@ -89,10 +90,15 @@ static void wakeup_softirqd(void)
> static bool ksoftirqd_should_handle(unsigned long pending)
> {
> struct task_struct *tsk = __this_cpu_read(ksoftirqd);
> + unsigned long ov_limit;
>
> if (pending & SOFTIRQ_NOW_MASK)
> return false;
> - return tsk && task_is_running(tsk) && !__kthread_should_park(tsk);
> + if (likely(!tsk || !task_is_running(tsk) || __kthread_should_park(tsk)))
> + return false;
> +
> + ov_limit = __this_cpu_read(overload_limit);
> + return time_is_after_jiffies(ov_limit);
return time_is_after_jiffies(__this_cpu_read(overload_limit));
Plus a comment explaining the magic, please.
> }
>
> #ifdef CONFIG_TRACE_IRQFLAGS
> @@ -492,6 +498,9 @@ asmlinkage __visible void do_softirq(void)
> #define MAX_SOFTIRQ_TIME msecs_to_jiffies(2)
> #define MAX_SOFTIRQ_RESTART 10
>
> +#define SOFTIRQ_OVERLOAD_TIME msecs_to_jiffies(100)
> +#define SOFTIRQ_DEFER_TIME msecs_to_jiffies(2)
> +
> #ifdef CONFIG_TRACE_IRQFLAGS
> /*
> * When we run softirqs from irq_exit() and thus on the hardirq stack we need
> @@ -588,10 +597,16 @@ asmlinkage __visible void __softirq_entry __do_softirq(void)
>
> pending = local_softirq_pending();
> if (pending) {
> - if (time_before(jiffies, end) && !need_resched() &&
> - --max_restart)
> + unsigned long limit;
> +
> + if (time_is_before_eq_jiffies(end) || !--max_restart)
> + limit = SOFTIRQ_OVERLOAD_TIME;
> + else if (need_resched())
> + limit = SOFTIRQ_DEFER_TIME;
> + else
> goto restart;
>
> + __this_cpu_write(overload_limit, jiffies + limit);
The logic of all this is non-obvious and I had to reread it 5 times to
conclude that it is matching the intent. Please add comments.
While I'm not a big fan of heuristical duct tape, this looks harmless
enough to not end up in an endless stream of tweaking. Famous last
words...
But without the sched_clock() changes the actual defer time depends on
HZ and the point in time where limit is set. That means it ranges from 0
to 1/HZ, i.e. the 2ms defer time ends up with close to 10ms on HZ=100 in
the worst case, which perhaps explains the 8ms+ stalls you are still
observing. Can you test with that sched_clock change applied, i.e. the
first two commits from
git://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git core/softirq
59be25c466d9 ("softirq: Use sched_clock() based timeout")
bd5a5bd77009 ("softirq: Rewrite softirq processing loop")
whether that makes a difference? Those two can be applied with some
minor polishing. The rest of that series is broken by f10020c97f4c
("softirq: Allow early break").
There is another issue with this overload limit. Assume max_restart or
timeout triggered and limit was set to now + 100ms. ksoftirqd runs and
gets the issue resolved after 10ms.
So for the remaining 90ms any invocation of raise_softirq() outside of
(soft)interrupt context, which wakes ksoftirqd again, prevents
processing on return from interrupt until ksoftirqd gets on the CPU and
goes back to sleep, because task_is_running() == true and the stale
limit is not after jiffies.
Probably not a big issue, but someone will notice on some weird workload
sooner than later and the tweaking will start nevertheless. :) So maybe
we fix it right away. :)
Thanks,
tglx
next prev parent reply other threads:[~2023-03-03 13:30 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-22 22:12 [PATCH 0/3] softirq: uncontroversial change Jakub Kicinski
2022-12-22 22:12 ` [PATCH 1/3] softirq: rename ksoftirqd_running() -> ksoftirqd_should_handle() Jakub Kicinski
2022-12-22 22:12 ` [PATCH 2/3] softirq: avoid spurious stalls due to need_resched() Jakub Kicinski
2023-01-31 22:32 ` Jakub Kicinski
2023-03-03 13:30 ` Thomas Gleixner [this message]
2023-03-03 15:18 ` Thomas Gleixner
2023-03-03 21:31 ` Jakub Kicinski
2023-03-03 22:37 ` Paul E. McKenney
2023-03-03 23:25 ` Dave Taht
2023-03-04 1:14 ` Paul E. McKenney
2023-03-03 23:36 ` Paul E. McKenney
2023-03-03 23:44 ` Jakub Kicinski
2023-03-04 1:25 ` Paul E. McKenney
2023-03-04 1:39 ` Jakub Kicinski
2023-03-04 3:11 ` Paul E. McKenney
2023-03-04 20:48 ` Paul E. McKenney
2023-03-05 20:43 ` Thomas Gleixner
2023-03-05 22:42 ` Paul E. McKenney
2023-03-05 23:00 ` Frederic Weisbecker
2023-03-06 4:30 ` Paul E. McKenney
2023-03-06 11:22 ` Frederic Weisbecker
2023-03-06 9:13 ` David Laight
2023-03-06 11:57 ` Frederic Weisbecker
2023-03-06 14:57 ` Paul E. McKenney
2023-03-07 0:51 ` Jakub Kicinski
2022-12-22 22:12 ` [PATCH 3/3] softirq: don't yield if only expedited handlers are pending Jakub Kicinski
2023-01-09 9:44 ` Peter Zijlstra
2023-01-09 10:16 ` Eric Dumazet
2023-01-09 19:12 ` Jakub Kicinski
2023-03-03 11:41 ` Thomas Gleixner
2023-03-03 14:17 ` Thomas Gleixner
2023-04-20 17:24 ` [PATCH 0/3] softirq: uncontroversial change Paolo Abeni
2023-04-20 17:41 ` Eric Dumazet
2023-04-20 20:23 ` Paolo Abeni
2023-04-21 2:48 ` Jason Xing
2023-04-21 9:33 ` Paolo Abeni
2023-04-21 9:46 ` Jason Xing
2023-05-09 19:56 ` [tip: irq/core] Revert "softirq: Let ksoftirqd do its job" tip-bot2 for Paolo Abeni
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=87r0u6j721.ffs@tglx \
--to=tglx@linutronix.de \
--cc=edumazet@google.com \
--cc=jstultz@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=peterz@infradead.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 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.