From: Marcelo Tosatti <mtosatti@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>,
linux-kernel@vger.kernel.org,
Frederic Weisbecker <frederic@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>
Cc: Frederic Weisbecker <frederic@kernel.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
linux-pm@vger.kernel.org, Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH v3] sched/idle: disable tick in idle=poll idle entry
Date: Mon, 8 Dec 2025 12:53:41 -0300 [thread overview]
Message-ID: <aTb0haA19YNVpJF7@tpad> (raw)
In-Reply-To: <aQtJzK7c/FpSWX74@tpad>
On Wed, Nov 05, 2025 at 09:57:48AM -0300, Marcelo Tosatti wrote:
> On Mon, Nov 03, 2025 at 01:30:23PM +0100, Peter Zijlstra wrote:
> > On Mon, Nov 03, 2025 at 08:48:14AM -0300, Marcelo Tosatti wrote:
> > >
> > > Commit a5183862e76fdc25f36b39c2489b816a5c66e2e5
> > > ("tick/nohz: Conditionally restart tick on idle exit") allows
> >
> > Quoting a commit usually shortens the hash to 12 charters, no?
> >
> > > a nohz_full CPU to enter idle and return from it with the
> > > scheduler tick disabled (since the tick might be undesired noise).
> > >
> > > The idle=poll case still unconditionally restarts the tick when entering
> > > idle.
> > >
> > > To reduce the noise for that case as well, stop the tick when entering
> > > idle, for the idle=poll case.
> > >
> > > Change tick_nohz_full_kick_cpu to set NEED_RESCHED bit, to handle the
> > > case where a new timer is added from an interrupt. This breaks out of
> > > cpu_idle_poll and rearms the timer if necessary.
> > >
> > > Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
> > >
> > > ---
> > >
> > > v3: Add comment with proper explanation (Frederic Weisbecker)
> > > Add signed-off-by (Thomas Gleixner)
> > > v2: Handle the case where a new timer is added from an interrupt (Frederic Weisbecker)
> > >
> > > include/linux/sched.h | 2 ++
> > > kernel/sched/core.c | 10 ++++++++++
> > > kernel/sched/idle.c | 2 +-
> > > kernel/time/tick-sched.c | 7 +++++++
> > > 4 files changed, 20 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/include/linux/sched.h b/include/linux/sched.h
> > > index cbb7340c5866..1f6938dc20cd 100644
> > > --- a/include/linux/sched.h
> > > +++ b/include/linux/sched.h
> > > @@ -2428,4 +2428,6 @@ extern void migrate_enable(void);
> > >
> > > DEFINE_LOCK_GUARD_0(migrate, migrate_disable(), migrate_enable())
> > >
> > > +void set_tif_resched_if_polling(int cpu);
> > > +
> > > #endif
> > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > > index f1ebf67b48e2..f0b84600084b 100644
> > > --- a/kernel/sched/core.c
> > > +++ b/kernel/sched/core.c
> > > @@ -988,6 +988,11 @@ static bool set_nr_if_polling(struct task_struct *p)
> > > return true;
> > > }
> > >
> > > +void set_tif_resched_if_polling(int cpu)
> > > +{
> > > + set_nr_if_polling(cpu_rq(cpu)->idle);
> > > +}
> > > +
> > > #else
> > > static inline bool set_nr_and_not_polling(struct thread_info *ti, int tif)
> > > {
> > > @@ -999,6 +1004,11 @@ static inline bool set_nr_if_polling(struct task_struct *p)
> > > {
> > > return false;
> > > }
> > > +
> > > +void set_tif_resched_if_polling(int cpu)
> > > +{
> > > + set_tsk_need_resched(cpu_rq(cpu)->idle);
> > > +}
> > > #endif
> > >
> > > static bool __wake_q_add(struct wake_q_head *head, struct task_struct *task)
> > > diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
> > > index c39b089d4f09..428c2d1cbd1b 100644
> > > --- a/kernel/sched/idle.c
> > > +++ b/kernel/sched/idle.c
> > > @@ -324,7 +324,7 @@ static void do_idle(void)
> > > * idle as we know that the IPI is going to arrive right away.
> > > */
> > > if (cpu_idle_force_poll || tick_check_broadcast_expired()) {
> > > - tick_nohz_idle_restart_tick();
> > > + tick_nohz_idle_stop_tick();
> > > cpu_idle_poll();
> > > } else {
> > > cpuidle_idle_call();
> > > diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
> > > index c527b421c865..9ec51da49591 100644
> > > --- a/kernel/time/tick-sched.c
> > > +++ b/kernel/time/tick-sched.c
> > > @@ -408,6 +408,13 @@ void tick_nohz_full_kick_cpu(int cpu)
> > > if (!tick_nohz_full_cpu(cpu))
> > > return;
> > >
> > > + /*
> > > + * When idle=poll, with the tick disabled (therefore idle CPU looping
> > > + * at cpu_idle_poll), if a new timer is added from an interrupt,
> > > + * the cpu_idle_poll only exits when TIF_NEED_RESCHED gets set.
> > > + */
> > > + set_tif_resched_if_polling(cpu);
> > > +
> > > irq_work_queue_on(&per_cpu(nohz_full_kick_work, cpu), cpu);
> > > }
> >
> > I'm confused. Why is this here and not in tick_nohz_start_idle() or
> > something?
> >
> >
>
> Hi Peter,
>
> The codepath being followed is:
>
> enqueue_timer -> trigger_dyntick_cpu -> wake_up_nohz_cpu ->
> wake_up_full_nohz_cpu -> tick_nohz_full_kick_cpu ->
> set_tif_resched_if_polling.
>
> So we only set the PF_RESCHED bit if there is a pending timer
> on the CPU.
>
> Calling unconditionally from tick_nohz_start_idle seems strange:
>
> /**
> * tick_nohz_idle_enter - prepare for entering idle on the current CPU
> *
> * Called when we start the idle loop.
> */
> void tick_nohz_idle_enter(void)
> {
> struct tick_sched *ts;
>
> lockdep_assert_irqs_enabled();
>
> local_irq_disable();
>
> ts = this_cpu_ptr(&tick_cpu_sched);
>
> WARN_ON_ONCE(ts->timer_expires_base);
>
> tick_sched_flag_set(ts, TS_FLAG_INIDLE);
> tick_nohz_start_idle(ts);
>
> local_irq_enable();
> }
>
> Can test for TS_FLAG_INIDLE before calling set_tif_resched_if_polling
> (but seems not necessary since tick_nohz_full_kick_cpu will wake up the
> CPU anyway and is a slow path (timer addition)).
>
> What do you think?
OK, it looks like there are no further comments on this patch.
Frederic, Peter, Thomas, can you ACK ???
Thanks
next prev parent reply other threads:[~2025-12-08 15:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-03 11:48 [PATCH v3] sched/idle: disable tick in idle=poll idle entry Marcelo Tosatti
2025-11-03 12:30 ` Peter Zijlstra
2025-11-05 12:57 ` Marcelo Tosatti
2025-12-08 15:53 ` Marcelo Tosatti [this message]
2025-12-10 13:43 ` Frederic Weisbecker
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=aTb0haA19YNVpJF7@tpad \
--to=mtosatti@redhat.com \
--cc=frederic@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=rafael@kernel.org \
--cc=tglx@linutronix.de \
/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;
as well as URLs for NNTP newsgroup(s).