Re: [PATCH 1/2] sched_ext: Initialize idle masks before ops.init()

Andrea Righi <[email protected]> Mon, 3 Aug 2026 07:46:57 +0200
Newsgroups dev.linux.lists.sched-ext,org.kernel.vger.linux-kernel
Message-ID <anArUap-URclDfww@gpd4>
Hi Tejun,

On Sun, Aug 02, 2026 at 09:19:48AM -1000, Tejun Heo wrote:
> Hello,
> 
> On Fri, Jul 31, 2026 at 08:23:33PM +0200, Andrea Righi wrote:
> > The built-in idle masks are reset with all online CPUs marked idle, but
> > idle state tracking starts only after the scheduler is fully enabled.
> > As a result, ops.init() can observe busy CPUs as idle, and those CPUs
> > remain incorrectly advertised until their next idle transition.
> > 
> > Enable built-in idle tracking before ops.init() and refresh every online
> > CPU under its rq lock. Once a CPU is refreshed, later transitions keep
> > its state accurate. Keep ops.update_idle() notifications disabled until
> > the scheduler is fully enabled.
> 
> While a sched is being loaded, bypass mode is on and when we get out of
> bypass mode, we set RENOTIFY and trigger kick each CPU, which, if the CPU
> has been or is entering idle, triggers ops.update_idle(). So, BPF
> implemented idle tracking gets the actual idle state update when bypass goes
> off, which makes sense. Would the problem you were seeing go away if we just
> clear all idle bits on load instead of setting them? The lifting of bypass
> mode at the end should set idle bits for all actually idle CPUs.

Yes, I think clearing the masks should be sufficient: it makes the initial state
conservative, so ops.init() sees no idle CPUs instead of potentially seeing busy
CPUs as idle.

Once __scx_enabled is set, exiting bypass arms the idle re-notification and
reschedules every online CPU, an idle-to-idle re-pick then updates the built-in
mask as well and triggers ops.update_idle(). Busy CPUs remain clear. The mask is
temporarily incomplete, including during ops.init(), but that should be safe and
it will quickly converge to the actual idle state. So everything should work.
I'll send a new version with this logic.

Thanks,
-Andrea