From nobody Wed Oct 8 21:39:07 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 932EE1DF98B for ; Tue, 24 Jun 2025 08:09:40 +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=1750752582; cv=pass; b=N7VSkYrIFZCXOZzi1Dw34hm0HyQXY2Qig+aBUwZL+Xuy1xPXlIctYZavBPjrTLRXa17WSzyBrVn0LBwkUuah6WWQaT1or4fkHPOmfu4IXw/U4IWuKb8FC7zRw+x1xYj5H7GlTOb5fBAdcCfYwlyUnJtwcxhCGdvx3NtqKg+Ptks= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750752582; c=relaxed/simple; bh=oxztMWmBEFZmnk5mzpPOmInc8CJ0XvgSTQhYUnDoiaA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AYWOmGg5719gqzNE8MnuPTDnmpn0UkhukyjA5lvJpVerVS9jqP2MbIgmGLMr53nRuLYAaeSFJ7Se1vRaTMEKOeK18HF/jteMrwF8GoZIYanJrhvL7YBmBQ33gxAP6jRXHDC3yQ3NLBD7lpMeTAu1JrIS9qz1RviWvctZnGyer6s= 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=bsjFlkcZ; 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="bsjFlkcZ" ARC-Seal: i=1; a=rsa-sha256; t=1750752510; cv=none; d=zohomail.com; s=zohoarc; b=EsLzLwEOaoFXzevEsP7NDwUbkTDLf/nwLMJhWtCXnMWW/jUMoOuuohQco++C7OpeKHN3gbrXjm50NTF+lK6m4gxMdtbxNC4w1/WndLozaMUb7NSz5fHmspB/TYsDtOx/2RuDEM4kjNIjY31VemvAFWJqCJGLYscW7dcVK+7MFw0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1750752510; 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=inpdI4jjHBay8by/ADyJAX9SBwP0Wlfs/Ocj4U4TvOY=; b=ZG3344gxmdrU6QbFKt1f/sYa1VJ3TvbflWwDbJFqxYDmga6Rg15iHgsm+flZJXpE6oZvKGj2HxSizI2Foc1EjkpKO0/SC9HnR5vgZNBVeMn1DG91h1PqiHw5VFXt4aNWGouSa6U51IzXGZlpSgpq7GhD7HJfy6gsB9ItYB6+WVg= 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=1750752510; 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=inpdI4jjHBay8by/ADyJAX9SBwP0Wlfs/Ocj4U4TvOY=; b=bsjFlkcZJiH23+lWYznKMZpea2YAjkiq54XVopyZ9bJlTBARoV0imQbkVuvWQ+b4 w5jQRK5qgKBlJocFvFGZ35+wd2duda7ehtWkQxq8/1pw51DK10ztnBmHgpTHMoj9K2C JzDHPKC5ROYfDFQE1OYe6c3jju1QSIPJRouTakZQ= Received: by mx.zohomail.com with SMTPS id 1750752507289328.68457917208616; Tue, 24 Jun 2025 01:08:27 -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 , K Prateek Nayak , Sohil Mehta , Brian Gerst , Patryk Wlazlyn , linux-kernel@vger.kernel.org, "Gautham R. Shenoy" , Li Chen Subject: [PATCH 1/2] x86/smpboot: Decrapify build_sched_topology() Date: Tue, 24 Jun 2025 16:08:07 +0800 Message-ID: <20250624080810.66821-2-me@linux.beauty> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250624080810.66821-1-me@linux.beauty> References: <20250624080810.66821-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: Thomas Gleixner The #ifdeffery and the initializers in build_sched_topology() are just disgusting. The SCHED_SMT #ifdef is also pointless because SCHED_SMT is unconditionally enabled when SMP is enabled. 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. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/smpboot.c | 45 +++++++++++++++------------------------ 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index fc78c2325fd29..7d202f9785362 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -478,43 +478,32 @@ static int x86_cluster_flags(void) */ static bool x86_has_numa_in_package; =20 -static struct sched_domain_topology_level x86_topology[6]; +#define DOMAIN(maskfn, flagsfn, dname) { .mask =3D maskfn, .sd_flags =3D f= lagsfn, .name =3D #dname } =20 -static void __init build_sched_topology(void) -{ - int i =3D 0; - -#ifdef CONFIG_SCHED_SMT - x86_topology[i++] =3D (struct sched_domain_topology_level){ - cpu_smt_mask, cpu_smt_flags, SD_INIT_NAME(SMT) - }; -#endif +static struct sched_domain_topology_level x86_topology[] =3D { + DOMAIN(cpu_smt_mask, cpu_smt_flags, SMT), #ifdef CONFIG_SCHED_CLUSTER - x86_topology[i++] =3D (struct sched_domain_topology_level){ - cpu_clustergroup_mask, x86_cluster_flags, SD_INIT_NAME(CLS) - }; + DOMAIN(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) - }; + DOMAIN(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) - }; - } + DOMAIN(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.49.0 From nobody Wed Oct 8 21:39:07 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 8F712248F64 for ; Tue, 24 Jun 2025 08:10:11 +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=1750752613; cv=pass; b=AfXfXBYlhvCoxYLA+OdoD1LSp2ogzI0IGoMosBVrFof5Eci2KfD5eVPwfLaI73M5v34tFeJW+9Ms1+sk/sTAl+DbbzUZ6WSTMAZCpZGnMmzPxEpvEZUCpiW9G3I9H93UjQKHelkU9Z5tf3pxjE34UPw8DeOeWMyCClWyRhjgM0s= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750752613; c=relaxed/simple; bh=QTbRXBTaq/jCZ/lInb8FzNkFUx23kzVe0jdYEFxEBio=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=O32oDCPBU6xHvpiKs2ZOUmMKv9Ja9deoLd3nQd6qnhVkr4SEFiRJihRhRkBMlvt6sF8BM3cVTK/IY+3pYNutwtLM5HAWvTcawE1ZIyhchukkyvD0fX6z9RPo1elXU4ogDJyRoteFiQpgdVmR+2LQl/HC4Hsg35VDfLDaTBgJsYo= 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=F/G1w55I; 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="F/G1w55I" ARC-Seal: i=1; a=rsa-sha256; t=1750752516; cv=none; d=zohomail.com; s=zohoarc; b=BIjHfJB/0UYt/JbQELm0MK2S/9P20W1fHhYUiDjs0eHJS8oT6ZxRIFHDVWf+LtRMhB+eCHYzxJIwQG5qA/lybQZ1oPuNKvSkbr/AXNqb6OIc6kDtVfZqUByZ6jrzqNM0MRA8vUXSHfahQYjUgPJrqWVgI9oNQTM9niRxfGQAnho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1750752516; 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=FKN1YEUyRRyyaJ4NQRmw+DP7WVbSHZzD+nJqHkMmIP8=; b=IbTB3j+6c0D1Vx6UoEXxI7d0ywpyrl4W2U6NeMX2D8Mdif4BjC4IWDuiKJTGONOej5A3irfWEXSc6H+FI6FgLxRQOeiQgZN9aFNWPIm5kBjrZPwSobp6YvQsXKxcsEEwWhYIALQRTNTOjJ1a4aQ7jwHCZ+0zT4xW8MTNKU56sq0= 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=1750752516; 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=FKN1YEUyRRyyaJ4NQRmw+DP7WVbSHZzD+nJqHkMmIP8=; b=F/G1w55IDpTjPMHG5VW/AxuptPKLyytCWHyBIK1N7F3j159YZNMvLcpit+6xvxgm KaXCaHBCo0zoe3VSsBl4O63bZOMOatAsaC/BqQDXpAAeSBYDYE8xaebnazjFHjGX7vr +aE84IfMyU1WxI9l/lx5jDDBcSnMVqsYxkQBHRTc= Received: by mx.zohomail.com with SMTPS id 1750752513528856.0116755516766; Tue, 24 Jun 2025 01:08:33 -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 , K Prateek Nayak , Sohil Mehta , Brian Gerst , Patryk Wlazlyn , linux-kernel@vger.kernel.org, "Gautham R. Shenoy" , Li Chen Subject: [PATCH 2/2] x86/smpboot: avoid SMT domain attach/destroy if SMT is not enabled Date: Tue, 24 Jun 2025 16:08:08 +0800 Message-ID: <20250624080810.66821-3-me@linux.beauty> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250624080810.66821-1-me@linux.beauty> References: <20250624080810.66821-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 CONFIG_SCHED_SMT is enabled. If cpu_attach_domain finds that the CPU SMT domain=E2=80=99s cpumask_weight is just 1, it will destroy_sched_domain it. On a large machine, such as one with 512 cores, this results in 512 redundant domain attach/destroy operations. We can avoid these unnecessary operations by simply checking cpu_smt_num_threads and not inserting SMT domain into x86_topology if SMT is not enabled. Signed-off-by: Li Chen --- arch/x86/kernel/smpboot.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 7d202f9785362..9ff8b10715cc1 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -492,8 +492,24 @@ static struct sched_domain_topology_level x86_topology= [] =3D { { NULL }, }; =20 +static void __init maybe_remove_smt_level(void) +{ + if (cpu_smt_num_threads <=3D 1) { + /* + * SMT level is x86_topology[0]. Shift the array left by one, + * keep the sentinel { NULL } at the end. + */ + memmove(&x86_topology[0], &x86_topology[1], + sizeof(x86_topology) - sizeof(x86_topology[0])); + memset(&x86_topology[ARRAY_SIZE(x86_topology) - 1], 0, + sizeof(x86_topology[0])); + } +} + static void __init build_sched_topology(void) { + maybe_remove_smt_level(); + /* * When there is NUMA topology inside the package invalidate the * PKG domain since the NUMA domains will auto-magically create the --=20 2.49.0