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

Fernand Sieber
2025-09-23T07:33:10Z

Hi Prateek,

On 9/23/2025 7:21 AM, K Prateek Nayak wrote:
> Based on the above return in __sched_balance_find_dst_group_cpu(), it
> should always return a valid CPU since "least_loaded_cpu" is initialized
> to "this_cpu".
>
> So, under what circumstance does "cpu" here turns out to be < 0?
> Am I missing something?

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);
+}
+

Thanks,
Fernand