Re: [PATCH 0/2] sched/core: Fix stale core_pick and forced idle after SM_IDLE fast path
From: Peter Zijlstra
Date: Wed Nov 18 2026 - 09:41:58 EST
On Tue, Nov 17, 2026 at 02:27:04PM +0000, Ibrahim Elshahed wrote:
> Here are the two test programs used for the numbers in the cover letter.
>
> 1. init.c runs as PID 1 in a KVM guest with one socket, two cores and
> two threads (CPUs 0 and 1 are one core). A cookied task yields on
> CPU0. Each attempt wakes a SCHED_FIFO task with another cookie, in
> its own cgroup, on CPU1 and migrates it to CPU2 0-50 us later. If
> the yielding task then makes no progress for 20 ms, the core is
> stuck forced idle ("STALE"): the program kills the task, removes its
> cgroup, waits 100 ms without touching CPUs 0 and 1, and wakes a task
> on CPU1. Without the series that reschedule oopses in
> __cgroup_account_cputime_field(). mode=nomigrate is a control that
> never migrates the woken task.
>
> Build and run:
>
> gcc -O2 -static -o init init.c
> mkdir -p root/dev root/proc root/sys/fs/cgroup && cp init root/
> (cd root && find . | cpio -o -H newc | gzip) > initramfs.cpio.gz
> qemu-system-x86_64 -enable-kvm -cpu host -m 2G -nographic -no-reboot \
> -smp 4,sockets=1,cores=2,threads=2 \
> -kernel bzImage -initrd initramfs.cpio.gz \
> -append "schedstats=enable idle=halt console=ttyS0 panic=-1 mode=migrate secs=240"
>
> The kernel needs CONFIG_SCHED_CORE, CONFIG_SCHEDSTATS, CONFIG_SCHED_SMT,
> CONFIG_CGROUP_SCHED and CONFIG_FAIR_GROUP_SCHED.
>
> 2. cschurn.c runs the same churn on bare metal on half of the SMT cores,
> using the other half as migration targets, and counts a stall when
> the yielding task makes no progress for 5 ms. It frees each woken
> task and its cgroup shortly after the check (2 ms by default, second
> argument), so it shows the stuck forced idle but not the
> use-after-free.
>
> gcc -O2 -o cschurn cschurn.c
> ./cschurn 300 # as root, cgroup2 at /sys/fs/cgroup,
> # kernel booted with schedstats=enable
>
Does it make sense to stick these in the selftests thing?