The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCHSET v2 sched_ext/for-7.3] sched_ext: Fix idle CPU state initialization and validation
@ 2026-07-31  8:59 Andrea Righi
  2026-07-31  8:59 ` [PATCH 1/2] sched_ext: Initialize idle masks before ops.init() Andrea Righi
  2026-07-31  8:59 ` [PATCH 2/2] selftests/sched_ext: Make allowed_cpus idle validation race-free Andrea Righi
  0 siblings, 2 replies; 8+ messages in thread
From: Andrea Righi @ 2026-07-31  8:59 UTC (permalink / raw)
  To: Tejun Heo, David Vernet, Changwoo Min
  Cc: Kuba Piecuch, sched-ext, linux-kernel

The built-in idle masks are initialized with all online CPUs marked idle, but
idle tracking currently starts only after sched_ext is fully enabled. This
leaves busy CPUs incorrectly advertised as idle during ops.init() and until
their next idle transition.

Moreover, the allowed_cpus selftest checks that a remotely selected CPU is no
longer present in the idle mask. An idle-to-idle re-pick can re-advertise the
CPU before the test performs this check, making the validation inherently racy.

Make the built-in idle CPU masks reliable from ops.init() onward by enabling
idle tracking early and synchronizing every online CPU's state under its rq
lock. During this early phase, only the built-in masks are updated;
ops.update_idle() notifications remain suppressed until the scheduler is fully
enabled.

Also rework the allowed_cpus kselftest to replace the racy remote-CPU check with
a stable local invariant that relies on the newly guaranteed initial idle-mask
state.

Changes in v2:
 - Move idle-mask initialization from the selftest into the sched_ext
   core (Kuba Piecuch)
 - Add a dedicated idle-tracking static key so transitions are tracked
   before the scheduler is fully enabled (Kuba Piecuch)
 - Rework the allowed_cpus selftest to validate the stable local CPU-idle
   invariant
 - Target sched_ext/for-7.3 instead of sched_ext/for-7.2-fixes
 - Link to v1: https://lore.kernel.org/all/20260726064754.378671-1-arighi@nvidia.com/

Andrea Righi (2):
      sched_ext: Initialize idle masks before ops.init()
      selftests/sched_ext: Make allowed_cpus idle validation race-free

 kernel/sched/ext/ext.h                             |  4 +-
 kernel/sched/ext/idle.c                            | 38 ++++++++++++++++++-
 .../testing/selftests/sched_ext/allowed_cpus.bpf.c | 43 ++++++++++++++++++----
 3 files changed, 75 insertions(+), 10 deletions(-)

^ permalink raw reply	[flat|nested] 8+ messages in thread
* [PATCHSET v3 sched_ext/for-7.3] sched_ext: Fix idle CPU state initialization and validation
@ 2026-07-31 18:23 Andrea Righi
  2026-07-31 18:23 ` [PATCH 2/2] selftests/sched_ext: Make allowed_cpus idle validation race-free Andrea Righi
  0 siblings, 1 reply; 8+ messages in thread
From: Andrea Righi @ 2026-07-31 18:23 UTC (permalink / raw)
  To: Tejun Heo, David Vernet, Changwoo Min
  Cc: Kuba Piecuch, sched-ext, linux-kernel

The built-in idle masks are initialized with all online CPUs marked idle, but
idle tracking currently starts only after sched_ext is fully enabled. This
leaves busy CPUs incorrectly advertised as idle during ops.init() and until
their next idle transition.

Moreover, the allowed_cpus selftest checks that a remotely selected CPU is no
longer present in the idle mask. An idle-to-idle re-pick can re-advertise the
CPU before the test performs this check, making the validation inherently racy.

Fix this by enabling built-in idle tracking before ops.init() and refreshing the
state of every online CPU under its rq lock. Early tracking updates the built-in
masks, while ops.update_idle() notifications remain suppressed until the
scheduler is fully enabled.

Also rework the allowed_cpus kselftest to replace the racy remote-CPU check with
a stable local invariant that relies on the newly reliable idle-mask state.

Changes in v3:
 - Reuse the built-in idle-selection static key instead of introducing a
   dedicated idle-tracking key (Kuba Piecuch)
 - Check the local CPU-idle invariant from both ops.select_cpu() and
   ops.enqueue() (Kuba Piecuch)
 - Inspect the idle mask without modifying it and perform the check before
   calling scx_bpf_select_cpu_and() (Kuba Piecuch)
 - Link to v2: https://lore.kernel.org/all/20260731090334.2911948-1-arighi@nvidia.com/

Changes in v2:
 - Move idle-mask initialization from the selftest into the sched_ext
   core (Kuba Piecuch)
 - Add a dedicated idle-tracking static key so transitions are tracked
   before the scheduler is fully enabled (Kuba Piecuch)
 - Rework the allowed_cpus selftest to validate the stable local CPU-idle
   invariant
 - Link to v1: https://lore.kernel.org/all/20260726064754.378671-1-arighi@nvidia.com/

Andrea Righi (2):
      sched_ext: Initialize idle masks before ops.init()
      selftests/sched_ext: Make allowed_cpus idle validation race-free

 kernel/sched/ext/ext.h                             |  5 ++-
 kernel/sched/ext/idle.c                            | 35 ++++++++++++++--
 .../testing/selftests/sched_ext/allowed_cpus.bpf.c | 49 ++++++++++++++++++----
 3 files changed, 78 insertions(+), 11 deletions(-)

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-07-31 18:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-31  8:59 [PATCHSET v2 sched_ext/for-7.3] sched_ext: Fix idle CPU state initialization and validation Andrea Righi
2026-07-31  8:59 ` [PATCH 1/2] sched_ext: Initialize idle masks before ops.init() Andrea Righi
2026-07-31 10:47   ` Kuba Piecuch
2026-07-31 15:01     ` Andrea Righi
2026-07-31  8:59 ` [PATCH 2/2] selftests/sched_ext: Make allowed_cpus idle validation race-free Andrea Righi
2026-07-31 11:12   ` Kuba Piecuch
2026-07-31 15:26     ` Andrea Righi
  -- strict thread matches above, loose matches on Subject: below --
2026-07-31 18:23 [PATCHSET v3 sched_ext/for-7.3] sched_ext: Fix idle CPU state initialization and validation Andrea Righi
2026-07-31 18:23 ` [PATCH 2/2] selftests/sched_ext: Make allowed_cpus idle validation race-free Andrea Righi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox