From nobody Tue Oct 7 10:35:43 2025 Received: from sender4-op-o15.zoho.com (sender4-op-o15.zoho.com [136.143.188.15]) (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 703052E4248; Thu, 10 Jul 2025 10:59:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.15 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752145164; cv=pass; b=VwNtIapGRRUk7hcI1Ev8eG/8soTd55zcsbXrVHAwkNTKseTwliLlmJlj1GuD8On42LkqBwcY4G/+dwmFJVrbBlvEpsdnS4v4SMVxte80lGFjE98hVT8CVmKSg1ibNLwbg6BSUyJp73fUwZtn/IwWwumb06G1qwGZTTpJbCuqBKA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752145164; c=relaxed/simple; bh=oNtAYai84O7Ncz6uzZ8RkEZayoUac4hgAsSQiW5DxeM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WHrC9JxbSdhy1/COEFj9lS029pU5JJDr3EfG3bCUxZxgg4D55hEJElZegXK6SqtKQyCZay2NWGTWL6SGXFKOWD1O67PzZraMMLXTQJVXX1DvT0Dk+b9Cu4sAWpQVRDRU8AzAh5TEf6V5TR28wvJqcMcpJNSyJFsr+xaJE9Nj1is= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux.beauty; spf=pass smtp.mailfrom=linux.beauty; dkim=pass (1024-bit key) header.d=linux.beauty header.i=me@linux.beauty header.b=XG/EuUFr; arc=pass smtp.client-ip=136.143.188.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux.beauty Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.beauty Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.beauty header.i=me@linux.beauty header.b="XG/EuUFr" ARC-Seal: i=1; a=rsa-sha256; t=1752145052; cv=none; d=zohomail.com; s=zohoarc; b=ZBGAHjspqPm4xCjCCo138Zi9x3j/3l1KpbRRGtuh4JEiWlqzVu2tAkirgwQBSb4wXy2vFcXnlthtxBSroK8ovXg6uOjLK9ZP7OWGn/BxxksB9rO5lW7yz213Te8uyly/jfCAuZYo9tmJXjr4HrDvOdE0bvfVW0lD9UkZSUU5jok= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752145052; h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=fovm6MYKiboCe5FxyWaHfC+A2oY5VAqlOylsUIo+kbo=; b=HiYjxHRpCQmXGSXVqRWXAdSk0tmJhrIgD5hqIaOWPznJimODP5H3U6hMr3AytUzbX5y8xzzpWmGhrW/zYm6z8U5S+obDwLvDk4EiCEQfuHzczNnzhXyXWRtAtACppzYv6/tQYNLe/O1FqNWU1AlmlNpuoQIHjJHzCfBpDEf+5S4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=linux.beauty; spf=pass smtp.mailfrom=me@linux.beauty; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1752145052; s=zmail; d=linux.beauty; i=me@linux.beauty; h=From:From:To:To:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To:Cc; bh=fovm6MYKiboCe5FxyWaHfC+A2oY5VAqlOylsUIo+kbo=; b=XG/EuUFr+Dd3e5Kj/dqUEReF1ky87KXHsTziwAlxhnoYtxCWLbqWQYg1nWdAsQRs W3YcXaSCPPKz0C9Dzaro97Wf68bHl12Ulkxktc8R6yLHUxYCQagpjD5oistX7CGArDR 5BdlAHAKtIJsRS3X22wefieFt+q1DMj2TvTxVfpM= Received: by mx.zohomail.com with SMTPS id 1752145051054917.4579948465466; Thu, 10 Jul 2025 03:57:31 -0700 (PDT) From: Li Chen To: "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , x86@kernel.org, "H . Peter Anvin" , "Rafael J . Wysocki" , "Peter Zijlstra" , "Sohil Mehta" , "Brian Gerst" , "Patryk Wlazlyn" , linux-kernel@vger.kernel.org, Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Li Chen , Huacai Chen , Bibo Mao , Tobias Huschle , Mete Durlu , Joel Granados , Guo Weikang , K Prateek Nayak , Swapnil Sapkal , linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org Subject: [PATCH v5 1/4] smpboot: introduce SDTL_INIT() helper to tidy sched topology setup Date: Thu, 10 Jul 2025 18:57:07 +0800 Message-ID: <20250710105715.66594-2-me@linux.beauty> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250710105715.66594-1-me@linux.beauty> References: <20250710105715.66594-1-me@linux.beauty> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" From: Li Chen Define a small SDTL_INIT(maskfn, flagsfn, name) macro and use it to build t= he sched_domain_topology_level array. Purely a cleanup; behaviour is unchanged. Signed-off-by: Li Chen Suggested-by: Thomas Gleixner Tested-by: K Prateek Nayak Reviewed-by: K Prateek Nayak --- arch/powerpc/kernel/smp.c | 34 +++++++++++++--------------------- arch/s390/kernel/topology.c | 10 +++++----- arch/x86/kernel/smpboot.c | 21 ++++++--------------- include/linux/sched/topology.h | 4 ++-- kernel/sched/topology.c | 24 ++++++++---------------- 5 files changed, 34 insertions(+), 59 deletions(-) diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c index 5ac7084eebc0b..0b7ab7d2eb142 100644 --- a/arch/powerpc/kernel/smp.c +++ b/arch/powerpc/kernel/smp.c @@ -1700,28 +1700,20 @@ static void __init build_sched_topology(void) #ifdef CONFIG_SCHED_SMT if (has_big_cores) { pr_info("Big cores detected but using small core scheduling\n"); - powerpc_topology[i++] =3D (struct sched_domain_topology_level){ - smallcore_smt_mask, powerpc_smt_flags, SD_INIT_NAME(SMT) - }; - } else { - powerpc_topology[i++] =3D (struct sched_domain_topology_level){ - cpu_smt_mask, powerpc_smt_flags, SD_INIT_NAME(SMT) - }; - } + powerpc_topology[i++] =3D + SDTL_INIT(smallcore_smt_mask, powerpc_smt_flags, SMT); + } else + powerpc_topology[i++] =3D SDTL_INIT(cpu_smt_mask, powerpc_smt_flags, SMT= ); #endif - if (shared_caches) { - powerpc_topology[i++] =3D (struct sched_domain_topology_level){ - shared_cache_mask, powerpc_shared_cache_flags, SD_INIT_NAME(CACHE) - }; - } - if (has_coregroup_support()) { - powerpc_topology[i++] =3D (struct sched_domain_topology_level){ - cpu_mc_mask, powerpc_shared_proc_flags, SD_INIT_NAME(MC) - }; - } - powerpc_topology[i++] =3D (struct sched_domain_topology_level){ - cpu_cpu_mask, powerpc_shared_proc_flags, SD_INIT_NAME(PKG) - }; + if (shared_caches) + powerpc_topology[i++] =3D + SDTL_INIT(shared_cache_mask, powerpc_shared_cache_flags, CACHE); + + if (has_coregroup_support()) + powerpc_topology[i++] =3D + SDTL_INIT(cpu_mc_mask, powerpc_shared_proc_flags, MC); + + powerpc_topology[i++] =3D SDTL_INIT(cpu_cpu_mask, powerpc_shared_proc_fla= gs, PKG); =20 /* There must be one trailing NULL entry left. */ BUG_ON(i >=3D ARRAY_SIZE(powerpc_topology) - 1); diff --git a/arch/s390/kernel/topology.c b/arch/s390/kernel/topology.c index 3df048e190b11..46569b8e47dde 100644 --- a/arch/s390/kernel/topology.c +++ b/arch/s390/kernel/topology.c @@ -531,11 +531,11 @@ static const struct cpumask *cpu_drawer_mask(int cpu) } =20 static struct sched_domain_topology_level s390_topology[] =3D { - { cpu_thread_mask, cpu_smt_flags, SD_INIT_NAME(SMT) }, - { cpu_coregroup_mask, cpu_core_flags, SD_INIT_NAME(MC) }, - { cpu_book_mask, SD_INIT_NAME(BOOK) }, - { cpu_drawer_mask, SD_INIT_NAME(DRAWER) }, - { cpu_cpu_mask, SD_INIT_NAME(PKG) }, + SDTL_INIT(cpu_thread_mask, cpu_smt_flags, SMT), + SDTL_INIT(cpu_coregroup_mask, cpu_core_flags, MC), + SDTL_INIT(cpu_book_mask, NULL, BOOK), + SDTL_INIT(cpu_drawer_mask, NULL, DRAWER), + SDTL_INIT(cpu_cpu_mask, NULL, PKG), { NULL, }, }; =20 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 58ede3fa6a75b..445127df2cb19 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -485,35 +485,26 @@ static void __init build_sched_topology(void) int i =3D 0; =20 #ifdef CONFIG_SCHED_SMT - x86_topology[i++] =3D (struct sched_domain_topology_level){ - cpu_smt_mask, cpu_smt_flags, SD_INIT_NAME(SMT) - }; + x86_topology[i++] =3D SDTL_INIT(cpu_smt_mask, cpu_smt_flags, SMT); #endif #ifdef CONFIG_SCHED_CLUSTER - x86_topology[i++] =3D (struct sched_domain_topology_level){ - cpu_clustergroup_mask, x86_cluster_flags, SD_INIT_NAME(CLS) - }; + x86_topology[i++] =3D SDTL_INIT(cpu_clustergroup_mask, x86_cluster_flags,= CLS); #endif #ifdef CONFIG_SCHED_MC - x86_topology[i++] =3D (struct sched_domain_topology_level){ - cpu_coregroup_mask, x86_core_flags, SD_INIT_NAME(MC) - }; + x86_topology[i++] =3D SDTL_INIT(cpu_coregroup_mask, x86_core_flags, MC); #endif /* * When there is NUMA topology inside the package skip the PKG domain * since the NUMA domains will auto-magically create the right spanning * domains based on the SLIT. */ - if (!x86_has_numa_in_package) { - x86_topology[i++] =3D (struct sched_domain_topology_level){ - cpu_cpu_mask, x86_sched_itmt_flags, SD_INIT_NAME(PKG) - }; - } + if (!x86_has_numa_in_package) + x86_topology[i++] =3D SDTL_INIT(cpu_cpu_mask, x86_sched_itmt_flags, PKG); =20 /* * There must be one trailing NULL entry left. */ - BUG_ON(i >=3D ARRAY_SIZE(x86_topology)-1); + BUG_ON(i >=3D ARRAY_SIZE(x86_topology) - 1); =20 set_sched_topology(x86_topology); } diff --git a/include/linux/sched/topology.h b/include/linux/sched/topology.h index e54e7fa76ba63..0d5daaa277b75 100644 --- a/include/linux/sched/topology.h +++ b/include/linux/sched/topology.h @@ -196,8 +196,8 @@ struct sched_domain_topology_level { extern void __init set_sched_topology(struct sched_domain_topology_level *= tl); extern void sched_update_asym_prefer_cpu(int cpu, int old_prio, int new_pr= io); =20 - -# define SD_INIT_NAME(type) .name =3D #type +#define SDTL_INIT(maskfn, flagsfn, dname) ((struct sched_domain_topology_l= evel) \ + { .mask =3D maskfn, .sd_flags =3D flagsfn, .name =3D #dname }) =20 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL) extern void rebuild_sched_domains_energy(void); diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 8e06b1d22e91e..d01f5a49f2e7a 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -1737,17 +1737,17 @@ sd_init(struct sched_domain_topology_level *tl, */ static struct sched_domain_topology_level default_topology[] =3D { #ifdef CONFIG_SCHED_SMT - { cpu_smt_mask, cpu_smt_flags, SD_INIT_NAME(SMT) }, + SDTL_INIT(cpu_smt_mask, cpu_smt_flags, SMT), #endif =20 #ifdef CONFIG_SCHED_CLUSTER - { cpu_clustergroup_mask, cpu_cluster_flags, SD_INIT_NAME(CLS) }, + SDTL_INIT(cpu_clustergroup_mask, cpu_cluster_flags, CLS), #endif =20 #ifdef CONFIG_SCHED_MC - { cpu_coregroup_mask, cpu_core_flags, SD_INIT_NAME(MC) }, + SDTL_INIT(cpu_coregroup_mask, cpu_core_flags, MC), #endif - { cpu_cpu_mask, SD_INIT_NAME(PKG) }, + SDTL_INIT(cpu_cpu_mask, NULL, PKG), { NULL, }, }; =20 @@ -2008,23 +2008,15 @@ void sched_init_numa(int offline_node) /* * Add the NUMA identity distance, aka single NODE. */ - tl[i++] =3D (struct sched_domain_topology_level){ - .mask =3D sd_numa_mask, - .numa_level =3D 0, - SD_INIT_NAME(NODE) - }; + tl[i++] =3D SDTL_INIT(sd_numa_mask, NULL, NODE); =20 /* * .. and append 'j' levels of NUMA goodness. */ for (j =3D 1; j < nr_levels; i++, j++) { - tl[i] =3D (struct sched_domain_topology_level){ - .mask =3D sd_numa_mask, - .sd_flags =3D cpu_numa_flags, - .flags =3D SDTL_OVERLAP, - .numa_level =3D j, - SD_INIT_NAME(NUMA) - }; + tl[i] =3D SDTL_INIT(sd_numa_mask, cpu_numa_flags, NUMA); + tl[i].numa_level =3D j; + tl[i].flags =3D SDTL_OVERLAP; } =20 sched_domain_topology_saved =3D sched_domain_topology; --=20 2.50.0 From nobody Tue Oct 7 10:35:43 2025 Received: from sender4-op-o15.zoho.com (sender4-op-o15.zoho.com [136.143.188.15]) (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 980A52E11B6 for ; Thu, 10 Jul 2025 10:59:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.15 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752145192; cv=pass; b=P0FpYszh8hPB8NuIM5ir8+hRj1qtI/V7Gtr/SeBpqHb3JFugWdmYOG5/GDTIyXB+TI2dMz8efYoCuI9rPpbKKxo48lEDEpldXcI4w2Ttf4DS/ETafV8tM+aQUE8NVdulyOv+Vg8tsGm6dmZLJSSUkPYMVoncd8zOLlkg0ZEZ7UM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752145192; c=relaxed/simple; bh=h9EYkzHtNDOmnM18XSlhyO9ckZKRO1SqUT9iLmhZXGA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nNIZqziIq/xzp8UBInQ4yrOJUyTGfTL5FIxizp+p+Bj9pCmWOZ+7vC1QyQxu0aO6evKXe9SQ+qa7inJVBNXrgulR05vNzXPycAeVBiNVg3161i4fa7Ut8//0/PhfhGNaI9zigvWQfubBtN6UlA2tjsrS7l3fkJ+G4aO+qAkEjIw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux.beauty; spf=pass smtp.mailfrom=linux.beauty; dkim=pass (1024-bit key) header.d=linux.beauty header.i=me@linux.beauty header.b=B7qr5mHF; arc=pass smtp.client-ip=136.143.188.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux.beauty Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.beauty Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.beauty header.i=me@linux.beauty header.b="B7qr5mHF" ARC-Seal: i=1; a=rsa-sha256; t=1752145058; cv=none; d=zohomail.com; s=zohoarc; b=Pe69LzQ5w8UObvZprD+M5gR47LBZFzJn5y5GRKG6wCTmjds22EKZIIakdZWOLF8XZ29GyJtH00LnTrWntBbezBKdw2gA7xOwV1A7r83OX4ICcm5DFOUt6FLieYSFwVHN9GfMvHEmp2Ab1LX7S0YR+N/DlTifz6q8cqP1TcwReFo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752145058; h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=amHXm20+VUY9kF5uInegJd53eq5CHYGSBoZSobGAG/U=; b=F7snErw9kya9RwLueLjPQcEeTWAgjncywHZFBYZFnrzFWrXKftb55jn6sePqkByZj+d9Y4TGPIeOtApkQgAjRVlJhlO7r/5pwlJLfd1oNpeotQi086dRwxeSI7nDL8UCwXb3FI1qcq+0qGqy41rY/F4eDbysGn45WNVytOwUnjs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=linux.beauty; spf=pass smtp.mailfrom=me@linux.beauty; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1752145058; s=zmail; d=linux.beauty; i=me@linux.beauty; h=From:From:To:To:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To:Cc; bh=amHXm20+VUY9kF5uInegJd53eq5CHYGSBoZSobGAG/U=; b=B7qr5mHFqEqvciDZsEpaq8pcs1xZFF0tj9AnyoD8SlEzemVtTEhdCG6htM6uKEvp oX5Ka7i3tj91LwXVItBUxtysDx/tpR1hzeZkqSaTXawT8DnGDfzFLLVM8VaO+NwauG0 NQn3YoyluV2WaXtl1b0rOSp2cuK+TIJNaWOTZ5vs= Received: by mx.zohomail.com with SMTPS id 1752145055823336.76079326442857; Thu, 10 Jul 2025 03:57:35 -0700 (PDT) From: Li Chen To: "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , x86@kernel.org, "H . Peter Anvin" , "Rafael J . Wysocki" , "Peter Zijlstra" , "Sohil Mehta" , "Brian Gerst" , "Patryk Wlazlyn" , linux-kernel@vger.kernel.org, Li Chen , K Prateek Nayak Subject: [PATCH v5 2/4] x86/smpboot: remove redundant CONFIG_SCHED_SMT Date: Thu, 10 Jul 2025 18:57:08 +0800 Message-ID: <20250710105715.66594-3-me@linux.beauty> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250710105715.66594-1-me@linux.beauty> References: <20250710105715.66594-1-me@linux.beauty> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" From: Li Chen CONFIG_SCHED_SMT is default y if SMP is enabled, so let's simply drop CONFIG_SCHED_SMT. Signed-off-by: Li Chen Suggested-by: Thomas Gleixner Tested-by: K Prateek Nayak Reviewed-by: K Prateek Nayak --- arch/x86/kernel/smpboot.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 445127df2cb19..3d0f5737a157c 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -484,9 +484,7 @@ static void __init build_sched_topology(void) { int i =3D 0; =20 -#ifdef CONFIG_SCHED_SMT x86_topology[i++] =3D SDTL_INIT(cpu_smt_mask, cpu_smt_flags, SMT); -#endif #ifdef CONFIG_SCHED_CLUSTER x86_topology[i++] =3D SDTL_INIT(cpu_clustergroup_mask, x86_cluster_flags,= CLS); #endif --=20 2.50.0 From nobody Tue Oct 7 10:35:43 2025 Received: from sender4-op-o15.zoho.com (sender4-op-o15.zoho.com [136.143.188.15]) (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 C0EB9248F55 for ; Thu, 10 Jul 2025 11:00:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.15 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752145220; cv=pass; b=PyDh5rNfLnl7jqX5DIEjqjmSTSdmIrUXKOsxeSnzqFmvJ7L/RaQdwb+fVEOobAYXewhN94vglf/pzh4XDKlIAeNbXbsZGtCh+4b7Wy1wlQ9DYATv01z4RoBtTaSWj8/63w0T37HZNrgfbFol/F+4oUkVb5qsGimpdgZeco/W/kE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752145220; c=relaxed/simple; bh=Wdc1SEXegXKG2z3+7sNJXlp7oo3GeKiNUFMXNK3IZQ4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N7GHK1Kt+JGNQ4TnKnT14z3gnrJ7+dqCKaxXKBtXJUOz4TITe2MfhagH9OWtw5BXGNIACbB3Zcn7YumQkse6jGZqfOig9lT5zh0QPDEj2iTTgyFF6HiQpyJbE3+FDZvRQRQPnTRdrpo2yxKjUCrve7smuPmpZFBF0pm/oF4FDs4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux.beauty; spf=pass smtp.mailfrom=linux.beauty; dkim=pass (1024-bit key) header.d=linux.beauty header.i=me@linux.beauty header.b=JCU4Sy9D; arc=pass smtp.client-ip=136.143.188.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux.beauty Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.beauty Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.beauty header.i=me@linux.beauty header.b="JCU4Sy9D" ARC-Seal: i=1; a=rsa-sha256; t=1752145062; cv=none; d=zohomail.com; s=zohoarc; b=IUVdpZ9hJlQnyjnuEuXoRWDNPy7og9UfQy9yMPlxBefnMQZMT5FVbrkJqb5jh2+/wxbKMLGdqRvJtSoV8nq+rg7L4gysjsDPPeYV+HeEZLeDQr96VyCGu2j6TbHsd+CjBC44pNdue4dfmea4lfWgsybNeAdEzeWPyZbK7R9P2D4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752145062; h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=bnYRiqvlzbdb50scC/9nYEdxihLR0vRbahpOwqmwAmw=; b=hGNbrGXKuiI1r549JBlUeQinfqKo87IpeG92tJOjJKy3v/+b7E7NfERftvpk84z3lJ9qTEajKXgYkBJvoIFakrpv2Tq/snjdyPd/7X/+EhbyE+3cvEE0SPqnqCDiYIOfB7PDRejxQpElHrLWQ5U621YpckZRT5jYL3VjBpxrtCg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=linux.beauty; spf=pass smtp.mailfrom=me@linux.beauty; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1752145062; s=zmail; d=linux.beauty; i=me@linux.beauty; h=From:From:To:To:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To:Cc; bh=bnYRiqvlzbdb50scC/9nYEdxihLR0vRbahpOwqmwAmw=; b=JCU4Sy9DTtWc+SK+0I3Mu7t8c0ibWGc61ork+bLDnjd5nG7DyZTbwwUaSoj/W/Yq Q87MzQ18oUJFFHlPDQHaxfGCClmdMKSOrmxfoJ2ZOegePXSl7UDomAquy66Eruogkkw g91yM2OiYujpA7dYaTPSIS3vNMvq0Y8Etay402Wo= Received: by mx.zohomail.com with SMTPS id 1752145059913404.6420273722525; Thu, 10 Jul 2025 03:57:39 -0700 (PDT) From: Li Chen To: "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , x86@kernel.org, "H . Peter Anvin" , "Rafael J . Wysocki" , "Peter Zijlstra" , "Sohil Mehta" , "Brian Gerst" , "Patryk Wlazlyn" , linux-kernel@vger.kernel.org, Li Chen , K Prateek Nayak Subject: [PATCH v5 3/4] x86/smpboot: moves x86_topology to static initialize and truncate Date: Thu, 10 Jul 2025 18:57:09 +0800 Message-ID: <20250710105715.66594-4-me@linux.beauty> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250710105715.66594-1-me@linux.beauty> References: <20250710105715.66594-1-me@linux.beauty> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" From: Li Chen The #ifdeffery and the initializers in build_sched_topology() are just disgusting. Statically initialize the domain levels in the topology array and let build_sched_topology() invalidate the package domain level when NUMA in package is available. Suggested-by: Thomas Gleixner Signed-off-by: Li Chen Tested-by: K Prateek Nayak Reviewed-by: K Prateek Nayak --- arch/x86/kernel/smpboot.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 3d0f5737a157c..309338033356f 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -478,32 +478,30 @@ static int x86_cluster_flags(void) */ static bool x86_has_numa_in_package; =20 -static struct sched_domain_topology_level x86_topology[6]; - -static void __init build_sched_topology(void) -{ - int i =3D 0; - - x86_topology[i++] =3D SDTL_INIT(cpu_smt_mask, cpu_smt_flags, SMT); +static struct sched_domain_topology_level x86_topology[] =3D { + SDTL_INIT(cpu_smt_mask, cpu_smt_flags, SMT), #ifdef CONFIG_SCHED_CLUSTER - x86_topology[i++] =3D SDTL_INIT(cpu_clustergroup_mask, x86_cluster_flags,= CLS); + SDTL_INIT(cpu_clustergroup_mask, x86_cluster_flags, CLS), #endif #ifdef CONFIG_SCHED_MC - x86_topology[i++] =3D SDTL_INIT(cpu_coregroup_mask, x86_core_flags, MC); + SDTL_INIT(cpu_coregroup_mask, x86_core_flags, MC), #endif - /* - * When there is NUMA topology inside the package skip the PKG domain - * since the NUMA domains will auto-magically create the right spanning - * domains based on the SLIT. - */ - if (!x86_has_numa_in_package) - x86_topology[i++] =3D SDTL_INIT(cpu_cpu_mask, x86_sched_itmt_flags, PKG); + SDTL_INIT(cpu_cpu_mask, x86_sched_itmt_flags, PKG), + { NULL }, +}; =20 +static void __init build_sched_topology(void) +{ /* - * There must be one trailing NULL entry left. + * When there is NUMA topology inside the package invalidate the + * PKG domain since the NUMA domains will auto-magically create the + * right spanning domains based on the SLIT. */ - BUG_ON(i >=3D ARRAY_SIZE(x86_topology) - 1); + if (x86_has_numa_in_package) { + unsigned int pkgdom =3D ARRAY_SIZE(x86_topology) - 2; =20 + memset(&x86_topology[pkgdom], 0, sizeof(x86_topology[pkgdom])); + } set_sched_topology(x86_topology); } =20 --=20 2.50.0 From nobody Tue Oct 7 10:35:43 2025 Received: from sender4-op-o15.zoho.com (sender4-op-o15.zoho.com [136.143.188.15]) (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 1038B13A3F7 for ; Thu, 10 Jul 2025 11:00:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.15 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752145250; cv=pass; b=kYau+qyixRdmi4O+7g4YUwuHqMqAWtHZxNoh97pA+yHjZJqCQlgol81hhfGmIrm62KBkd0YbD2Tc9GOOgdauB72jCZSzsIaZX6oCSsf5Hj6jVE8np6hSP/i5pgPCwnekHT9BIyx598BCer005iDMj6cywN3CSxWEJZlhbcxxaP4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752145250; c=relaxed/simple; bh=WeJ7nLzzYX9w/yXG8eF7UcGkqRCD7wVgaxfg/gkT5zE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rdjqnnJTpgx3EF5Ub0mHpfowbUkK98VjSscq1NScx6mq3FVOPmWS8SczTAr/HOiJ1fEdFe0sR66go/eQjSd4lVIP6fWbB4jKt/oZq28WjmifGtxlw0Y9pISACAIHhF9YKhjYcncXRz0hYhQTJXT/87yDWTtlE5L4zO5JtmYXQko= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux.beauty; spf=pass smtp.mailfrom=linux.beauty; dkim=pass (1024-bit key) header.d=linux.beauty header.i=me@linux.beauty header.b=PLiFXUxI; arc=pass smtp.client-ip=136.143.188.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux.beauty Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.beauty Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.beauty header.i=me@linux.beauty header.b="PLiFXUxI" ARC-Seal: i=1; a=rsa-sha256; t=1752145067; cv=none; d=zohomail.com; s=zohoarc; b=QPniWKImVzzTqJqASSXiLsuByMr6be2w0+B5LKqAWz2oMHrDeD6cAna/A1jDPc9oqbb8xA14dk2oCVjKQhZoNJ22sQVflPpApKU0RY00cJaRTar0/xH7sbaYqTKJTe0uUIOP5uVnVJZn62sMjhmuHz3yZLI730qWt/4Di/w7oUE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752145067; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=JZAqLf5C1ufJQ4vDDRf1XK8WtbRAUiR0MUD2YR45ZZI=; b=XmByn/FiP58Rczl0MjAu8DspQCU30YgfjHt74KXFLDeL44muhTG1RA4QpYRg/EvGaTzfGk4Va3SKEYsqxDwrcjcqYTGry1KrJnsLgmtptOGIiMAV6L3PO2kvvv/3Nfx+xxj12zvpDV8aaVabCD8G87OmA0J/EYYlsV9FNXl6YAk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=linux.beauty; spf=pass smtp.mailfrom=me@linux.beauty; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1752145067; s=zmail; d=linux.beauty; i=me@linux.beauty; h=From:From:To:To:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To:Cc; bh=JZAqLf5C1ufJQ4vDDRf1XK8WtbRAUiR0MUD2YR45ZZI=; b=PLiFXUxIhsfPrYY818SXcWjW06MyOFXq4Myf/5krDcnlzHTkxCge+eNbMhbGS//z ITI/q+v8YqLzeJnssSmGsp+GOXq3C8rstnCwaejdGITircGuE41ojAhhbrdM9Wfn8qn qGUJjmOaotf7nSnN1Abj5SszZC5GJO1Vtx7Zr7yM= Received: by mx.zohomail.com with SMTPS id 1752145063904192.72775722438178; Thu, 10 Jul 2025 03:57:43 -0700 (PDT) From: Li Chen To: "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , x86@kernel.org, "H . Peter Anvin" , "Rafael J . Wysocki" , "Peter Zijlstra" , "Sohil Mehta" , "Brian Gerst" , "Patryk Wlazlyn" , linux-kernel@vger.kernel.org, Li Chen , K Prateek Nayak Subject: [PATCH v5 4/4] x86/smpboot: avoid SMT domain attach/destroy if SMT is not enabled Date: Thu, 10 Jul 2025 18:57:10 +0800 Message-ID: <20250710105715.66594-5-me@linux.beauty> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250710105715.66594-1-me@linux.beauty> References: <20250710105715.66594-1-me@linux.beauty> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External From: Li Chen Currently, the SMT domain is added into sched_domain_topology by default. If cpu_attach_domain() finds that the CPU SMT domain=E2=80=99s cpumask_weig= ht is just 1, it will destroy it. On a large machine, such as one with 512 cores, this results in 512 redundant domain attach/destroy operations. Avoid these unnecessary operations by simply checking cpu_smt_num_threads and skip SMT domain if the SMT domain is not enabled. Suggested-by: K Prateek Nayak Tested-by: K Prateek Nayak Signed-off-by: Li Chen Reviewed-by: K Prateek Nayak --- arch/x86/kernel/smpboot.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 309338033356f..33e166f6ab122 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -492,6 +492,8 @@ static struct sched_domain_topology_level x86_topology[= ] =3D { =20 static void __init build_sched_topology(void) { + struct sched_domain_topology_level *topology =3D x86_topology; + /* * When there is NUMA topology inside the package invalidate the * PKG domain since the NUMA domains will auto-magically create the @@ -502,7 +504,15 @@ static void __init build_sched_topology(void) =20 memset(&x86_topology[pkgdom], 0, sizeof(x86_topology[pkgdom])); } - set_sched_topology(x86_topology); + + /* + * Drop the SMT domains if there is only one thread per-core + * since it'll get degenerated by the scheduler anyways. + */ + if (cpu_smt_num_threads <=3D 1) + ++topology; + + set_sched_topology(topology); } =20 void set_cpu_sibling_map(int cpu) --=20 2.50.0