Re: [PATCH v2] sched/core: Skip rq->avg_idle update without a valid idle_stamp
John Stultz <[email protected]>
| Newsgroups | org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <CANDhNCogJqpZVPnG11Jp10vPW9T2TB6ua64wEr2rPKMpU7AQxg@mail.gmail.com> |
On Thu, Aug 6, 2026 at 5:26 PM Shubhang Kaushik (Ampere) <[email protected]> wrote: > > Commit 4b603f1551a73 ("sched: Update rq->avg_idle when a task is moved > to an idle CPU") moved rq->avg_idle accounting out of the wakeup path and > into put_prev_task_idle(), so that the idle interval is consumed whenever > the idle task is switched out. > > The wakeup-side accounting that it replaced only updated rq->avg_idle > when rq->idle_stamp was non-zero. The new helper lost that validity > check and unconditionally computes: > > rq_clock(rq) - rq->idle_stamp > > If rq->idle_stamp is zero, this uses rq_clock(rq) as the sample. That is > not a valid idle duration and can immediately drive rq->avg_idle to its > clamp. > > This can happen when the scheduler switches to the idle task through a > path that did not set rq->idle_stamp via newidle_balance(), for example > during find_proxy_task() or force-idling. > > Restore the idle_stamp validity check in update_rq_avg_idle() and skip > the rq->avg_idle update when there is no measured idle interval. > > Fixes: 4b603f1551a73 ("sched: Update rq->avg_idle when a task is moved to an idle CPU") > Reviewed-by: K Prateek Nayak <[email protected]> > Signed-off-by: Shubhang Kaushik (Ampere) <[email protected]> > --- > Temporary tracing under hackbench load confirmed that > update_rq_avg_idle() can be reached with rq->idle_stamp == 0. > Hackbench showed no material regression versus v7.2-rc5 mainline. > > Related discussion: > https://lore.kernel.org/r/[email protected] > > This is a narrower variant of the earlier proposal. It keeps the > rq->idle_stamp guard in update_rq_avg_idle(), but intentionally does not > stamp idle entry from set_next_task_idle(), preserving the existing > newidle accounting model and avoiding forced/proxy idle accounting > concerns. Thanks for sending this out! Acked-by: John Stultz <[email protected]>