mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	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>,
	Valentin Schneider <vschneid@redhat.com>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	Rik van Riel <riel@surriel.com>,
	Neeraj Upadhyay <neeraj.upadhyay@kernel.org>,
	Leonardo Bras <leobras@redhat.com>,
	Thorsten Blum <thorsten.blum@toblux.com>,
	Zqiang <qiang.zhang1211@gmail.com>, Tejun Heo <tj@kernel.org>,
	NeilBrown <neilb@suse.de>,
	Caleb Sander Mateos <csander@purestorage.com>,
	"Gautham R . Shenoy" <gautham.shenoy@amd.com>,
	Chen Yu <yu.c.chen@intel.com>,
	Julia Lawall <Julia.Lawall@inria.fr>
Subject: Re: [PATCH v3 5/5] softirq: Avoid unnecessary wakeup of ksoftirqd when a call to do_sofirq() is pending
Date: Fri, 25 Oct 2024 19:03:26 +0200	[thread overview]
Message-ID: <20241025170326.ChR4tfjG@linutronix.de> (raw)
In-Reply-To: <20241014090339.2478-6-kprateek.nayak@amd.com>

On 2024-10-14 09:03:39 [+0000], K Prateek Nayak wrote:
> Since commit b2a02fc43a1f4 ("smp: Optimize
> send_call_function_single_ipi()"), sending an actual interrupt to an
> idle CPU in TIF_POLLING_NRFLAG mode can be avoided by queuing the SMP
> call function on the call function queue of the CPU and setting the
> TIF_NEED_RESCHED bit in idle task's thread info. The call function is
> handled in the idle exit path when do_idle() calls
> flush_smp_call_function_queue().
> 
> However, since flush_smp_call_function_queue() is executed in idle
> thread's context, in_interrupt() check within a call function will
> return false. raise_softirq() uses this check to decide whether to wake
> ksoftirqd, since, a softirq raised from an interrupt context will be
> handled at irq exit. In all other cases, raise_softirq() wakes up
> ksoftirqd to handle the softirq on !PREEMPT_RT kernel.

Stupid question. You talk about the invocation from nohz_csd_func(),
right?.
Given that this is an IPI and always invoked from an IRQ then the
softirq is invoked on IRQ-exit. If it is flushed from
flush_smp_call_function_queue() then the softirq is handled via
do_softirq_post_smp_call_flush(). In that case couldn't you just tell
nohz_csd_func() to use __raise_softirq_irqoff(SCHED_SOFTIRQ) ? This
should solve this, right?

> diff --git a/kernel/softirq.c b/kernel/softirq.c
> index 0730c2b43ae4..3a6b3e67ea24 100644
> --- a/kernel/softirq.c
> +++ b/kernel/softirq.c
> @@ -99,6 +99,10 @@ EXPORT_PER_CPU_SYMBOL_GPL(hardirq_context);
>   *
>   * The per CPU counter prevents pointless wakeups of ksoftirqd in case that
>   * the task which is in a softirq disabled section is preempted or blocks.
> + *
> + * The bottom bits of softirq_ctrl::cnt is used to indicate an impending call
> + * to do_softirq() to prevent pointless wakeups of ksoftirqd since the CPU
> + * promises to handle softirqs soon.
>   */

The comment that you are extending and the comment regarding
SOFTIRQ_OFFSET were nearby. I don't like that those two are now far
apart.

>  struct softirq_ctrl {
>  	local_lock_t	lock;
> @@ -109,6 +113,16 @@ static DEFINE_PER_CPU_ALIGNED(struct softirq_ctrl, softirq_ctrl) = {
>  	.lock	= INIT_LOCAL_LOCK(softirq_ctrl.lock),
>  };
>  
> +inline void set_do_softirq_pending(void)
> +{
> +	__this_cpu_inc(softirq_ctrl.cnt);
> +}
> +
> +inline void clr_do_softirq_pending(void)

there should be no inline here.

> +{
> +	__this_cpu_dec(softirq_ctrl.cnt);
> +}
> +
>  static inline bool should_wake_ksoftirqd(void)
>  {
>  	return !this_cpu_read(softirq_ctrl.cnt);

Sebastian

  reply	other threads:[~2024-10-25 17:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-14  9:03 [PATCH v3 0/5] Idle Load Balance fixes and softirq enhancements K Prateek Nayak
2024-10-14  9:03 ` [PATCH v3 1/5] softirq: Allow raising SCHED_SOFTIRQ from SMP-call-function on RT kernel K Prateek Nayak
2024-10-14  9:03 ` [PATCH v3 2/5] sched/core: Remove the unnecessary need_resched() check in nohz_csd_func() K Prateek Nayak
2024-10-14  9:03 ` [PATCH v3 3/5] softirq: Mask reads of softirq_ctrl.cnt with SOFTIRQ_MASK for PREEMPT_RT K Prateek Nayak
2024-10-14  9:03 ` [PATCH v3 4/5] softirq: Unify should_wakeup_ksoftirqd() K Prateek Nayak
2024-10-14  9:03 ` [PATCH v3 5/5] softirq: Avoid unnecessary wakeup of ksoftirqd when a call to do_sofirq() is pending K Prateek Nayak
2024-10-25 17:03   ` Sebastian Andrzej Siewior [this message]
2024-10-28  4:23     ` K Prateek Nayak

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=20241025170326.ChR4tfjG@linutronix.de \
    --to=bigeasy@linutronix.de \
    --cc=Julia.Lawall@inria.fr \
    --cc=bsegall@google.com \
    --cc=csander@purestorage.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=gautham.shenoy@amd.com \
    --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=neeraj.upadhyay@kernel.org \
    --cc=neilb@suse.de \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=qiang.zhang1211@gmail.com \
    --cc=riel@surriel.com \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=thorsten.blum@toblux.com \
    --cc=tj@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=yu.c.chen@intel.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

all inboxes | Powered by JetHome®