Re: [PATCH 1/4] sched/fair: Fix cookie check on __select_idle_cpu()

Madadi Vineeth Reddy
2025-09-25T06:36:21Z

Hi Prateek,

On 23/09/25 14:12, K Prateek Nayak wrote:
> Hello Fernand,
>
> On 9/22/2025 6:09 PM, Fernand Sieber wrote:
>> @@ -7447,7 +7447,7 @@ static inline int sched_balance_find_dst_cpu(struct sched_domain *sd, struct tas
>> static inline int __select_idle_cpu(int cpu, struct task_struct *p)
>> {
>> if ((available_idle_cpu(cpu) || sched_idle_cpu(cpu)) &&
>> - sched_cpu_cookie_match(cpu_rq(cpu), p))
>> + sched_core_cookie_match(cpu_rq(cpu), p))
>
> __select_idle_cpu() is only called when "has_idle_core" is false which
> means it is highly unlikely we'll find an idle core. In such cases, just
> matching the cookie should be sufficient right?

Agreed. The only code path I could find where __select_idle_cpu() is called
with has_idle_core == true is in the non-CONFIG_SCHED_SMT case, which is not
relevant to core scheduling.

Thanks,
Madadi Vineeth Reddy

>
> Do you have any benchmark numbers which shows a large difference with
> these changes?
>
>> return cpu;
>>
>> return -1;
>> @@ -7546,6 +7546,9 @@ static int select_idle_smt(struct task_struct *p, struct sched_domain *sd, int t
>> {
>> int cpu;
>>
>> + if (!sched_core_cookie_match(cpu_rq(target), p))
>> + return -1;
>> +
>
> select_idle_smt() is again called when "has_idle_core" is false and
> sched_cpu_cookie_match() should be sufficient for most part here too.
>
>> for_each_cpu_and(cpu, cpu_smt_mask(target), p->cpus_ptr) {
>> if (cpu == target)
>> continue;
>