mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tim Chen <tim.c.chen@linux.intel.com>
To: Vincent Guittot <vincent.guittot@linaro.org>,
	mingo@redhat.com,  peterz@infradead.org, juri.lelli@redhat.com,
	dietmar.eggemann@arm.com,  rostedt@goodmis.org,
	bsegall@google.com, mgorman@suse.de, vschneid@redhat.com,
		kprateek.nayak@amd.com, linux-kernel@vger.kernel.org,
	lukasz.luba@arm.com, 	rafael@kernel.org,
	linux-pm@vger.kernel.org, tj@kernel.org, void@manifault.com,
		arighi@nvidia.com, changwoo@igalia.com,
	sched-ext@lists.linux.dev
Cc: qyousef@layalina.io, christian.loehle@arm.com,
	pierre.gondois@arm.com,  sshegde@linux.ibm.com
Subject: Re: [PATCH 11/18 v2] sched/fair: Support not wakeup case in select_idle_sibling
Date: Wed, 07 Oct 2026 10:55:15 -0700	[thread overview]
Message-ID: <62547ac28298442a246abe0471647e36518a93cb.camel@linux.intel.com> (raw)
In-Reply-To: <20261002154415.2270586-12-vincent.guittot@linaro.org>

On Fri, 2026-10-02 at 17:44 +0200, Vincent Guittot wrote:
> With push callback mecanism, select_task_rq_fair can be called for a task
> that is already enqueued. Task into account this case when choosing idle
> CPU.
> 
> Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
> ---
>  kernel/sched/fair.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 6ed3e5bb7fd6..38eb80dbd1a4 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -7974,10 +7974,13 @@ static int choose_sched_idle_rq(struct rq *rq, struct task_struct *p)
>  	return sched_idle_rq(rq) && !task_has_idle_policy(p);
>  }
>  
> +static int idle_cpu_without(int cpu, struct task_struct *p);
> +
>  static int choose_idle_cpu(int cpu, struct task_struct *p)
>  {
>  	return available_idle_cpu(cpu) ||
> -	       choose_sched_idle_rq(cpu_rq(cpu), p);
> +	       choose_sched_idle_rq(cpu_rq(cpu), p) ||
> +	       idle_cpu_without(cpu, p);
>  }
>  
>  static void


Hi Vincent,

One concern I have is that many CPUs will try to push
their tasks onto the same idle CPU and causes over stacking.

idle_cpu_without() doesn't check nr_running. Its comment says:

         * rq->nr_running can't be used but an updated version without the
         * impact of p on cpu must be used instead. The updated nr_running
         * be computed and tested before calling idle_cpu_without().

and update_sg_wakeup_stats() does this:

        if (!nr_running && idle_cpu_without(i, p))

choose_idle_cpu() calls it without that test. So a CPU that runs its
idle task but already has a queued task is now idle for every caller:
the target, prev and recent_used_cpu checks, __select_idle_cpu(),
select_idle_smt() and select_idle_capacity(). This affects wakeups
too, not only pushes.

For a wakeup to an idle CPU, the wakelist usually sets ttwu_pending,
which idle_cpu_without() checks. A push enqueues the task directly, so
after a push the destination stays idle for everyone until it
schedules. If it wakes up from a deep idle state, this can take a
while, and other CPUs can push or wake their tasks onto it in the
meantime.

The fixup below removes p from nr_running when p is queued on the CPU,
and calls idle_cpu_without() only when nothing else is queued. The
tick case that this patch is for still works: p is the only task, so
its CPU is still idle without it.

It is build tested only.

Thanks,
Tim

