From: Peter Zijlstra <peterz@infradead.org>
To: Tejun Heo <tj@kernel.org>
Cc: mingo@kernel.org, juri.lelli@redhat.com,
vincent.guittot@linaro.org, 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, ziqianlu@bytedance.com
Subject: Re: [PATCH v2 12/12] sched: Remove sched_class::balance()
Date: Wed, 11 Nov 2026 14:11:52 +0100 [thread overview]
Message-ID: <20261111131152.GD2669272@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20261111130512.GO2668200@noisy.programming.kicks-ass.net>
On Wed, Nov 11, 2026 at 02:05:12PM +0100, Peter Zijlstra wrote:
> On Wed, Nov 11, 2026 at 01:18:42AM -1000, Tejun Heo wrote:
> > Hello,
> >
> > On Sat, Nov 07, 2026 at 12:59:25PM +0100, Peter Zijlstra wrote:
> > > static struct task_struct *pick_task_rt(struct rq *rq, struct rq_flags *rf)
> > > {
> > > - struct task_struct *p;
> > > + rq_modified_begin(rq, &rt_sched_class);
> > > + balance_rt(rq, rf);
> > > + if (rq_modified_above(rq, &rt_sched_class))
> > > + return RETRY_TASK;
> >
> > This exposes an underlying problem on the DL side. rq->next_class is
> > raised only by wakeup_preempt(), but dl_server_start(), dl_task_timer()
> > and dl_server_timer() enqueue a DL entity and open-code resched_curr()
> > without going through it. prev_balance() ran before any class was
> > picked, so it didn't matter. Now, pick_task_dl() has already returned
> > NULL when balance_rt() drops the lock, and rq_modified_above() is the
> > only thing which can notice a DL entity queued in the meantime:
> >
> > CPU0 RT task blocks, pick_task_dl() returns NULL
> > pick_task_rt(), balance_rt() drops the rq lock
> > CPU1 wakes a fair task onto CPU0, dl_server_start()
> > CPU0 relocks, rq_modified_above() is false
> > picks an RT task with the fair server queued
>
> A very nice catch, but I'm not entirely convinced it wasn't a problem
> before.
>
> Similar argument could be made for FAIR vs EXT, and picking a FAIR task
> while an EXT server is pickable.
>
> > resched_curr() doesn't help as __schedule() clears it on prev after the
> > pick. I can trigger this with NO_RT_PUSH_IPI and a delay added in the
> > lock drop. With RT_PUSH_IPI, pull_rt_task() doesn't drop the lock.
> >
> > Maybe the DL sites should raise rq->next_class where they enqueue and
> > resched, so that they behave the same as regular wakeups?
>
> Yes, something like that. I think the below captures all enqueues,
> irrespective of rescheds. I'll add it as fix at the start of the series.
>
> (although maybe I'll massage this a little more and create a helper,
> doing the same thing over and over like this is daft)
>
> Thanks!
---
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -715,8 +715,7 @@ static struct rq *dl_task_offline_migrat
return later_rq;
}
-static void
-enqueue_dl_entity(struct sched_dl_entity *dl_se, int flags);
+static void enqueue_dl_entity(struct rq *rq, struct sched_dl_entity *dl_se, int flags);
static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags);
static void dequeue_dl_entity(struct sched_dl_entity *dl_se, int flags);
static void wakeup_preempt_dl(struct rq *rq, struct task_struct *p, int flags);
@@ -1184,7 +1183,7 @@ static enum hrtimer_restart dl_server_ti
dl_se->dl_defer_running = 1;
}
- enqueue_dl_entity(dl_se, ENQUEUE_REPLENISH);
+ enqueue_dl_entity(rq, dl_se, ENQUEUE_REPLENISH);
if (!dl_task(dl_se->rq->curr) || dl_entity_preempt(dl_se, &dl_se->rq->curr->dl))
resched_curr(rq);
@@ -1520,7 +1519,7 @@ static void update_curr_dl_se(struct rq
replenish_dl_new_period(dl_se, rq);
start_dl_timer(dl_se);
} else {
- enqueue_dl_entity(dl_se, ENQUEUE_REPLENISH);
+ enqueue_dl_entity(rq, dl_se, ENQUEUE_REPLENISH);
}
} else {
enqueue_task_dl(rq, dl_task_of(dl_se), ENQUEUE_REPLENISH);
@@ -1812,7 +1811,7 @@ void dl_server_start(struct sched_dl_ent
trace_sched_dl_server_start_tp(dl_se, cpu_of(rq), dl_get_type(dl_se, rq));
dl_se->dl_server_active = 1;
- enqueue_dl_entity(dl_se, ENQUEUE_WAKEUP);
+ enqueue_dl_entity(rq, dl_se, ENQUEUE_WAKEUP);
if (!dl_task(dl_se->rq->curr) || dl_entity_preempt(dl_se, &rq->curr->dl))
resched_curr(dl_se->rq);
}
@@ -2379,8 +2378,8 @@ static void __dequeue_dl_entity(struct s
dec_dl_tasks(dl_se, dl_rq);
}
-static void
-enqueue_dl_entity(struct sched_dl_entity *dl_se, int flags)
+static bool
+_enqueue_dl_entity(struct sched_dl_entity *dl_se, int flags)
{
WARN_ON_ONCE(on_dl_rq(dl_se));
@@ -2418,7 +2417,7 @@ enqueue_dl_entity(struct sched_dl_entity
if (flags & ENQUEUE_WAKEUP)
task_contending(dl_se, flags);
- return;
+ return false;
}
/*
@@ -2442,7 +2441,7 @@ enqueue_dl_entity(struct sched_dl_entity
* deferred task and still got to wait, don't enqueue.
*/
if (dl_se->dl_throttled && start_dl_timer(dl_se))
- return;
+ return false;
/*
* We're about to enqueue, make sure we're not ->dl_throttled!
@@ -2457,6 +2456,13 @@ enqueue_dl_entity(struct sched_dl_entity
}
__enqueue_dl_entity(dl_se);
+ return true;
+}
+
+static void enqueue_dl_entity(struct rq *rq, struct sched_dl_entity *dl_se, int flags)
+{
+ if (_enqueue_dl_entity(dl_se, flags))
+ rq->next_class = &dl_sched_class;
}
static void dequeue_dl_entity(struct sched_dl_entity *dl_se, int flags)
@@ -2534,7 +2540,7 @@ static void enqueue_task_dl(struct rq *r
if (task_on_rq_migrating(p))
flags |= ENQUEUE_MIGRATING;
- enqueue_dl_entity(dl_se, flags);
+ enqueue_dl_entity(rq, dl_se, flags);
if (dl_server(dl_se))
return;
next prev parent reply other threads:[~2026-11-11 13:11 UTC|newest]
Thread overview: 30+ 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-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-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 [this message]
2026-11-11 11:46 ` [PATCH v2 00/12] sched: core-sched fixes and balancing 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=20261111131152.GD2669272@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@kernel.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®