From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from BN8PR05CU002.outbound.protection.outlook.com (mail-eastus2azon11011061.outbound.protection.outlook.com [52.101.57.61]) (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 115B031E849 for ; Thu, 23 Apr 2026 07:42:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.57.61 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776930149; cv=fail; b=u35Gv2vV/c84d525QXpxJAmcYsCxVWgyD6+kfJ2MdU2uo0qcmy8F77hJMW8t8d/30qICXZnoGKKHJr8CwysAWiUaul/jdhstVemmrUCuGyfF2vTHJxZYutSU2Pw2rotvVbp6B8kJomuVRRRTqXsol/CGWs4iO9xEsAKk2x1nbSM= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776930149; c=relaxed/simple; bh=lrSeSC1H9DMwYqKlzy/ePfMH2oWnVssi+PH5GXB4rRQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=NG14RVxdzTZrrP6MdFCKiyDs8NIYRIR/5Skgy2qvKEE2cAPHyqA6s45U+0TszOAIt73s42M02a0uDgOnVHnFNd+iR5kyJ2QBnxKvz1nhUhvo/Sj5u5VY1jqOdgMNTU0xmtm+CM3B8Ed2ruLvlpFid3mC0/glAlMqrR11CCiGX2I= 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=JaoEOknQ; arc=fail smtp.client-ip=52.101.57.61 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="JaoEOknQ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=S2nsixzZ1+Jo4MWtvk2OVwqn4AhpPP/RPBy321wiVucDoeU5BJkbXBX7fCcsThl0lwEEgiis+ESAsXlhR5tIAs9PGTCEqkd59E2u89jzWvH470mWVY/C3Z58/YgKH4mQflOMv0VjkjBSEyGD1EHhk6Vik2WQxtLXTGnSwOsRo5Y1n62XOCgQKrNnUjcZYat6Psuch3jkIW6PQspIvMmRXlSNeLAVGule6madtFUc3bGKCMsHhMynFGqpelo17eC2yp3+I0wd+1DGVjaLDuqSbQRuCtKB0wRYybA14uy52LBEPZ3JxZjh/BNDF7+duT0HEKl0sTvzGbaZWpOkJUoQJg== 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=5GMZgRoNQMeJNjL3E3vke8JFqxIVz/9IJdI61UOogcY=; b=wOyk7+TroPbc70y7gGgqxBtbrvt29kHnRiD8JZL/1+3ljUNKew6fvVnqsGBiHAALaWF4xKqd693Yzt5b7qq1Z/MVl8Ra9Jy+EQ5RVM+0u5cIJUNB+kelmHOxdzamEkIoE/WqgY0jIyhwilw2BVisGA5rH49/6OfXNPITxjbA/5exp42TvTx46c8MvU2Nux8FC12cC4Fp2TOy+/8nHvNUUtdLu6KAZ0KoBNmu5tBjZUu6I8Nm0s+N4RMUUXQXLWIxYUikk2+gQrAC6sv09jMsDECMhKE4HKIvf6ClkwatzYd/P8grMWFPDgBYGt0DHFJ1r4TkF/ySL7KWwPHPtctsIA== 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=5GMZgRoNQMeJNjL3E3vke8JFqxIVz/9IJdI61UOogcY=; b=JaoEOknQdm5V6q8ukqRD2KrX3MHLpIKe9jONMM+VAmoEF12HHwUt5RjJAmsYD1RyVEpdip0JPgsulO3aswu6oqQ+8nuWXZog1oOKUNNsRf5O8vZ+ERXZotPYf6utKiIQyzFrt4hA/7Ni/m2JIygD2V4vSwXPqsjVyJarWIwyEDz7mmUfyedNvkLmfqrJ5t2uNSwM6bdh+9OmRHyfQu+j0aSppENqHfHGe+2ChDx5QCkxo0fGfciyPY13xO1xr4MyMgDr3k3LS0am+9qkf6td0cyQbtjRYx4pu8hSYa2xBHufCj5Uv2qJJxg/J+YNKl4eZvZtZef7r6kixPQU//yCyw== 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 BL4PR12MB9534.namprd12.prod.outlook.com (2603:10b6:208:58f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9846.21; Thu, 23 Apr 2026 07:42:24 +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.9846.019; Thu, 23 Apr 2026 07:42:24 +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 , Joel Fernandes , Shrikanth Hegde , linux-kernel@vger.kernel.org Subject: [PATCH 5/5] sched/fair: Make asym CPU capacity idle rank values self-documenting Date: Thu, 23 Apr 2026 09:36:49 +0200 Message-ID: <20260423074135.380390-6-arighi@nvidia.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260423074135.380390-1-arighi@nvidia.com> References: <20260423074135.380390-1-arighi@nvidia.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SJ0PR05CA0183.namprd05.prod.outlook.com (2603:10b6:a03:330::8) 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_|BL4PR12MB9534:EE_ X-MS-Office365-Filtering-Correlation-Id: e767cc49-6f1a-4838-4a51-08dea10bdbca X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|366016|56012099003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: RyxCWrecRHL/CvWhqVRmVBY/IY7HbPOro4K2IcpX7Rf7gJzZdUDGsBBW63q64gbDfAQAKTjZskzB3YFHkQVncznrnqaawBeN905my0ekYOv2ubMsjQXdkTI2EIRGK5B8KL7TKewKljPi6HH7rqsE0Pp9bccDqS4QkAKP1TUpvsiJehRQl3ntGF72gyObTlxXliIBmsOgysaTtgyFJWT08hbUE+txTE4PSKFbprL6wTVnYVNvRA5lFr4mJLLAJU2pxi171p5ZHJECNtmO6sE+uA5MyhcMj1tNSxkwOKkXffKPsUuzXB29juB4rERs8v1f62dVOAgk676j2siXwmNJy9OWPn1EHXMzdNK5AfNtcXjZjF3wG3VCB/pr5LH20kx+kN4pyWYlYCPi8ucC0EKJUgRjt0Zdonfq+UB4pengbVnAkNZtOef1y6iJ6HMzIFS1qh5quPdgRdFNMgivGghMz4NT1LOK4aqwGx06djXAa/y7RxEC4st8RcDwQ6+0JOt0K7sPhFM9iazZlkjklVOZ+bsd4TMH2HdssbT1L87snN0fGyYdZSc+TNHSaG7pUCyy31m4X/ZUK9uCRkdb1CgZe8wA2+lnVEWl/oLKxFeYXGbO29zNoWOFuXAGSR5v01aGfCqHnaoHgXkyA1b+hmq+jgdI32ctjnF7WC5BQJKxgz0pcDVL7lF4lvpw5+sAXELhLeFR8xypEgTSrwoEkQdAJmaYVutDITI/WIWa0Ox3U9Q= 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)(7416014)(366016)(56012099003)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?MFjfLWyEjhnrAG5pF7CjNDisVwWVoq4RkUzVKGD379mh0O7+2mQZ+4ZxYOTz?= =?us-ascii?Q?bwMlGoIw/Mp5OpU7NCIOmNQbXljdkMfg1LozZ+vV8z/+qZ9WZF+cq5EpTepF?= =?us-ascii?Q?6ZgALGdrSA8eiR9F8+XaPvCvM5Gc/7mcNRu2ethpFkMzRW8F2NXo2vAcgNEI?= =?us-ascii?Q?F8G+b/txsn+LXgngQ6iHYams4sztEtjgIw6mvnhHDRhmWs8UiAfwLKet0iD2?= =?us-ascii?Q?RvpGyj+NnKuz7YvC74UBLkN2hSAxr3DEf0KC1Jx4H5kWJDYKDuXsLjYMZHeB?= =?us-ascii?Q?waNgJYDLj/ehatbd2WBcgIcopYSCFid7l1jA7BQlYHcPXfVaPdZdFVSauIcs?= =?us-ascii?Q?T+tV0HPlO6Vn/SxXPdFqZvkEsQ9rX93o53XrhxFRFas0eoLpYvZW8I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?ycodzsiUvJnLuDoHhA9oA8cvsl4dfdtm0693wsGUL12e5nR2pmTg5ImKiVW5?= =?us-ascii?Q?W3WkSMwqVEWSZ6tJZ7W6cOcezTNmQY3iLScrZRXnFym+S02SDF2nAjIUVEi+?= =?us-ascii?Q?0N+Dwr7CetSSJ3DKC3rJlZWjU3wdGePy+VJzqQeGgl6PTyA4FIFmrNuP8oH1?= =?us-ascii?Q?Xntj+8IM4jlcq2D2fhYGDfIJwxoe0jm2lL/QbD2T6wrbM7P8lYjftigclOvR?= =?us-ascii?Q?IVv3NOgDwDkz2mwv9nXIVGP0HtQKrdplD+OcQuh7hl+vdpKwK72jnNXnIdNI?= =?us-ascii?Q?tZ2nnWLF2nAPMELeWyHlJJNMvRlWGRZDT7cPobwh/hmPmB1UeMr1DBI1StVF?= =?us-ascii?Q?yMhgKI6XnPf6UU9acFlT8GCRtiyz/1RS8IwdUKVdxt/oKVHdNnlReYwV49SA?= =?us-ascii?Q?JLn+ksCUNB59Kfflq9XDRPP6oxtBsPCRcvtBnx2pTr+P/NTXDLsBUqjgUFDG?= =?us-ascii?Q?kGHFFe583w=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e767cc49-6f1a-4838-4a51-08dea10bdbca X-MS-Exchange-CrossTenant-AuthSource: LV8PR12MB9620.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Apr 2026 07:42:23.9374 (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: 9BEKmq5ljpEchlSR2mgn+lpLUGsBVPkf9I94M0V5m0WqklrHmld5Qeh5zkLYS3EMPxDB/ecMop4ki7WP9PV+5Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL4PR12MB9534 From: K Prateek Nayak Introduce enum asym_fits_state for select_idle_capacity() scan preferences, instead of using raw constants to improve readability. No functional change. Signed-off-by: K Prateek Nayak --- kernel/sched/fair.c | 48 ++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 6b67049f04c3e..a3ecbed43c34f 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -7989,6 +7989,22 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool return idle_cpu; } +/* + * Idle-capacity scan ranks transformed util_fits_cpu() outcomes; lower values + * are more preferred (see select_idle_capacity()). + */ +enum asym_fits_state { + /* In descending order of preference */ + ASYM_IDLE_CORE_UCLAMP_MISFIT = -4, + ASYM_IDLE_CORE_COMPLETE_MISFIT, + ASYM_IDLE_THREAD_FITS, + ASYM_IDLE_THREAD_UCLAMP_MISFIT, + ASYM_IDLE_COMPLETE_MISFIT, + + /* asym_fits_cpu() bias for an idle core. */ + ASYM_IDLE_CORE_BIAS = -3, +}; + /* * Scan the asym_capacity domain for idle CPUs; pick the first idle one on which * the task fits. If no CPU is big enough, but there are idle ones, try to @@ -7999,7 +8015,7 @@ 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 fits, best_fits = ASYM_IDLE_COMPLETE_MISFIT; int cpu, best_cpu = -1; struct cpumask *cpus; int nr = INT_MAX; @@ -8032,7 +8048,7 @@ select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int target) unsigned long cpu_cap = capacity_of(cpu); /* We have found a good enough target. Just use it. */ - if (--nr <= 0 && best_fits == -4) + if (--nr <= 0 && best_fits == ASYM_IDLE_CORE_UCLAMP_MISFIT) return best_cpu; if (!choose_idle_cpu(cpu, p)) @@ -8051,25 +8067,28 @@ select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int target) 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 + * but the util fits CPU capacity. Set fits to ASYM_IDLE_THREAD_FITS + * so the effective range becomes + * [ASYM_IDLE_THREAD_FITS, ASYM_IDLE_COMPLETE_MISFIT], where: + * ASYM_IDLE_COMPLETE_MISFIT - does not fit + * ASYM_IDLE_THREAD_UCLAMP_MISFIT - fits with the exception of UCLAMP_MIN + * ASYM_IDLE_THREAD_FITS - fits with the exception of preferred_core */ else if (fits > 0) - fits = -2; + fits = ASYM_IDLE_THREAD_FITS; /* * 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. + * of [ASYM_IDLE_THREAD_UCLAMP_MISFIT, ASYM_IDLE_COMPLETE_MISFIT] to + * [ASYM_IDLE_CORE_UCLAMP_MISFIT, ASYM_IDLE_CORE_COMPLETE_MISFIT]. + * 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; + fits += ASYM_IDLE_CORE_BIAS; /* * First, select CPU which fits better (lower is more preferred). @@ -8084,15 +8103,16 @@ select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int target) } /* - * A value in the [-4, -3] range means the chosen CPU is in a fully idle - * SMT core. Values above -3 mean we never ranked such a CPU best. + * A value in the [ASYM_IDLE_CORE_UCLAMP_MISFIT, ASYM_IDLE_CORE_BIAS] + * range means the chosen CPU is in a fully idle SMT core. Values above + * ASYM_IDLE_CORE_BIAS mean we never ranked such a CPU best. * * The asym-capacity wakeup path returns from select_idle_sibling() * after this function and never runs select_idle_cpu(), so the usual * select_idle_cpu() tail that clears idle cores must live here when the * idle-core preference did not win. */ - if (prefers_idle_core && best_fits > -3) + if (prefers_idle_core && best_fits > ASYM_IDLE_CORE_BIAS) set_idle_cores(target, false); return best_cpu; -- 2.54.0