Re: [PATCH 1/4] sched/fair: Prefer fully-idle SMT cores in asym-capacity idle selection
From: K Prateek Nayak
Date: Fri Mar 27 2026 - 07:19:12 EST
Hello Andrea,
On 3/27/2026 4:28 PM, Andrea Righi wrote:
> On Fri, Mar 27, 2026 at 04:14:57PM +0530, K Prateek Nayak wrote:
>> Hello Andrea,
>>
>> On 3/26/2026 8:32 PM, Andrea Righi wrote:
>>> /* This CPU fits with all requirements */
>>> - if (fits > 0)
>>> - return cpu;
>>> + if (fits > 0) {
>>> + if (prefer_idle_cores && on_idle_core)
>>> + return cpu;
>>> + if (!prefer_idle_cores)
>>> + return cpu;
>>
>> nit.
>>
>> Can the above two be re-wittern as:
>>
>> if (!prefer_idle_cores || on_idle_core)
>> return cpu;
>>
>> since they are equivalent.
>
> Oh yes, indeed.
Also, can we just rewrite this Patch as:
(Includes feedback from Vincent; Only build tested)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 700d0f145ca6..cffd5649b54e 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -7946,6 +7946,7 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool
static int
select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int target)
{
+ bool prefers_idle_core = sched_smt_active() && test_idle_cores(target);
unsigned long task_util, util_min, util_max, best_cap = 0;
int fits, best_fits = 0;
int cpu, best_cpu = -1;
@@ -7959,6 +7960,7 @@ select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int target)
util_max = uclamp_eff_value(p, UCLAMP_MAX);
for_each_cpu_wrap(cpu, cpus, target) {
+ bool preferred_core = !prefers_idle_core || is_core_idle(cpu);
unsigned long cpu_cap = capacity_of(cpu);
if (!choose_idle_cpu(cpu, p))
@@ -7967,7 +7969,7 @@ select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int target)
fits = util_fits_cpu(task_util, util_min, util_max, cpu);
/* This CPU fits with all requirements */
- if (fits > 0)
+ if (fits > 0 && preferred_core)
return cpu;
/*
* Only the min performance hint (i.e. uclamp_min) doesn't fit.
@@ -7976,6 +7978,14 @@ select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int target)
else if (fits < 0)
cpu_cap = get_actual_cpu_capacity(cpu);
+ /*
+ * If we are on an preferred core, translate the range of fits
+ * from [-1, 1] to [-4, -2]. This ensures that an idle core
+ * is always given priority over (paritally) busy core.
+ */
+ if (preferred_core)
+ fits -= 3;
+
/*
* First, select CPU which fits better (-1 being better than 0).
* Then, select the one with best capacity at same level.
---
My naive eyes say it should be equivalent of what you have but maybe
I'm wrong?
--
Thanks and Regards,
Prateek