From: Peter Zijlstra <peterz@infradead.org>
To: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Ingo Molnar <mingo@redhat.com>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
linux-kernel@vger.kernel.org,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
Valentin Schneider <vschneid@redhat.com>,
"Paul E. McKenney" <paulmck@kernel.org>,
Imran Khan <imran.f.khan@oracle.com>,
Leonardo Bras <leobras@redhat.com>, Guo Ren <guoren@kernel.org>,
Rik van Riel <riel@surriel.com>, Tejun Heo <tj@kernel.org>,
Cruz Zhao <CruzZhao@linux.alibaba.com>,
Lai Jiangshan <jiangshanlai@gmail.com>,
Joel Fernandes <joel@joelfernandes.org>,
Zqiang <qiang.zhang1211@gmail.com>,
Julia Lawall <julia.lawall@inria.fr>,
"Gautham R. Shenoy" <gautham.shenoy@amd.com>
Subject: Re: [RFC PATCH 3/3] softirq: Avoid waking up ksoftirqd from flush_smp_call_function_queue()
Date: Wed, 10 Jul 2024 17:05:57 +0200 [thread overview]
Message-ID: <20240710150557.GB27299@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20240710090210.41856-4-kprateek.nayak@amd.com>
On Wed, Jul 10, 2024 at 09:02:10AM +0000, K Prateek Nayak wrote:
> diff --git a/kernel/sched/smp.h b/kernel/sched/smp.h
> index 21ac44428bb0..3731e79fe19b 100644
> --- a/kernel/sched/smp.h
> +++ b/kernel/sched/smp.h
> @@ -9,7 +9,9 @@ extern void sched_ttwu_pending(void *arg);
> extern bool call_function_single_prep_ipi(int cpu);
>
> #ifdef CONFIG_SMP
> +extern bool do_softirq_pending(void);
> extern void flush_smp_call_function_queue(void);
> #else
> +static inline bool do_softirq_pending(void) { return false; }
> static inline void flush_smp_call_function_queue(void) { }
> #endif
> diff --git a/kernel/smp.c b/kernel/smp.c
> index f085ebcdf9e7..2eab5e1d5cef 100644
> --- a/kernel/smp.c
> +++ b/kernel/smp.c
> @@ -559,6 +559,36 @@ static void __flush_smp_call_function_queue(bool warn_cpu_offline)
> }
> }
>
> +/* Indicate an impending call to do_softirq_post_smp_call_flush() */
> +static DEFINE_PER_CPU_ALIGNED(bool, will_do_softirq_post_flush);
> +
> +static __always_inline void __set_will_do_softirq_post_flush(void)
> +{
> + this_cpu_write(will_do_softirq_post_flush, true);
> +}
> +
> +static __always_inline void __clr_will_do_softirq_post_flush(void)
> +{
> + this_cpu_write(will_do_softirq_post_flush, false);
> +}
> +
> +/**
> + * do_softirq_pending - Check if do_softirq_post_smp_call_flush() will
> + * be called after the invocation of
> + * __flush_smp_call_function_queue()
> + *
> + * When flush_smp_call_function_queue() executes in the context of idle,
> + * migration thread, a softirq raised from the smp-call-function ends up
> + * waking ksoftirqd despite an impending softirq processing via
> + * do_softirq_post_smp_call_flush().
> + *
> + * Indicate an impending do_softirq() to should_wake_ksoftirqd() despite
> + * not being in an interrupt context.
> + */
> +__always_inline bool do_softirq_pending(void)
> +{
> + return this_cpu_read(will_do_softirq_post_flush);
> +}
>
> /**
> * flush_smp_call_function_queue - Flush pending smp-call-function callbacks
> @@ -583,7 +613,9 @@ void flush_smp_call_function_queue(void)
> local_irq_save(flags);
> /* Get the already pending soft interrupts for RT enabled kernels */
> was_pending = local_softirq_pending();
> + __set_will_do_softirq_post_flush();
> __flush_smp_call_function_queue(true);
> + __clr_will_do_softirq_post_flush();
> if (local_softirq_pending())
> do_softirq_post_smp_call_flush(was_pending);
>
> diff --git a/kernel/softirq.c b/kernel/softirq.c
> index 02582017759a..b39eeed03042 100644
> --- a/kernel/softirq.c
> +++ b/kernel/softirq.c
> @@ -34,6 +34,8 @@
> #define CREATE_TRACE_POINTS
> #include <trace/events/irq.h>
>
> +#include "sched/smp.h"
> +
> /*
> - No shared variables, all the data are CPU local.
> - If a softirq needs serialization, let it serialize itself
> @@ -413,7 +415,13 @@ static inline void ksoftirqd_run_end(void)
>
> static inline bool should_wake_ksoftirqd(void)
> {
> - return true;
> + /*
> + * Avoid waking up ksoftirqd when a softirq is raised from a
> + * call-function executed by flush_smp_call_function_queue()
> + * in idle, migration thread's context since it'll soon call
> + * do_softirq_post_smp_call_flush().
> + */
> + return !do_softirq_pending();
> }
On first reading I wonder why you've not re-used and hooked into the
PREEMPT_RT variant of should_wake_ksoftirqd(). That already has a per
CPU variable to do exactly this.
next prev parent reply other threads:[~2024-07-10 15:06 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-10 9:02 [PATCH 0/3] sched/core: Fixes and enhancements around spurious need_resched() and idle load balancing K Prateek Nayak
2024-07-10 9:02 ` [PATCH 1/3] sched/core: Remove the unnecessary need_resched() check in nohz_csd_func() K Prateek Nayak
2024-07-10 14:53 ` Peter Zijlstra
2024-07-10 17:57 ` K Prateek Nayak
2024-07-23 6:46 ` K Prateek Nayak
2024-07-10 9:02 ` [PATCH 2/3] sched/core: Introduce SM_IDLE and an idle re-entry fast-path in __schedule() K Prateek Nayak
2024-07-11 8:00 ` Vincent Guittot
2024-07-11 9:19 ` Peter Zijlstra
2024-07-11 13:14 ` Vincent Guittot
2024-07-12 6:40 ` K Prateek Nayak
2024-07-30 16:13 ` Chen Yu
2024-08-04 4:05 ` Chen Yu
2024-08-05 4:03 ` K Prateek Nayak
2024-07-10 9:02 ` [RFC PATCH 3/3] softirq: Avoid waking up ksoftirqd from flush_smp_call_function_queue() K Prateek Nayak
2024-07-10 15:05 ` Peter Zijlstra [this message]
2024-07-10 18:20 ` K Prateek Nayak
2024-07-23 4:50 ` K Prateek Nayak
2024-07-29 2:42 ` [PATCH 0/3] sched/core: Fixes and enhancements around spurious need_resched() and idle load balancing Chen Yu
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=20240710150557.GB27299@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=CruzZhao@linux.alibaba.com \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=gautham.shenoy@amd.com \
--cc=guoren@kernel.org \
--cc=imran.f.khan@oracle.com \
--cc=jiangshanlai@gmail.com \
--cc=joel@joelfernandes.org \
--cc=julia.lawall@inria.fr \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=leobras@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=paulmck@kernel.org \
--cc=qiang.zhang1211@gmail.com \
--cc=riel@surriel.com \
--cc=rostedt@goodmis.org \
--cc=tj@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox