From nobody Mon Apr 6 21:53:25 2026 Received: from DM5PR21CU001.outbound.protection.outlook.com (mail-centralusazon11011041.outbound.protection.outlook.com [52.101.62.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B2EE24468C for ; Fri, 3 Apr 2026 05:37:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.62.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775194677; cv=fail; b=bGiV36yMOXAXVgPlmAbeqIjpVX3Jxy2Udt5qTngt//4dMEFoIOkiqEhfORXR/RhA/yOYCypIHLVku370mAxhBFe+kk6r7Jt2X/irFwiIwTwCqck6JqDX7MnK/jTR2OBtJFnzaEbrBra9Ify1JkSOg1bnzEHT4cLJnt4Bq/FITXI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775194677; c=relaxed/simple; bh=BmXMw498iSe3uG1qzouEKtZShv6gV3ZOuKEv+3xkVAg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=TpoNKGyIWPWARMkV6xDB6F6hZ/69nxCew5TWfpiyxT6C9eAJQrif6eGtnoxcukEUMaVERfWhUzbyPtxdkJ7vLjMWsNbabkwLlPCSEyRJ207wTlUm9nQ29l9Yg3/hcAfSd7FI5RQxjWsYKHeDG8+0ae3DNAAPNMYga2pV05EIfNM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=IWeSLzBK; arc=fail smtp.client-ip=52.101.62.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="IWeSLzBK" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VdOSxI0zNmW9tqawjYWKqK6UJolYkZI+wj6MbxtJCd1ghZxgcuZyIfctwAdmHlyo4b8u6Y2UH067fADZe440KK4gf2jOE3IkVWVL5/uZGE7ByS20wkJp3n0tXyJAQzYjP7QyHy9lSXyehs14SVhLiH3+SOeMJXJQUL7ocb+L2Xvy2xD2eNqCIiUngaNBo36D/oAe4FiBPmkrzUI8UJSTwaeJzMbABYgQRcKtWkHKPyWBoBXNXOyVAitecxhj91Ics10vFgQvlE87aVFOdBXubV+upL4zcVnjZhXlMCet/oO1b8aJ9NjdVLfjLDJNMNfnd1TNfnxZMShaPbr/pDd0Vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7CQ+042fnVvBPzWuQ/1vAh5FJKCQAMObXDdxKcwnWSU=; b=NaZXVZwk+5vQ2SxysRORquKgYExdL3fSKrMSIk5Asr6MYtWOmEcFW2+wk6wBBQq+7ZB1KwGpj5MC78PQEpntjUFMZGxWTA5vgzATJBAW3nMBrum1DDcCl2bg0JqYtxKpFoi62nxeRNvfkYkOXnsmOwcW/AeGbayY0CqsAWHlVXj7P9B+/Ua2Gm6BngPDmJDs+6ZElrslwz46g2adsU1+pKsryRP0IS5vqY3tZCXnqK+50S4Fz2Cioy6ZWbmaL2JaeNJcAl2jdvRCfCHRehoyHjyPauwI27tTrzTB7zD1kKj3//NMoFwu/VeRLNuiSg4hi8bFpkYVpiG9hxPh8gxQyw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7CQ+042fnVvBPzWuQ/1vAh5FJKCQAMObXDdxKcwnWSU=; b=IWeSLzBKwUx3d8uUD50q3o3l3CSt/IDxqkdapJpBXyy0QCDUUj8AmKI13ZZUhMzWklEsNREFwoCJtXsKPSXRKIzeBZz+ijtyMXzGJ36Yo0VGVNz8OoGrCmM0HxkZeSxnNNq22lA5rKVYS9XM3i7Rxv4+Mt8JDGfiGCL4xGl85lupDLis2v/U0BEiQ3nD/mIH8QTwsXtOb0RtxaBzkKMFjj5Cgq0G/bmUjrp4nQlR9UQ4Q4VnJ8+/btoRUqIxlD43euqVSRfqnsjVmhBVxip2rIY6ZxZGwPApc3ABHA4GBRubQS5YoVT8tB+VcbFNIrwHFh2GJtgAN+/OM5DjbOvtvA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV8PR12MB9620.namprd12.prod.outlook.com (2603:10b6:408:2a1::19) by PH8PR12MB7110.namprd12.prod.outlook.com (2603:10b6:510:22e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9769.12; Fri, 3 Apr 2026 05:37:18 +0000 Received: from LV8PR12MB9620.namprd12.prod.outlook.com ([fe80::299d:f5e0:3550:1528]) by LV8PR12MB9620.namprd12.prod.outlook.com ([fe80::299d:f5e0:3550:1528%5]) with mapi id 15.20.9769.017; Fri, 3 Apr 2026 05:37:18 +0000 From: Andrea Righi To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot Cc: 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 Subject: [PATCH 1/2] sched/fair: Prefer fully-idle SMT cores in asym-capacity idle selection Date: Fri, 3 Apr 2026 07:31:05 +0200 Message-ID: <20260403053654.1559142-2-arighi@nvidia.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260403053654.1559142-1-arighi@nvidia.com> References: <20260403053654.1559142-1-arighi@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MI2PEPF00000B85.ITAP293.PROD.OUTLOOK.COM (2603:10a6:298:1::41c) To LV8PR12MB9620.namprd12.prod.outlook.com (2603:10b6:408:2a1::19) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV8PR12MB9620:EE_|PH8PR12MB7110:EE_ X-MS-Office365-Filtering-Correlation-Id: dfff87e0-7e4d-4a6a-ff13-08de914311dc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016|7416014|56012099003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: fn4rA8tUSz/S64DjilrjyFN0LfkB98l4vVLXtVSP0rF7PqZ/PwJUDGWkgIsix8oa+eVeS9AfShCSWtRNvHZpQb/Nmp8RIMu6ESH6EEryKHeWx+sdhQz5VavyUS+p0yPMy1HDvh++77Iczwuu95Ah6O+8dvVNNNC+BlZyekRWHuPUgtRLBx0ouaLMXOnHejAR3jj1sQRqihUh/WgP0+AMkIeP6iqiHQegFr0mqqjKPVwciZU8i3k2ejhO+v3Ag7g6Tao5X4zTCjs13/MNZjTGVLoucscnk4A84bFlMqNn/47fOSge9a1xUstGUi3R0dNmh9q51JSA6vbUQyOXaPdIzKPEaqB9VE4kp0pEh+/f3Gkua/970VqcfNB+x2jTMx0reAltyFqXZj7PBTzWCBVDZ/oXbHJN/DUh7H0T716xEVeWUKUqcIM0dPUZPE4QMd+qK4ZvpZSADpkAsjYeE40kxQkrKQNBwXETyf5r4MDywxHKUuaMu3zg93jl/z5gBEwhYBa8lXYSO4f1e6DizjhG2qk+q3QZ2nz1N3ZrT4pf/keVTNmsn22czBnyMS4VfdBVNjJtPPT9vC6MRjLOLKu+syo5C8xNaH3FaYGereIErSc1kJLjuq6Q8qbhxOsktfYz0y19l+YJqGzdSmSPqpj8X1ifAuEfF7dIckZI+Vw8BtTKT1yqusDmOMgPxwZlApayhAfAKnD1ZVtXfP4Z6wcr3ZEeTvBVf/cOcxkJCIn5PSw= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV8PR12MB9620.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(366016)(7416014)(56012099003)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Hr4XQeW+y0LMjMjISk8WWMXJDTuwh61FjOC3DdpqZ1igwyJ61x0weymv40pE?= =?us-ascii?Q?HJhae/F7AqBt3mEeMFzpeCRIiwYkcpJWhK1/xlfjdutwaNyCjE/kKe8gbtCo?= =?us-ascii?Q?4Fin0AWXYCBf/+IVCOZ19pyoM/v3V2Ohhj/KGpT13v6nE9vvDeXOzKU3u2pQ?= =?us-ascii?Q?dgRUBBZ8JzPnnncWtgzCufhxGCMQ/PjBWvGLa4fVTxxoMneRbkaEyde25Nzs?= =?us-ascii?Q?KA5KGLPgEU1LUDZyZz+sD+0MQuQvvF8KVV2zxsF0iKIQE5pk2xkeUMm0IccX?= =?us-ascii?Q?f1c+S+RF6VKtRbW0YhctS2yPq5IX03LmeCuaG1stKDKD0oZ/no2GSc9nOx0D?= =?us-ascii?Q?O+2/6olFAKmHEJak3TQnQF9ISkfFv6eWMJxG56x4bKt3kHbul8brcJwAAaMC?= =?us-ascii?Q?dF/Ov2tcwCocmB6aYWDvI2GnehEiinUDzXIPU0Yv50ZotMpbuVBRMABaa165?= =?us-ascii?Q?rhEOgovauoNhIJZSKP95cCL46BFtEx+mFkT05gjJ94DVns4S+eAR+3i5JD9B?= =?us-ascii?Q?ELYAj98h3NLEKglQpANLIIugTOYjsi/oZUUWB32WXfODMkysVK1oCYhwcKAb?= =?us-ascii?Q?++ZczUD+LQ/+uDSdNOONkdkU4x3KPey0M6+Vv5jWqLFIO21jttI7MjVN2s1c?= =?us-ascii?Q?5bAVv8DrbRbIdnVhO7KOCbi5immzDRkgx6r0vw0iCP2IoZQNmjTMk/Tj2VMy?= =?us-ascii?Q?z3dLo/HpgAYNu6e+pzNToXCsI7Ov5KozPHb7hIihOnpeWiDa8vB7zlxmkHHE?= =?us-ascii?Q?zRHuxdYXD/p4KOJOSlmIcd4uF4dOo2qtYvCObeOjjGQDgQRhK7+QhAGVWF4/?= =?us-ascii?Q?1afJ2PhrNkW1i851m1G3uJDifetQ3HphuAd6yg68ho56AfZIFe9utPjphz3u?= =?us-ascii?Q?h71fVFaFyYGBCxC1EFNQBfNUH1EYRRL01OU7hDmR7qFZ+gGHTFrY2oDaQ8OJ?= =?us-ascii?Q?juRVTg3fJ2TKifjnqxVxqxMa7dIqmNtgaw1hGONnJaPICwwENjg1zHVknCkp?= =?us-ascii?Q?t163I5vaBF2ejwRBSwOC5UdznuL6IFXJU6n2D44eRrH5smPzYirLsXavUTDu?= =?us-ascii?Q?dvf9YGLm+RCGzTBbVv/4mSte8In7scyMzc1UHjtaK9Be83odnRomF6JONCfv?= =?us-ascii?Q?eL/QA8fv3whurfdbjkHaKXNzmteP3UNcTq+/8XKqs3a9XIKS4/6kIF+NV5pb?= =?us-ascii?Q?eblWtneV7Ddtm/IZ9T0vk/BSXilF2dmSYvSpVENls/HPpYEbTbsNaPisRnKY?= =?us-ascii?Q?IZ4zETp2KOwpdjOtUBckwWQBFXeMmcOS7LyJhnivPbPrfNE85guouzUZfgHM?= =?us-ascii?Q?s3NR2pwpE3DeTo/r3jS+pPmwS5Wx7iqiPOqpisKFYFyywEtiFTaE8uZHumsF?= =?us-ascii?Q?DJmK2nbTizVxJVdTcfLNcR+SM9DkcPMF507Dgs4vCLk7J7pWO/DUb1fCPO8K?= =?us-ascii?Q?l9VIGT7AT5b06YU3kYwbRPwmgtitXZJLActcswv8HG6D0z6a65a8S5nw5912?= =?us-ascii?Q?EFkCkz6Ka7bwab09vI1XPMA+I5KEvFCgPag60Bu7aN28nLD79iC1T72uP1fk?= =?us-ascii?Q?pr/X8Z0f9EFSbHCgrxdCr0RCt7xp8gV5BlvogE9t3YAf+PHHj+0E76I+ma6p?= =?us-ascii?Q?WiTykXNseMsLkMx2QGBoKfjlFAM8yeWUYZy/RliZwEjZKofPmsHQLuitHDni?= =?us-ascii?Q?TYD5LaNNCsT+Da1pefSUdbikYW/hstPbGSyx+NVqrMXp/W/qQpeN9xk0EEGv?= =?us-ascii?Q?sWa1IVMN+w=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: dfff87e0-7e4d-4a6a-ff13-08de914311dc X-MS-Exchange-CrossTenant-AuthSource: LV8PR12MB9620.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Apr 2026 05:37:18.3480 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: f5WFxAIuv+r5cDM9bWD0dUyvDn09e1jlASqHg+E9lnojUWd80VfBH5EGahQtFmRwerqEJCjCaXHGwJsTe7NFcQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7110 Content-Type: text/plain; charset="utf-8" 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, str= uct sched_domain *sd, bool static int select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int t= arget) { + bool prefers_idle_core =3D sched_smt_active() && test_idle_cores(target); unsigned long task_util, util_min, util_max, best_cap =3D 0; int fits, best_fits =3D 0; int cpu, best_cpu =3D -1; @@ -7787,6 +7788,7 @@ select_idle_capacity(struct task_struct *p, struct sc= hed_domain *sd, int target) util_max =3D uclamp_eff_value(p, UCLAMP_MAX); =20 for_each_cpu_wrap(cpu, cpus, target) { + bool preferred_core =3D !prefers_idle_core || is_core_idle(cpu); unsigned long cpu_cap =3D capacity_of(cpu); =20 if (!available_idle_cpu(cpu) && !sched_idle_cpu(cpu)) @@ -7795,7 +7797,7 @@ select_idle_capacity(struct task_struct *p, struct sc= hed_domain *sd, int target) fits =3D util_fits_cpu(task_util, util_min, util_max, cpu); =20 /* 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 s= ched_domain *sd, int target) */ else if (fits < 0) cpu_cap =3D 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 =3D -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 -=3D 3; =20 /* - * 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) || @@ -7824,12 +7847,17 @@ static inline bool asym_fits_cpu(unsigned long util, unsigned long util_max, int cpu) { - if (sched_asym_cpucap_active()) + if (sched_asym_cpucap_active()) { /* * Return true only if the cpu fully fits the task requirements * which include the utilization and the performance hints. + * + * When SMT is active, also require that the core has no busy + * siblings. */ - return (util_fits_cpu(util, util_min, util_max, cpu) > 0); + return (!sched_smt_active() || is_core_idle(cpu)) && + (util_fits_cpu(util, util_min, util_max, cpu) > 0); + } =20 return true; } --=20 2.53.0