From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from PH0PR06CU001.outbound.protection.outlook.com (mail-westus3azon11011071.outbound.protection.outlook.com [40.107.208.71]) (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 AAF4B357CE5 for ; Fri, 3 Jul 2026 09:40:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.208.71 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783071633; cv=fail; b=hxBe20vgrO43DAb7auFYIRp1M8rP1vyBAcaPvVAYCXN/LNDoXssTo78OX/5pnrC+ywemOXPa+lHsIAsHnqeLJLdEkwIRpnu/gbiVlxJyieik5m52JM0R3+3MiIYDGb+Ekr9T89+ExIYwo6fmKU9wocdkrbguouaRxryCfrEx3ZU= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783071633; c=relaxed/simple; bh=QGmb6oQ5XzVeCK3klw0dGaUnXpkV4Qr6t/xs0MlZqTA=; h=Date:From:To:Cc:Subject:Message-ID:References:Content-Type: Content-Disposition:In-Reply-To:MIME-Version; b=nsaPIW+hwC6dUxIK1LYZvHFOReEyQ264fMCtOY9wuau91u/IlsH/p80YGT4QvbAW06R5QawAAlE0On0BY2orGsbqUpDR6OGPuuM3rPVBjKaOCmeZIUErf7cvskIISuLQOm9U2DbycPioxxu7Mgcaf03vxRwhayw/kAEtPFOJpfI= 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=mK3WU/n+; arc=fail smtp.client-ip=40.107.208.71 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="mK3WU/n+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=H/mxAoWIHPz5B8W3csOQFNjy9KqrNbWXY+ubBZbYN8tCfQtrAcZLwijxJzI2Mils8q5//1PXe9Q3S3UjL5YX+TRnyToLUohTysEDkvALdAAiFRfkFOXveq2Z9ps/IS8poo+FO6lBn+p6M3O3w/weobB19JtRp//hx0fGlNp1W+LVzVwq256nopFMuFfFvOyTzIoddKwqtdChNDcEcWJ325+7U5TYlGpabezND0LjdbIqec2g+cCiFyvz+urrtBPhjoGPwabt/73Pi1StV7KSRHrzSuRrJCRqmmlQdrFJUAZouPvSSCOjFO6gQRx+AZfRkMNb3CleJb710b+by4cMkw== 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=4tePsUbe3bNo/FKldhDGhobPS26quURpijm9kISrHBA=; b=PiKoGf3TFNsNsaEOUimSMGuIxXBV165pvy/Gtg6+c0JSQHaD7Gn8QbY7sTwMQbkWAGvggmt4KeTmJJKyRktWhQTpNx6Uv7a3s2vAtcKlKX86jJ4K/EMglBNnD03iovcEmSCkO6rbe17iYSbuHjzuNC1b+zMAescYL7E377VMoANEiZJcvpVmPak0MfLN+oFpYXyYorHio+D3/NI1JjFhB66RizdfRPfgqKseGH4KfIwOq1Ljd185WMo+NT37i0PejAW/G+ohPQV6lRNNmJ3ZgdQBGbsKCtDcnAS12ewkVARvk8Gs/VSRQHb8fkrodHj0yRAp8NWSN3D2g9aAaIAiuw== 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=4tePsUbe3bNo/FKldhDGhobPS26quURpijm9kISrHBA=; b=mK3WU/n+7lijNg/2CzQeccpfqaSu7TX9ZnjxmJjmljZJGjEiOY+wzLbjse+2ajd3dB/SEP+xxPys4YR+aRHpQIJ+6wZp18knp1ucw9PH4vEflUWnHKA7d5nMuGN44WROQNe9Qs9kqiTTsYaXWv5krK7qSAJGfvKg9RiECxiNXF4EV0QG7Sk2skc9bPEUcJRPSoorFoiO7PJJDf4fhiaP8Ft/gvIVFgcYAHaBJUfzBxNkjD2MO2JNAwTqPO6SC2iUmZs3LI9r5aTyP4s7++dSvA0L52ORiWsofKAzul+fSGAOBKDcA7JynKKr91rtrl51L3AeMJNxUp7UY1ggt3rMxw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4827.namprd12.prod.outlook.com (2603:10b6:5:1d6::14) by PH7PR12MB5928.namprd12.prod.outlook.com (2603:10b6:510:1db::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.181.10; Fri, 3 Jul 2026 09:40:27 +0000 Received: from DM6PR12MB4827.namprd12.prod.outlook.com ([fe80::6261:3040:864b:159c]) by DM6PR12MB4827.namprd12.prod.outlook.com ([fe80::6261:3040:864b:159c%3]) with mapi id 15.21.0181.010; Fri, 3 Jul 2026 09:40:27 +0000 Date: Fri, 3 Jul 2026 11:40:18 +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 , Ricardo Neri , Christian Loehle , Shrikanth Hegde , Felix Abecassis , Joel Fernandes , Phil Auld , linux-kernel@vger.kernel.org, Julia Lawall Subject: Re: [PATCH] sched/fair: Stabilize idle SMT core selection with asym-capacity Message-ID: References: <20260630152747.128746-1-arighi@nvidia.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: ZRAP278CA0014.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:10::24) To DM6PR12MB4827.namprd12.prod.outlook.com (2603:10b6:5:1d6::14) 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: DM6PR12MB4827:EE_|PH7PR12MB5928:EE_ X-MS-Office365-Filtering-Correlation-Id: 26f2df68-b358-4f05-cffc-08ded8e71ca6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|7416014|376014|1800799024|366016|6133799003|11063799006|56012099006|4143699003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: o/bRk7lbeaAupt6mt4bfI7DbF0b1irAgsQYpfibgcuWQKGnNwWv1NWXGsclqaMRJPve6/T+evDaaKny/vA2l8VGoP4tiZzIFcWg0J8qDe+N9t9lhsvgLj9l9+vSuS9ZEPY79aUd54gurDBDGcIzR+FNyJetKAg4Z+oYobzPxi5iWyYDLEhW7AcEZf03Lvo6kJQ9uRgjqgN3+j3N/u5LCG8woUrVP015DC4r95qP/okxGrEBu/IXD0HGgoLFJdGxtxJpYv7NHawJirt7xjwUa+9fvnkF0Mf7NJ9eN6kUmvgn7pyoYJVXRAYrJ4gWQVM/x/VFaJxIWuzGg4fljjbvPoqz6oeZ6U23DOADePokJAreLjxKSO6glQ07shTv8GhlobV0Ox19x+R4w/ZWRz1qPt3auTIN+CGvigz8qjEFaDKW+EN42kaKu1hQXSQFt2RGFTarRtuzjPdXWamUSGNoAZVZRLgQpiJgEY8w9vfXtOXnr7mTHO52zTFYsTDvxlIII5n55GzbtHuTDpWRemCo7rrH3e1FYUx+RmdTSWN1fH6EQU7CRd+epg3xRiR5ikMmC+uPqfKEYe586EU9dE6nhqRBET3v8ofsSvwv/NsFDVqHI1fFRfj0QuhyVtuiGU7PiLFysaXgtCP3HXK3BbhZ5NOajOtHVIAzZx7RRmT6lwPA= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4827.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(7416014)(376014)(1800799024)(366016)(6133799003)(11063799006)(56012099006)(4143699003)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?BjIZf9ZZ+wg2ysWvpDvltEqeJThF5eMCFXKzssEEczIu6dG5yzK+Qrn8F5Pg?= =?us-ascii?Q?6M4Bcy6VOhdd4mXy73YEvvyhXOZTRbojsLr+Irg0mpnT6parJSyavDWT1Bes?= =?us-ascii?Q?eHzGmc/S463AYM6q3FGy96HXU1eznhsrm4XifvR/uqWWz/BScj5H/hKuHT/s?= =?us-ascii?Q?FN1nfGKT2LFaii0lLLeb0sG616HjPk1IRj5mAAdGNuhLugsE/IThPv7v8Hoz?= =?us-ascii?Q?rc+ReBeyfm/HJOIkH5T4NJZ4B8vQvWAMrNYdv7Z2EfY7EokKhJZpTPCasZww?= =?us-ascii?Q?K1OP8dHbTr4rTFwSmVq8jVaC0yjHo8/UF4xp+kDsCw8qctmeS0ytUuk8t7DV?= =?us-ascii?Q?Nxhi/QG06slbjqy1HzS/XxhsMdXy++HVKSMS2tOxLX51EswC5wXZ8lFmTH+Q?= =?us-ascii?Q?QLnEIpxLGlsIQEC0xtd/cz1Wjy5F/S4Ix91uc5VY/uN0EneHpbwiXQMUnTT2?= =?us-asc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sfMW4kfDRw1?= =?us-ascii?Q?4UmoZ7LmfS20XKGK601Sl6C4dgTnjY/RiReQ63Bk1tszSn5TuTIrQE9MawOI?= =?us-ascii?Q?F28AWrurlJ2prb3nkbjFFsf9FizGds9NPEjaE8rLxmBB5rymb9yvrKyq+Z9S?= =?us-ascii?Q?y8j6edx91x3ijyx3NcyPPxOhP/WERe25aT19KF3PegXpDhfy30RxJLSFsUJt?= =?us-ascii?Q?VQyjlWTyutISnqZvAW391SxOnvAjeB7DvYwpYlcN4tA+9BxBHq+gu4kO33ro?= =?us-ascii?Q?ZSM6fQTRjOpkucBGtO/7PA19aXGSmzihxh4Dl3VbJK2DgIYfagCMCS/VdSY+?= =?us-ascii?Q?q8fo/q8ZPJqq2BUTnMYj9CZQ8Yj9VgAlIFTyNsk9q6PQuUyETqaSMmKwE3qI?= =?us-ascii?Q?ouhrDCS3Sw=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 26f2df68-b358-4f05-cffc-08ded8e71ca6 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4827.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2026 09:40:27.0909 (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: mLgvm6FGdNQIyFNIO+f+fUKyOCEFzTC7+6IXeyRsa1dfWjpkxjkP1MsNL0LnDLOqJIYdXc9IbO3BBB9WDKdJ3w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5928 Hi Prateek, On Fri, Jul 03, 2026 at 11:21:57AM +0530, K Prateek Nayak wrote: > Hello Andrea, > > On 6/30/2026 8:57 PM, Andrea Righi wrote: > > select_idle_capacity() scans all logical CPUs also when it is looking > > for a fully idle SMT core. Two concurrent wakeups can therefore observe > > the same core as idle, encounter different siblings first, and place one > > task on each sibling while another core remains unused. > > > > Make every logical CPU of a selected idle core resolve to the same > > stable CPU representative within the scan's existing affinity and > > scheduling-domain mask. If the first task is enqueued before the next > > scan examines the core, that scan rejects the now-busy core. If both > > scans observe the core as idle, they select the same runqueue even if > > the first enqueue becomes visible before the second scan finishes, > > exposing the imbalance to the load balancer. > > > > The symmetric CPU idle selection path is subject to the same race, but > > normally returns as soon as select_idle_core() finds a fully idle core, > > reducing the conflict window. The per-CPU capacity scan can retain an > > idle-core candidate while evaluating other CPUs, giving concurrent > > wakeups more opportunity to select different siblings of the same SMT > > core. Therefore, limit the normalization to the asym-capacity path, > > where this behavior has a measurable impact. > > > > On NVIDIA Vera Rubin (arm64, 176 CPUs/88 cores per NUMA node), a > > CPU-intensive NVPL SGEMM workload restricted to 88 threads (one per > > core) showed a consistent 23% increase in mean throughput across > > multiple runs. > > Interesting! This reads like active balance across cores is not aggressive > enough for this workload and, as a result, stacking somehow helps. > > I would have expected balance within the core would trigger first and that > would just lead to the same scenario as both sibling sibling busy but I > guess there is a higher order effect of stacking. I think the key here is that temporary runqueue stacking is preferable to consuming both SMT siblings when fully-idle SMT cores are available, more than having benfits from the stacking itself. > > perf sched stats reports for this workload before and after > applying your patch may help to see what changes for the load > balancer to start doing better. Ack, I'll collect some perf stats and share. > > Could you check if something like this helps: > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index fc6cd55f9d22..f50f12316dd3 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -13221,7 +13221,8 @@ imbalanced_active_balance(struct lb_env *env) > * threads on a system with spare capacity > */ > if ((env->migration_type == migrate_task) && > - (sd->nr_balance_failed > sd->cache_nice_tries+2)) > + ((sd->groups->flags & SD_SHARE_CPUCAPACITY) || > + sd->nr_balance_failed > sd->cache_nice_tries+2)) I did a quick test and I don't see any significant difference with this applied. Let's see if the perf stats tell us more. > return 1; > > return 0; > --- > > I'm assuming we have group_has_spare for the destination CPU and the > busy core appears as group_fully_busy or group_has_spare. > calculate_imbalance() will take the sibling_imbalance() path since we > are balancing amongst cores (SD_PREFER_SIBLING domain) and we get > "migrate_task" with imbalance of 1. > > Then we single down on a rq with a single task on it but that requires > active balance and need_active_balance() is too slow as a result of > imbalanced_active_balance() bailout on cache_nice_tries which requires > at least 3 failures and on a 176 CPUs system, it can take upwards of > 176 ticks per retry and with 250Hz tick, that time goes into seconds > which might be too late. > > I remember Julia had similar problem where balancing was taking too > long and setting very aggressive "min_interval" and "max_interval" for > load balancing helped her. Maybe you can try that too: > > # Needed to toggle /sys/kernel/debug/sched/domains/* visible > echo Y > /sys/kernel/debug/sched/verbose > for i in /sys/kernel/debug/sched/domains/cpu*/domain[1-5]/*_interval; do echo 10 > $i; done > echo N > /sys/kernel/debug/sched/verbose > > This will ensure there is one balance every 10 ticks on domains above > SMT. You can try make it more aggressive to see if that helps too. Tried this as well (both with the patched and unpatched kernels), also no measurable difference. > > > > > For comparison, DCPerf MediaWiki running at system saturation (with all > > SMT siblings busy) showed neither a benefit nor a regression: throughput > > and Nginx request latency remained within measurement error. > > > > Likewise, schbench under partially idle conditions showed no material > > change in wakeup latency, request latency, or throughput (within 0.1%). > > Tail wakeup latency was more consistent across runs with this change > > applied. > > > > Signed-off-by: Andrea Righi > > --- > > kernel/sched/fair.c | 19 +++++++++++++++++-- > > 1 file changed, 17 insertions(+), 2 deletions(-) > > > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > > index d78467ec6ee13..f846fbe7379f4 100644 > > --- a/kernel/sched/fair.c > > +++ b/kernel/sched/fair.c > > @@ -8647,6 +8647,16 @@ enum asym_fits_state { > > ASYM_IDLE_CORE_BIAS = -3, > > }; > > > > +/* > > + * Return a stable CPU representative of @cpu's SMT core within @cpus. > > + */ > > +static int select_idle_core_cpu(int cpu, const struct cpumask *cpus) > > +{ > > + int sibling = cpumask_first_and(cpu_smt_mask(cpu), cpus); > > + > > + return sibling < nr_cpu_ids ? sibling : cpu; > > +} > > + > > /* > > * 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 > > @@ -8661,6 +8671,7 @@ select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int target) > > * collapses to the plain capacity scan. > > */ > > bool has_idle_core = sched_smt_active() && test_idle_cores(target); > > + bool best_idle_core = false; > > unsigned long task_util, util_min, util_max, best_cap = 0; > > int fits, best_fits = ASYM_IDLE_THREAD_MISFIT; > > int cpu, best_cpu = -1; > > @@ -8686,7 +8697,8 @@ select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int target) > > } > > > > for_each_cpu_wrap(cpu, cpus, target) { > > - bool preferred_core = !has_idle_core || is_core_idle(cpu); > > + bool idle_core = !sched_smt_active() || is_core_idle(cpu); > > + bool preferred_core = !has_idle_core || idle_core; > > Do you want to take overhead of is_core_idle() for !has_idle_core too? > Wouldn't a simple: > > /* True iff has_idle_core was true and is_core_idle() returned true. */ > bool idle_core = !has_idle_core ^ preferred_core; > > after computing preferred_core do just fine? Ah yes, or maybe something this, which looks a bit more readable: bool preferred_core = !has_idle_core || is_core_idle(cpu); bool idle_core = has_idle_core && preferred_core; Thanks, -Andrea