From: Kayra Cizmeci <kayracizmeci@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: mingo@kernel.org, linux-kernel@vger.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, joshdon@google.com, tj@kernel.org,
jakub@okonski.org
Subject: Re: [PATCH 2/3] sched/fair: Make cfs_rq::idle the sum of ancestor tg::idle
Date: Fri, 6 Nov 2026 12:01:18 +0300 [thread overview]
Message-ID: <au2WhI-GE4CPVcGg@scheduler.schedules> (raw)
In-Reply-To: <20261106085320.GB1922751@noisy.programming.kicks-ass.net>
On Fri, Nov 06, 2026 at 09:53:20AM +0100, Peter Zijlstra wrote:
> On Fri, Nov 06, 2026 at 09:31:06AM +0100, Peter Zijlstra wrote:
> > > > --- a/kernel/sched/fair.c
> > > > +++ b/kernel/sched/fair.c
> > > > @@ -15594,8 +15594,10 @@ static void set_next_task_fair(struct rq
> > > > hrtick_start_fair(rq, p);
> > > > }
> > > >
> > > > -void init_cfs_rq(struct cfs_rq *cfs_rq)
> > > > +void init_cfs_rq(struct cfs_rq *cfs_rq, struct cfs_rq *parent)
> > > > {
> > > > + if (parent)
> > > > + cfs_rq->idle = parent->idle;
> > >
> > > AFAICT this creates a race:
> >
> > > Or am I missing something?
> >
> > Nah, you're right, this needs rq->lock.
>
> Something like so..
>
> ---
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -8970,7 +8970,7 @@ void __init sched_init(void)
> rq->nr_running = 0;
> rq->calc_load_active = 0;
> rq->calc_load_update = jiffies + LOAD_FREQ;
> - init_cfs_rq(&rq->cfs, NULL);
> + init_cfs_rq(&rq->cfs);
> init_rt_rq(&rq->rt);
> init_dl_rq(&rq->dl);
> #ifdef CONFIG_FAIR_GROUP_SCHED
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -15594,10 +15594,8 @@ static void set_next_task_fair(struct rq
> hrtick_start_fair(rq, p);
> }
>
> -void init_cfs_rq(struct cfs_rq *cfs_rq, struct cfs_rq *parent)
> +void init_cfs_rq(struct cfs_rq *cfs_rq)
> {
> - if (parent)
> - cfs_rq->idle = parent->idle;
> cfs_rq->tasks_timeline = RB_ROOT_CACHED;
> cfs_rq->zero_vruntime = (u64)(-(1LL << 20));
> raw_spin_lock_init(&cfs_rq->removed.lock);
> @@ -15648,7 +15646,7 @@ int alloc_fair_sched_group(struct task_g
> goto err;
>
> se = tg_se(tg, i);
> - init_cfs_rq(cfs_rq, tg_cfs_rq(parent, i));
> + init_cfs_rq(cfs_rq);
> init_tg_cfs_entry(tg, cfs_rq, se, i, tg_se(parent, i));
> init_entity_runnable_average(se);
> }
> @@ -15661,19 +15659,20 @@ int alloc_fair_sched_group(struct task_g
>
> void online_fair_sched_group(struct task_group *tg)
> {
> - struct sched_entity *se;
> - struct rq_flags rf;
> - struct rq *rq;
> int i;
>
> for_each_possible_cpu(i) {
> - rq = cpu_rq(i);
> - se = tg_se(tg, i);
> - rq_lock_irq(rq, &rf);
> + struct cfs_rq *cfs_rq = tg_cfs_rq(tg, i);
> + struct sched_entity *se = tg_se(tg, i);
> + struct rq *rq = cpu_rq(i);
> +
> + guard(rq_lock_irq)(rq);
> +
> update_rq_clock(rq);
> attach_entity_cfs_rq(se);
> sync_throttle(tg, i);
> - rq_unlock_irq(rq, &rf);
> +
> + cfs_rq->idle = tg_cfs_rq(tg->parent, i)->idle;
> }
> }
>
Yeah this should do the job.
Thanks!
Kayra
next prev parent reply other threads:[~2026-11-06 9:01 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 16:55 [PATCH 0/3] sched/fair: Fix cgroup::idle preemption Peter Zijlstra
2026-11-05 16:55 ` [PATCH 1/3] sched/fair: Use guard in sched_group_set_idle() Peter Zijlstra
2026-11-05 17:42 ` Kayra Cizmeci
2026-11-06 16:04 ` Vincent Guittot
2026-11-05 16:55 ` [PATCH 2/3] sched/fair: Make cfs_rq::idle the sum of ancestor tg::idle Peter Zijlstra
2026-11-05 19:20 ` Kayra Cizmeci
2026-11-06 8:31 ` Peter Zijlstra
2026-11-06 8:53 ` Peter Zijlstra
2026-11-06 9:01 ` Kayra Cizmeci [this message]
2026-11-06 8:57 ` Kayra Cizmeci
2026-11-06 9:01 ` Peter Zijlstra
2026-11-06 9:11 ` Kayra Cizmeci
2026-11-06 16:24 ` Vincent Guittot
2026-11-05 16:55 ` [RFC][PATCH 3/3] sched/eevdf: Fix sched idle task group preemption Peter Zijlstra
2026-11-05 20:10 ` 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=au2WhI-GE4CPVcGg@scheduler.schedules \
--to=kayracizmeci@gmail.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=jakub@okonski.org \
--cc=joshdon@google.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=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tj@kernel.org \
--cc=vincent.guittot@linaro.org \
--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®