From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from SN4PR0501CU005.outbound.protection.outlook.com (mail-southcentralusazon11011050.outbound.protection.outlook.com [40.93.194.50]) (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 B5CF1322C73 for ; Mon, 8 Dec 2025 09:31:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.194.50 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765186266; cv=fail; b=T9XowdXgg0Z7cOFUR0LIdzvgQes7uONqT14zpY7zs62GmxpMpQUspBvoP69Qgyqjm1LLONu+HpzbsyOdn+88h38LRE/1jwZB4BEThCs9XHXZOkrSGaB+zplHGRZiFp/cLfhv3fpDai4lVfxOvDKzFRHd1nNayeGmtU6VI801BpU= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765186266; c=relaxed/simple; bh=2CQxfqGpnL+GSLpUdaxOHHaxAeoyO4gCwADj9aDNWHc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gi3KnV3GUy10UIOU6/bDrfI7tQjCyrzNjBu34nxth9Em188IbeR5rF4NeSqfpEXw94s7KvBpVXNXJaNDHj/W2Dr/uAfG9vGGoOF0nas/O5OE4iXz68nkXYim7uxStW4CjmRpDG5TgasMlxkU0MEeWxWDzpd4D/qbIqfh9t6lH5w= 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=glto9u7B; arc=fail smtp.client-ip=40.93.194.50 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="glto9u7B" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=I+kgpuT9xhdE/DgR2CL3T2eyMK2TXzdBJa+vlIo+cZxGXsY0imoq4+90LZZEoAfjK015a+EJ2TdjRwvMBsM1Fq1Lop5vFLOk6zbwqbXswa/gmgepmG7WkgGXRPgpScg7ksKfJ0iWp+wxmPk0BP/HL5VHbLZ3mjab2/ARxDc354Nzp0IljwdvMTZsBehMq1ZH0Vi69GbltuS8ozPkIK+ikEXJI+sLI4WS55C1TBJOcJLUCd2RG4jPWpYQr8gnn25k5bbshOy9/NKezz3nWqitFA/Gd9rpKhn3c6SUhTVCx1YvAyMO5ZA3Q8gc8fS/KXLcO0wquTn35Fd0QARthlL4aA== 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=XUTQF3QqP81Pkw+l97EnoV4YGr6Qb0rXOKbfgyejjpY=; b=afnTZ5c0vJ33nCJNAxjwJZTtAKDo+Hp/9ZNvsMDEc/bS4p1/AB9CX9hno5GMu9v+guEgtD8Aas3Y46xTCOtGu0VQoE5GTaRfM0X4Qh6R9m2w5Ac3XyMYopfFm3n1E90uJl7a295he7OXBeqXC9hA6iFi25KHyPeYNTCViY346sKekPolTc2kd5IUNyzDs3xwEtUOLJU82ss40yXZlif8ffgyEIxEGBd0n9MaWKsgMQTElluWLZMslahbZj9kN7DJBTyu3jKEQ+j3+85FHki5iiPNtZoRuIokjHlT86vF2aVUhI3Cekaui/k6sNa4QFx+aiBGBZ9BYQRcA87HoDS5Hg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.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=XUTQF3QqP81Pkw+l97EnoV4YGr6Qb0rXOKbfgyejjpY=; b=glto9u7BFu6zdj1mkRhdpHX8Zlq6PZiEAg+zDBCbnpRFdwxMDh2TjRf7m/ZzR0pNc8KEMnY77IPySETiktrn1Tm60t4/HV8GG+SqrhKCTTMmssZwC45+S3Jw4loUrFJqmplYCH0juMrRitwStQN8zWrIrDZxexMNEKRhyEoG4oU= Received: from DM6PR11CA0071.namprd11.prod.outlook.com (2603:10b6:5:14c::48) by CY1PR12MB9584.namprd12.prod.outlook.com (2603:10b6:930:fe::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9388.14; Mon, 8 Dec 2025 09:30:56 +0000 Received: from DS3PEPF0000C37C.namprd04.prod.outlook.com (2603:10b6:5:14c:cafe::8d) by DM6PR11CA0071.outlook.office365.com (2603:10b6:5:14c::48) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9388.14 via Frontend Transport; Mon, 8 Dec 2025 09:30:56 +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 DS3PEPF0000C37C.mail.protection.outlook.com (10.167.23.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9412.4 via Frontend Transport; Mon, 8 Dec 2025 09:30:56 +0000 Received: from BLRKPRNAYAK.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Mon, 8 Dec 2025 03:30:50 -0600 From: K Prateek Nayak To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner CC: , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "Gautham R. Shenoy" , Swapnil Sapkal , Shrikanth Hegde , Chen Yu Subject: [RESEND RFC PATCH v2 11/29] sched/topology: Attach new hierarchy in rq_attach_root() Date: Mon, 8 Dec 2025 09:26:57 +0000 Message-ID: <20251208092744.32737-11-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251208083602.31898-1-kprateek.nayak@amd.com> References: <20251208083602.31898-1-kprateek.nayak@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37C:EE_|CY1PR12MB9584:EE_ X-MS-Office365-Filtering-Correlation-Id: 1e528c46-5129-4090-e729-08de363c7d5b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700013|376014|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?EfgryYJpD14wrMkKfFZE5FGP/sCCy68S0KVTmYYA8u3JwNY9NkyUvV11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ioBICdwQueUxg9U6fRgj/FTX+?= =?us-ascii?Q?+6TcHPsjmkIWm6VwF5255FE0Svd0AFvy/+lR6gIFyuPiWreYGNLIPiPFap2W?= =?us-ascii?Q?X4U3hFKqgH+2z/T18PyhiIP/yzx/tpmUkS3anKtIj+sYFErGNhBrwHTQAdwn?= =?us-ascii?Q?z3O6ppluxRa3Zps6EJ3GHO1buZ27n7oTKx4KBINNIznF8R67bTQi1BAWG83e?= =?us-ascii?Q?pW4XvzDDelADevpXpMf6Fv/ASf4Ijp6wpFxCnmWyjsnsfg9K4f+9gPOrP4Va?= =?us-ascii?Q?xrznTYLHao7D4WMPu0hQ//clX2KVlOxrk7ZJkMP61V8bFDU1foQUW0hwOLHQ?= =?us-ascii?Q?jFA56UpLRZVGkd8z96c2DAz2R433gFq7jNMAUl+JwE8FYNsF9GVy9fdkHpdE?= =?us-ascii?Q?UkyS2aQPJtSSxwkoMJ4E0h0c/ycusylrew55JrX09gvOJp6pbPuFoNU/ehKR?= =?us-ascii?Q?Twndyx18cOAFirWSEfiSvUhxfrRXVaWjDxsd3+v277kQeR2Jaxk4S7TjiRSS?= =?us-ascii?Q?HryzKm2KkU3kvO+loKCVG7T+txzG3lbvOvv4VsEnUusi/O2NKw3GpYuMPtRo?= =?us-ascii?Q?/SOi73ZtT44et9VxnlX45O48vlX6PYpm9sUx+vL1lBRA8WUB8wMM9NKyWNOO?= =?us-ascii?Q?7yZML/7TocAbsKKA/gQ=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)(1800799024)(82310400026)(36860700013)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2025 09:30:56.1493 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1e528c46-5129-4090-e729-08de363c7d5b 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: DS3PEPF0000C37C.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB9584 Gregory Haskins introduced the concept of root domain in commit 57d885fea0da ("sched: add sched-domain roots") which put rq_attach_root() before rcu_assign_pointer(rq->sd, sd). Further development around dynamic sched domain allocation, and update_top_cache_domain() that came later relied on the new sched domain hierarchy and was naturaturally done after rq->sd was updated. Since subsequent changes around nohz idle CPU tracking creates a dependency for the fair_sched_class->offline() callback to use the old hierarchy and the fair_sched_class->online() callback to use the updated hierarchy, update rq->sd and the top cache domains within rq_attach_root() between the two callbacks. This modifies the flow as follows: old flow new flow ======== ======== rq_attach_root() rq_attach_root() set_rq_offline(); set_rq_offline(); /* Operate on old sd_llc */ set_rq_online(); rq->sd = sd; rq->sd = sd; update_top_cache_domain() update_top_cache_domain() set_rq_online(); /* Operate on new sd_llc */ No functional changes intended. Signed-off-by: K Prateek Nayak --- kernel/sched/core.c | 2 +- kernel/sched/sched.h | 2 +- kernel/sched/topology.c | 38 ++++++++++++++++++++++++-------------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 0c4ff93eeb78..35cb640b7266 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -8666,7 +8666,7 @@ void __init sched_init(void) INIT_LIST_HEAD(&rq->cfs_tasks); - rq_attach_root(rq, &def_root_domain); + rq_attach_root(rq, &def_root_domain, NULL); #ifdef CONFIG_NO_HZ_COMMON rq->last_blocked_load_update_tick = jiffies; atomic_set(&rq->nohz_flags, 0); diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 659e712f348f..7b0f9fbfc65b 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1044,7 +1044,7 @@ struct root_domain { extern void init_defrootdomain(void); extern int sched_init_domains(const struct cpumask *cpu_map); -extern void rq_attach_root(struct rq *rq, struct root_domain *rd); +extern void rq_attach_root(struct rq *rq, struct root_domain *rd, struct sched_domain *sd); extern void sched_get_rd(struct root_domain *rd); extern void sched_put_rd(struct root_domain *rd); diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 8870b38d4072..a212ae52cdac 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -469,9 +469,12 @@ static void free_rootdomain(struct rcu_head *rcu) kfree(rd); } -void rq_attach_root(struct rq *rq, struct root_domain *rd) +static void update_top_cache_domain(int cpu); + +void rq_attach_root(struct rq *rq, struct root_domain *rd, struct sched_domain *sd) { struct root_domain *old_rd = NULL; + int cpu = cpu_of(rq); struct rq_flags rf; rq_lock_irqsave(rq, &rf); @@ -494,6 +497,8 @@ void rq_attach_root(struct rq *rq, struct root_domain *rd) } atomic_inc(&rd->refcount); + rcu_assign_pointer(rq->sd, sd); + update_top_cache_domain(cpu); rq->rd = rd; cpumask_set_cpu(rq->cpu, rd->span); @@ -711,16 +716,27 @@ static void update_top_cache_domain(int cpu) rcu_assign_pointer(per_cpu(sd_asym_cpucapacity, cpu), sd); } +struct s_data { + struct sched_domain_shared * __percpu *sds; + struct sched_domain * __percpu *sd; + struct root_domain *rd; +}; + /* * Attach the domain 'sd' to 'cpu' as its base domain. Callers must * hold the hotplug lock. */ static void -cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu) +cpu_attach_domain(struct s_data *d, int cpu) { + struct root_domain *rd = d->rd; + struct sched_domain *sd = NULL; struct rq *rq = cpu_rq(cpu); struct sched_domain *tmp; + if (d->sd) + sd = *per_cpu_ptr(d->sd, cpu); + /* Remove the sched domains which do not contribute to scheduling. */ for (tmp = sd; tmp; ) { struct sched_domain *parent = tmp->parent; @@ -776,21 +792,13 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu) sched_domain_debug(sd, cpu); - rq_attach_root(rq, rd); tmp = rq->sd; - rcu_assign_pointer(rq->sd, sd); + rq_attach_root(rq, rd, sd); dirty_sched_domain_sysctl(cpu); destroy_sched_domains(tmp); - update_top_cache_domain(cpu); } -struct s_data { - struct sched_domain_shared * __percpu *sds; - struct sched_domain * __percpu *sd; - struct root_domain *rd; -}; - enum s_alloc { sa_rootdomain, sa_sd, @@ -2717,9 +2725,8 @@ build_sched_domains(const struct cpumask *cpu_map, struct sched_domain_attr *att rcu_read_lock(); for_each_cpu(i, cpu_map) { rq = cpu_rq(i); - sd = *per_cpu_ptr(d.sd, i); - cpu_attach_domain(sd, d.rd, i); + cpu_attach_domain(&d, i); if (lowest_flag_domain(i, SD_CLUSTER)) has_cluster = true; @@ -2824,6 +2831,9 @@ int __init sched_init_domains(const struct cpumask *cpu_map) static void detach_destroy_domains(const struct cpumask *cpu_map) { unsigned int cpu = cpumask_any(cpu_map); + struct s_data d = { + .rd = &def_root_domain, + }; int i; if (rcu_access_pointer(per_cpu(sd_asym_cpucapacity, cpu))) @@ -2834,7 +2844,7 @@ static void detach_destroy_domains(const struct cpumask *cpu_map) rcu_read_lock(); for_each_cpu(i, cpu_map) - cpu_attach_domain(NULL, &def_root_domain, i); + cpu_attach_domain(&d, i); rcu_read_unlock(); } -- 2.43.0