Re: [PATCH v11 15/43] sched/deadline: Keep a task in the root domain that counts its bandwidth
From: sashiko-bot
Date: Wed Nov 25 2026 - 20:38:08 EST
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] sched/deadline: select_fallback_rq() bypasses local NUMA node
search
- [Medium] sched/deadline: __set_cpus_allowed_ptr_locked() clobbers
valid wake_cpu
--
commit 4af84b97f62357ff3460aae481348b8b367fe8d9
Author: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
sched/deadline: Keep a task in the root domain that counts its bandwidth
This commit introduces dl_task_bw_span() and updates CPU selection paths
during affinity changes, wakeups, CPU offline, and sched domain rebuilds
to prefer CPUs within the root domain that accounts for a deadline task's
bandwidth.
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 7615ba02d52b3..3dd42581cc177 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -3264,6 +3264,27 @@ static int __set_cpus_allowed_ptr_locked(struct task_struct *p,
> dest_cpu = ctx->dl_bw_cpu;
> if (!task_on_rq_queued(p))
> p->wake_cpu = dest_cpu;
> + } else {
> + const struct cpumask *span = dl_task_bw_span(p);
> + unsigned int cpu = nr_cpu_ids;
> +
> + /*
> + * No room was made for @p in another root domain. Keep @p
> + * in the root domain that counts its bandwidth, if the new
> + * mask holds one of its CPUs. Also wake a sleeping @p up
> + * there. A wakeup during a rebuild of the sched domains has
> + * no span to prefer.
> + */
> + if (span && cpumask_test_cpu(dest_cpu, span))
> + cpu = dest_cpu;
> + else if (span)
> + cpu = cpumask_first_and_and(cpu_valid_mask,
> + ctx->new_mask, span);
> + if (cpu < nr_cpu_ids) {
> + dest_cpu = cpu;
> + if (!task_on_rq_queued(p))
> + p->wake_cpu = dest_cpu;
> + }
> }
[Severity: Medium]
Does this overwrite p->wake_cpu for a sleeping deadline task even when
its existing p->wake_cpu is still valid in ctx->new_mask and span?
dest_cpu is chosen earlier via cpumask_any_and_distribute(cpu_valid_mask,
ctx->new_mask). Unlike a queued task (where affine_move_task() leaves p
on task_cpu(p) if it remains in the new mask), a sleeping deadline task
has p->wake_cpu unconditionally replaced with the pseudo-random dest_cpu
whenever span is non-NULL, forcing an unnecessary migration on the next
wakeup.
Only updating p->wake_cpu when it is not already in cpu_valid_mask,
ctx->new_mask, and span would preserve wakeup locality.
> @@ -3668,8 +3689,22 @@ static int select_fallback_rq(int cpu, struct task_struct *p)
> int nid = cpu_to_node(cpu);
> const struct cpumask *nodemask = NULL;
> enum { cpuset, possible, fail } state = cpuset;
> + const struct cpumask *span;
> + bool span_forced = false;
> int dest_cpu;
>
> + /*
> + * Keep a deadline task in the root domain that counts its
> + * bandwidth, if one of its CPUs is allowed and online.
> + */
> + span = dl_task_bw_span(p);
> + if (span) {
> + for_each_cpu_and(dest_cpu, span, p->cpus_ptr) {
> + if (is_cpu_allowed(p, dest_cpu))
> + return dest_cpu;
> + }
> + }
> +
> /*
> * If the node that the CPU is on has been offlined, cpu_to_node()
> * will return -1. There is no CPU on the node, and we should
[Severity: Medium]
Does this early return bypass the local NUMA node search in
select_fallback_rq() for deadline tasks?
Because dl_task_bw_span(p) returns rd->span for any admitted deadline
task outside a domain rebuild, scanning span & p->cpus_ptr in ascending
CPU order and returning before the cpumask_of_node(nid) loop below skips
same-node CPU selection on multi-node NUMA systems and always sends the
task to the lowest-numbered allowed CPU in its root domain.
Checking cpumask_of_node(nid) intersected with span first when span is
non-NULL would keep the task in its root domain while preserving NUMA
locality.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795646914.git.mathieu.desnoyers@xxxxxxxxxxxx?part=15