From nobody Wed Oct 8 19:18:27 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 B616833E4 for ; Wed, 25 Jun 2025 03:47:10 +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=1750823232; cv=pass; b=LS8FW5VmSk1IoO35MFvh+6FlJOzTVXX66gccEX7QCU2nvbO0Qz7LUAmWPYWZYOIFnb8ltB1JBrpWcoMw74gsvM05kDVplEKzISoekCZX+TePr5cD/8gigAvJFZz6eApCCmAfZYPV5CvGB1xMghTglWo080MO0uQ0O4YbwsQkkk4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750823232; c=relaxed/simple; bh=oxztMWmBEFZmnk5mzpPOmInc8CJ0XvgSTQhYUnDoiaA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=leuma87ApF8JSFrpa9+Vc8Sk9MSY5vY68/i0FrmMWrOXExOUZP7/k7UuopctNhMAiaKj1RgvIlrT7Ag70Pe/30TYct6hA6qKaIawTfn2tNndh0c9tsyBiH1hijOIlSzIt0kikPgrdNMaRgUcSC5U5rmpd2aS6LXsVhjXzPMZ/Vg= 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=mVXBi5go; 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="mVXBi5go" ARC-Seal: i=1; a=rsa-sha256; t=1750823164; cv=none; d=zohomail.com; s=zohoarc; b=b5kp+14EDgl5HAs9oxGnjby9yePAB1wyeMy944iM0L9KpdiTOa8f1jI/z0u16nRWh8P16oEU7LMBsdqh5Z/1MaPRLCPNWcWNSYbF9Q0+nA3VdyaEvhM/9odlJJ20GIP4BidERGpc/dpN/IOUTyoN9XeLuwTNNeepTiQDoPYbHog= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1750823164; 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=npvQSbvkgBbyxSM63qdTRfR5POqrITaC29SVbqjV8/vxclBW469F+6uRWgZFE2mJ7Y66QKMLgawY2O0nK5lutBk0UArrJMTDB7ZqE5njBYf3Gg9zNIX9QGDtg27x3VJ5xuwidE28jN6eGljuT6vf5MHgDpNu8w/22+PFN5Yxci4= 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=1750823164; 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=mVXBi5goeuPTyJUdSloaAbSpJMbAifxDJM64jcOr6o7qpckI9gIkvQr+y/c1XNrq lbFTqN8XrWjPbl9K2gyRwbj9VkYWWbzxpnQcOq/om6gNPnsy9mJZFghUaXpaGd0PhKI 31NAce6kTYTcEmCD3IIYrNd1YyttMubrlyAIjWIw= Received: by mx.zohomail.com with SMTPS id 1750823162759927.9038940040223; Tue, 24 Jun 2025 20:46:02 -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, Li Chen Subject: [PATCH v3 1/2] x86/smpboot: Decrapify build_sched_topology() Date: Wed, 25 Jun 2025 11:45:49 +0800 Message-ID: <20250625034552.42365-2-me@linux.beauty> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250625034552.42365-1-me@linux.beauty> References: <20250625034552.42365-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 Tested-by: K Prateek Nayak --- 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 19:18:27 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 2D1D733E4 for ; Wed, 25 Jun 2025 03:47:38 +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=1750823262; cv=pass; b=U280hu1NByX/qkVFh4Sxm2Dy71Tm0a9ZMSM1qB+Hfw8xBP6LQbYn4pZrisFSVPLuWzReX9YHxAD+Ip5V5bEEP9JpphUN5/SZGlzp9qqrQ08UjBlblbyYyP71oEkOO+1tsynUVVK1vjdOSTWsfzR/6PAWL9pRq7sRyv3gj7je1v0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750823262; c=relaxed/simple; bh=JP26mKnlstWQd02lHyws56EmzQCjDY8MetuTGwA3c/M=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MvhsB8Jtu4Hq4X3XKX0cT5MnsLAW9W9dkgr0fT5KPrcYnYkefabmLUI6t1lCA2GtojHRxawrM4AzH9hMZRfAD9CmiYbhwB8wVoWbTsTeHiP7FnQ+/XvKcy6dQ/PPNEfmHWGRgugN7fNlFOtnDzBzwEMOIxOBHD/fTu2C/fjhw5o= 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=asvfwpn8; 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="asvfwpn8" ARC-Seal: i=1; a=rsa-sha256; t=1750823170; cv=none; d=zohomail.com; s=zohoarc; b=H6wU9jp5UENsHWc5Zw+/FuQQker8QugDtICeQqdw/2FiPOGcG9p61gGah4q4704C62wmcsOjId5kIJLS6vuB6gP6P+7tKtbbp9CJIMQW1YbiR75BTtfDkqezBtWf3QEs5od79uBgJ8ezu2wlYEiojEZ9b89s3KRPa6aS8KrW03Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1750823170; 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=RdGgv5ETNd0Zsp1nHqiyPSrLOVxivkC0P66w4cAdGsU=; b=OkCElp4h0yM6T4Hzw0rE0df6JX5z/Rxsf4pnKGNfcYK0XU33wuR1K3yZ9XWtpr7fJgR2Htajv7yE8j7SjX0sZG3rdqD6w+qHifsoGRuuBPHkaOvLnsa0qo74cauO7SM6A2zR4277gE/dghTNE5n6AQXnYMfpAgS1fqgdWpxj9CY= 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=1750823170; 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=RdGgv5ETNd0Zsp1nHqiyPSrLOVxivkC0P66w4cAdGsU=; b=asvfwpn8pbFkG2lF6J5zRtDPlVQNn+8B5WOM/67WgCQnPdVrXUvTTp2RVzEYva4E RYDQx4grcyu/s2wf/Na1xWSfVKsnxJorG9NOjA8VNCZss/eSiSWh+8XQyUnNejuUcjZ OYCVw0T5ssoKEen/dO7f9j0vbdX+bVkquhy0yTyE= Received: by mx.zohomail.com with SMTPS id 175082316749596.95391557947278; Tue, 24 Jun 2025 20:46:07 -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 v3 2/2] x86/smpboot: avoid SMT domain attach/destroy if SMT is not enabled Date: Wed, 25 Jun 2025 11:45:50 +0800 Message-ID: <20250625034552.42365-3-me@linux.beauty> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250625034552.42365-1-me@linux.beauty> References: <20250625034552.42365-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 remove SMT domain if the SMT domain is not enabled, and adjust the PKG index accordingly if NUMA-in-package invalidates that level as well. Signed-off-by: Li Chen Tested-by: K Prateek Nayak --- changelog: v2: fix wording issue as suggested by Thomas [1] v3: remove pointless memset and adjust PKG index accordingly, as suggested by Thomas [2]=20 [1]: https://lore.kernel.org/all/87msa2r018.ffs@tglx/ [2]: https://lore.kernel.org/all/875xglntx1.ffs@tglx/ arch/x86/kernel/smpboot.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 7d202f9785362..4b6daa1545445 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -494,13 +494,29 @@ static struct sched_domain_topology_level x86_topolog= y[] =3D { =20 static void __init build_sched_topology(void) { + bool smt_dropped =3D false; + + if (cpu_smt_num_threads <=3D 1) { + /* + * SMT level is x86_topology[0]. Shift the array left by one, + */ + memmove(&x86_topology[0], &x86_topology[1], + sizeof(x86_topology) - sizeof(x86_topology[0])); + smt_dropped =3D true; + } + /* * 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. */ if (x86_has_numa_in_package) { - unsigned int pkgdom =3D ARRAY_SIZE(x86_topology) - 2; + unsigned int pkgdom; + + if (smt_dropped) + pkgdom =3D ARRAY_SIZE(x86_topology) - 3; + else + pkgdom =3D ARRAY_SIZE(x86_topology) - 2; =20 memset(&x86_topology[pkgdom], 0, sizeof(x86_topology[pkgdom])); } --=20 2.49.0