From: Peter Zijlstra <peterz@infradead.org>
To: Tejun Heo <tj@kernel.org>
Cc: David Vernet <void@manifault.com>,
linux-kernel@vger.kernel.org, kernel-team@meta.com
Subject: Re: [PATCH sched_ext/for-6.12] sched_ext: Handle cases where pick_task_scx() is called without preceding balance_scx()
Date: Thu, 5 Sep 2024 17:00:12 +0200 [thread overview]
Message-ID: <20240905150012.GF4928@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20240905092858.GA15400@noisy.programming.kicks-ass.net>
On Thu, Sep 05, 2024 at 11:28:58AM +0200, Peter Zijlstra wrote:
> On Wed, Sep 04, 2024 at 02:47:03PM -1000, Tejun Heo wrote:
> > sched_ext dispatches tasks from the BPF scheduler from balance_scx() and
> > thus every pick_task_scx() call must be preceded by balance_scx(). While
> > this usually holds, there are rare cases where a higher sched class's
> > balance() returns true indicating that it has tasks to run on the CPU and
> > thus terminating balance() calls but fails to actually find the next task to
> > run when pick_task() is called.
>
> Oh cute. Which class in particular did you see this do?
>
> Looking at balance_fair() / sched_balance_newidle() I suppose we could
> verify we actually have a runnable task once we've re-acquired the
> rq-lock and have pulled_task > 0.
>
>
> Tightening all that up would probably be better than trying to deal with
> the fallout like this, hmm?
Something like so. Haven't yet looked at the rt/dl classes.
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 11e890486c1b..7db42735d504 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -12716,6 +12716,12 @@ static int sched_balance_newidle(struct rq *this_rq, struct rq_flags *rf)
if (this_rq->cfs.h_nr_running && !pulled_task)
pulled_task = 1;
+ /*
+ * We pulled a task, but it got stolen before we re-acquired rq->lock.
+ */
+ if (!this_rq->cfs.h_nr_running && pulled_task)
+ pulled_task = 0;
+
/* Is there a task of a high priority class? */
if (this_rq->nr_running != this_rq->cfs.h_nr_running)
pulled_task = -1;
next prev parent reply other threads:[~2024-09-05 15:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-05 0:47 [PATCH sched_ext/for-6.12] sched_ext: Handle cases where pick_task_scx() is called without preceding balance_scx() Tejun Heo
2024-09-05 9:28 ` Peter Zijlstra
2024-09-05 15:00 ` Peter Zijlstra [this message]
2024-09-05 16:41 ` Tejun Heo
2024-09-06 1:17 ` Tejun Heo
2024-09-06 2:08 ` Tejun Heo
2024-09-06 9:04 ` Peter Zijlstra
2024-09-06 18:16 ` [PATCH sched_ext/for-6.12] sched_ext: Temporarily work around pick_task_scx() being called without balance_scx() Tejun Heo
2024-11-09 20:17 ` [PATCH sched_ext/for-6.12] sched_ext: Handle cases where pick_task_scx() is called without preceding balance_scx() Tejun Heo
2024-11-09 20:50 ` [PATCH sched_ext/for-6.12-fixes v2] " Tejun Heo
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=20240905150012.GF4928@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.org \
--cc=void@manifault.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