From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB1244A23 for ; Sun, 19 Apr 2026 10:20:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.208.52 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776594057; cv=pass; b=ouCWzWQhqndY5uTaOfoaNNcRmZVGRLNjgIrgP7f8o6JRdIFcyGcJMFkHsyj4BS5dEDH+VyOHGuCk0FyKvmCaj0yNGuJO+VGagXUtMaX+xwykzT0FvONdQ3kRVJlWKbHjsy/7jqPz5v+NLLXf5bAJEf3CaaCmmpos7ZUhhM/5rHE= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776594057; c=relaxed/simple; bh=qNXctQro720jQRAz9n+eGlB4dQQhIk87Bq1b2Cw4VIk=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=f+TwC7qbHNjBZQV43ikjLKVhSc/nL7ry6YsPSy3xZnFfC9VwCJUFT+g/uINtRayXu/J8nyYEL+bV0YEJKfCEdOR/3VbE7tSUeubYAmEQhctZxuUqeiJtsqqoBYpSdqlYrkjJmzSSRYm2O21eOG6zYq5kMjBNqazE0Wb2axUGE98= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=lGWivPkK; arc=pass smtp.client-ip=209.85.208.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="lGWivPkK" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-66e8cf72a93so2615849a12.0 for ; Sun, 19 Apr 2026 03:20:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1776594054; cv=none; d=google.com; s=arc-20240605; b=Toih075SEbIrj1LwLysbUc3AEyWxPtY4pKlk4kvQpJjjMGAMeLS6PQiTjaHzj4EXst AtIxdlh43gb8eur8YkCNk4lRdDRsD4qNMAOchK4Z1iP09Ye3SglW/7lC7HaB8Mvf7Zcp vwQF83HE535XbRmLCXj5THY0nrbcf9T0uLmilWukGcviYr+99Vsd1ESVBQFuLYB5ettj VpVLR1T4DNFUhkP50YdwpklZN7wF+8B4rZWG5Xb3WDO3Vp5+dvC64VdP/KjgCqV2uizs 34LfEY3FII5ZDpxV59H6VjukxrJmxJgpMM+YZ5OIcaLiIyC0ih8PhHicunf9gCWaS2+a XQqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=6dBQMhai06Qn0aCYeoiBnfd09jq77R4jiqi5tqgq0Rw=; fh=Nbubj2510p8/vM/l9gIQqxir70LUnXcyF1k584ZFlRg=; b=OYFD09CJ60++UEQlN/4NdYNEmJXkV4Ddh+tMXMd/zNI8vxBfPWGlRhU729X06kSyFw jAPzj66itjSMgHy2GpF9E0l6+Rea3iptuGlg1sIUXH7tACZECHu4rGeKAGnZ/e8SNv6a 9wQlyw/3V00u3LscSCyGSzzPY1WiviRc4Aj2USsIyTiQGbczeJKANaMPl9Fd38fmFLc8 Kw4QgqUJAKuqvG4wM6ekLksUmiHaLCxCKAt5VK60/uLQoJYm9EabkST0TVxXhtG0qV48 63UVMlr2cP2rGxbkYLqWUcpJTtjxRvwiExneHumgrZ03jVS9xUM9+AO+HKwLh7Ra7oK1 5irQ==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1776594054; x=1777198854; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=6dBQMhai06Qn0aCYeoiBnfd09jq77R4jiqi5tqgq0Rw=; b=lGWivPkK+RT8w+s93BVEjH0+iXOOlMPNARbFtvL4d/8pc+HvAJzgvqw9138Kjt8jYY XM1XJ/VfKsJHAI0Lq693TfNuxdPy5DphC4o2y6WnYpl3lM9CN6/7JOZQYTyEdw+ZSFwV rxNjQBbumpX5GLxU24+EFNwi5EzWJsjW1/NqzM2Erxecp0K/OvBBKLEAVBVJhn5GTRX5 /5hBos6NiU5gKeJ6StACmaQbz2BVhKq8btHWgUlRst9D9bdgbbyl2W+pSMQ5hLWJk6u1 MabPsDBJoqGm3KQyscCPZDBqoRm0CcseDCA6ChVod38lcQAlO80iAA85kRVsl09XZRzM bV9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776594054; x=1777198854; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=6dBQMhai06Qn0aCYeoiBnfd09jq77R4jiqi5tqgq0Rw=; b=HEI36aA8TEw/gR+hpE/L597UBmmOc6yQeA3Qw9G6aCdMu2OYnmIeGdhV9/D+NLWd3A qpFwAp699/iSeZEswFx4gkxjnwopfjIvQeEMtvTuw6AYF55pOyJXWkZjA5yeAWRKNGm6 TnKccVU4lpbBNW/RB00BwphHB4zLeXGlJZabpIclhveSKnly5/hkELhZp09A5hD8Fccy Pmj4D6uopShXHQBwVEWZIdSMFt3v/tVZE52x6PkWt2RFm+BTi7xznxYZ+eiCVCshwILs 9wsxC27YkSAw/kQvtaAUUrnQlW7F0kR9E1Fpcz3ysaEs5obsfa2NLvZY7HQkAKvfglbD I4fg== X-Forwarded-Encrypted: i=1; AFNElJ/WPzueVnVcaTT0cNwqyIIkRXR44pC/IaSOqBSmZPTjupfXE/TYy5cg33OsZyIbRnDTk/r6W4RG1Px28Z8=@vger.kernel.org X-Gm-Message-State: AOJu0YxK+ZtMfBKydMfTK4/zn4SwqZmWKQwZD3jloq+Mm+9+ziu3uvtD XlPwiHYDzrfUrrcbodJXn8UFbHBbfMFAeRQ2ufDJBhjkrhlzWjBLsj7VZ2/lCynGNIjJqoIHUQZ ssfYhEiM75L/ICGc/gBn1EpZFnERNSDLwKHvZE15qiw== X-Gm-Gg: AeBDieukTCPWxreFdAEp9W9o8BC78nlHzvHhr1jT11491crPVgks1N2Ls+Xr9q8dPdn 46nVfQ398tN6Nb5Cr9MLAliA1braQy/DrhwIYk4djiyZNt7EYFT6sCMQQEW8O5Zy+4gIsxBGN6O ZkQ2HyFQsXiXWpKtl/kXvhZRMpurQAoUQpAfopXuWUYifdDyBEqEc0TLQACZu0A/YrTupZusWvV udk/EBRYJXcXLPWZlJq38SWHeXK14HqqlyTLaM9/QenhSy84dXX32qY3DW+maQUyBbzO3OzTnBW TmnFX9epzd2Bd6THdACa3tTjn+38y5GotT5x7xgR1jufow== X-Received: by 2002:a05:6402:1943:b0:670:8b7b:51b0 with SMTP id 4fb4d7f45d1cf-672bfd8538dmr3670833a12.3.1776594054014; Sun, 19 Apr 2026 03:20:54 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20260403053654.1559142-1-arighi@nvidia.com> <20260403053654.1559142-2-arighi@nvidia.com> In-Reply-To: From: Vincent Guittot Date: Sun, 19 Apr 2026 12:20:42 +0200 X-Gm-Features: AQROBzAtsE7KfvwxvquCvs67KqyikFZUhQDfrPyRr3EsZe0I80cW-woLPT_JFRQ Message-ID: Subject: Re: [PATCH 1/2] sched/fair: Prefer fully-idle SMT cores in asym-capacity idle selection To: Andrea Righi Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , Christian Loehle , Koba Ko , Felix Abecassis , Balbir Singh , Shrikanth Hegde , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" On Sat, 18 Apr 2026 at 08:02, Andrea Righi wrote: > > Hi Vincent, > > On Fri, Apr 17, 2026 at 11:39:21AM +0200, Vincent Guittot wrote: > > On Fri, 3 Apr 2026 at 07:37, Andrea Righi wrote: > > > > > > On systems with asymmetric CPU capacity (e.g., ACPI/CPPC reporting > > > different per-core frequencies), the wakeup path uses > > > select_idle_capacity() and prioritizes idle CPUs with higher capacity > > > for better task placement. > > > > > > However, when those CPUs belong to SMT cores, their effective capacity > > > can be much lower than the nominal capacity when the sibling thread is > > > busy: SMT siblings compete for shared resources, so a "high capacity" > > > CPU that is idle but whose sibling is busy does not deliver its full > > > capacity. This effective capacity reduction cannot be modeled by the > > > static capacity value alone. > > > > > > When SMT is active, teach asym-capacity idle selection to treat a > > > logical CPU as a weaker target if its physical core is only partially > > > idle: select_idle_capacity() no longer returns on the first idle CPU > > > whose static capacity fits the task when that CPU still has a busy > > > sibling, it keeps scanning for an idle CPU on a fully-idle core and only > > > if none qualify does it fall back to partially-idle cores, using shifted > > > fit scores so fully-idle cores win ties; asym_fits_cpu() applies the > > > same fully-idle core requirement when asym capacity and SMT are both > > > active. > > > > > > This improves task placement, since partially-idle SMT siblings deliver > > > less than their nominal capacity. Favoring fully idle cores, when > > > available, can significantly enhance both throughput and wakeup latency > > > on systems with both SMT and CPU asymmetry. > > > > > > No functional changes on systems with only asymmetric CPUs or only SMT. > > > > > > Cc: K Prateek Nayak > > > Cc: Vincent Guittot > > > Cc: Dietmar Eggemann > > > Cc: Christian Loehle > > > Cc: Koba Ko > > > Reported-by: Felix Abecassis > > > Signed-off-by: Andrea Righi > > > --- > > > kernel/sched/fair.c | 36 ++++++++++++++++++++++++++++++++---- > > > 1 file changed, 32 insertions(+), 4 deletions(-) > > > > > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > > > index bf948db905ed1..7f09191014d18 100644 > > > --- a/kernel/sched/fair.c > > > +++ b/kernel/sched/fair.c > > > @@ -7774,6 +7774,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; > > > @@ -7787,6 +7788,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 (!available_idle_cpu(cpu) && !sched_idle_cpu(cpu)) > > > @@ -7795,7 +7797,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. > > > @@ -7803,9 +7805,30 @@ select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int target) > > > */ > > > else if (fits < 0) > > > cpu_cap = get_actual_cpu_capacity(cpu); > > > + /* > > > + * fits > 0 implies we are not on a preferred core > > > + * but the util fits CPU capacity. Set fits to -2 so > > > + * the effective range becomes [-2, 0] where: > > > + * 0 - does not fit > > > + * -1 - fits with the exception of UCLAMP_MIN > > > + * -2 - fits with the exception of preferred_core > > > + */ > > > + else if (fits > 0) > > > + fits = -2; > > > + > > > + /* > > > + * If we are on a preferred core, translate the range of fits > > > + * of [-1, 0] to [-4, -3]. This ensures that an idle core > > > + * is always given priority over (partially) busy core. > > > + * > > > + * A fully fitting idle core would have returned early and hence > > > + * fits > 0 for preferred_core need not be dealt with. > > > + */ > > > + if (preferred_core) > > > + fits -= 3; > > > > > > /* > > > - * First, select CPU which fits better (-1 being better than 0). > > > + * First, select CPU which fits better (lower is more preferred). > > > * Then, select the one with best capacity at same level. > > > */ > > > if ((fits < best_fits) || > > > > You have to clear idle_core if you were looking of an idle core but > > didn't find one while looping on CPUs. > > > > You need the following to clear idle core: > > > > @@ -7739,6 +7739,11 @@ select_idle_capacity(struct task_struct *p, > > struct sched_domain *sd, int target) > > } > > } > > > > + /* The range [-4, -3] implies at least one idle core, the values above > > + * imply that we didn't find anyone while looping CPUs */ > > + if (prefers_idle_core && fits > -3) > > + set_idle_cores(target, false); > > + > > return best_cpu; > > } > > That makes sense! But it should be best_fits instead of fits, right? yes, of course > > Thanks, > -Andrea