Re: [PATCH 2/4] sched/fair: Still look for the idlest cpu with no matching cookie

Fernand Sieber
2025-09-23T07:45:04Z

On 9/23/2025 9:32 AM, Fernand Sieber wrote:
> Hey Prateek. Thanks for the catch. I'll fix as follows for next rev:
>
> +/*
> + * sched_balance_find_dst_group_cpu - find the idlest CPU among the CPUs in the group.
> + */
> +static inline int
> +sched_balance_find_dst_group_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
> +{
> + int cpu = __sched_balance_find_dst_group_cpu(group, p, -1, true);
> + return cpu >= 0 ? cpu : __sched_balance_find_dst_group_cpu(group, p, this_cpu, false);
> +}

On second thoughts, this doesn't work as it breaks the original fallback path.
A better modification would be this:

@@ -7341,7 +7341,7 @@ __sched_balance_find_dst_group_cpu(struct sched_group *group, struct task_struct
unsigned long load, min_load = ULONG_MAX;
unsigned int min_exit_latency = UINT_MAX;
u64 latest_idle_timestamp = 0;
- int least_loaded_cpu = this_cpu;
+ int least_loaded_cpu = -1;
int shallowest_idle_cpu = -1;
int i;

@@ -7357,6 +7357,9 @@ __sched_balance_find_dst_group_cpu(struct sched_group *group, struct task_struct
if (cookie_match ^ sched_core_cookie_match(rq, p))
continue;

+ if (least_loaded_cpu < 0)
+ least_loaded_cpu = this_cpu;
+
if (sched_idle_cpu(i))
return i;

Thanks,
Fernand