From nobody Thu Oct 2 04:51:51 2025 Received: from fra-out-014.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-014.esa.eu-central-1.outbound.mail-perimeter.amazon.com [18.199.210.3]) (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 D8E733074BD for ; Mon, 22 Sep 2025 12:40:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=18.199.210.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758544820; cv=none; b=mkQaMn1fcx3reCsRh2hVQTVKcfImho3De1UtNxOqoWHYZ74M/k9kUwkHdpjgvFIIVTn6KxCuCC2G56fmyr94tI/IcaQD1u6s4yKVfuY9de3tX/bmauyxYNUtBtIrtlBdnTxIeqsV3L3JyvDsnMx8XZE65AMNpo1J10rY8wLMhqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758544820; c=relaxed/simple; bh=39eC2m8LomvJUbPd0x6YvKOxV7n7FU1/dvMN0kt6RNg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jJG150hHFaYy6eFFpwcw7SbeCU7rQwPhvkZN9fJHXVJ1BL3iaXbLW28oleToPbcv1lybqOD6focb9261CjmeOj0qCLqY9H1BvGfgtsiIsuZDG6GP/qKGjoMiY2AddRPEX1e1gWwO/5WJXlrqb0/U4kLVoAx8fMht2D2bERZmCqM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b=PO8kMW9h; arc=none smtp.client-ip=18.199.210.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b="PO8kMW9h" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1758544819; x=1790080819; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RLJmOk9CHgieXzTT5gl1bkuWDqTXwImg9yrbL4Lw1WA=; b=PO8kMW9h3oJIzabrZ532mY0eM/10WfJ6MmNBtgjuW5IlkCeVHBeFB9Pe AslUMV8/7BdDp23M4LXOi/WIVBGTxFF0qVbeINYlZNl+zxLazuEnsjeYb oZKY4hEYnBDO6lovLPfRhycZRIulPixF0f0v43akRXNW+DPsyIorkuAzc 7GdeLvApk745bbDLeFSZC6vXGYvZz2QJ7abS4Y6QDtaQNj2SNv1/CYUHY SnwiTxz6LMIOdisspGGXbM5GDd9zlThtryPybzImGJgLXRN0OQUp61gg1 wEjSlHV6FrO+om2i9dcoway5mdzt7IAA4no8PTjXycF7FfUqUGGfPXhDz w==; X-CSE-ConnectionGUID: KcywKFZBQuCrVC8ld1TY5g== X-CSE-MsgGUID: 1SnE9fZpTF+uR5e8YD2SpQ== X-IronPort-AV: E=Sophos;i="6.18,285,1751241600"; d="scan'208";a="2379604" Received: from ip-10-6-6-97.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.6.97]) by internal-fra-out-014.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2025 12:40:08 +0000 Received: from EX19MTAEUC001.ant.amazon.com [54.240.197.225:31291] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.33.43:2525] with esmtp (Farcaster) id cc76c455-72b7-44b5-8a43-38c608c38c7a; Mon, 22 Sep 2025 12:40:08 +0000 (UTC) X-Farcaster-Flow-ID: cc76c455-72b7-44b5-8a43-38c608c38c7a Received: from EX19D003EUB001.ant.amazon.com (10.252.51.97) by EX19MTAEUC001.ant.amazon.com (10.252.51.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 12:40:06 +0000 Received: from u5934974a1cdd59.ant.amazon.com (10.146.13.222) by EX19D003EUB001.ant.amazon.com (10.252.51.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 12:40:00 +0000 From: Fernand Sieber To: , CC: , , , , , , , , , , , Subject: [PATCH 1/4] sched/fair: Fix cookie check on __select_idle_cpu() Date: Mon, 22 Sep 2025 14:39:22 +0200 Message-ID: <64ca6d7f73625cc63fa0bc1800c9b199462a5ef3.1758543008.git.sieberf@amazon.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D035UWB002.ant.amazon.com (10.13.138.97) To EX19D003EUB001.ant.amazon.com (10.252.51.97) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The __select_idle_cpu() function uses sched_cpu_cookie_match() to determine if a task can be placed on an idle CPU. This function incorrectly returns false when the whole core is idle but the task has a cookie, preventing proper task placement. Replace sched_cpu_cookie_match() with sched_core_cookie_match() which correctly handles the idle core case. Refactor select_idle_smt() to avoid duplicate work by checking core cookie compatibility only once in the SMT mask. Fixes: 97886d9dcd868 ("sched: Migration changes for core scheduling") Signed-off-by: Fernand Sieber --- kernel/sched/fair.c | 5 ++++- kernel/sched/sched.h | 14 -------------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index b173a059315c..43ddfc25af99 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -7447,7 +7447,7 @@ static inline int sched_balance_find_dst_cpu(struct s= ched_domain *sd, struct tas static inline int __select_idle_cpu(int cpu, struct task_struct *p) { if ((available_idle_cpu(cpu) || sched_idle_cpu(cpu)) && - sched_cpu_cookie_match(cpu_rq(cpu), p)) + sched_core_cookie_match(cpu_rq(cpu), p)) return cpu; =20 return -1; @@ -7546,6 +7546,9 @@ static int select_idle_smt(struct task_struct *p, str= uct sched_domain *sd, int t { int cpu; =20 + if (!sched_core_cookie_match(cpu_rq(target), p)) + return -1; + for_each_cpu_and(cpu, cpu_smt_mask(target), p->cpus_ptr) { if (cpu =3D=3D target) continue; diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index be9745d104f7..4e7080123a4c 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1386,15 +1386,6 @@ extern void task_vruntime_update(struct rq *rq, stru= ct task_struct *p, bool in_f * A special case is that the task's cookie always matches with CPU's core * cookie if the CPU is in an idle core. */ -static inline bool sched_cpu_cookie_match(struct rq *rq, struct task_struc= t *p) -{ - /* Ignore cookie match if core scheduler is not enabled on the CPU. */ - if (!sched_core_enabled(rq)) - return true; - - return rq->core->core_cookie =3D=3D p->core_cookie; -} - static inline bool sched_core_cookie_match(struct rq *rq, struct task_stru= ct *p) { bool idle_core =3D true; @@ -1468,11 +1459,6 @@ static inline raw_spinlock_t *__rq_lockp(struct rq *= rq) return &rq->__lock; } =20 -static inline bool sched_cpu_cookie_match(struct rq *rq, struct task_struc= t *p) -{ - return true; -} - static inline bool sched_core_cookie_match(struct rq *rq, struct task_stru= ct *p) { return true; --=20 2.43.0 Amazon Development Centre (South Africa) (Proprietary) Limited 29 Gogosoa Street, Observatory, Cape Town, Western Cape, 7925, South Africa Registration Number: 2004 / 034463 / 07 From nobody Thu Oct 2 04:51:51 2025 Received: from fra-out-004.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-004.esa.eu-central-1.outbound.mail-perimeter.amazon.com [3.74.81.189]) (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 CF403308F08 for ; Mon, 22 Sep 2025 12:40:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=3.74.81.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758544827; cv=none; b=k6MVEXEgs5twX94wXD1z/8RiQ2KU+5JS+iNCdOEMPrXkk28C0Mj6E2tLJ4XOMRHArhl8G4MokGlS2FHprrz55yJLVnwI/qIrYOoXi1WzECCnu8a6NrRZfbdoN48wVXdZEToHLO2sFdVLCZoWcfuqdiHqW8LA7VOKI6gt0uKeMfg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758544827; c=relaxed/simple; bh=/lGoL1yFTeaAJo+p/08Px2KgHWPnnxEGStFVGbqonfw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=n31Ele5gGMY3bw6Zn3C8lH6VeywaEgJGeoQp5BKtSzhar4swYloTDWbhH/699pMT7Goi4D+/S8yaR/stXYil9GMwe5+kn/nbPNC+QkIFoYwzjOW1DGAbxh9HyU/8MZJnvY5ch7MFCR1OQeRJhh3f5LQm/XnviNTvLaT5u0CjLk8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b=CmqLbo2f; arc=none smtp.client-ip=3.74.81.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b="CmqLbo2f" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1758544826; x=1790080826; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=onGsTLIeK7VNe4TI9Csjky6vfaTM2IQytblGmkdw2ww=; b=CmqLbo2fgvzSkW8UzK+NFkkOr82HMeAZxA1O7/b25WNx7U59XgeBm8IR zXxPM0EJ+neZ/802OzybLj1qci1rNggy28FrbzeOcz+K/S44yfZ2L8QMl 2T5k/MdIH/S3quc3StOlwGbn4Y3H0/lttI9KFf9yyJR8mdBpxTYValeOM l67a9CRBLRMZXh10pAAxwH0KJ2RO1cAu7VupUehPSrxBOENFHZOjpanBF gytlThpOd/nQwzBj2cTR/8U5dffO+FF6HdZ5LZ3HGkfNp/h+Jo3U5dGoh wq7ZrPD9zGPMT1d66vZtbX3c81fGm6uJb+QCnC49OianarzK71yMovEVj Q==; X-CSE-ConnectionGUID: ZkHR7wrxSZ6nVcaAuxVzyA== X-CSE-MsgGUID: wlrGUOg+RayN14vjkVhcQw== X-IronPort-AV: E=Sophos;i="6.18,285,1751241600"; d="scan'208";a="2483909" Received: from ip-10-6-11-83.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.11.83]) by internal-fra-out-004.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2025 12:40:14 +0000 Received: from EX19MTAEUA001.ant.amazon.com [54.240.197.233:2157] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.38.97:2525] with esmtp (Farcaster) id cd3a0e7f-5359-42d6-9b31-8ff496d17386; Mon, 22 Sep 2025 12:40:14 +0000 (UTC) X-Farcaster-Flow-ID: cd3a0e7f-5359-42d6-9b31-8ff496d17386 Received: from EX19D003EUB001.ant.amazon.com (10.252.51.97) by EX19MTAEUA001.ant.amazon.com (10.252.50.192) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 12:40:14 +0000 Received: from u5934974a1cdd59.ant.amazon.com (10.146.13.222) by EX19D003EUB001.ant.amazon.com (10.252.51.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 12:40:07 +0000 From: Fernand Sieber To: , CC: , , , , , , , , , , , Subject: [PATCH 2/4] sched/fair: Still look for the idlest cpu with no matching cookie Date: Mon, 22 Sep 2025 14:39:23 +0200 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D035UWB002.ant.amazon.com (10.13.138.97) To EX19D003EUB001.ant.amazon.com (10.252.51.97) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The slow path for waking tasks currently discards all potential targets when no cookie-matching CPU is found, leading to suboptimal task placement. Fall back to selecting the idlest CPU when no cookie-matching target is available, ensuring better CPU utilization while maintaining the preference for cookie-compatible placements. Signed-off-by: Fernand Sieber --- kernel/sched/fair.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 43ddfc25af99..67746899809e 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -7335,7 +7335,8 @@ sched_balance_find_dst_group(struct sched_domain *sd,= struct task_struct *p, int * sched_balance_find_dst_group_cpu - find the idlest CPU among the CPUs i= n the group. */ static int -sched_balance_find_dst_group_cpu(struct sched_group *group, struct task_st= ruct *p, int this_cpu) +__sched_balance_find_dst_group_cpu(struct sched_group *group, struct task_= struct *p, + int this_cpu, bool cookie_match) { unsigned long load, min_load =3D ULONG_MAX; unsigned int min_exit_latency =3D UINT_MAX; @@ -7352,7 +7353,8 @@ sched_balance_find_dst_group_cpu(struct sched_group *= group, struct task_struct * for_each_cpu_and(i, sched_group_span(group), p->cpus_ptr) { struct rq *rq =3D cpu_rq(i); =20 - if (!sched_core_cookie_match(rq, p)) + /* Only matching tasks if cookie_match, else only unmatching tasks */ + if (cookie_match ^ sched_core_cookie_match(rq, p)) continue; =20 if (sched_idle_cpu(i)) @@ -7391,6 +7393,17 @@ sched_balance_find_dst_group_cpu(struct sched_group = *group, struct task_struct * return shallowest_idle_cpu !=3D -1 ? shallowest_idle_cpu : least_loaded_c= pu; } =20 +/* + * sched_balance_find_dst_group_cpu - find the idlest CPU among the CPUs i= n the group. + */ +static inline int +sched_balance_find_dst_group_cpu(struct sched_group *group, struct task_st= ruct *p, int this_cpu) +{ + int cpu =3D __sched_balance_find_dst_group_cpu(group, p, this_cpu, true); + + return cpu >=3D 0 ? cpu : __sched_balance_find_dst_group_cpu(group, p, th= is_cpu, false); +} + static inline int sched_balance_find_dst_cpu(struct sched_domain *sd, stru= ct task_struct *p, int cpu, int prev_cpu, int sd_flag) { --=20 2.43.0 Amazon Development Centre (South Africa) (Proprietary) Limited 29 Gogosoa Street, Observatory, Cape Town, Western Cape, 7925, South Africa Registration Number: 2004 / 034463 / 07 From nobody Thu Oct 2 04:51:51 2025 Received: from fra-out-005.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-005.esa.eu-central-1.outbound.mail-perimeter.amazon.com [63.176.194.123]) (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 941883081A8 for ; Mon, 22 Sep 2025 12:41:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=63.176.194.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758544874; cv=none; b=naxfEQxlu+fB7NM10zWVvEI2ItVpEX9BIgxl52Q3wNg1F0Jb8D0aT+hNEap7ntW/XVHDh3/5wXphtEGOi794bBoyRQHhvvsZahnGJrXyvrx+dDJKR6WmNyvd6ngT1wKlFra75qDXMOsu05gKUMhpEZlRwn1iLuQLCfy0nx6HyTw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758544874; c=relaxed/simple; bh=lHiyIX9bGuVzwTz5m0YFqeLu0Dr0xvsVn8gw4+3KUmk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=V5MivTVvdU0dbZKrS3i/flRA2NFSTyd5qz/lysgA/2BsY4tziJIXE41v8JE4052y0R/nUf8qPFrE6tyydK0N5imFu7eRg/pBTKkdXHVyuXWMDWV0Y+uwfRelpyAlVLvJtbJtZ0MDrLGSET0Ryt7U8V7FXGKJnrVFpr8tBpVD2s8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b=LKDkbZje; arc=none smtp.client-ip=63.176.194.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b="LKDkbZje" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1758544871; x=1790080871; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YySKg3TXYuCaKbbwvti+jSac7ZDfip0GnEqCMdXQqXE=; b=LKDkbZjevGMGFsnWr7ypkiylewekibmK0WTcX5GYzTecbWJBL8vXthW1 CzZmLAb8tnwUfaButFUHDuF3ALp2On/8tZ1U8JAT0DQGQP2ymKiVmwUwG cNk6gdKmiegBT8/deKrQdsswJKdNyOsFjTgdZVFyNPVSqOCxgpEWinySp OOi7memTq5IlzJ8PoOsXrTwSS/ZrllLnaVGlVO3Qv1LigjWqsP2JygAkF LSgorLPLoSKsWigsI5danjwUY6LFSLnRYZTCDFiZWnhfDuwV2ptEBm3RM bm56HRDj6XZKKi2VB86l0foYuugR+ljj2rSTVA/iv6e0KVLW5uATm+emX g==; X-CSE-ConnectionGUID: 6j5+wCStTCC31FN1JHIYSA== X-CSE-MsgGUID: tmg5z7jXRuKbnkwM4dLTOA== X-IronPort-AV: E=Sophos;i="6.18,285,1751241600"; d="scan'208";a="2484248" Received: from ip-10-6-11-83.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.11.83]) by internal-fra-out-005.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2025 12:40:58 +0000 Received: from EX19MTAEUA001.ant.amazon.com [54.240.197.233:4387] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.2.208:2525] with esmtp (Farcaster) id bacbf2c8-65f9-45d0-b9c4-8c261b6287b2; Mon, 22 Sep 2025 12:40:58 +0000 (UTC) X-Farcaster-Flow-ID: bacbf2c8-65f9-45d0-b9c4-8c261b6287b2 Received: from EX19D003EUB001.ant.amazon.com (10.252.51.97) by EX19MTAEUA001.ant.amazon.com (10.252.50.192) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 12:40:57 +0000 Received: from u5934974a1cdd59.ant.amazon.com (10.146.13.222) by EX19D003EUB001.ant.amazon.com (10.252.51.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 12:40:50 +0000 From: Fernand Sieber To: , CC: , , , , , , , , , , , Subject: [PATCH 3/4] sched/fair: Add cookie checks on wake idle path Date: Mon, 22 Sep 2025 14:39:24 +0200 Message-ID: <64a2df7604e82d42a966b62b479479a97d545e76.1758543008.git.sieberf@amazon.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D044UWB003.ant.amazon.com (10.13.139.168) To EX19D003EUB001.ant.amazon.com (10.252.51.97) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The wake_affine_idle() function determines whether the previous CPU or the waking CPU are suitable for running a waking task. Currently it does not consider core scheduling constraints. Add cookie compatibility checks to prevent considering a CPU idle when placing the task there would immediately cause force idle due to an incompatible sibling task. This reduces unnecessary force idle scenarios in the wake-up path. Signed-off-by: Fernand Sieber --- kernel/sched/fair.c | 19 +++++++++++++------ kernel/sched/sched.h | 33 ++++++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 67746899809e..78b36225a039 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -7235,7 +7235,7 @@ static int wake_wide(struct task_struct *p) * for the overloaded case. */ static int -wake_affine_idle(int this_cpu, int prev_cpu, int sync) +wake_affine_idle(struct task_struct *p, int this_cpu, int prev_cpu, int sy= nc) { /* * If this_cpu is idle, it implies the wakeup is from interrupt @@ -7249,17 +7249,24 @@ wake_affine_idle(int this_cpu, int prev_cpu, int sy= nc) * a cpufreq perspective, it's better to have higher utilisation * on one CPU. */ - if (available_idle_cpu(this_cpu) && cpus_share_cache(this_cpu, prev_cpu)) - return available_idle_cpu(prev_cpu) ? prev_cpu : this_cpu; + if (available_idle_cpu(this_cpu) && + cpus_share_cache(this_cpu, prev_cpu) && + sched_core_cookie_match(cpu_rq(this_cpu), p)) { + return available_idle_cpu(prev_cpu) && + sched_core_cookie_match(cpu_rq(prev_cpu), p) ? + prev_cpu : this_cpu; + } =20 if (sync) { struct rq *rq =3D cpu_rq(this_cpu); =20 - if ((rq->nr_running - cfs_h_nr_delayed(rq)) =3D=3D 1) + if (((rq->nr_running - cfs_h_nr_delayed(rq)) =3D=3D 1) && + sched_core_cookie_match_sync(rq, p)) return this_cpu; } =20 - if (available_idle_cpu(prev_cpu)) + if (available_idle_cpu(prev_cpu) && + sched_core_cookie_match(cpu_rq(prev_cpu), p)) return prev_cpu; =20 return nr_cpumask_bits; @@ -7314,7 +7321,7 @@ static int wake_affine(struct sched_domain *sd, struc= t task_struct *p, int target =3D nr_cpumask_bits; =20 if (sched_feat(WA_IDLE)) - target =3D wake_affine_idle(this_cpu, prev_cpu, sync); + target =3D wake_affine_idle(p, this_cpu, prev_cpu, sync); =20 if (sched_feat(WA_WEIGHT) && target =3D=3D nr_cpumask_bits) target =3D wake_affine_weight(sd, p, this_cpu, prev_cpu, sync); diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 4e7080123a4c..97cc8c66519e 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1386,27 +1386,41 @@ extern void task_vruntime_update(struct rq *rq, str= uct task_struct *p, bool in_f * A special case is that the task's cookie always matches with CPU's core * cookie if the CPU is in an idle core. */ -static inline bool sched_core_cookie_match(struct rq *rq, struct task_stru= ct *p) +static inline bool __sched_core_cookie_match(struct rq *rq, + struct task_struct *p, + bool sync) { - bool idle_core =3D true; int cpu; =20 /* Ignore cookie match if core scheduler is not enabled on the CPU. */ if (!sched_core_enabled(rq)) return true; =20 + if (rq->core->core_cookie =3D=3D p->core_cookie) + return true; + for_each_cpu(cpu, cpu_smt_mask(cpu_of(rq))) { - if (!available_idle_cpu(cpu)) { - idle_core =3D false; - break; - } + if (sync && cpu_of(rq) =3D=3D cpu) + continue; + if (!available_idle_cpu(cpu)) + return false; } =20 /* * A CPU in an idle core is always the best choice for tasks with * cookies. */ - return idle_core || rq->core->core_cookie =3D=3D p->core_cookie; + return true; +} + +static inline bool sched_core_cookie_match(struct rq *rq, struct task_stru= ct *p) +{ + return __sched_core_cookie_match(rq, p, false); +} + +static inline bool sched_core_cookie_match_sync(struct rq *rq, struct task= _struct *p) +{ + return __sched_core_cookie_match(rq, p, true); } =20 static inline bool sched_group_cookie_match(struct rq *rq, @@ -1464,6 +1478,11 @@ static inline bool sched_core_cookie_match(struct rq= *rq, struct task_struct *p) return true; } =20 +static inline bool sched_core_cookie_match_sync(struct rq *rq, struct task= _struct *p) +{ + return true; +} + static inline bool sched_group_cookie_match(struct rq *rq, struct task_struct *p, struct sched_group *group) --=20 2.43.0 Amazon Development Centre (South Africa) (Proprietary) Limited 29 Gogosoa Street, Observatory, Cape Town, Western Cape, 7925, South Africa Registration Number: 2004 / 034463 / 07 From nobody Thu Oct 2 04:51:51 2025 Received: from fra-out-005.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-005.esa.eu-central-1.outbound.mail-perimeter.amazon.com [63.176.194.123]) (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 70166308F1A for ; Mon, 22 Sep 2025 12:41:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=63.176.194.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758544871; cv=none; b=lO/bhpw0hGbbl9bxEqk8ACeYLTHEwNziL024wf9Bq++KkFlVuyjJ6u8bleRrygg6TyV3jptEm+MihpUuzHmLwogMtVCD4zyxnQ3LWnT7yJlTJw5CyqDzJK7E0LdQuh5WISI0TTkc5UBgGHC/SvaHCKCf/UFaIdBhuTh6AE8hiUk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758544871; c=relaxed/simple; bh=9k4asiHFcCuAOaOpFe1BOMBARruZk7/0jebnh+l4Mw0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PWX787qP314+wZvvK9mqU891LCfOn9CTOONr4hfZKWn8fXCqczNFXMgiteQp1y3pFeVevSO/ygNRi4WoHSKVkxs1OyxQvXUB1dDg/RMXsmgnq9RetizI/zc8MH/51AteucfNa0VTQChauxxCd3NfUS3sbxk6KD1m5xJvlJ673sE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b=YSucknLi; arc=none smtp.client-ip=63.176.194.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b="YSucknLi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1758544868; x=1790080868; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6ZftVsvw9ECNftLFUV1PeW6Cl8JH9hXM5u/v1PG+AFI=; b=YSucknLicgKroa51JxxXb7WWkq7kOrQKfD12H4Q2r9Ewf2gKJ87/UwlS GAusd/cYTfcVcIUnO1Hvh3gwdiDXUh7/x/U+dvdliorWqNApp4jDDKMft jyuHPyT7erspZDPH72XXmLaP0Lzx8LdgyR2/0RO2OnR8re/y2AFGfqwFf EGSYTkA59UID8Ja59yf0sLOIAssnm2N7ZTZEkuFGUnidLcwCpoToI31VY CBtrQ4+tdowXZfj1AdKkEDZAbccqtP/7B16/KtZB5SP1Ec5EZrGPTuhdq 3v42+Z8lLmgyRFFQX+PVr+NAangfxyOVWmyLH2DOsnotPdOvUu/Qgg+OD A==; X-CSE-ConnectionGUID: tnYAuXy4S3yXcpkkX6a9eg== X-CSE-MsgGUID: GXVDan9ASqufDS9Zzldorg== X-IronPort-AV: E=Sophos;i="6.18,285,1751241600"; d="scan'208";a="2484259" Received: from ip-10-6-11-83.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.11.83]) by internal-fra-out-005.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2025 12:41:05 +0000 Received: from EX19MTAEUA002.ant.amazon.com [54.240.197.232:15731] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.23.230:2525] with esmtp (Farcaster) id 7e3dc8b9-c5d0-4925-9eb4-d7bf2020d9a6; Mon, 22 Sep 2025 12:41:05 +0000 (UTC) X-Farcaster-Flow-ID: 7e3dc8b9-c5d0-4925-9eb4-d7bf2020d9a6 Received: from EX19D003EUB001.ant.amazon.com (10.252.51.97) by EX19MTAEUA002.ant.amazon.com (10.252.50.124) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 12:41:04 +0000 Received: from u5934974a1cdd59.ant.amazon.com (10.146.13.222) by EX19D003EUB001.ant.amazon.com (10.252.51.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 12:40:57 +0000 From: Fernand Sieber To: , CC: , , , , , , , , , , , Subject: [PATCH 4/4] sched/fair: Add more core cookie check in wake up fast path Date: Mon, 22 Sep 2025 14:39:25 +0200 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D044UWB003.ant.amazon.com (10.13.139.168) To EX19D003EUB001.ant.amazon.com (10.252.51.97) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Fernand Sieber --- kernel/sched/fair.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 78b36225a039..a9cbb0e9bb43 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -7578,7 +7578,7 @@ static int select_idle_smt(struct task_struct *p, str= uct 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) !=3D -1) return cpu; } =20 @@ -7771,7 +7771,7 @@ static int select_idle_sibling(struct task_struct *p,= int prev, int target) */ lockdep_assert_irqs_disabled(); =20 - if ((available_idle_cpu(target) || sched_idle_cpu(target)) && + if ((__select_idle_cpu(target, p) !=3D -1) && asym_fits_cpu(task_util, util_min, util_max, target)) return target; =20 @@ -7779,7 +7779,7 @@ static int select_idle_sibling(struct task_struct *p,= int prev, int target) * If the previous CPU is cache affine and idle, don't be stupid: */ if (prev !=3D target && cpus_share_cache(prev, target) && - (available_idle_cpu(prev) || sched_idle_cpu(prev)) && + (__select_idle_cpu(prev, p) !=3D -1) && asym_fits_cpu(task_util, util_min, util_max, prev)) { =20 if (!static_branch_unlikely(&sched_cluster_active) || @@ -7811,7 +7811,7 @@ static int select_idle_sibling(struct task_struct *p,= int prev, int target) if (recent_used_cpu !=3D prev && recent_used_cpu !=3D target && cpus_share_cache(recent_used_cpu, target) && - (available_idle_cpu(recent_used_cpu) || sched_idle_cpu(recent_used_cp= u)) && + (__select_idle_cpu(recent_used_cpu, p) !=3D -1) && cpumask_test_cpu(recent_used_cpu, p->cpus_ptr) && asym_fits_cpu(task_util, util_min, util_max, recent_used_cpu)) { =20 --=20 2.43.0 Amazon Development Centre (South Africa) (Proprietary) Limited 29 Gogosoa Street, Observatory, Cape Town, Western Cape, 7925, South Africa Registration Number: 2004 / 034463 / 07