From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from PH8PR06CU001.outbound.protection.outlook.com (mail-westus3azon11012062.outbound.protection.outlook.com [40.107.209.62]) (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 63DE03C09F8 for ; Thu, 4 Jun 2026 05:06:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.209.62 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780549591; cv=fail; b=iSBNyOtQjHXHz/UU8rgx7YWbCUcDE0YYPBT7HoprRxX+3r2ng75Gp6/x+P4jmtahdVkf2lL+wUqbz+fX5SwA8goiMLBB4iz4ribhSMKAgKWDNlwvn7fFqXhGnpybaH3ZUheVDYRkIHlUm1T9eoBQ+A9bOIw9srH7poVC6EvBsog= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780549591; c=relaxed/simple; bh=RZVncm4vrSDL72cF/OikvL6vk/f1rmE6U7j91EC/93o=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=DVfYP9K/5AelDkZHoxju+KCftmfuyBaCCzHk42tKtQfZofqVGXppm2r/iHx200yTi2Il8yO5FOIF2MZ3RD55A72V2DFJIzFl14QSwx73J7UEtUmrl5YHicemdRvl8WphBhcf5B7ZCIXfyHC5diXhmRL4UZL+cBgfBgZ67wnOOyA= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=OwcAX+Li; arc=fail smtp.client-ip=40.107.209.62 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="OwcAX+Li" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YYf12tf6k04uHAHX27N35IfsAMm0Rje5yuUEoxMGLIaG29Lx/CKzkeiDbymhwSUMJ5qj0oInkY9NybMUV8AjdKFlYzQWvW2HP+s+m1z9p9sNTOCdtJjyhUDw1K/TByEW+hXTLqf7ZM7Q4Hcgl8aHcOpoIAqx+fhm2KqvVnEMt/SQgEsGSS5HMk9/TKCAiT5djY3JAJHjW4RDAaFaFc8SHNQW6AV9XxJME2crvscqghJaMxWqjfU+YnxO30OFy9IuJZKfxNicQiBID4Kcs0EHDMnrjdB/Eqd/WRwvDzETMgWJUL5GoVF4m48xs0QH0waRDkRQkP7N6hkl3wpTt7N87g== 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=UO/oiUn/3z0yi25zNx73inyfUyxAb8JUkQvDIGT0qnI=; b=mYGmK2VZ0Yb/0/PuiCESunV5cVIOfPOKNIIU+3VVdnRpQD3f+UL5Jth0VfifSalAzgoNfcyThcBhNAA5MT3yjHNYH3xa7wgnQzwd8kkkLbswaMzWSEsnznWJ9LePFsUHbjQyLCuepr9y0KpJEKnTul7+HyvM/JkjqM8znQOEOHcLM3nrtjPhJguHidRZP9Un2Xhhptjmey4hdWq1VcdpzZe1ykHzxkHwitNV+F+TKpvzvYSePvLVuw7KMFn8jldz28/r88009WyX18GtCS8oDwxP6hYsIvUr7YsOoAqFmUKvdF5+ytraWHAO15a9VyYNU90l86iJEgWfIyBitshZ1Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux.ibm.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UO/oiUn/3z0yi25zNx73inyfUyxAb8JUkQvDIGT0qnI=; b=OwcAX+LiAsCkAjIdxCxLw/jDo3VQ+FOUf8cwOsddgFS4/b3ZqoipD74lEf8VV3+OVWHbL5DM5wMlMoWUz2PcmNEZMS1UnQcye3G8X9JdWN58Mx3eem/0Abw/gw8HASTRuSp9MxLP9f8yRpNHAxX1SDchupLHqsOsPPYich1X9kk= Received: from MN0PR05CA0018.namprd05.prod.outlook.com (2603:10b6:208:52c::30) by CH2PR12MB4327.namprd12.prod.outlook.com (2603:10b6:610:7d::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.92.7; Thu, 4 Jun 2026 05:06:25 +0000 Received: from BL6PEPF00020E60.namprd04.prod.outlook.com (2603:10b6:208:52c:cafe::73) by MN0PR05CA0018.outlook.office365.com (2603:10b6:208:52c::30) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.92.7 via Frontend Transport; Thu, 4 Jun 2026 05:06:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb08.amd.com; pr=C Received: from satlexmb08.amd.com (165.204.84.17) by BL6PEPF00020E60.mail.protection.outlook.com (10.167.249.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.92.5 via Frontend Transport; Thu, 4 Jun 2026 05:06:25 +0000 Received: from satlexmb08.amd.com (10.181.42.217) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Thu, 4 Jun 2026 00:06:24 -0500 Received: from [10.136.33.4] (10.180.168.240) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server id 15.2.2562.41 via Frontend Transport; Thu, 4 Jun 2026 00:06:16 -0500 Message-ID: Date: Thu, 4 Jun 2026 10:36:15 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 06/20] sched/core: allow only preferred CPUs in is_cpu_allowed To: Shrikanth Hegde , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , References: <20260514152204.481115-1-sshegde@linux.ibm.com> <20260514152204.481115-7-sshegde@linux.ibm.com> Content-Language: en-US From: K Prateek Nayak In-Reply-To: <20260514152204.481115-7-sshegde@linux.ibm.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF00020E60:EE_|CH2PR12MB4327:EE_ X-MS-Office365-Filtering-Correlation-Id: 55a5b104-9f54-4d7c-44c9-08dec1f70770 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|36860700016|82310400026|11063799006|6133799003|22082099003|18002099003|56012099006|4143699003; X-Microsoft-Antispam-Message-Info: F0lweibYXwF6Nqr06I30KIPVgi/4keDm3ywkvXByb5wH+B7jGdpbF4zCOerh158cM6iu9ZKRnhXtCGB4qhDFLja1P04f9w5frYsw3gQ2lhiC8B5r3TOrrAhAoENCPITqx8wUSmSqZGciulsYOr5pmpdHdc+o8YSGQCk4P5RxGgtk5+Z33UYnxJtQqOZLny+xmdNXVexdTx62rTdz6pltueyOGYKZAqRukoGSbdcfxO3K+eGrrbitf9ANar//QCR6dzmqGIpFlu4GQvvTqfHfh/kEQWLXxjE4pwL0URLydEz8RxKXHtc2wT+nct/Y79nZD3WeG1PO/SH2yIe6YzCX9l+t1QRPnDC9yigOX7hHIcAS4hISZNmsy+02QtnFIGdiRlUmpBJtIVb9NNuHTpMq8uEhuDvVJ/NW8DTIGYX9sVQVQomEP7v1nhUV7AQI1EZkwJlTjWbVKAAw5W/XDoSPPP+ZPY3GxQr9wpw8pLeiqQspRmueZ++SBAmMPrtgIS2lvYUyjEP4P2p0hcxVI0GEUAepk+pVsNeInFjofR6Nutm+vqMWISA95JWXkXRFYPxAfDamJCSm0hvErIcV2XRVyt7YHgqn9abfkImlTKi972mjHyEMKAXJlX2sx//T9YBFJ1MNFfk5tHKGMXD0bmEtwf4ygEoG65DqUByzy5bTrKAiKJkV1bs1Uo6BvFPT1yra3g1Ll3UWv9i+TfLiu8E4nsD58+shApWt6MiLK/0YAZo= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb08.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(376014)(7416014)(36860700016)(82310400026)(11063799006)(6133799003)(22082099003)(18002099003)(56012099006)(4143699003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: phvdsnbhYu6oRVzRiaZjGNPF+oim8zJ9yqqvArspPj13vDbHDQ7Hgl5q4Hun9SrvXSD9jF5nXfblHdRYIDlK0KX9kTTzvYfZh5MHi1DO/9q+fOxmu7RcJRkap+JIGxSCvyu8aAvGuYu554mAZG/37OkGImuz3ILfVUTdMjmtZM9+Q474+TQ/6qZadJdVZ6TqBenza0Qd0OG3IlvoOjtp1QMqTDPnGK65079/rsN45PiTIq6LRCq+MhDocE24myHiZLnJKe+z/uAqHO3FA6P2ZizJnMQVjyTZ4/+iFFbOfhE8PfdPzZ/gFxAH28pR1YKVEdKhHQspqAKirt/ihx5H9zDuIGL96GzrYfysvR0eS0ifzHM+VCBZNdVmN4eB/lRP9kKnMinviixypyIDOGN+fsaLiTMSCIuQ47ueLyLknzaVjhI3KKuG0SUBFz9tYEVB X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jun 2026 05:06:25.8683 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 55a5b104-9f54-4d7c-44c9-08dec1f70770 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb08.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF00020E60.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4327 Hello Shrikanth, On 5/14/2026 8:51 PM, Shrikanth Hegde wrote: > + /* > + * This is essential to maintain user affinities when preferred > + * CPUs change. A task pinned on non-preferred CPU should continue > + * to run there, since this is non-user triggered. > + * > + * For majority of the cases this would still keep select_fallback_rq > + * as O(N). task_has_preferred_cpus which is O(N) is called only if > + * !cpu_preferred. Then task running there is expected to move out. > + * So subsequent it should run on preferred CPU. This becomes O(N**2) > + * only for tasks pinned only non preferred CPUs. That is rare case. > + */ > + task_has_preferred_cpu = !cpu_preferred(cpu) && task_has_preferred_cpus(p); For this O(N**2) bit, can't we cache the result of cpumask_intersect() in the task_struct similar to "p->sched_task_hot" when entering select_fallback_rq() and clear it at the end? > + > /* Non kernel threads are not allowed during either online or offline. */ > - if (!(p->flags & PF_KTHREAD)) > - return cpu_active(cpu); > + if (!(p->flags & PF_KTHREAD)) { > + if (!cpu_active(cpu)) > + return false; > + if (task_has_preferred_cpu) > + return false; Shouldn't this return true at the end here for cpu_active() && !task_has_preferred_cpu? Essentially, this: diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 77a172f31862..3bf7e3c4d518 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2489,6 +2489,7 @@ static inline bool is_cpu_allowed(struct task_struct *p, int cpu) return false; if (task_has_preferred_cpu) return false; + return true; } /* KTHREAD_IS_PER_CPU is always allowed. */ --- Otherwise, it starts evaluating kthread bits for user tasks. > + } > > /* KTHREAD_IS_PER_CPU is always allowed. */ > if (kthread_is_per_cpu(p)) -- Thanks and Regards, Prateek