---

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 3eb8a0170902..cb00f24a58fa 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -7978,9 +7978,16 @@ static int idle_cpu_without(int cpu, struct task_struct *p);

 static int choose_idle_cpu(int cpu, struct task_struct *p)
 {
+       struct rq *rq = cpu_rq(cpu);
+       unsigned int nr_running = rq->nr_running;
+
+       /* idle_cpu_without() needs nr_running without p */
+       if (task_cpu(p) == cpu && task_on_rq_queued(p))
+               nr_running--;
+
        return available_idle_cpu(cpu) ||
-              choose_sched_idle_rq(cpu_rq(cpu), p) ||
-              idle_cpu_without(cpu, p);
+              choose_sched_idle_rq(rq, p) ||
+              (!nr_running && idle_cpu_without(cpu, p));
 }

 static void


  reply	other threads:[~2026-10-07 17:55 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-02 15:43 [PATCH 00/18 v2] Improving latency of short slice tasks Vincent Guittot
2026-10-02 15:43 ` [PATCH 01/18 v2] sched/eevdf: Decay positive lag of sleeping entities Vincent Guittot
2026-10-02 15:43 ` [PATCH 02/18] sched/eevdf: Reset lag when waking up on idle cpu Vincent Guittot
2026-10-04 17:30   ` Kayra Cizmeci
2026-10-02 15:44 ` [PATCH 03/18 v2] sched/eevdf: Add per cpu cached min_slice Vincent Guittot
2026-10-02 15:44 ` [PATCH 04/18 v2] sched/eevdf: Compare min slice during wake_affine Vincent Guittot
2026-10-05 15:58   ` Kayra Cizmeci
2026-10-02 15:44 ` [PATCH 05/18 v2] sched/eevdf: Add min slice check when selecting CPU Vincent Guittot
2026-10-04 19:18   ` Kayra Cizmeci
2026-10-02 15:44 ` [PATCH 06/18 v2] sched/fair: Prepare select_task_rq_fair() to be called for new cases Vincent Guittot
2026-10-06 22:25   ` Tim Chen
2026-10-02 15:44 ` [PATCH 07/18] sched/fair: Add push task mechanism for fair Vincent Guittot
2026-10-07  2:45   ` Chen Yu
2026-10-02 15:44 ` [PATCH 08/18] sched/fair: Optimize " Vincent Guittot
2026-10-02 15:44 ` [PATCH 09/18 v2] sched/core: Add rq flag to tick parameters Vincent Guittot
2026-10-02 15:44 ` [PATCH 10/18 v2] sched/fair: Add force push task mechanism for fair Vincent Guittot
2026-10-06 19:24   ` Kayra Cizmeci
2026-10-02 15:44 ` [PATCH 11/18 v2] sched/fair: Support not wakeup case in select_idle_sibling Vincent Guittot
2026-10-07 17:55   ` Tim Chen [this message]
2026-10-02 15:44 ` [PATCH 12/18 v2] sched/eevdf: Try to push short slice task on a better CPU Vincent Guittot
2026-10-02 15:44 ` [PATCH 13/18 v2] sched/eevdf: Push short slice task that are not picked Vincent Guittot
2026-10-02 15:44 ` [PATCH 14/18 v2] sched/fair: Enable push task for preempt short Vincent Guittot
2026-10-02 15:44 ` [PATCH 15/18 v2] energy model: Add a get previous state function Vincent Guittot
2026-10-02 15:44 ` [PATCH 16/18 v2] sched/fair: Rework feec() to use cost instead of spare capacity Vincent Guittot
2026-10-02 15:44 ` [PATCH 17/18 v2] energy model: Remove unused em_cpu_energy() Vincent Guittot
2026-10-02 15:44 ` [PATCH 18/18 v2] sched/fair: Take into account slice in EAS Vincent Guittot
2026-10-07 14:36   ` Kayra Cizmeci

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=62547ac28298442a246abe0471647e36518a93cb.camel@linux.intel.com \
    --to=tim.c.chen@linux.intel.com \
    --cc=arighi@nvidia.com \
    --cc=bsegall@google.com \
    --cc=changwoo@igalia.com \
    --cc=christian.loehle@arm.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=pierre.gondois@arm.com \
    --cc=qyousef@layalina.io \
    --cc=rafael@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=sched-ext@lists.linux.dev \
    --cc=sshegde@linux.ibm.com \
    --cc=tj@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=void@manifault.com \
    --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

all inboxes | Powered by JetHome®