Re: [PATCH] sched_ext: Rebuild fair weight when disabling BPF scheduler

From: Andrea Righi

Date: Tue May 26 2026 - 13:32:00 EST


Hi Zicheng,

On Tue, May 26, 2026 at 09:52:11PM +0800, Zicheng Qu wrote:
> From: Zicheng Qu <quzicheng@xxxxxxxxxx>
>
> When a BPF scheduler is disabled, scx_root_disable() switches tasks
> from ext_sched_class back to fair_sched_class directly. This does not
> go through __setscheduler_params(), so p->se.load is not rebuilt for
> tasks returning to fair.
>
> For example, after enabling a sched_ext BPF scheduler and creating
> CPU-bound tasks with different nice values, disabling the BPF scheduler
> can leave them running under fair with stale p->se.load. They may then
> split CPU time according to the stale weight instead of their current
> nice weights.
>
> Rebuild the fair load weight when scx_root_disable() switches a task
> from ext_sched_class to fair_sched_class. Use set_load_weight(p, false)
> so CFS gets a native load_weight derived from the task's current
> policy/static_prio before the task is enqueued on fair.
>
> Fixes: f0e1a0643a59 ("sched_ext: Implement BPF extensible scheduler class")
> Signed-off-by: Zicheng Qu <quzicheng@xxxxxxxxxx>
> ---
> kernel/sched/ext.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> index 65631e577ee9..e5b8509ce7ee 100644
> --- a/kernel/sched/ext.c
> +++ b/kernel/sched/ext.c
> @@ -5967,6 +5967,10 @@ static void scx_root_disable(struct scx_sched *sch)
>
> scoped_guard (sched_change, p, queue_flags) {
> p->sched_class = new_class;
> +
> + if (old_class == &ext_sched_class &&
> + new_class == &fair_sched_class)
> + set_load_weight(p, false);

I'm wondering if we have a similar issue for tasks moving from SCHED_EXT to
SCHED_NORMAL when a scx scheduler is running in partial mode. Maybe we need to
intercept this special case in __sched_setscheduler()? (not necessarily for this
patch, it can be addressed later as a separate follow-up patch).

For now, this makes sense to me.

Reviewed-by: Andrea Righi <arighi@xxxxxxxxxx>

Thanks,
-Andrea

> }
>
> scx_disable_and_exit_task(scx_task_sched(p), p);
> --
> 2.43.0
>