sched_ext, sched/fair: Drain blocked load on scx_switched_all
Subsystems (3)
PATCH v3 1/1 sched_ext, sched/fair: Drain blocked load on scx_switched_all
Tasks that exit or migrate while sleeping queue their PELT load and utilization in cfs_rq->removed rather than deducting and propagating immediately. When scx_enable() switches all fair tasks to sched_ext, switched_from_fair() only visits cfs_rq chains that still hold live fair tasks, leaving unvisited leaf cfs_rqs undrained in rq->cfs.avg.
Once __scx_switched_all is enabled, scheduler_tick() skips sched_balance_trigger() and fair_sched_class is bypassed, freezing blocked-load updates. Stale rq->cfs.avg.util_sum can then combine with active RT/DL util_sum in update_idle_rq_clock_pelt() to exceed divider, inflating rq->lost_idle_time and stalling rq_clock_pelt().
Export __sched_balance_update_blocked_averages() and call it on each CPU in scx_enable()'s per-CPU scx_switched_all() loop so pending cfs_rq->removed entries and task-group propagations are drained cleanly.
---
Peter, Tejun mentioned on v2 [1] that this looks fine to go through sched_ext and asked for your ack on exporting __sched_balance_update_blocked_averages() -- resending as a standalone patch after dropping v2 patch 1/2.
Changes in v3:
- Drop v2 patch 1/2 (clearing residual _sum in update_tg_cfs_*()) per Vincent Guittot and resend as a standalone patch.
- Collect Reviewed-by from Vincent Guittot.
- Rebase onto sched_ext/for-7.4-fixes.
Changes in v2:
- Drop the pelt.h workaround from v1 and reuse __sched_balance_update_blocked_averages() in scx_enable() under scx_switched_all() to drain remaining blocked fair load (Vincent Guittot, Tejun Heo).
[1] https://lore.kernel.org/r/[email protected]
v1: https://lore.kernel.org/r/[email protected]
v2: https://lore.kernel.org/r/[email protected]
kernel/sched/ext/ext.c | 9 ++++----- kernel/sched/fair.c | 7 ++++++- kernel/sched/sched.h | 1 + 3 files changed, 11 insertions(+), 6 deletions(-)
kernel/sched/ext/ext.c +4 -5
@@ -9086,11 +9086,9 @@ static void scx_root_enable_workfn(struct kthread_work *work)static_branch_enable (&__scx_switched_all);/* -* Detach the fair_server bandwidth reservation now that the switch -* is fully committed. In full mode (!SCX_OPS_SWITCH_PARTIAL) no -* task will ever run in the fair class, so give that bandwidth -* back to the RT class. The matching ext_server attach already -* happened earlier; this only releases bandwidth and cannot fail. +* Detach the fair_server bandwidth reservation and drain any +* remaining blocked or removed fair load now that the switch is +* fully committed and periodic fair blocked-load updates stop. * * In partial mode keep fair_server attached. */
@@ -9101,6 +9099,7 @@ static void scx_root_enable_workfn(struct kthread_work *work)guard (rq_lock_irqsave)(rq);update_rq_clock (rq);dl_server_detach_bw (&rq->fair_server); +__sched_balance_update_blocked_averages (rq); } }
kernel/sched/fair.c +6 -1
@@ -11623,10 +11623,15 @@ static unsigned long task_h_load(struct task_struct *p) }#endif /* !CONFIG_FAIR_GROUP_SCHED */ -static void __sched_balance_update_blocked_averages (struct rq *rq) +/* +* Update blocked PELT averages for RT/DL/IRQ and fair cfs_rqs on @rq. +* Caller must hold @rq's lock and have updated @rq's clock. +*/ +void __sched_balance_update_blocked_averages (struct rq *rq) {bool decayed = false, done = true; +lockdep_assert_rq_held (rq);update_blocked_load_tick (rq); decayed |=__update_blocked_others (rq, &done);
kernel/sched/sched.h +1 -0
@@ -2958,6 +2958,7 @@ extern struct task_struct *pick_task_idle(struct rq *rq, struct rq_flags *rf);extern void update_group_capacity (struct sched_domain *sd,int cpu);extern void sched_balance_trigger (struct rq *rq); +void __sched_balance_update_blocked_averages (struct rq *rq);extern int __set_cpus_allowed_ptr (struct task_struct *p,struct affinity_context *ctx);extern void set_cpus_allowed_common (struct task_struct *p,struct affinity_context *ctx);
base-commit: b2b011d3d9cd7e01308ba8fa5775dcd1f2f11f70
Signature · 1 line
2.56.1.839.g22a8290db9-goog