rusty: Check for offline CPU in rusty_dispatch()

There's currently a slight issue on existing kernels on the hotplug
path wherein we can start to receive scheduling callbacks on a CPU
before that CPU has received hotplug events. For CPUs going online, this
can possibly confuse a scheduler because it may not be expecting
anything to ever happen on that CPU, and therefore may do things that
could cause the scheduler to crash. For example, without this patch in
scx_rusty, we try to consume from a bogus DSQ that doesn't exist, which
causes ext.c to boot out the scheduler.

Though this issue will soon be fixed in ext.c, let's explicitly avoid
dispatching from an onlining CPU in rusty so that we properly support
hotplug on older kernels as well.

Signed-off-by: David Vernet <void@manifault.com>
This commit is contained in:
David Vernet 2024-05-03 17:49:19 -05:00
parent 0d6b00238f
commit 6f1dc6067a
No known key found for this signature in database
GPG Key ID: 59E4B86965C4F364

View File

@ -1171,6 +1171,16 @@ void BPF_STRUCT_OPS(rusty_dispatch, s32 cpu, struct task_struct *prev)
struct pcpu_ctx *pcpuc; struct pcpu_ctx *pcpuc;
u32 node_doms, my_node, i; u32 node_doms, my_node, i;
/*
* In older kernels, we may receive an ops.dispatch() callback when a
* CPU is coming online during a hotplug _before_ the hotplug callback
* has been invoked. We're just going to exit in that hotplug callback,
* so let's just defer consuming here to avoid triggering a bad DSQ
* error in ext.c.
*/
if (unlikely(is_offline_cpu(cpu)))
return;
if (scx_bpf_consume(dom)) { if (scx_bpf_consume(dom)) {
stat_add(RUSTY_STAT_DSQ_DISPATCH, 1); stat_add(RUSTY_STAT_DSQ_DISPATCH, 1);
return; return;