mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: K Prateek Nayak <kprateek.nayak@amd.com>
To: Peter Zijlstra <peterz@infradead.org>, <mingo@kernel.org>
Cc: <juri.lelli@redhat.com>, <vincent.guittot@linaro.org>,
	<dietmar.eggemann@arm.com>, <rostedt@goodmis.org>,
	<bsegall@google.com>, <mgorman@suse.de>, <vschneid@redhat.com>,
	<linux-kernel@vger.kernel.org>, <tj@kernel.org>,
	<ziqianlu@bytedance.com>
Subject: Re: [PATCH v2 12/12] sched: Remove sched_class::balance()
Date: Thu, 12 Nov 2026 12:16:06 +0530	[thread overview]
Message-ID: <56e1d372-c938-468a-950b-4f984ad6bde1@amd.com> (raw)
In-Reply-To: <20261107120208.153536827@infradead.org>

Hello Peter,

On 11/7/2026 5:29 PM, Peter Zijlstra wrote:
> Ever since commit 50653216e4ff ("sched: Add support to pick functions to take
> rf"), we have the unfortunate situation that both sched_class::balance() and
> sched_class::pick_task() have overlapping functionality in that they drop
> rq->lock and balance tasks.
> 
> Additionally, prev_balance() is only called for a single RQ in the core-sched
> case, resulting in 'missed' balance opportunities in this case.

So I have a fundamental question - looking at the deadline and rt balance
callbacks, the balance is only done if rq->donor was taken off of rq
(blocked / throttled) and we need to pull a waiting task that might be of
higher priority.

Now, if the balance (say for RT) failed, and later, a different class' (fair's)
balance callback dropped the lock during which a RT task was woken up on the
CPU, I believe the wakeup path would have already done the balance while
considering this CPU for wakeup right?

In that case, why should RETRY_TASK want to try balance again for the old
"rq->donor" for which we have already ran balanced for? Shouldn't it simply
pick the task then? Am I missing something?

> Just like pick_task(), prev_balance() would iterate the classes and stop when
> there is a runnable task found. The only difference is that pick_task() starts
> from the top class, while prev_balance() would start from prev->class.
> 
> This means that if prev was an RT task, we'd get an extra visit to balance_dl()
> -- and similary, if prev is fair, we'd visit balance_{dl,rt}() both. However,
> this is not a problem, because both need_pull_{dl,rt}_task() will DTRT.

Balance still sees old donor and it can still try a pull if the newly
woken task is on a lower priority than the rq->donor. Is that desirable?

> Therefore, move balance_{rt,dl}() into pick_task_{rt,dl}() and remove
> sched_class::balance().

Until commit 50653216e4f ("sched: Add support to pick functions to take rf")
that was how pick worked and we should perhaps stick to that. commit 67692435c41
("sched: Rework pick_next_task() slow-path"), made it such that none of the picks
could actually return RETRY_TASK and we are actually moving back to the same
state as 67692435c41~1 with these changes.

IMO, we should re-introduce balance_fair() for newidle_balance, and drain all
the delayed task if !h_nr_runnable && h_nr_queued to avoid pick hitting the idle
label altogether.

Doing newidle balance for every idle rq's core pick seems too aggressive. I
think we should let idle balance / balance callback handle those movements after
rq->core_cookie is stable.

This also allows for us to now do rq->next_class->pick_task() and that should
always return a runnable task and we don't have to ever juggle rq_lock between
picks which has already led to a bunch of issues.

-- 
Thanks and Regards,
Prateek


  parent reply	other threads:[~2026-11-12  6:46 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-07 11:59 [PATCH v2 00/12] sched: core-sched fixes and balancing Peter Zijlstra
2026-11-07 11:59 ` [PATCH v2 01/12] sched/core: Fix pick_next_task() self recursion Peter Zijlstra
2026-11-11  0:30   ` Tejun Heo
2026-11-11 10:45     ` Peter Zijlstra
2026-11-07 11:59 ` [PATCH v2 02/12] sched/core: Introduce rq_drop_lock() Peter Zijlstra
2026-11-08  9:25   ` Kayra Cizmeci
2026-11-11 10:46     ` Peter Zijlstra
2026-11-07 11:59 ` [PATCH v2 03/12] sched/core: Decompose update_rq_clock() Peter Zijlstra
2026-11-07 11:59 ` [PATCH v2 04/12] sched/core: Make __update_rq_clock() skip updates on UPDATED Peter Zijlstra
2026-11-11  1:11   ` Tejun Heo
2026-11-11 10:28     ` Peter Zijlstra
2026-11-11 12:25       ` Peter Zijlstra
2026-11-11 17:08         ` Tejun Heo
2026-11-07 11:59 ` [PATCH v2 05/12] sched/core: Abstract/fix rq_clock_start_loop_update() Peter Zijlstra
2026-11-08 22:26   ` Kayra Cizmeci
2026-11-11  9:10     ` K Prateek Nayak
2026-11-11  9:51       ` Kayra Cizmeci
2026-11-11 16:39     ` Peter Zijlstra
2026-11-07 11:59 ` [PATCH v2 06/12] sched/core: New rq_{pin,drop,repin,unpin}_lock() semantics Peter Zijlstra
2026-11-11 10:41   ` Tejun Heo
2026-11-07 11:59 ` [PATCH v2 07/12] sched/core: Simplify/fix time updates Peter Zijlstra
2026-11-07 11:59 ` [PATCH v2 08/12] sched/core: Allow newidle for core-sched Peter Zijlstra
2026-11-07 11:59 ` [PATCH v2 09/12] sched/rt: Add early exit on balance path Peter Zijlstra
2026-11-07 11:59 ` [PATCH v2 10/12] sched/fair: Reflow pick_task_fair() / newidle Peter Zijlstra
2026-11-11 11:02   ` Tejun Heo
2026-11-11 12:31     ` Peter Zijlstra
2026-11-07 11:59 ` [PATCH v2 11/12] sched/fair: Push sched_balance_newidle() unlock down Peter Zijlstra
2026-11-07 11:59 ` [PATCH v2 12/12] sched: Remove sched_class::balance() Peter Zijlstra
2026-11-11 11:18   ` Tejun Heo
2026-11-11 13:05     ` Peter Zijlstra
2026-11-11 13:11       ` Peter Zijlstra
2026-11-11 14:57         ` Kayra Cizmeci
2026-11-11 15:47           ` Peter Zijlstra
2026-11-11 16:15             ` Peter Zijlstra
2026-11-11 18:53               ` Kayra Cizmeci
2026-11-12  6:46   ` K Prateek Nayak [this message]
2026-11-11 11:46 ` [PATCH v2 00/12] sched: core-sched fixes and balancing Tejun Heo
2026-11-11 13:57   ` Peter Zijlstra

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=56e1d372-c938-468a-950b-4f984ad6bde1@amd.com \
    --to=kprateek.nayak@amd.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tj@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=ziqianlu@bytedance.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®