From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from PH0PR06CU001.outbound.protection.outlook.com (mail-westus3azon11011044.outbound.protection.outlook.com [40.107.208.44]) (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 A5B4F3D3CEA for ; Mon, 30 Mar 2026 13:22:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.208.44 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774876952; cv=fail; b=kpxpxIoldJftsy4+K5slIMR5rH1b9C2uZzjqpIcDHoYrXSLo1LtHtcrEIV6+scbXY7/FGr/uVXoOpKr7AOx64RLk5lXenUPaGiDQ1f+A4jNDodUW1eLnZhxYDfPFvztygz7WJQzB/FNKGIBC5g5RV2MxKBTKE7th30uj3FKFmgs= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774876952; c=relaxed/simple; bh=1PMpU2WftGV7a/qo62wfRKOAZykCjX/zu4Yiq7ENF9A=; h=Date:From:To:Cc:Subject:Message-ID:References:Content-Type: Content-Disposition:In-Reply-To:MIME-Version; b=Kusjh2zKgaV6zU5MQX5XoUEYTQH/i3J7nXsLT3drNL8dHOSk68xBHOEFhJYas4BCQuL2+zXDabP4824u1DBxDUA6MJFfBUunj9+EqyC4eg1JB1kTJoGedY08pR7lj3ycAvhVUUkP+yBVUxNy4WS4aoaKN1A/4JwZMhYMJ46PIKE= 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=WTW89J0u; arc=fail smtp.client-ip=40.107.208.44 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="WTW89J0u" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZBhCbBQnwprs2eP0oPYQ3i5o8RiUvJuEmUKDFgOj/939K3fMOXjGjU3DCmU3tF5MUZc9BfjWPH2r+kPtTtu7BMevbc+CI1H5/rdB8t6Mo6DPMUT75jZSpMVLfDFcbp1oF4fbE8TOCsLR6p3LKPM3uiGj7WtuSK6J+Vndpyy2adk2JZIYbaKLBPAIztjxHFtifgm+MOCeDl6ITubuFhtwN+YWzCsv3cZVqx/hNGpYFXYMIZsWVm4Ytk4X5T9BtTQZ9N18wqzqJnmqT+/qYYpmUsY3DM3fWeV1JxANhhO2PvAXyAtKatgzVdCUVKVMWOYrxdRmtHvraJNh28rlCEszQA== 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=Lw+DZ5pN0llwkJLJCKqEbkwAHNG2B/EYsf1qAj7H1kc=; b=x9uAjVOrboMuUBRe84U1TkyUcMnWjOa3bNKgIciV6ndLgvXLGqiPR7yDJQCM2oy+4a+Swtu4pBhMchNmRTPCYEfiuaWfWZlvFSSK/0n3hF5AWeAIgV/WcE4FB1NR+F4VUYoaPdmigIbm+G0NgSMjjX9j0HA+MSp+ETvc8Db7gXKO1s0445aj3/Y9+oQ728S7MmBDWHiBWgeVNvLliqF3KBTLr4/5S7fdf7B6kVpJZ1MKd9ATLO+CWaeWFlFOSbYt1bZSriATEsfTktptYsjOFbEq0J5JpFis6DukGK/ooFuyGgGtYVayMl687+bX9kSTxhKHfUwqde5D/upjk+MoUw== 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=Lw+DZ5pN0llwkJLJCKqEbkwAHNG2B/EYsf1qAj7H1kc=; b=WTW89J0uQqJmiJN8DChJXUTnpObuWRd1Ql4nv59j20ykb9pI1U0aulCubCEt9ez789BKJ+noGIx2USczzS8U50AiYDdIc3tYZ3F2TRah5chdr1xabpSafjjG+lQE4BIKpCSrimUao0o+pOqT2V5MRmngLn0FS6HSGXJJby+Zke0EeNDigzQS7iCmVScbVYSyv7Ct8WTx1rFDyrg+9J9Wub1Fc2Utd8RzKv0upbF5/gt+XxLMM1sB/9iah69vXbVnSRf47KojCPJgYjBwMh7QA8Q2TWWGgrwpUrGuiqxg4qmVEQIEUJbjrXZ3eHE64i6m1DW1r+oPuDyq1JMZHuhjzA== 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 BL1PR12MB5898.namprd12.prod.outlook.com (2603:10b6:208:396::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9769.15; Mon, 30 Mar 2026 13:22:26 +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.014; Mon, 30 Mar 2026 13:22:26 +0000 Date: Mon, 30 Mar 2026 15:22:13 +0200 From: Andrea Righi To: K Prateek Nayak Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Christian Loehle , Koba Ko , Felix Abecassis , Balbir Singh , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/4] sched/fair: Prefer fully-idle SMT cores in asym-capacity idle selection Message-ID: References: <20260326151211.1862600-1-arighi@nvidia.com> <20260326151211.1862600-2-arighi@nvidia.com> <258e2e94-ee42-4ea4-998c-4770732cbad0@amd.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <258e2e94-ee42-4ea4-998c-4770732cbad0@amd.com> X-ClientProxiedBy: ZR0P278CA0011.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:16::21) 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_|BL1PR12MB5898:EE_ X-MS-Office365-Filtering-Correlation-Id: 69d385f4-84ac-422d-8281-08de8e5f62db X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016|56012099003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: CCIMV40Eg3mmFdS03upVcNT//dJ/Oh3IkNVo7tRRC8pUQTB1MFd9nG/zPcZz8MYPCumKYTuDtgvNHi0TnAyOo+Vbn2qMnNc1XyjBVp3sKengwyMvL4vR4c3WrVmQteQZbuVL2b6o4oxGQh2lQ7c49KaNa8DMWN7qwa4KfauY7LmqHTj4HrkWnCZqu/pNxJkpUHSeCyPo0awMKXi0Utqr5DL6stxdXmsFd1RpA/B1RQqyWGRpX4bti+KHTjcWNx/eIO+A7puHfIBVe7LxiE33/udwatgWsez+BUtCcApEvq/Mi/ZpOzCndPXhzj+uPdAQPPrB9R47wClCy32RSQsMf6/qAzc1JX8LQQpADgvpjCECwPuC6E9NJTYLC5XvRx1Y4JEufNE51T5E6uR3aekJuzjAEM1tAUd/+RxL+THb9VGoZJexIVnvlLSYkCiInY+GtklAPQe2wGbzIbrz7aU86NqFcubWjBY2mv8KZ2ATeTL4pKZDgAY6ccHi/fkQfndxsZJiiS1sb1XGEnWoEVR0x7GFFh2ELnhf6z4KUmMhLrh5zuaBUScnzQB1O1X38QD8YbIec/ZnR3CLa3enYaw33ixOJt0L3S2v2YDDvNOLO/XOMep3n3rKD0vd+2CFjsNJkyVVMQqPCcmGr6NmEMhN8MEjoLo0kSBtff6ItZkbvn/4rxsphym3cSr6lZ0DGTWkc3vvcK1rqZlS1erkoH/IM0HGI2rSItLggWEG7Mv/NhE= 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)(7416014)(376014)(1800799024)(366016)(56012099003)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?/trrjjmRm6McEyD5R9i2NF5OyMsZnL29ULam/O+Zu30fERsJTIskkpCggXHq?= =?us-ascii?Q?f6e4gJTiIn8N0tyEacsRtoCarKV2Yiv5AFtJ6Jkzj90u4HapSLC/AkuxWqn7?= =?us-ascii?Q?3ZAjEV5+6/4CRKVhcd4Oxv0d8gBGbEjBFV3p1FunUGNJGGbTx9w1wXeAztDS?= =?us-ascii?Q?EdnOwfxGgG0iT3ftf8yVBuDZyj7B9I7b+9Jn/DW1h5if6HqJ4Hz8Y4TXZA9n?= =?us-ascii?Q?juP+Po6NDsTotJz9JX6Iwae/ooBLD+dFmtieMrmihO4Zy70eofE+/qrwekEO?= =?us-ascii?Q?mGJ7Jelrc9vbGmdubCUyhzRIsMpVUr3e/BGjoqij5y3X0u2FQuTubfdcmPSg?= =?us-ascii?Q?1M6NFgYPX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nMC?= =?us-ascii?Q?VaAJAreW4TWUt4wx5sgfYcNnZjp86fC50aD/TRM7X5AuFqLcHQWwr5Vqcvfc?= =?us-ascii?Q?qDMYZoOsfX7Jn9ctYHSkWThwJPbVkTtTPn7+++ZmQg2AKzrpx0idtW9TFDl9?= =?us-ascii?Q?4aQY2dgqP5L1dxUaRYFW4PUl1i1ZzM2tv/LrhafaWBVuCDOLBdLoH4LAKeiK?= =?us-ascii?Q?sDUydlUOjmCuenzsuyvbFOS2Tch2woJss1j4PUvUar0nKofNHNrfbstDqktK?= =?us-ascii?Q?RPzDT6bQZts6XRUA2A6QPHBj+2CvaKUWlJ99SlnOZ125bX97YOhNejFtK3w/?= =?us-ascii?Q?M5cOF4eYvzs6PloNpo6SPYJhwedODt22anPhiCbVM4CekrCiUXEeYDCXyg9a?= =?us-ascii?Q?eadGO/T9YTF4191veBaVNpIrCh+mZOy8AVecxJWZ5wMJLtq3BDxsfahipxHo?= =?us-ascii?Q?izrwbEFhbgXl6EjFiLQx3Bk6AcUZNYKrtUvFIf7Jp3BTEdXpeMxCEh867nem?= =?us-ascii?Q?DxYcyqfHMg=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 69d385f4-84ac-422d-8281-08de8e5f62db X-MS-Exchange-CrossTenant-AuthSource: LV8PR12MB9620.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2026 13:22:26.6690 (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: YgCpq9wONI2GGh/zy/HJJ8pbaDMCJ8L7W3tYrNZjtFvr2gRCwAOS/Wddh3fBeoo1JEWzRVVOOObXpJEGF6nW/w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5898 Hi Prateek, On Mon, Mar 30, 2026 at 03:47:07PM +0530, K Prateek Nayak wrote: > Hello Andrea, > > On 3/27/2026 10:09 PM, Andrea Righi wrote: > >> My naive eyes say it should be equivalent of what you have but maybe > >> I'm wrong? > > > > It seems correct to my naive eyes as well. Will test this out to make sure. > > So I found one small problem with fits > 0 && !preferred_core where even > though it is an ideal target, we don't end up preferring it because of > the larger "fits" value. > > Here is an updated diff: > > (Only build tested) I'm getting worse performance with this one (but better than mainline). I'm trying to understand why. BTW, we also need to fix asym_fits_cpu() to do something like this: return (!sched_smt_active() || is_core_idle(cpu)) && (util_fits_cpu(util, util_min, util_max, cpu) > 0); ...or we'd return early from select_idle_sibling() with busy SMT cores. Thanks, -Andrea > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 226509231e67..580218656865 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -7949,6 +7949,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; > @@ -7962,6 +7963,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)) > @@ -7970,7 +7972,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. > @@ -7978,9 +7980,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 an 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) || > --- > > Sorry for the oversight but this should now be equivalent to your > Patch 1. I'll let Vincent comment if he prefers this to the original > or not :-) > > -- > Thanks and Regards, > Prateek >