From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from SA9PR02CU001.outbound.protection.outlook.com (mail-southcentralusazon11013063.outbound.protection.outlook.com [40.93.196.63]) (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 CA9D978F26 for ; Fri, 21 Nov 2025 02:54:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.196.63 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763693672; cv=fail; b=WSn25sRAUMVHB2VTWURREaU/rBFnToBIlodsvb/faBx2XiEer8wZeCrQE/SVA07se9P8Tj2RVeuxyiiAzpTxFYWHCtTEhufQukk07rQ7PazGFunlsVmAjPOFZuNP2kf/3fcBzfYYexQ3EHbxD6dqilfROez+q2zYutBtkh56MCk= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763693672; c=relaxed/simple; bh=hDYcz056+PtvYZf8YcllB9agtQ7Ni53KBfWMj7F3xxw=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=UoJFFBUFmFSEw59UWxe6iTq0IbmxCK5syOnToT6uQlMwnDGh0HxBGBGoWL2u6H54Ire+H6iloSMZMKG/ETomojSdNrV1/RFseObrRAm0cs0AXaSUUYF1gtxLAfoWPbW+lkLS1AWsI8t7j1MSVNM9qTiEdXeA4U1CYkRYUvJWnD8= 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=PF9goRWr; arc=fail smtp.client-ip=40.93.196.63 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="PF9goRWr" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HlCXypjltUeW5NueC1NViep33kkAWIqHLS6oTWGEFo42oFUSwGFWD3hY54F9GUv8v4OOpW84g258CKY5ENVRGhhh6vTB68E3tkoW68s12FtIe2u7qVNn78zQ8o/jFcia9Y+7/Gavw/VUBW4XmM1S1Lx7lSre287IXNNvbC22Bqlzt2dzkiJ7caCc7ruHwiI9eXVqUV3GQ7CAQ9LZH6YByy8hxJjjc6GjU7nIhGGkbnQA653hErbwvAG9NsUPSqgFC5TC4ago58x/YuGRLdoj+X8mes+XmQEP4QrINMP7+KALTk/7FnHuY5f4/QACy9fVbn8st4GtbNRUEWrCL7Pqtg== 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=W/Sm+3L3dW0YLpv8wMy2lC8rSV7xw3VpAj/FgBNYqMk=; b=pogLvTQx3AztXHhAed/dr46XcjEfBgkX9Un1tMM6TXxzja+713PGf/HUSHXNXPthzXlJF/QcJXb2oSdaM8y3APzzpgJJ2VADHpWLa28I1Fa+PyFU5FJ63V67zNmHLNCpgpzJqKqGqYPscGNvC0phls7egTGcQQ10LNXYXk7KrBswsXV0qe1ryb9+jb2mLlwZ/K2PrsYy58JIsQcSXe4uI7sWPoYNJvKLRmRY70PVlVKtkFVXKUIJJ1olLILtUSCX3dhw57oB2q97xfpcYwvr8brFuJ2ubBNCioiNIJRw1WuoEV2KArg0zVOb5tOkuDTeiqjUHFa20X88L/4Wa1scpA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=amazon.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=W/Sm+3L3dW0YLpv8wMy2lC8rSV7xw3VpAj/FgBNYqMk=; b=PF9goRWr8TtJW69O/8uQ1/3AigeRvSAvaWCLFU4CUYLsY2qv+E43kTfwYmu1nvC//vOre8S/XsQUKCsSEsr7qniXZ0Gn5nLmldoZQ6Tk5KubFy41yxPMCGpsI5FYRibB1dzCHFyfIARb5PrgNslLrn0CJMrk4ktWefhm8V+nCQY= Received: from SA0PR11CA0154.namprd11.prod.outlook.com (2603:10b6:806:1bb::9) by DS0PR12MB999082.namprd12.prod.outlook.com (2603:10b6:8:302::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9343.11; Fri, 21 Nov 2025 02:54:27 +0000 Received: from SN1PEPF000252A4.namprd05.prod.outlook.com (2603:10b6:806:1bb:cafe::72) by SA0PR11CA0154.outlook.office365.com (2603:10b6:806:1bb::9) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9343.11 via Frontend Transport; Fri, 21 Nov 2025 02:54: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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SN1PEPF000252A4.mail.protection.outlook.com (10.167.242.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9343.9 via Frontend Transport; Fri, 21 Nov 2025 02:54:27 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.17; Thu, 20 Nov 2025 18:54:27 -0800 Received: from satlexmb07.amd.com (10.181.42.216) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 20 Nov 2025 20:54:26 -0600 Received: from [10.136.37.179] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server id 15.2.2562.17 via Frontend Transport; Thu, 20 Nov 2025 18:54:23 -0800 Message-ID: <92c22ad2-d84c-44e4-b34f-a80f7f3748a6@amd.com> Date: Fri, 21 Nov 2025 08:24:17 +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] sched/fair: Add more core cookie check in wake up fast path To: Fernand Sieber , , CC: , , , , , , , , , , References: <20251120101955.968586-1-sieberf@amazon.com> Content-Language: en-US From: K Prateek Nayak In-Reply-To: <20251120101955.968586-1-sieberf@amazon.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF000252A4:EE_|DS0PR12MB999082:EE_ X-MS-Office365-Filtering-Correlation-Id: b7b78baa-643c-4e5e-b382-08de28a94940 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|376014|7416014|7053199007; X-Microsoft-Antispam-Message-Info: =?utf-8?B?SkdZa0VQOHZnNnJObWlpb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f-8?B?dkR3VXdnZk45TTVINWZXbUh6eXpkc3Y1dUNxcUF4S2pJSVAycm1Va1BMbkdv?= =?utf-8?B?cXM2NzZwUjhYaHRoYy8vdVNjcFV2RHdoQS8yMmQrVVFSbG9qSEhjSTJlMkNs?= =?utf-8?B?UHROY3VOUjI5UnRWazBBVmVmVk9uSnBFMmdTNEwzZ1lEZUFOS3hMOHJTcDk5?= =?utf-8?B?VDlpT0dvcnkya2R6SktqQnpKTzNJbE5EMi9FR2lYeEtrWWMzaUlxQk45OWxI?= =?utf-8?B?Yld5bUNBL0dvWEVZenJ1aCtwUUpLaXVyQWQwdHNkakVOcTg2SWF3SXcyQVov?= =?utf-8?Q?C3ZY=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(1800799024)(376014)(7416014)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2025 02:54:27.6100 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b7b78baa-643c-4e5e-b382-08de28a94940 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF000252A4.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB999082 Hello Fernand, On 11/20/2025 3:49 PM, Fernand Sieber wrote: > The fast path in select_idle_sibling() can place tasks on CPUs without > considering core scheduling constraints, potentially causing immediate > force idle when the sibling runs an incompatible task. > > Add cookie compatibility checks before selecting a CPU in the fast path. > This prevents placing waking tasks on CPUs where the sibling is running > an incompatible task, reducing force idle occurrences. > > Testing > ======= > > Perf testing using 10 threads on 8 CPUs on a platform with each core > sporting two hyperthreads. > Each thread is running 1200 iterations of a cycle consisting of a random > period of work between 0-10ms followed by a random period of sleep 0-30ms. > > The goal of this configuration is to apply a light load on the system > (33%), with randomization causing opportunities for scheduling placement > including all cases of idle cores, partially idle cores and fully busy > cores. > > Each test configuration is run 3 times and time to work completion is > measured and averaged. First configuration doesn't use cookies, second > configuration groups the 10 threads in 5 pairs of cookies, third > configuration also groups the 10 threads in 5 pairs of cookies, but with > this patch applied. > > Test Results (seconds) > > Configuration Run 1 Run 2 Run 3 Average Overhead > No cookie 24.653 24.454 24.586 24.564 0.000 > Cookie 25.896 26.256 25.979 26.044 1.480 > Cookie + patch 25.346 25.007 25.042 25.132 0.568 > > The patch reduces cookie overhead by 61.7% (0.568/1.480 = 0.383) Thank you for including the benchmark numbers. > > Signed-off-by: Fernand Sieber > --- > kernel/sched/fair.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 5b752324270b..90ceb3da2251 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -7647,7 +7647,7 @@ static int select_idle_smt(struct task_struct *p, struct sched_domain *sd, int t > */ > if (!cpumask_test_cpu(cpu, sched_domain_span(sd))) > continue; > - if (available_idle_cpu(cpu) || sched_idle_cpu(cpu)) > + if (__select_idle_cpu(cpu, p) != -1) > return cpu; > } > > @@ -7841,6 +7841,7 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target) > lockdep_assert_irqs_disabled(); > > if ((available_idle_cpu(target) || sched_idle_cpu(target)) && > + sched_core_cookie_match(cpu_rq(target), p) && nit. You can replace the whole (available_idle_cpu() || sched_idle_cpu()) && sched_core_cookie_match() with "__select_idle_cpu() != 1" but since this pattern keeps repeating, you can perhaps extract it into a helper __is_idle_cpu() that returns a boolean and you can add a follow up cleanup to convert all the: idle_cpu = __select_idle_cpu(cpu, p); if ((unsigned int)idle_cpu < nr_cpumask_bits) return idle_cpu; pattern to: if (__is_idle_cpu(cpu, p)) return cpu; after which select_idle_core() for !CONFIG_SCHED_SMT would be the only user of __select_idle_cpu() and you can move that entire logic into the select_idle_core() function. Thoughts? Apart from that, these changes look good to me since they are making all the idle cpu checks along the wakeup path consistent with those in select_idle_cpu() so feel free to add: Reviewed-by: K Prateek Nayak > asym_fits_cpu(task_util, util_min, util_max, target)) > return target; > > @@ -7849,6 +7850,7 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target) > */ > if (prev != target && cpus_share_cache(prev, target) && > (available_idle_cpu(prev) || sched_idle_cpu(prev)) && > + sched_core_cookie_match(cpu_rq(prev), p) && > asym_fits_cpu(task_util, util_min, util_max, prev)) { > > if (!static_branch_unlikely(&sched_cluster_active) || > @@ -7881,6 +7883,7 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target) > recent_used_cpu != target && > cpus_share_cache(recent_used_cpu, target) && > (available_idle_cpu(recent_used_cpu) || sched_idle_cpu(recent_used_cpu)) && > + sched_core_cookie_match(cpu_rq(recent_used_cpu), p) && > cpumask_test_cpu(recent_used_cpu, p->cpus_ptr) && > asym_fits_cpu(task_util, util_min, util_max, recent_used_cpu)) { > -- Thanks and Regards, Prateek