Skip to content

Commit dde8f4c

Browse files
authored
Merge pull request #1609 from hodgesds/p2dq-affinitized-locality
scx_p2dq: Improve locality for affinitized tasks
2 parents 4c72457 + 2991bcd commit dde8f4c

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

scheds/rust/scx_p2dq/src/bpf/main.bpf.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,41 @@ static s32 pick_idle_cpu(struct task_struct *p, struct task_ctx *taskc,
460460
goto found_cpu;
461461
}
462462

463-
// TODO: handle affinitized tasks to be more topology aware
463+
if (taskc->mask && llcx->cpumask)
464+
bpf_cpumask_and(taskc->mask, cast_mask(llcx->cpumask),
465+
p->cpus_ptr);
466+
467+
// First try to find an idle SMT in the LLC
468+
if (smt_enabled && taskc->mask) {
469+
cpu = scx_bpf_pick_idle_cpu(cast_mask(taskc->mask),
470+
SCX_PICK_IDLE_CORE);
471+
if (cpu >= 0) {
472+
*is_idle = true;
473+
goto found_cpu;
474+
}
475+
}
476+
477+
// Next try to find an idle CPU in the LLC
478+
if (taskc->mask) {
479+
cpu = scx_bpf_pick_idle_cpu(cast_mask(taskc->mask), 0);
480+
if (cpu >= 0) {
481+
*is_idle = true;
482+
goto found_cpu;
483+
}
484+
}
485+
486+
// Next try to find an idle CPU in the node
487+
if (nodec->cpumask && taskc->mask) {
488+
bpf_cpumask_and(taskc->mask, cast_mask(nodec->cpumask),
489+
p->cpus_ptr);
490+
if (taskc->mask &&
491+
(cpu = scx_bpf_pick_idle_cpu(cast_mask(taskc->mask), 0)) >= 0) {
492+
*is_idle = true;
493+
goto found_cpu;
494+
}
495+
}
496+
497+
// Fallback to anywhere the task can run
464498
cpu = bpf_cpumask_any_distribute(p->cpus_ptr);
465499
goto found_cpu;
466500
}

0 commit comments

Comments
 (0)