sched/fair: Fix cgroup::idle preemption
Peter Zijlstra
maintainercover sched/fair: Fix cgroup::idle preemption
Hi!
so I finally got around to looking at this again with a fresh mind and an LLM generated testcase. It appears to actually work now.
I'm still not convinced on the whole find_matching_se() thing; at the end of the day we mark a subtree 'idle', which is akin to saying 'dont care', so then actually caring about how it ends up preempting on a different level is weird to me.
As such, I have Vincent's patch last; modified to use the new idle state as optimization.
Peter Zijlstra
maintainerPATCH 1/3 sched/fair: Use guard in sched_group_set_idle()
Cleanup the code by using guards; prepares for further changes in this function.
--- kernel/sched/fair.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
kernel/sched/fair.c +4 -12
@@ -15790,12 +15790,9 @@ int sched_group_set_idle(struct task_groif (idle <0 || idle >1 )return -EINVAL ; -mutex_lock (&shares_mutex); - -if (tg->idle == idle) { -mutex_unlock (&shares_mutex); +guard (mutex)(&shares_mutex); +if (tg->idle == idle)return 0 ; - } tg->idle = idle;
@@ -15805,13 +15802,12 @@ int sched_group_set_idle(struct task_grostruct cfs_rq *grp_cfs_rq =tg_cfs_rq (tg, i);bool was_idle =cfs_rq_is_idle (grp_cfs_rq);long idle_task_delta; -struct rq_flags rf; -rq_lock_irqsave (rq, &rf); +guard (rq_lock_irqsave)(rq); grp_cfs_rq->idle = idle;if (WARN_ON_ONCE (was_idle ==cfs_rq_is_idle (grp_cfs_rq))) - goto next_cpu; +continue ; idle_task_delta = grp_cfs_rq->h_nr_queued - grp_cfs_rq->h_nr_idle;
@@ -15830,9 +15826,6 @@ int sched_group_set_idle(struct task_groif (cfs_rq_is_idle (cfs_rq))break ; } - -next_cpu: -rq_unlock_irqrestore (rq, &rf); }/* Idle groups have minimum weight. */
@@ -15841,7 +15834,6 @@ int sched_group_set_idle(struct task_groelse __sched_group_set_shares (tg,NICE_0_LOAD ); -mutex_unlock (&shares_mutex);return 0 ; }
Re: [PATCH 1/3] sched/fair: Use guard in sched_group_set_idle()
Hi Peter,
Quoted 53 lines · Peter Zijlstra
Cleanup the code by using guards; prepares for further changes in this function.
Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- kernel/sched/fair.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)kernel/sched/fair.c +4
-11@@ -15790,12 +15790,9 @@ int sched_group_set_idle(struct task_groif (idle <0 || idle >1 )return -EINVAL ; -mutex_lock (&shares_mutex); - -if (tg->idle == idle) { -mutex_unlock (&shares_mutex); +guard (mutex)(&shares_mutex); +if (tg->idle == idle)return 0 ; - } tg->idle = idle;@@ -15805,13 +15802,12 @@ int sched_group_set_idle(struct task_grostruct cfs_rq *grp_cfs_rq =tg_cfs_rq (tg, i);bool was_idle =cfs_rq_is_idle (grp_cfs_rq);long idle_task_delta; -struct rq_flags rf; -rq_lock_irqsave (rq, &rf); +guard (rq_lock_irqsave)(rq); grp_cfs_rq->idle = idle;if (WARN_ON_ONCE (was_idle ==cfs_rq_is_idle (grp_cfs_rq))) - goto next_cpu; +continue ; idle_task_delta = grp_cfs_rq->h_nr_queued - grp_cfs_rq->h_nr_idle;@@ -15830,9 +15826,6 @@ int sched_group_set_idle(struct task_groif (cfs_rq_is_idle (cfs_rq))break ; } - -next_cpu: -rq_unlock_irqrestore (rq, &rf); }/* Idle groups have minimum weight. */
kernel/sched/fair.c int sched_group_set_idle(struct task_gro · line 15839
Quoted 7 lines
kernel/sched/fair.c +0
-1@@ -15841,7 +15834,6 @@ int sched_group_set_idle(struct task_groelse __sched_group_set_shares (tg,NICE_0_LOAD ); -mutex_unlock (&shares_mutex);return 0 ; }
LGTM.
Cheers,
Kayra
Re: [PATCH 1/3] sched/fair: Use guard in sched_group_set_idle()
In reply to Peter ZijlstraQuoted 4 lines · Peter Zijlstra
Cleanup the code by using guards; prepares for further changes in this function.
Signed-off-by Peter Zijlstra (Intel) <[email protected]>
Quoted 57 lines
--- kernel/sched/fair.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)kernel/sched/fair.c +4
-12@@ -15790,12 +15790,9 @@ int sched_group_set_idle(struct task_groif (idle <0 || idle >1 )return -EINVAL ; -mutex_lock (&shares_mutex); - -if (tg->idle == idle) { -mutex_unlock (&shares_mutex); +guard (mutex)(&shares_mutex); +if (tg->idle == idle)return 0 ; - } tg->idle = idle;@@ -15805,13 +15802,12 @@ int sched_group_set_idle(struct task_grostruct cfs_rq *grp_cfs_rq =tg_cfs_rq (tg, i);bool was_idle =cfs_rq_is_idle (grp_cfs_rq);long idle_task_delta; -struct rq_flags rf; -rq_lock_irqsave (rq, &rf); +guard (rq_lock_irqsave)(rq); grp_cfs_rq->idle = idle;if (WARN_ON_ONCE (was_idle ==cfs_rq_is_idle (grp_cfs_rq))) - goto next_cpu; +continue ; idle_task_delta = grp_cfs_rq->h_nr_queued - grp_cfs_rq->h_nr_idle;@@ -15830,9 +15826,6 @@ int sched_group_set_idle(struct task_groif (cfs_rq_is_idle (cfs_rq))break ; } - -next_cpu: -rq_unlock_irqrestore (rq, &rf); }/* Idle groups have minimum weight. */ @@ -15841,7 +15834,6 @@ int sched_group_set_idle(struct task_groelse __sched_group_set_shares (tg,NICE_0_LOAD ); -mutex_unlock (&shares_mutex);return 0 ; }
Re: [PATCH 1/3] sched/fair: Use guard in sched_group_set_idle()
In reply to Peter ZijlstraQuoted 7 lines · Peter Zijlstra
Cleanup the code by using guards; prepares for further changes in this function.
Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- kernel/sched/fair.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
Thanks Peter,
[tip: sched/urgent] sched/fair: Use guard in sched_group_set_idle()
In reply to Peter ZijlstraThe following commit has been merged into the sched/urgent branch of tip:
The following commit has been merged into the sched/urgent branch of tip:
Commit-ID: 9a92f776dfa6a88fc16fe0512c725734190bf9d0 Gitweb: https://git.kernel.org/tip/9a92f776dfa6a88fc16fe0512c725734190bf9d0 Author: Peter Zijlstra <[email protected]> AuthorDate: Thu, 05 Nov 2026 17:55:26 +01:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Wed, 18 Nov 2026 14:32:16 +01:00
sched/fair: Use guard in sched_group_set_idle()
Cleanup the code by using guards; prepares for further changes in this function.
--- kernel/sched/fair.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
kernel/sched/fair.c +4 -12
@@ -15803,12 +15803,9 @@ int sched_group_set_idle(struct task_group *tg, long idle)if (idle <0 || idle >1 )return -EINVAL ; -mutex_lock (&shares_mutex); - -if (tg->idle == idle) { -mutex_unlock (&shares_mutex); +guard (mutex)(&shares_mutex); +if (tg->idle == idle)return 0 ; - } tg->idle = idle;
@@ -15818,13 +15815,12 @@ int sched_group_set_idle(struct task_group *tg, long idle)struct cfs_rq *grp_cfs_rq =tg_cfs_rq (tg, i);bool was_idle =cfs_rq_is_idle (grp_cfs_rq);long idle_task_delta; -struct rq_flags rf; -rq_lock_irqsave (rq, &rf); +guard (rq_lock_irqsave)(rq); grp_cfs_rq->idle = idle;if (WARN_ON_ONCE (was_idle ==cfs_rq_is_idle (grp_cfs_rq))) - goto next_cpu; +continue ; idle_task_delta = grp_cfs_rq->h_nr_queued - grp_cfs_rq->h_nr_idle;
@@ -15843,9 +15839,6 @@ int sched_group_set_idle(struct task_group *tg, long idle)if (cfs_rq_is_idle (cfs_rq))break ; } - -next_cpu: -rq_unlock_irqrestore (rq, &rf); }/* Idle groups have minimum weight. */
@@ -15854,7 +15847,6 @@ next_cpu:else __sched_group_set_shares (tg,NICE_0_LOAD ); -mutex_unlock (&shares_mutex);return 0 ; }
Peter Zijlstra
maintainerPATCH 2/3 sched/fair: Make cfs_rq::idle the sum of ancestor tg::idle
In reply to Peter ZijlstraRather than keeping cfs_rq::idle as a copy of tg::idle, make it the sum of all ancestor tg::idle. This makes it trivial to tell if the current cgroup is marked idle somewhere along its ancestral path.
This makes se_id_idle() behave differently. Notably is will now be true when there is a idle cgroup anywhere in the ancestor path. This addresses an issue where preemption of cgroup::idle was overlooked when flattening the runqueue.
--- kernel/sched/core.c | 2 - kernel/sched/debug.c | 1 kernel/sched/fair.c | 73 ++++++++++++++++++++++++++++++++------------------- kernel/sched/sched.h | 4 +- 4 files changed, 50 insertions(+), 30 deletions(-)
kernel/sched/core.c +1 -1
@@ -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); +init_cfs_rq (&rq->cfs,NULL );init_rt_rq (&rq->rt);init_dl_rq (&rq->dl);#ifdef CONFIG_FAIR_GROUP_SCHED
kernel/sched/debug.c +1 -0
@@ -1090,6 +1090,7 @@ void print_cfs_rq(struct seq_file *m, inSEQ_printf (m," .%-30s: %d\n" ,"h_nr_runnable" , cfs_rq->h_nr_runnable);SEQ_printf (m," .%-30s: %d\n" ,"h_nr_queued" , cfs_rq->h_nr_queued);SEQ_printf (m," .%-30s: %d\n" ,"h_nr_idle" , cfs_rq->h_nr_idle); +SEQ_printf (m," .%-30s: %d\n" ,"idle" , cfs_rq->idle);SEQ_printf (m," .%-30s: %ld\n" ,"load" , cfs_rq->load.weight);SEQ_printf (m," .%-30s: %lu\n" ,"load_avg" , cfs_rq->avg.load_avg);
kernel/sched/fair.c +46 -27
101 lines not on this page · raw message
kernel/sched/sched.h +2 -2
@@ -751,7 +751,7 @@ struct cfs_rq {struct list_head leaf_cfs_rq_list;struct task_group *tg;/* Group that "owns" this runqueue */ -/* Locally cached copy of our task_group's idle value */ +/* Sum of all ancestor tg->idle. */ int idle;# ifdef CONFIG_CFS_BANDWIDTH
@@ -3520,7 +3520,7 @@ print_numa_stats(struct seq_file *m, int unsigned long tpf, unsigned long gsf, unsigned long gpf);#endif /* CONFIG_NUMA_BALANCING */ -extern void init_cfs_rq (struct cfs_rq *cfs_rq); +extern void init_cfs_rq (struct cfs_rq *cfs_rq,struct cfs_rq *parent);extern void init_rt_rq (struct rt_rq *rt_rq);extern void init_dl_rq (struct dl_rq *dl_rq);
Re: [PATCH 2/3] sched/fair: Make cfs_rq::idle the sum of ancestor tg::idle
Quoted 8 lines · Peter Zijlstra
Rather than keeping
cfs_rq::idleas a copy oftg::idle, make it the sum of all ancestortg::idle. This makes it trivial to tell if the current cgroup is marked idle somewhere along its ancestral path.This makes
se_id_idle()behave differently. Notably is will now be true when there is a idle cgroup anywhere in the ancestor path. This addresses an issue where preemption ofcgroup::idlewas overlooked when flattening the runqueue.
How? The diff doesn't touches se_is_idle(). se_is_idle() just looks to the policy for tasks:
static int se_is_idle(struct sched_entity *se)
{
if (entity_is_task(se))
return task_has_idle_policy(task_of(se));
return cfs_rq_is_idle(group_cfs_rq(se));
}And the issue in the preemption path is in the entity_is_task() path.
cse_is_idle = se_is_idle(se); pse_is_idle = se_is_idle(pse); nse = se; /* * Preempt an idle entity in favor of a non-idle entity (and don't preempt * in the inverse case). */ if (cse_is_idle && !pse_is_idle) goto preempt; update_curr_fair(rq); if (cse_is_idle != pse_is_idle) goto update;
Or am I getting something wrong?
Quoted 34 lines
Fixes 85570f10a4c6 ("sched/eevdf: Move to a single runqueue")Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- kernel/sched/core.c | 2 - kernel/sched/debug.c | 1 kernel/sched/fair.c | 73 ++++++++++++++++++++++++++++++++------------------- kernel/sched/sched.h | 4 +- 4 files changed, 50 insertions(+), 30 deletions(-)kernel/sched/core.c +1
-1@@ -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); +init_cfs_rq (&rq->cfs,NULL );init_rt_rq (&rq->rt);init_dl_rq (&rq->dl);#ifdef CONFIG_FAIR_GROUP_SCHED kernel/sched/debug.c +1
-0@@ -1090,6 +1090,7 @@ void print_cfs_rq(struct seq_file *m, inSEQ_printf (m," .%-30s: %d\n" ,"h_nr_runnable" , cfs_rq->h_nr_runnable);SEQ_printf (m," .%-30s: %d\n" ,"h_nr_queued" , cfs_rq->h_nr_queued);SEQ_printf (m," .%-30s: %d\n" ,"h_nr_idle" , cfs_rq->h_nr_idle); +SEQ_printf (m," .%-30s: %d\n" ,"idle" , cfs_rq->idle);SEQ_printf (m," .%-30s: %ld\n" ,"load" , cfs_rq->load.weight);SEQ_printf (m," .%-30s: %lu\n" ,"load_avg" , cfs_rq->avg.load_avg);
kernel/sched/fair.c static void set_next_task_fair(struct rq · line 15600
Quoted 8 lines
kernel/sched/fair.c +3
-1@@ -15594,8 +15594,10 @@ static void set_next_task_fair(struct rqhrtick_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:
Let's say we are creating a group under GA named GB.
We first call sched_create_group(), that calls alloc_fair_sched_group() and that calls init_cfs_rq(). If the parent groups idle state changes before GB gets into place in something like this:
* GA is not idle GB idle = 0
* GA gets idle in the window
* GB setells in
* GA then gets idle = 0 again
Now this happens:
GB idle = -1 and GA idle = 0.
So below, in tg_set_idle_up() the code things something changed and h_nr_idle starts to corrupt.
Or am I missing something?
Quoted 42 lines
kernel/sched/fair.c +27
-1cfs_rq->tasks_timeline =RB_ROOT_CACHED ; cfs_rq->zero_vruntime = (u64)(-(1LL <<20 ));raw_spin_lock_init (&cfs_rq->removed.lock);@@ -15646,7 +15648,7 @@ int alloc_fair_sched_group(struct task_g goto err; se =tg_se (tg, i); -init_cfs_rq (cfs_rq); +init_cfs_rq (cfs_rq,tg_cfs_rq (parent, i));init_tg_cfs_entry (tg, cfs_rq, se, i,tg_se (parent, i));init_entity_runnable_average (se); }@@ -15780,6 +15782,43 @@ int sched_group_set_shares(struct task_greturn ret; } +struct tg_set_idle_struct { +long idle; +int cpu; +}; + +static int tg_set_idle_up (struct task_group *tg,void *data) +{ +struct tg_set_idle_struct *tsi = data; +struct cfs_rq *grp_cfs_rq =tg_cfs_rq (tg, tsi->cpu); +struct sched_entity *se =tg_se (tg, tsi->cpu); +int old_idle = grp_cfs_rq->idle; +int task_delta; + + grp_cfs_rq->idle += tsi->idle; + +if (!!old_idle == !!grp_cfs_rq->idle) +return 0 ; + + task_delta = grp_cfs_rq->h_nr_queued - grp_cfs_rq->h_nr_idle; +if (!task_delta) +return 0 ; + + task_delta *= tsi->idle; +for_each_sched_entity (se) { +struct cfs_rq *cfs_rq =cfs_rq_of (se); +
kernel/sched/fair.c int sched_group_set_shares(struct task_g · line 15820
Quoted 10 lines
kernel/sched/fair.c +10
-0+if (!se->on_rq) +break ; + + cfs_rq->h_nr_idle += task_delta; + +if (cfs_rq_is_idle (cfs_rq)) +break ; + } +return 0 ; +}
Cheers,
Kayra :-)
Peter Zijlstra
maintainerRe: [PATCH 2/3] sched/fair: Make cfs_rq::idle the sum of ancestor tg::idle
Quoted 13 lines · Kayra Cizmeci
Quoted 8 lines · Peter Zijlstra
Rather than keeping
cfs_rq::idleas a copy oftg::idle, make it the sum of all ancestortg::idle. This makes it trivial to tell if the current cgroup is marked idle somewhere along its ancestral path.This makes
se_id_idle()behave differently. Notably is will now be true when there is a idle cgroup anywhere in the ancestor path. This addresses an issue where preemption ofcgroup::idlewas overlooked when flattening the runqueue.How? The diff doesn't touches
se_is_idle().se_is_idle()just looks to the policy for tasks:
Quoted 8 lines
static int
se_is_idle(struct sched_entity *se){ if (entity_is_task(se)) return task_has_idle_policy(task_of(se)); return cfs_rq_is_idle(group_cfs_rq(se)); }Or am I getting something wrong?
cfs_rq_is_idle() := cfs_rq->idle > 0
and cfs_rq->idle is now getting incremented for the whole subtree. So if any ancestor is idle, this is now true.
Quoted 14 lines
kernel/sched/fair.c static void set_next_task_fair(struct rq · line 15600
Quoted 11 lines
kernel/sched/fair.c +3
-1@@ -15594,8 +15594,10 @@ static void set_next_task_fair(struct rqhrtick_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:
Quoted 1 line
Or am I missing something?
Nah, you're right, this needs rq->lock.
Peter Zijlstra
maintainerRe: [PATCH 2/3] sched/fair: Make cfs_rq::idle the sum of ancestor tg::idle
Quoted 14 lines · Peter Zijlstra
Quoted 13 lines
kernel/sched/fair.c static void set_next_task_fair(struct rq · line 15600
Quoted 11 lines
kernel/sched/fair.c +3
-1@@ -15594,8 +15594,10 @@ static void set_next_task_fair(struct rqhrtick_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:
Quoted 3 lines
Quoted 1 line
Or am I missing something?
Nah, you're right, this needs
rq->lock.
Something like so..
---
kernel/sched/core.c +1 -1
@@ -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
kernel/sched/fair.c +10 -11
@@ -15594,10 +15594,8 @@ static void set_next_task_fair(struct rqhrtick_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_gvoid 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; } }
Re: [PATCH 2/3] sched/fair: Make cfs_rq::idle the sum of ancestor tg::idle
Quoted 74 lines · Peter Zijlstra
Quoted 14 lines · Peter Zijlstra
Quoted 13 lines
kernel/sched/fair.c static void set_next_task_fair(struct rq · line 15600
Quoted 11 lines
kernel/sched/fair.c +3
-1@@ -15594,8 +15594,10 @@ static void set_next_task_fair(struct rqhrtick_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:
Quoted 3 lines
Quoted 1 line
Or am I missing something?
Nah, you're right, this needs
rq->lock.Something like so..
---
kernel/sched/core.c +1
-1@@ -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 kernel/sched/fair.c +7
-10@@ -15594,10 +15594,8 @@ static void set_next_task_fair(struct rqhrtick_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_gvoid 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);
kernel/sched/fair.c int alloc_fair_sched_group(struct task_g · line 15678
Quoted 10 lines
kernel/sched/fair.c +3
-1+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
Re: [PATCH 2/3] sched/fair: Make cfs_rq::idle the sum of ancestor tg::idle
In reply to Peter ZijlstraQuoted 21 lines · Peter Zijlstra
Quoted 19 lines · Kayra Cizmeci
Quoted 8 lines · Peter Zijlstra
Rather than keeping
cfs_rq::idleas a copy oftg::idle, make it the sum of all ancestortg::idle. This makes it trivial to tell if the current cgroup is marked idle somewhere along its ancestral path.This makes
se_id_idle()behave differently. Notably is will now be true when there is a idle cgroup anywhere in the ancestor path. This addresses an issue where preemption ofcgroup::idlewas overlooked when flattening the runqueue.How? The diff doesn't touches
se_is_idle().se_is_idle()just looks to the policy for tasks:static int
se_is_idle(struct sched_entity *se){ if (entity_is_task(se)) return task_has_idle_policy(task_of(se)); return cfs_rq_is_idle(group_cfs_rq(se)); }
Quoted 6 lines
Quoted 1 line
Or am I getting something wrong?
cfs_rq_is_idle():=cfs_rq->idle> 0and
cfs_rq->idleis now getting incremented for the whole subtree. So if any ancestor is idle, this is now true.
Yeah, it is for group path. But we call se_is_idle for tasks in wakeup_preempt_fair(). Not groups, no?
Peter Zijlstra
maintainerRe: [PATCH 2/3] sched/fair: Make cfs_rq::idle the sum of ancestor tg::idle
Quoted 24 lines · Kayra Cizmeci
Quoted 23 lines · Peter Zijlstra
Quoted 21 lines · Kayra Cizmeci
Quoted 8 lines · Peter Zijlstra
Rather than keeping
cfs_rq::idleas a copy oftg::idle, make it the sum of all ancestortg::idle. This makes it trivial to tell if the current cgroup is marked idle somewhere along its ancestral path.This makes
se_id_idle()behave differently. Notably is will now be true when there is a idle cgroup anywhere in the ancestor path. This addresses an issue where preemption ofcgroup::idlewas overlooked when flattening the runqueue.How? The diff doesn't touches
se_is_idle().se_is_idle()just looks to the policy for tasks:static int
se_is_idle(struct sched_entity *se){ if (entity_is_task(se)) return task_has_idle_policy(task_of(se)); return cfs_rq_is_idle(group_cfs_rq(se)); }Or am I getting something wrong?
Quoted 8 lines
Quoted 4 lines
cfs_rq_is_idle():=cfs_rq->idle> 0and
cfs_rq->idleis now getting incremented for the whole subtree. So if any ancestor is idle, this is now true.Yeah, it is for group path. But we call
se_is_idlefor tasks inwakeup_preempt_fair(). Not groups, no?
Ah, that's what you meant. So we should do something like:
if (entity_is_task(se)) return task_has_idle_policy(task_of(se)) || cfs_rq_is_idle(cfs_rq_of(se)); return cfs_rq_is_idle(group_cfs_rq(se));
no?
Re: [PATCH 2/3] sched/fair: Make cfs_rq::idle the sum of ancestor tg::idle
Quoted 34 lines · Peter Zijlstra
Quoted 24 lines · Kayra Cizmeci
Quoted 23 lines · Peter Zijlstra
Quoted 21 lines · Kayra Cizmeci
Quoted 8 lines · Peter Zijlstra
Rather than keeping
cfs_rq::idleas a copy oftg::idle, make it the sum of all ancestortg::idle. This makes it trivial to tell if the current cgroup is marked idle somewhere along its ancestral path.This makes
se_id_idle()behave differently. Notably is will now be true when there is a idle cgroup anywhere in the ancestor path. This addresses an issue where preemption ofcgroup::idlewas overlooked when flattening the runqueue.How? The diff doesn't touches
se_is_idle().se_is_idle()just looks to the policy for tasks:static int
se_is_idle(struct sched_entity *se){ if (entity_is_task(se)) return task_has_idle_policy(task_of(se)); return cfs_rq_is_idle(group_cfs_rq(se)); }Or am I getting something wrong?
Quoted 8 lines
Quoted 4 lines
cfs_rq_is_idle():=cfs_rq->idle> 0and
cfs_rq->idleis now getting incremented for the whole subtree. So if any ancestor is idle, this is now true.Yeah, it is for group path. But we call
se_is_idlefor tasks inwakeup_preempt_fair(). Not groups, no?
Quoted 9 lines
Ah, that's what you meant. So we should do something like:
if (entity_is_task(se)) return task_has_idle_policy(task_of(se)) || cfs_rq_is_idle(cfs_rq_of(se)); return cfs_rq_is_idle(group_cfs_rq(se));no?
Yeah. AFAICT this should do the magic.
BTW there was an issue about set_next_buddy() because of this I *think*. A task in a idle group could still be picked for buddy, but this change fixes that too.
Cheers,
Kayra
Vincent Guittot
maintainerRe: [PATCH 2/3] sched/fair: Make cfs_rq::idle the sum of ancestor tg::idle
In reply to Peter ZijlstraQuoted 32 lines · Peter Zijlstra
Quoted 30 lines · Kayra Cizmeci
Quoted 27 lines · Peter Zijlstra
Quoted 13 lines · Kayra Cizmeci
Quoted 8 lines · Peter Zijlstra
Rather than keeping
cfs_rq::idleas a copy oftg::idle, make it the sum of all ancestortg::idle. This makes it trivial to tell if the current cgroup is marked idle somewhere along its ancestral path.This makes
se_id_idle()behave differently. Notably is will now be true when there is a idle cgroup anywhere in the ancestor path. This addresses an issue where preemption ofcgroup::idlewas overlooked when flattening the runqueue.How? The diff doesn't touches
se_is_idle().se_is_idle()just looks to the policy for tasks:Quoted 8 lines
static int
se_is_idle(struct sched_entity *se)
{
if (entity_is_task(se))return task_has_idle_policy(task_of(se));return cfs_rq_is_idle(group_cfs_rq(se));
}Or am I getting something wrong?
cfs_rq_is_idle():=cfs_rq->idle> 0and
cfs_rq->idleis now getting incremented for the whole subtree. So if any ancestor is idle, this is now true.
Quoted 8 lines
Quoted 2 lines
Yeah, it is for group path. But we call
se_is_idlefor tasks inwakeup_preempt_fair(). Not groups, no?Ah, that's what you meant. So we should do something like:
if (entity_is_task(se)) return task_has_idle_policy(task_of(se)) || cfs_rq_is_idle(cfs_rq_of(se)); return cfs_rq_is_idle(group_cfs_rq(se));
This is necessary for the 1st check in wakeup_preempt_sched_idle() to prevent useless call to find_matching_se()
Quoted 4 lines
no?
Peter Zijlstra
maintainerPATCH v2 2/3 sched/fair: Make cfs_rq::idle the sum of ancestor tg::idle
In reply to Peter ZijlstraRather than keeping cfs_rq::idle as a copy of tg::idle, make it the sum of all ancestor tg::idle. This makes it trivial to tell if the current cgroup is marked idle somewhere along its ancestral path.
--- kernel/sched/debug.c | 1 kernel/sched/fair.c | 88 +++++++++++++++++++++++++++++++-------------------- kernel/sched/sched.h | 2 - 3 files changed, 56 insertions(+), 35 deletions(-)
kernel/sched/debug.c +1 -0
@@ -1090,6 +1090,7 @@ void print_cfs_rq(struct seq_file *m, inSEQ_printf (m," .%-30s: %d\n" ,"h_nr_runnable" , cfs_rq->h_nr_runnable);SEQ_printf (m," .%-30s: %d\n" ,"h_nr_queued" , cfs_rq->h_nr_queued);SEQ_printf (m," .%-30s: %d\n" ,"h_nr_idle" , cfs_rq->h_nr_idle); +SEQ_printf (m," .%-30s: %d\n" ,"idle" , cfs_rq->idle);SEQ_printf (m," .%-30s: %ld\n" ,"load" , cfs_rq->load.weight);SEQ_printf (m," .%-30s: %lu\n" ,"load_avg" , cfs_rq->avg.load_avg);
kernel/sched/fair.c +54 -34
121 lines not on this page · raw message
kernel/sched/sched.h +1 -1
@@ -751,7 +751,7 @@ struct cfs_rq {struct list_head leaf_cfs_rq_list;struct task_group *tg;/* Group that "owns" this runqueue */ -/* Locally cached copy of our task_group's idle value */ +/* Sum of all ancestor tg->idle. */ int idle;# ifdef CONFIG_CFS_BANDWIDTH
Re: [PATCH v2 2/3] sched/fair: Make cfs_rq::idle the sum of ancestor tg::idle
Hi Peter!
Quoted 6 lines · Peter Zijlstra
Rather than keeping
cfs_rq::idleas a copy oftg::idle, make it the sum of all ancestortg::idle. This makes it trivial to tell if the current cgroup is marked idle somewhere along its ancestral path.Signed-off-by Peter Zijlstra (Intel) <[email protected]>
First of all,
With this, now tasks in an idle cfs_rq cannot be buddies. But IMO that's more of a fix. Maybe it would be good to add a fixes tag?
Cheers,
Kayra
Re: [PATCH v2 2/3] sched/fair: Make cfs_rq::idle the sum of ancestor tg::idle
In reply to Peter ZijlstraQuoted 7 lines · Peter Zijlstra
Rather than keeping
cfs_rq::idleas a copy oftg::idle, make it the sum of all ancestortg::idle. This makes it trivial to tell if the current cgroup is marked idle somewhere along its ancestral path.Signed-off-by Peter Zijlstra (Intel) <[email protected]>
Quoted 154 lines
--- kernel/sched/debug.c | 1 kernel/sched/fair.c | 88 +++++++++++++++++++++++++++++++-------------------- kernel/sched/sched.h | 2 - 3 files changed, 56 insertions(+), 35 deletions(-)kernel/sched/debug.c +1
-0@@ -1090,6 +1090,7 @@ void print_cfs_rq(struct seq_file *m, inSEQ_printf (m," .%-30s: %d\n" ,"h_nr_runnable" , cfs_rq->h_nr_runnable);SEQ_printf (m," .%-30s: %d\n" ,"h_nr_queued" , cfs_rq->h_nr_queued);SEQ_printf (m," .%-30s: %d\n" ,"h_nr_idle" , cfs_rq->h_nr_idle); +SEQ_printf (m," .%-30s: %d\n" ,"idle" , cfs_rq->idle);SEQ_printf (m," .%-30s: %ld\n" ,"load" , cfs_rq->load.weight);SEQ_printf (m," .%-30s: %lu\n" ,"load_avg" , cfs_rq->avg.load_avg);kernel/sched/fair.c +54
-34@@ -445,8 +445,10 @@ static int cfs_rq_is_idle(struct cfs_rqstatic int se_is_idle (struct sched_entity *se) { -if (entity_is_task (se)) -return task_has_idle_policy (task_of (se)); +if (entity_is_task (se)) { +return task_has_idle_policy (task_of (se)) || +cfs_rq_is_idle (cfs_rq_of (se)); + }return cfs_rq_is_idle (group_cfs_rq (se)); }@@ -15659,19 +15661,20 @@ int alloc_fair_sched_group(struct task_gvoid 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; } }@@ -15780,6 +15783,43 @@ int sched_group_set_shares(struct task_greturn ret; } +struct tg_set_idle_struct { +long idle; +int cpu; +}; + +static int tg_set_idle_up (struct task_group *tg,void *data) +{ +struct tg_set_idle_struct *tsi = data; +struct cfs_rq *grp_cfs_rq =tg_cfs_rq (tg, tsi->cpu); +struct sched_entity *se =tg_se (tg, tsi->cpu); +int old_idle = grp_cfs_rq->idle; +int task_delta; + + grp_cfs_rq->idle += tsi->idle; + +if (!!old_idle == !!grp_cfs_rq->idle) +return 0 ; + + task_delta = grp_cfs_rq->h_nr_queued - grp_cfs_rq->h_nr_idle; +if (!task_delta) +return 0 ; + + task_delta *= tsi->idle; +for_each_sched_entity (se) { +struct cfs_rq *cfs_rq =cfs_rq_of (se); + +if (!se->on_rq) +break ; + + cfs_rq->h_nr_idle += task_delta; + +if (cfs_rq_is_idle (cfs_rq)) +break ; + } +return 0 ; +} +int sched_group_set_idle (struct task_group *tg,long idle) {int i;@@ -15798,34 +15838,14 @@ int sched_group_set_idle(struct task_grofor_each_possible_cpu (i) {struct rq *rq =cpu_rq (i); -struct sched_entity *se =tg_se (tg, i); -struct cfs_rq *grp_cfs_rq =tg_cfs_rq (tg, i); -bool was_idle =cfs_rq_is_idle (grp_cfs_rq); -long idle_task_delta;guard (rq_lock_irqsave)(rq); - grp_cfs_rq->idle = idle; -if (WARN_ON_ONCE (was_idle ==cfs_rq_is_idle (grp_cfs_rq))) -continue ; - - idle_task_delta = grp_cfs_rq->h_nr_queued - - grp_cfs_rq->h_nr_idle; -if (!cfs_rq_is_idle (grp_cfs_rq)) - idle_task_delta *=-1 ; - -for_each_sched_entity (se) { -struct cfs_rq *cfs_rq =cfs_rq_of (se); - -if (!se->on_rq) -break ; - - cfs_rq->h_nr_idle += idle_task_delta; - -/* Already accounted at parent level and above. */ -if (cfs_rq_is_idle (cfs_rq)) -break ; - } +struct tg_set_idle_struct tsi = { + .idle = idle ?1 :-1 , + .cpu = i, + }; +walk_tg_tree_from (tg, tg_nop, tg_set_idle_up, &tsi); }/* Idle groups have minimum weight. */ kernel/sched/sched.h +1
-1@@ -751,7 +751,7 @@ struct cfs_rq {struct list_head leaf_cfs_rq_list;struct task_group *tg;/* Group that "owns" this runqueue */ -/* Locally cached copy of our task_group's idle value */ +/* Sum of all ancestor tg->idle. */ int idle;# ifdef CONFIG_CFS_BANDWIDTH
Re: [PATCH v2 2/3] sched/fair: Make cfs_rq::idle the sum of ancestor tg::idle
In reply to Peter ZijlstraQuoted 6 lines · Peter Zijlstra
Rather than keeping
cfs_rq::idleas a copy oftg::idle, make it the sum of all ancestortg::idle. This makes it trivial to tell if the current cgroup is marked idle somewhere along its ancestral path.
Quoted 6 lines
Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- kernel/sched/debug.c | 1 kernel/sched/fair.c | 88 +++++++++++++++++++++++++++++++-------------------- kernel/sched/sched.h | 2 - 3 files changed, 56 insertions(+), 35 deletions(-)
I think this needs better handling now in the next patch in this chain, but this one looks good. I'll move that discussion over to patch 3.
[tip: sched/urgent] sched/fair: Make cfs_rq::idle the sum of ancestor tg::idle
In reply to Peter ZijlstraThe following commit has been merged into the sched/urgent branch of tip:
The following commit has been merged into the sched/urgent branch of tip:
Commit-ID: 75545668ae0fd80c08fe8fd0c6799b2ba9284557 Gitweb: https://git.kernel.org/tip/75545668ae0fd80c08fe8fd0c6799b2ba9284557 Author: Peter Zijlstra <[email protected]> AuthorDate: Sat, 07 Nov 2026 12:36:39 +01:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Wed, 18 Nov 2026 14:32:16 +01:00
sched/fair: Make cfs_rq::idle the sum of ancestor tg::idle
Rather than keeping cfs_rq::idle as a copy of tg::idle, make it the sum of all ancestor tg::idle. This makes it trivial to tell if the current cgroup is marked idle somewhere along its ancestral path.
This makes se_is_idle() behave differently. Notably is will now be true when there is a idle cgroup anywhere in the ancestor path. This addresses an issue where preemption of cgroup::idle was overlooked when flattening the runqueue.
--- kernel/sched/debug.c | 1 +- kernel/sched/fair.c | 88 ++++++++++++++++++++++++++----------------- kernel/sched/sched.h | 2 +- 3 files changed, 56 insertions(+), 35 deletions(-)
kernel/sched/debug.c +1 -0
@@ -1112,6 +1112,7 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq) atomic_long_read(&cfs_rq->tg->load_avg));SEQ_printf (m," .%-30s: %lu\n" ,"h_load" , cfs_rq->h_load); +SEQ_printf (m," .%-30s: %d\n" ,"idle" , cfs_rq->idle);#endif /* CONFIG_FAIR_GROUP_SCHED */ #ifdef CONFIG_CFS_BANDWIDTH SEQ_printf(m, " .%-30s: %d\n", "throttled",
kernel/sched/fair.c +54 -34
121 lines not on this page · raw message
kernel/sched/sched.h +1 -1
@@ -751,7 +751,7 @@ struct cfs_rq {struct list_head leaf_cfs_rq_list;struct task_group *tg;/* Group that "owns" this runqueue */ -/* Locally cached copy of our task_group's idle value */ +/* Sum of all ancestor tg->idle. */ int idle;# ifdef CONFIG_CFS_BANDWIDTH
Re: [PATCH 2/3] sched/fair: Make cfs_rq::idle the sum of ancestor tg::idle
In reply to Peter Zijlstra:-(.
Look here: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Quoted 32 lines · Peter Zijlstra
Rather than keeping
cfs_rq::idleas a copy oftg::idle, make it the sum of all ancestortg::idle. This makes it trivial to tell if the current cgroup is marked idle somewhere along its ancestral path.This makes
se_id_idle()behave differently. Notably is will now be true when there is a idle cgroup anywhere in the ancestor path. This addresses an issue where preemption ofcgroup::idlewas overlooked when flattening the runqueue.Fixes 85570f10a4c6 ("sched/eevdf: Move to a single runqueue")Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- kernel/sched/core.c | 2 - kernel/sched/debug.c | 1 kernel/sched/fair.c | 73 ++++++++++++++++++++++++++++++++------------------- kernel/sched/sched.h | 4 +- 4 files changed, 50 insertions(+), 30 deletions(-)kernel/sched/core.c +1
-1@@ -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); +init_cfs_rq (&rq->cfs,NULL );init_rt_rq (&rq->rt);init_dl_rq (&rq->dl);#ifdef CONFIG_FAIR_GROUP_SCHED
kernel/sched/debug.c void print_cfs_rq(struct seq_file *m, in · line 1093
Quoted 4 lines
kernel/sched/debug.c +1
-0@@ -1090,6 +1090,7 @@ void print_cfs_rq(struct seq_file *m, inSEQ_printf (m," .%-30s: %d\n" ,"h_nr_runnable" , cfs_rq->h_nr_runnable);SEQ_printf (m," .%-30s: %d\n" ,"h_nr_queued" , cfs_rq->h_nr_queued);SEQ_printf (m," .%-30s: %d\n" ,"h_nr_idle" , cfs_rq->h_nr_idle); +SEQ_printf (m," .%-30s: %d\n" ,"idle" , cfs_rq->idle);
idle is only in the CONFIG_FAIR_GROUP_SCHED :-(.
So as the robot says, this breaks compiling in !CONFIG_FAIR_GROUP_SCHED.
AFAICT tho, moving this down below in CONFIG_FAIR_GROUP_SCHED next to h_load and other guys will solve the issue no?
Cheers,
Kayra
Peter Zijlstra
maintainerRe: [PATCH 2/3] sched/fair: Make cfs_rq::idle the sum of ancestor tg::idle
Quoted 45 lines · Kayra Cizmeci
:-(.
Look here: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Quoted 32 lines · Peter Zijlstra
Rather than keeping
cfs_rq::idleas a copy oftg::idle, make it the sum of all ancestortg::idle. This makes it trivial to tell if the current cgroup is marked idle somewhere along its ancestral path.This makes
se_id_idle()behave differently. Notably is will now be true when there is a idle cgroup anywhere in the ancestor path. This addresses an issue where preemption ofcgroup::idlewas overlooked when flattening the runqueue.Fixes 85570f10a4c6 ("sched/eevdf: Move to a single runqueue")Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- kernel/sched/core.c | 2 - kernel/sched/debug.c | 1 kernel/sched/fair.c | 73 ++++++++++++++++++++++++++++++++------------------- kernel/sched/sched.h | 4 +- 4 files changed, 50 insertions(+), 30 deletions(-)kernel/sched/core.c +1
-1@@ -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); +init_cfs_rq (&rq->cfs,NULL );init_rt_rq (&rq->rt);init_dl_rq (&rq->dl);#ifdef CONFIG_FAIR_GROUP_SCHED kernel/sched/debug.c void print_cfs_rq(struct seq_file *m, in · line 1093
Quoted 4 lines
kernel/sched/debug.c +1
-0@@ -1090,6 +1090,7 @@ void print_cfs_rq(struct seq_file *m, inSEQ_printf (m," .%-30s: %d\n" ,"h_nr_runnable" , cfs_rq->h_nr_runnable);SEQ_printf (m," .%-30s: %d\n" ,"h_nr_queued" , cfs_rq->h_nr_queued);SEQ_printf (m," .%-30s: %d\n" ,"h_nr_idle" , cfs_rq->h_nr_idle); +SEQ_printf (m," .%-30s: %d\n" ,"idle" , cfs_rq->idle);idle is only in the
CONFIG_FAIR_GROUP_SCHED:-(.
So as the robot says, this breaks compiling in !CONFIG_FAIR_GROUP_SCHED.
Quoted 2 lines
AFAICT tho, moving this down below in
CONFIG_FAIR_GROUP_SCHEDnext toh_loadand other guys will solve the issue no?
Yeah, pushed out again, lets see if the robots find more ;-)
Peter Zijlstra
maintainerRFC PATCH 3/3 sched/eevdf: Fix sched idle task group preemption
In reply to Peter ZijlstraFrom: Vincent Guittot <[email protected]>
Even with flat hierarchy which puts all runnable tasks in the same cfs rq, we need to parse the hierarchy to check for sched_idle task group.
---
Changes since v1:
- fix prototype and cleanup unsued variable
kernel/sched/fair.c | 87 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 74 insertions(+), 13 deletions(-)
kernel/sched/fair.c +74 -13
@@ -433,6 +433,38 @@ static inline struct sched_entity *parenreturn se->parent; } +static void +find_matching_se (struct sched_entity **se,struct sched_entity **pse) +{ +int se_depth, pse_depth; + +/* +* preemption test can be made between sibling entities who are in the +* same cfs_rq i.e who have a common parent. Walk up the hierarchy of +* both tasks until we find their ancestors who are siblings of common +* parent. +*/ + +/* First walk up until both entities are at same depth */ + se_depth = (*se)->depth; + pse_depth = (*pse)->depth; + +while (se_depth > pse_depth) { + se_depth--; + *se =parent_entity (*se); + } + +while (pse_depth > se_depth) { + pse_depth--; + *pse =parent_entity (*pse); + } + +while (!is_same_group (*se, *pse)) { + *se =parent_entity (*se); + *pse =parent_entity (*pse); + } +} +static int tg_is_idle (struct task_group *tg) {return tg->idle >0 ;
@@ -476,6 +508,11 @@ static inline struct sched_entity *parenreturn NULL ; } +static inline void +find_matching_se (struct sched_entity **se,struct sched_entity **pse) +{ +} +static inline int tg_is_idle (struct task_group *tg) {return 0 ;
@@ -10130,7 +10167,40 @@ preempt_sync(struct rq *rq, int wake_fla }/* -* Preempt the current task with a newly woken task if needed: +* Preempt an idle entity in favor of a non-idle entity (and don't preempt +* in the inverse case). +*/ +static inline enum preempt_wakeup_action +wakeup_preempt_sched_idle (struct sched_entity *cse,struct sched_entity *pse) +{ +int cse_is_idle, pse_is_idle; + + cse_is_idle =se_is_idle (cse); + pse_is_idle =se_is_idle (pse); + +if (cse_is_idle || pse_is_idle) { +find_matching_se (&cse, &pse); +WARN_ON_ONCE (!pse); + + cse_is_idle =se_is_idle (cse); + pse_is_idle =se_is_idle (pse); + +/* +* Preempt an idle entity in favor of a non-idle entity (and +* don't preempt in the inverse case). +*/ +if (cse_is_idle && !pse_is_idle) +return PREEMPT_WAKEUP_RESCHED ; + +if (cse_is_idle != pse_is_idle) +return PREEMPT_WAKEUP_NONE ; + } + +return PREEMPT_WAKEUP_PICK ; +} + +/* +* Preempt the current task with a newly woken task if needed. */ static void wakeup_preempt_fair (struct rq *rq,struct task_struct *p,int wake_flags) {
@@ -10138,7 +10208,6 @@ static void wakeup_preempt_fair(struct rstruct task_struct *donor = rq->donor;struct sched_entity *nse, *se = &donor->se, *pse = &p->se;struct cfs_rq *cfs_rq = &rq->cfs; -int cse_is_idle, pse_is_idle;/* * XXX Getting preempted by higher class, try and find idle CPU?
@@ -10175,22 +10244,14 @@ static void wakeup_preempt_fair(struct rif (!sched_feat (WAKEUP_PREEMPTION ))return ; -WARN_ON_ONCE (!pse); - - cse_is_idle =se_is_idle (se); - pse_is_idle =se_is_idle (pse); + preempt_action =wakeup_preempt_sched_idle (se, pse); - nse = se; -/* -* Preempt an idle entity in favor of a non-idle entity (and don't preempt -* in the inverse case). -*/ -if (cse_is_idle && !pse_is_idle) +if (preempt_action ==PREEMPT_WAKEUP_RESCHED ) goto preempt;update_curr_fair (rq); -if (cse_is_idle != pse_is_idle) +if (preempt_action ==PREEMPT_WAKEUP_NONE ) goto update;/*
Re: [RFC][PATCH 3/3] sched/eevdf: Fix sched idle task group preemption
Quoted 79 lines · Peter Zijlstra
From: Vincent Guittot <[email protected]>
Even with flat hierarchy which puts all runnable tasks in the same cfs rq, we need to parse the hierarchy to check for
sched_idletask group.Fixes 85570f10a4c6 ("sched/eevdf: Move to a single runqueue")Reported-by Jakub Okoński <[email protected]>Signed-off-by Vincent Guittot <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>---
Changes since v1:
- fix prototype and cleanup unsued variablekernel/sched/fair.c | 87 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 74 insertions(+), 13 deletions(-)kernel/sched/fair.c +39
-1@@ -433,6 +433,38 @@ static inline struct sched_entity *parenreturn se->parent; } +static void +find_matching_se (struct sched_entity **se,struct sched_entity **pse) +{ +int se_depth, pse_depth; + +/* +* preemption test can be made between sibling entities who are in the +* same cfs_rq i.e who have a common parent. Walk up the hierarchy of +* both tasks until we find their ancestors who are siblings of common +* parent. +*/ + +/* First walk up until both entities are at same depth */ + se_depth = (*se)->depth; + pse_depth = (*pse)->depth; + +while (se_depth > pse_depth) { + se_depth--; + *se =parent_entity (*se); + } + +while (pse_depth > se_depth) { + pse_depth--; + *pse =parent_entity (*pse); + } + +while (!is_same_group (*se, *pse)) { + *se =parent_entity (*se); + *pse =parent_entity (*pse); + } +} +static int tg_is_idle (struct task_group *tg) {return tg->idle >0 ;@@ -476,6 +508,11 @@ static inline struct sched_entity *parenreturn NULL ; } +static inline void +find_matching_se (struct sched_entity **se,struct sched_entity **pse) +{ +} +static inline int tg_is_idle (struct task_group *tg) {return 0 ;@@ -10130,7 +10167,40 @@ preempt_sync(struct rq *rq, int wake_fla }/* -* Preempt the current task with a newly woken task if needed: +* Preempt an idle entity in favor of a non-idle entity (and don't preempt +* in the inverse case).
kernel/sched/fair.c preempt_sync(struct rq *rq, int wake_fla · line 10181
Quoted 10 lines
kernel/sched/fair.c +10
-0+*/ +static inline enum preempt_wakeup_action +wakeup_preempt_sched_idle (struct sched_entity *cse,struct sched_entity *pse) +{ +int cse_is_idle, pse_is_idle; + + cse_is_idle =se_is_idle (cse); + pse_is_idle =se_is_idle (pse); + +if (cse_is_idle || pse_is_idle) {
We pass tasks to wakeup_preempt_sched_idle() (below) so this se_is_idle() would just look to policy.
So even if they are in a idle group, if they don't have idle policy themselves it just returns false.
Or am I getting something wrong?
kernel/sched/fair.c preempt_sync(struct rq *rq, int wake_fla · line 10186
Quoted 5 lines
kernel/sched/fair.c +5
-0+find_matching_se (&cse, &pse); +WARN_ON_ONCE (!pse); + + cse_is_idle =se_is_idle (cse); + pse_is_idle =se_is_idle (pse);
Look here:
ROOT
|
GA*
/\
/ \
GB GC*
| |
TA TBNormally in the old code if TB is waking and TA is running we wouldn't preempt TA. But because se_is_idle() returns true if idle is bigger than 0, both GB and GC is considered the same (if my other issue is true, walk doesn't even starts so we don't come even come here)
Is this knowingly like this?
Quoted 46 lines
kernel/sched/fair.c +18
-11+ +/* +* Preempt an idle entity in favor of a non-idle entity (and +* don't preempt in the inverse case). +*/ +if (cse_is_idle && !pse_is_idle) +return PREEMPT_WAKEUP_RESCHED ; + +if (cse_is_idle != pse_is_idle) +return PREEMPT_WAKEUP_NONE ; + } + +return PREEMPT_WAKEUP_PICK ; +} + +/* +* Preempt the current task with a newly woken task if needed. */ static void wakeup_preempt_fair (struct rq *rq,struct task_struct *p,int wake_flags) {@@ -10138,7 +10208,6 @@ static void wakeup_preempt_fair(struct rstruct task_struct *donor = rq->donor;struct sched_entity *nse, *se = &donor->se, *pse = &p->se;struct cfs_rq *cfs_rq = &rq->cfs; -int cse_is_idle, pse_is_idle;/* * XXX Getting preempted by higher class, try and find idle CPU? @@ -10175,22 +10244,14 @@ static void wakeup_preempt_fair(struct rif (!sched_feat (WAKEUP_PREEMPTION ))return ; -WARN_ON_ONCE (!pse); - - cse_is_idle =se_is_idle (se); - pse_is_idle =se_is_idle (pse); + preempt_action =wakeup_preempt_sched_idle (se, pse); - nse = se; -/* -* Preempt an idle entity in favor of a non-idle entity (and don't preempt -* in the inverse case). -*/ -if (cse_is_idle && !pse_is_idle)
kernel/sched/fair.c static void wakeup_preempt_fair(struct r · line 10257
Quoted 10 lines
kernel/sched/fair.c +2
-1+if (preempt_action ==PREEMPT_WAKEUP_RESCHED ) goto preempt;update_curr_fair (rq); -if (cse_is_idle != pse_is_idle) +if (preempt_action ==PREEMPT_WAKEUP_NONE ) goto update;/*
Cheers,
Kayra
Re: [RFC][PATCH 3/3] sched/eevdf: Fix sched idle task group preemption
In reply to Peter ZijlstraQuoted 11 lines · Peter Zijlstra
From: Vincent Guittot <[email protected]>
Even with flat hierarchy which puts all runnable tasks in the same cfs rq, we need to parse the hierarchy to check for
sched_idletask group.Fixes 85570f10a4c6 ("sched/eevdf: Move to a single runqueue")Reported-by Jakub Okoński <[email protected]>Signed-off-by Vincent Guittot <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>
My first old concern is solved. So..
(Dramatic Wait With A Really Serious Song)
...
...
Re: [RFC][PATCH 3/3] sched/eevdf: Fix sched idle task group preemption
In reply to Peter ZijlstraHi Peter,
Quoted 23 lines · Peter Zijlstra
From: Vincent Guittot <[email protected]>
Even with flat hierarchy which puts all runnable tasks in the same cfs rq, we need to parse the hierarchy to check for
sched_idletask group.Fixes 85570f10a4c6 ("sched/eevdf: Move to a single runqueue")Reported-by Jakub Okoński <[email protected]>Signed-off-by Vincent Guittot <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>---
Changes since v1:
- fix prototype and cleanup unsued variablekernel/sched/fair.c | 87 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 74 insertions(+), 13 deletions(-)
kernel/sched/fair.c static inline struct sched_entity *paren · line 437
Quoted 5 lines
kernel/sched/fair.c +2
-0@@ -433,6 +433,38 @@ static inline struct sched_entity *parenreturn se->parent; } +static void +find_matching_se (struct sched_entity **se,struct sched_entity **pse)
Thank you for restoring this :)
Quoted 57 lines
kernel/sched/fair.c +42
-1+{ +int se_depth, pse_depth; + +/* +* preemption test can be made between sibling entities who are in the +* same cfs_rq i.e who have a common parent. Walk up the hierarchy of +* both tasks until we find their ancestors who are siblings of common +* parent. +*/ + +/* First walk up until both entities are at same depth */ + se_depth = (*se)->depth; + pse_depth = (*pse)->depth; + +while (se_depth > pse_depth) { + se_depth--; + *se =parent_entity (*se); + } + +while (pse_depth > se_depth) { + pse_depth--; + *pse =parent_entity (*pse); + } + +while (!is_same_group (*se, *pse)) { + *se =parent_entity (*se); + *pse =parent_entity (*pse); + } +} +static int tg_is_idle (struct task_group *tg) {return tg->idle >0 ;@@ -476,6 +508,11 @@ static inline struct sched_entity *parenreturn NULL ; } +static inline void +find_matching_se (struct sched_entity **se,struct sched_entity **pse) +{ +} +static inline int tg_is_idle (struct task_group *tg) {return 0 ;@@ -10130,7 +10167,40 @@ preempt_sync(struct rq *rq, int wake_fla }/* -* Preempt the current task with a newly woken task if needed: +* Preempt an idle entity in favor of a non-idle entity (and don't preempt +* in the inverse case). +*/ +static inline enum preempt_wakeup_action +wakeup_preempt_sched_idle (struct sched_entity *cse,struct sched_entity *pse) +{ +int cse_is_idle, pse_is_idle;
kernel/sched/fair.c preempt_sync(struct rq *rq, int wake_fla · line 10186
Quoted 10 lines
kernel/sched/fair.c +10
-0+ + cse_is_idle =se_is_idle (cse); + pse_is_idle =se_is_idle (pse); + +if (cse_is_idle || pse_is_idle) { +find_matching_se (&cse, &pse); +WARN_ON_ONCE (!pse); + + cse_is_idle =se_is_idle (cse); + pse_is_idle =se_is_idle (pse);
now that se_is_idle() is checking for any ancestors with idle, this doesn't appear to be correct. Some motivaing examples:
Ex 1:
regular task and SCHED_IDLE task both inside an idle cgroup. se_is_idle() will be true for both se's, and so the regular task will not end up preempting the SCHED_IDLE task, which would be the desirable behavior (the task is not idle relative to the SCHED_IDLE task)
cgrp A (idle)
/ \regular_task SCHED_IDLE task
Ex2:
more complex example with a hierarchy of cgroups
root
|
cgrp A (idle)
/ \
cgrp B cgrp C (idle)
| |
task_1 task_2
task_1 should preempt task_2, and the inverse should also never happen. However, the matching_se here are cgroups B and C, and both show se_is_idle() as true
I can think of two simple ways to fix that, either seems fine
1) use the existing se_is_idle() check for knowing when we can fast-path skip the whole find_matching_se() business, but when we do find the matching se, rather than use se_is_idle, use a more targeted helper that directly compares just those two entities without any of their ancestors (ie. for the task case just check if it has an idle policy, and for the group case, just check tg_is_idle())
2) once you find the matching se, just compare the ->idle values, since if one of them is bigger (by at most 1?), then that one must be the "idle" one relatively speaking. Handling the task vs group case here seems a bit messier compared to the first option, so my suggestion would be to go with the above
Quoted 46 lines
kernel/sched/fair.c +18
-11+ +/* +* Preempt an idle entity in favor of a non-idle entity (and +* don't preempt in the inverse case). +*/ +if (cse_is_idle && !pse_is_idle) +return PREEMPT_WAKEUP_RESCHED ; + +if (cse_is_idle != pse_is_idle) +return PREEMPT_WAKEUP_NONE ; + } + +return PREEMPT_WAKEUP_PICK ; +} + +/* +* Preempt the current task with a newly woken task if needed. */ static void wakeup_preempt_fair (struct rq *rq,struct task_struct *p,int wake_flags) {@@ -10138,7 +10208,6 @@ static void wakeup_preempt_fair(struct rstruct task_struct *donor = rq->donor;struct sched_entity *nse, *se = &donor->se, *pse = &p->se;struct cfs_rq *cfs_rq = &rq->cfs; -int cse_is_idle, pse_is_idle;/* * XXX Getting preempted by higher class, try and find idle CPU? @@ -10175,22 +10244,14 @@ static void wakeup_preempt_fair(struct rif (!sched_feat (WAKEUP_PREEMPTION ))return ; -WARN_ON_ONCE (!pse); - - cse_is_idle =se_is_idle (se); - pse_is_idle =se_is_idle (pse); + preempt_action =wakeup_preempt_sched_idle (se, pse); - nse = se; -/* -* Preempt an idle entity in favor of a non-idle entity (and don't preempt -* in the inverse case). -*/ -if (cse_is_idle && !pse_is_idle)
kernel/sched/fair.c static void wakeup_preempt_fair(struct r · line 10257
Quoted 10 lines
kernel/sched/fair.c +2
-1+if (preempt_action ==PREEMPT_WAKEUP_RESCHED ) goto preempt;update_curr_fair (rq); -if (cse_is_idle != pse_is_idle) +if (preempt_action ==PREEMPT_WAKEUP_NONE ) goto update;/*
Best,
Josh
Re: [RFC][PATCH 3/3] sched/eevdf: Fix sched idle task group preemption
Hi Josh!
Quoted 14 lines · Josh Don
Quoted 14 lines
/*
- * Preempt the current task with a newly woken task if needed:
+ * Preempt an idle entity in favor of a non-idle entity (and don't preempt
+ * in the inverse case).
+ */kernel/sched/fair.c +9
-0+static inline enum preempt_wakeup_action +wakeup_preempt_sched_idle (struct sched_entity *cse,struct sched_entity *pse) +{ +int cse_is_idle, pse_is_idle; + + cse_is_idle =se_is_idle (cse); + pse_is_idle =se_is_idle (pse); + +if (cse_is_idle || pse_is_idle) {
Quoted 8 lines
kernel/sched/fair.c preempt_sync(struct rq *rq, int wake_fla · line 10186
Quoted 5 lines
kernel/sched/fair.c +5
-0+find_matching_se (&cse, &pse); +WARN_ON_ONCE (!pse); + + cse_is_idle =se_is_idle (cse); + pse_is_idle =se_is_idle (pse);now that
se_is_idle()is checking for any ancestors with idle, this doesn't appear to be correct. Some motivaing examples:
So we want to keep the idle difference between groups with idle ancestors? FWIW, I asked about this but then thought it was knowingly and that was what we wanted. I'm still not sure what we want...
Quoted 41 lines
Ex 1:
regular task andSCHED_IDLEtask both inside an idle cgroup.se_is_idle()will be true for both se's, and so the regular task will not end up preempting theSCHED_IDLEtask, which would be the desirable behavior (the task is not idle relative to theSCHED_IDLEtask)cgrp A (idle)
/ \regular_taskSCHED_IDLEtaskEx2:
more complex example with a hierarchy of cgroupsroot
|
cgrp A (idle)
/ \
cgrp B cgrp C (idle)
| |
task_1task_2
task_1should preempttask_2, and the inverse should also never happen. However, thematching_sehere are cgroups B and C, and both showse_is_idle()as trueI can think of two simple ways to fix that, either seems fine
1) use the existingse_is_idle()check for knowing when we can fast-path skip the wholefind_matching_se()business, but when we do find the matching se, rather than usese_is_idle, use a more targeted helper that directly compares just those two entities without any of their ancestors (ie. for the task case just check if it has an idle policy, and for the group case, just checktg_is_idle())
2) once you find the matching se, just compare the ->idle values, since if one of them is bigger (by at most 1?), then that one must be the "idle" one relatively speaking. Handling the task vs group case here seems a bit messier compared to the first option, so my suggestion would be to go with the above
Quoted 2 lines
Best,
Josh
Cheers,
Kayra :-).
Re: [RFC][PATCH 3/3] sched/eevdf: Fix sched idle task group preemption
Quoted 28 lines · Kayra Cizmeci
Hi Josh!
Quoted 14 lines · Josh Don
Quoted 14 lines
/*
- * Preempt the current task with a newly woken task if needed:
+ * Preempt an idle entity in favor of a non-idle entity (and don't preempt
+ * in the inverse case).
+ */kernel/sched/fair.c +9
-0+static inline enum preempt_wakeup_action +wakeup_preempt_sched_idle (struct sched_entity *cse,struct sched_entity *pse) +{ +int cse_is_idle, pse_is_idle; + + cse_is_idle =se_is_idle (cse); + pse_is_idle =se_is_idle (pse); + +if (cse_is_idle || pse_is_idle) {Quoted 8 lines
kernel/sched/fair.c preempt_sync(struct rq *rq, int wake_fla · line 10186
Quoted 5 lines
kernel/sched/fair.c +5
-0+find_matching_se (&cse, &pse); +WARN_ON_ONCE (!pse); + + cse_is_idle =se_is_idle (cse); + pse_is_idle =se_is_idle (pse);now that
se_is_idle()is checking for any ancestors with idle, this doesn't appear to be correct. Some motivaing examples:
Quoted 3 lines
So we want to keep the idle difference between groups with idle ancestors? FWIW, I asked about this but then thought it was knowingly and that was what we wanted. I'm still not sure what we want...
cgroup properties are cgroup hierarchy position relative, this just maintins that behavior for cpu.idle as well. There was a more extensive discussion on this in the previous RFC, which is how we landed back on the find_matching_se() restoration.
ie. user given a cgroup can sub-delegate portions of their job as idle relative to their main workload, but all of this still runs at the user's priority vs other users on the system
Quoted 48 lines
Quoted 42 lines
Ex 1:
regular task andSCHED_IDLEtask both inside an idle cgroup.se_is_idle()will be true for both se's, and so the regular task will not end up preempting theSCHED_IDLEtask, which would be the desirable behavior (the task is not idle relative to theSCHED_IDLEtask)cgrp A (idle)
/ \regular_taskSCHED_IDLEtaskEx2:
more complex example with a hierarchy of cgroupsroot
|
cgrp A (idle)
/ \
cgrp B cgrp C (idle)
| |
task_1task_2
task_1should preempttask_2, and the inverse should also never happen. However, thematching_sehere are cgroups B and C, and both showse_is_idle()as trueI can think of two simple ways to fix that, either seems fine
1) use the existingse_is_idle()check for knowing when we can fast-path skip the wholefind_matching_se()business, but when we do find the matching se, rather than usese_is_idle, use a more targeted helper that directly compares just those two entities without any of their ancestors (ie. for the task case just check if it has an idle policy, and for the group case, just checktg_is_idle())
2) once you find the matching se, just compare the ->idle values, since if one of them is bigger (by at most 1?), then that one must be the "idle" one relatively speaking. Handling the task vs group case here seems a bit messier compared to the first option, so my suggestion would be to go with the aboveQuoted 2 lines
Best,
JoshCheers,
Kayra :-).
Peter Zijlstra
maintainerRe: [RFC][PATCH 3/3] sched/eevdf: Fix sched idle task group preemption
Quoted 29 lines · Josh Don
Quoted 28 lines · Kayra Cizmeci
Hi Josh!
Quoted 22 lines · Josh Don
Quoted 9 lines
/*
- * Preempt the current task with a newly woken task if needed:
+ * Preempt an idle entity in favor of a non-idle entity (and don't preempt
+ * in the inverse case).
+ */kernel/sched/fair.c +4
-0+static inline enum preempt_wakeup_action +wakeup_preempt_sched_idle (struct sched_entity *cse,struct sched_entity *pse) +{ +int cse_is_idle, pse_is_idle;kernel/sched/fair.c preempt_sync(struct rq *rq, int wake_fla · line 10186
Quoted 10 lines
kernel/sched/fair.c +10
-0+ + cse_is_idle =se_is_idle (cse); + pse_is_idle =se_is_idle (pse); + +if (cse_is_idle || pse_is_idle) { +find_matching_se (&cse, &pse); +WARN_ON_ONCE (!pse); + + cse_is_idle =se_is_idle (cse); + pse_is_idle =se_is_idle (pse);now that
se_is_idle()is checking for any ancestors with idle, this doesn't appear to be correct. Some motivaing examples:
Quoted 8 lines
Quoted 3 lines
So we want to keep the idle difference between groups with idle ancestors? FWIW, I asked about this but then thought it was knowingly and that was what we wanted. I'm still not sure what we want...
cgroup properties are cgroup hierarchy position relative, this just maintins that behavior for cpu.idle as well. There was a more extensive discussion on this in the previous RFC, which is how we landed back on the
find_matching_se()restoration.
Well, I'm still not convinced we need this.
Realistically idle means: "don't care, run whenever you have a minute". To then preempt such a task for another such a task just because its somewhere else in the hierarchy makes no sense, you don't care about either of them, we shouldn't be preempting.
Anyway, I've pushed out the first two patches to queue/sched/urgent since they address the worst of it. We can chew on all this a bit more I suppose. But I cannot convince myself that there is any situation in which we (should) actually care about the timeliness of anything in a cgroup::idle container.
Peter Zijlstra
maintainerRe: [RFC][PATCH 3/3] sched/eevdf: Fix sched idle task group preemption
Quoted 46 lines · Peter Zijlstra
Quoted 29 lines · Josh Don
Quoted 28 lines · Kayra Cizmeci
Hi Josh!
Quoted 22 lines · Josh Don
Quoted 9 lines
/*
- * Preempt the current task with a newly woken task if needed:
+ * Preempt an idle entity in favor of a non-idle entity (and don't preempt
+ * in the inverse case).
+ */kernel/sched/fair.c +4
-0+static inline enum preempt_wakeup_action +wakeup_preempt_sched_idle (struct sched_entity *cse,struct sched_entity *pse) +{ +int cse_is_idle, pse_is_idle;kernel/sched/fair.c preempt_sync(struct rq *rq, int wake_fla · line 10186
Quoted 10 lines
kernel/sched/fair.c +10
-0+ + cse_is_idle =se_is_idle (cse); + pse_is_idle =se_is_idle (pse); + +if (cse_is_idle || pse_is_idle) { +find_matching_se (&cse, &pse); +WARN_ON_ONCE (!pse); + + cse_is_idle =se_is_idle (cse); + pse_is_idle =se_is_idle (pse);now that
se_is_idle()is checking for any ancestors with idle, this doesn't appear to be correct. Some motivaing examples:Quoted 8 lines
Quoted 3 lines
So we want to keep the idle difference between groups with idle ancestors? FWIW, I asked about this but then thought it was knowingly and that was what we wanted. I'm still not sure what we want...
cgroup properties are cgroup hierarchy position relative, this just maintins that behavior for cpu.idle as well. There was a more extensive discussion on this in the previous RFC, which is how we landed back on the
find_matching_se()restoration.Well, I'm still not convinced we need this.
Realistically idle means: "don't care, run whenever you have a minute". To then preempt such a task for another such a task just because its somewhere else in the hierarchy makes no sense, you don't care about either of them, we shouldn't be preempting.
Quoted 5 lines
Anyway, I've pushed out the first two patches to queue/sched/urgent since they address the worst of it. We can chew on all this a bit more I suppose. But I cannot convince myself that there is any situation in which we (should) actually care about the timeliness of anything in a
cgroup::idlecontainer.
Perhaps even to the point that we should have idle (either the task or the cgroup property) imply an extra long slice length, much like how it implies a very low weight.
Re: [RFC][PATCH 3/3] sched/eevdf: Fix sched idle task group preemption
Quoted 54 lines · Peter Zijlstra
Quoted 46 lines · Peter Zijlstra
Quoted 29 lines · Josh Don
Quoted 28 lines · Kayra Cizmeci
Hi Josh!
Quoted 22 lines · Josh Don
Quoted 9 lines
/*
- * Preempt the current task with a newly woken task if needed:
+ * Preempt an idle entity in favor of a non-idle entity (and don't preempt
+ * in the inverse case).
+ */kernel/sched/fair.c +4
-0+static inline enum preempt_wakeup_action +wakeup_preempt_sched_idle (struct sched_entity *cse,struct sched_entity *pse) +{ +int cse_is_idle, pse_is_idle;kernel/sched/fair.c preempt_sync(struct rq *rq, int wake_fla · line 10186
Quoted 10 lines
kernel/sched/fair.c +10
-0+ + cse_is_idle =se_is_idle (cse); + pse_is_idle =se_is_idle (pse); + +if (cse_is_idle || pse_is_idle) { +find_matching_se (&cse, &pse); +WARN_ON_ONCE (!pse); + + cse_is_idle =se_is_idle (cse); + pse_is_idle =se_is_idle (pse);now that
se_is_idle()is checking for any ancestors with idle, this doesn't appear to be correct. Some motivaing examples:Quoted 8 lines
Quoted 3 lines
So we want to keep the idle difference between groups with idle ancestors? FWIW, I asked about this but then thought it was knowingly and that was what we wanted. I'm still not sure what we want...
cgroup properties are cgroup hierarchy position relative, this just maintins that behavior for cpu.idle as well. There was a more extensive discussion on this in the previous RFC, which is how we landed back on the
find_matching_se()restoration.Well, I'm still not convinced we need this.
Realistically idle means: "don't care, run whenever you have a minute". To then preempt such a task for another such a task just because its somewhere else in the hierarchy makes no sense, you don't care about either of them, we shouldn't be preempting.
Quoted 5 lines
Anyway, I've pushed out the first two patches to queue/sched/urgent since they address the worst of it. We can chew on all this a bit more I suppose. But I cannot convince myself that there is any situation in which we (should) actually care about the timeliness of anything in a
cgroup::idlecontainer.
Quoted 3 lines
Perhaps even to the point that we should have idle (either the task or the cgroup property) imply an extra long slice length, much like how it implies a very low weight.
Does the example I gave earlier with separate users (jobs) that can subdivide their own cpu slice into regular and "idle" usage not feel convincing to you? If a user is entitled to 50% of the cpu, and they have both latency sensitive and background batch work to do, they still want their batch work entitled to forward progress under the job's overall 50% system cpu share.