From nobody Sun Feb 8 19:24:10 2026 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (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 260FA1BD006 for ; Tue, 6 Aug 2024 08:59:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.35 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934776; cv=none; b=tA89zsRJjWdV5Kg4s9Q36T3FUOhAFCjHMSS9gpVkuUyBh+bedSid41NdOIi+Ovi0Y7nyMYR8enakMJbLt7xjwr24eaD1m7tAbfuddxyhW7d0BwCG/AdA+cNwNr5Q0F7gA6hFOMmrj+DS22GXsrm+TyiVq7Yx5bWZntT4H3oO/Uc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934776; c=relaxed/simple; bh=WDF/r+6egignnSjHAddYiXtfN1ZrKWnOTd2V0MS7O+s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=e/0+AsM7vv2+jwGoP9zxMPieoWamPh8/aKekY0tXPX5CHERsP9DeWkVV23qIjoUD3dEgbYAkmWTbjzvOS3YHqCSrlOrLVV/iW+0wWoil8QmWORGY9n+ObGKNYEHEk9IMoRdXpEqSUxcvLmnb58P7EKBuuLl7iVdU744gq/SJMVs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4WdRvY33Zqz1S76G; Tue, 6 Aug 2024 16:54:49 +0800 (CST) Received: from kwepemd200014.china.huawei.com (unknown [7.221.188.8]) by mail.maildlp.com (Postfix) with ESMTPS id 5645B140157; Tue, 6 Aug 2024 16:59:31 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by kwepemd200014.china.huawei.com (7.221.188.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Tue, 6 Aug 2024 16:59:30 +0800 From: Yicong Yang To: , , , , , , , , , CC: , , , , , , , , , , , Subject: [PATCH v5 1/4] cpu/SMT: Provide a default topology_is_primary_thread() Date: Tue, 6 Aug 2024 16:53:17 +0800 Message-ID: <20240806085320.63514-2-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20240806085320.63514-1-yangyicong@huawei.com> References: <20240806085320.63514-1-yangyicong@huawei.com> 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-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd200014.china.huawei.com (7.221.188.8) Content-Type: text/plain; charset="utf-8" From: Yicong Yang Currently if architectures want to support HOTPLUG_SMT they need to provide a topology_is_primary_thread() telling the framework which thread in the SMT cannot offline. However arm64 doesn't have a restriction on which thread in the SMT cannot offline, a simplest choice is that just make 1st thread as the "primary" thread. So just make this as the default implementation in the framework and let architectures like x86 that have special primary thread to override this function. There's no need to provide a stub function if !CONFIG_SMP or !CONFIG_HOTPLUG_SMP. In such case the testing CPU is already the 1st CPU in the SMT so it's always the primary thread. Signed-off-by: Yicong Yang --- arch/powerpc/include/asm/topology.h | 1 + arch/x86/include/asm/topology.h | 2 +- include/linux/topology.h | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/include/asm/topology.h b/arch/powerpc/include/asm= /topology.h index f4e6f2dd04b7..e0971777f2d9 100644 --- a/arch/powerpc/include/asm/topology.h +++ b/arch/powerpc/include/asm/topology.h @@ -151,6 +151,7 @@ static inline bool topology_is_primary_thread(unsigned = int cpu) { return cpu =3D=3D cpu_first_thread_sibling(cpu); } +#define topology_is_primary_thread topology_is_primary_thread =20 static inline bool topology_smt_thread_allowed(unsigned int cpu) { diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topolog= y.h index abe3a8f22cbd..86c077f8ee99 100644 --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -219,11 +219,11 @@ static inline bool topology_is_primary_thread(unsigne= d int cpu) { return cpumask_test_cpu(cpu, cpu_primary_thread_mask); } +#define topology_is_primary_thread topology_is_primary_thread =20 #else /* CONFIG_SMP */ static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return = 0; } static inline int topology_max_smt_threads(void) { return 1; } -static inline bool topology_is_primary_thread(unsigned int cpu) { return t= rue; } static inline unsigned int topology_amd_nodes_per_pkg(void) { return 1; } #endif /* !CONFIG_SMP */ =20 diff --git a/include/linux/topology.h b/include/linux/topology.h index 52f5850730b3..9c9f6b9f3462 100644 --- a/include/linux/topology.h +++ b/include/linux/topology.h @@ -240,6 +240,20 @@ static inline const struct cpumask *cpu_smt_mask(int c= pu) } #endif =20 +#ifndef topology_is_primary_thread +#define topology_is_primary_thread topology_is_primary_thread +static inline bool topology_is_primary_thread(unsigned int cpu) +{ + /* + * On SMT hotplug the primary thread of the SMT won't be disabled. + * Architectures do have a special primary thread (e.g. x86) need + * to override this function. Otherwise just make the first thread + * in the SMT as the primary thread. + */ + return cpu =3D=3D cpumask_first(topology_sibling_cpumask(cpu)); +} +#endif + static inline const struct cpumask *cpu_cpu_mask(int cpu) { return cpumask_of_node(cpu_to_node(cpu)); --=20 2.24.0 From nobody Sun Feb 8 19:24:10 2026 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (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 94C8B1BD501 for ; Tue, 6 Aug 2024 08:59:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934776; cv=none; b=hFb+p4Eb7Qqw30IfnGeWJdX06xiRUjSgjNvQKg5c88YJ/EtwP6mzv682jhBOreXEEIHtnFhlqI643DgBhayfv1vGBhOlY6Fv5jMpZDxNcIsf2yj7rEYD+hLHb3HKhkojnKBquXi068IaNOmuLLCxE1mtxQS8Hq3dE03+40ZBX4A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934776; c=relaxed/simple; bh=6JnnqaIXe7PHt7I+mVGT45OA30w7a2TRSyVk4JkpKLM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EySYEWQeP0ucQn+0P3oMCNrM2lJd7p5Bny2X8sUbDWdXXA3Htm0TDyS/4H0DqFLuUQKi+ONbcDvHajyE6IQrOF0n+cKJRPoQrrl12dudwY3I3nbSgNoQ+UNG56/ERaXtxGMfufVp+UfEhYaeyXthNbCOdQ/3ETdJ92m/pKrRVpU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4WdRyp5JJdzfZtB; Tue, 6 Aug 2024 16:57:38 +0800 (CST) Received: from kwepemd200014.china.huawei.com (unknown [7.221.188.8]) by mail.maildlp.com (Postfix) with ESMTPS id 14C9C180105; Tue, 6 Aug 2024 16:59:32 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by kwepemd200014.china.huawei.com (7.221.188.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Tue, 6 Aug 2024 16:59:31 +0800 From: Yicong Yang To: , , , , , , , , , CC: , , , , , , , , , , , Subject: [PATCH v5 2/4] arch_topology: Support SMT control for OF based system Date: Tue, 6 Aug 2024 16:53:18 +0800 Message-ID: <20240806085320.63514-3-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20240806085320.63514-1-yangyicong@huawei.com> References: <20240806085320.63514-1-yangyicong@huawei.com> 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-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd200014.china.huawei.com (7.221.188.8) Content-Type: text/plain; charset="utf-8" From: Yicong Yang On building the topology from the devicetree, we've already gotten the SMT thread number of each core. Update the largest SMT thread number to enable the SMT control. Signed-off-by: Yicong Yang --- drivers/base/arch_topology.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 75fcb75d5515..95513abd664f 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -531,6 +532,16 @@ static int __init get_cpu_for_node(struct device_node = *node) return cpu; } =20 +static void __init update_smt_num_threads(unsigned int num_threads) +{ + static unsigned int max_smt_thread_num =3D 1; + + if (num_threads > max_smt_thread_num) { + max_smt_thread_num =3D num_threads; + cpu_smt_set_num_threads(max_smt_thread_num, max_smt_thread_num); + } +} + static int __init parse_core(struct device_node *core, int package_id, int cluster_id, int core_id) { @@ -561,6 +572,8 @@ static int __init parse_core(struct device_node *core, = int package_id, i++; } while (1); =20 + update_smt_num_threads(i); + cpu =3D get_cpu_for_node(core); if (cpu >=3D 0) { if (!leaf) { --=20 2.24.0 From nobody Sun Feb 8 19:24:10 2026 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (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 4D3701BD507 for ; Tue, 6 Aug 2024 08:59:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934778; cv=none; b=l/d9pFL+L2lz9rwKHW6OC7nGMSxnAO4vzdKjjbyfGLr+3kDNj8NKqjshqyC1dCBUGDCUfDmZ+YbzZEmFJlTTVVY3pSk6XEdNcZpGFxwMoZAw4kyBwG/d3JyrxX05SOWVE04r5AHcZDPEHSMbaA9ii7bS5U0RjhSjJoMxkvHtFsg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934778; c=relaxed/simple; bh=ug6TQ0Oc1jLSDCX8oHX8vABMdkpnSFcNVdIGOcgjyDQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YMA24dwWRnp+KXICpuSjK2r4RP0/iZ8obvw0oVM0zTqDEAjKMUGN/HdQNHbRRIIxhW7pzX+IAGloP3rje+6zamDvwzPZJfxhL/JhDTHgeJLsoVtfAoNIh3hBA6w4zNVK/Fv7106yZ55UnQ4Q/XDj1UnmaI1ZTjK4jEI1oopeW/Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4WdRvv15sVzQngm; Tue, 6 Aug 2024 16:55:07 +0800 (CST) Received: from kwepemd200014.china.huawei.com (unknown [7.221.188.8]) by mail.maildlp.com (Postfix) with ESMTPS id A30A118009B; Tue, 6 Aug 2024 16:59:32 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by kwepemd200014.china.huawei.com (7.221.188.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Tue, 6 Aug 2024 16:59:31 +0800 From: Yicong Yang To: , , , , , , , , , CC: , , , , , , , , , , , Subject: [PATCH v5 3/4] arm64: topology: Support SMT control on ACPI based system Date: Tue, 6 Aug 2024 16:53:19 +0800 Message-ID: <20240806085320.63514-4-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20240806085320.63514-1-yangyicong@huawei.com> References: <20240806085320.63514-1-yangyicong@huawei.com> 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-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd200014.china.huawei.com (7.221.188.8) Content-Type: text/plain; charset="utf-8" From: Yicong Yang For ACPI we'll build the topology from PPTT and we cannot directly get the SMT number of each core. Instead using a temporary xarray to record the SMT number of each core when building the topology and we can know the largest SMT number in the system. Then we can enable the support of SMT control. Signed-off-by: Yicong Yang --- arch/arm64/kernel/topology.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c index 1a2c72f3e7f8..f72e1e55b05e 100644 --- a/arch/arm64/kernel/topology.c +++ b/arch/arm64/kernel/topology.c @@ -15,8 +15,10 @@ #include #include #include +#include #include #include +#include =20 #include #include @@ -43,11 +45,16 @@ static bool __init acpi_cpu_is_threaded(int cpu) */ int __init parse_acpi_topology(void) { + int thread_num, max_smt_thread_num =3D 1; + struct xarray core_threads; int cpu, topology_id; + void *entry; =20 if (acpi_disabled) return 0; =20 + xa_init(&core_threads); + for_each_possible_cpu(cpu) { topology_id =3D find_acpi_cpu_topology(cpu, 0); if (topology_id < 0) @@ -57,6 +64,20 @@ int __init parse_acpi_topology(void) cpu_topology[cpu].thread_id =3D topology_id; topology_id =3D find_acpi_cpu_topology(cpu, 1); cpu_topology[cpu].core_id =3D topology_id; + + entry =3D xa_load(&core_threads, topology_id); + if (!entry) { + xa_store(&core_threads, topology_id, + xa_mk_value(1), GFP_KERNEL); + } else { + thread_num =3D xa_to_value(entry); + thread_num++; + xa_store(&core_threads, topology_id, + xa_mk_value(thread_num), GFP_KERNEL); + + if (thread_num > max_smt_thread_num) + max_smt_thread_num =3D thread_num; + } } else { cpu_topology[cpu].thread_id =3D -1; cpu_topology[cpu].core_id =3D topology_id; @@ -67,6 +88,9 @@ int __init parse_acpi_topology(void) cpu_topology[cpu].package_id =3D topology_id; } =20 + cpu_smt_set_num_threads(max_smt_thread_num, max_smt_thread_num); + + xa_destroy(&core_threads); return 0; } #endif --=20 2.24.0 From nobody Sun Feb 8 19:24:10 2026 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (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 C00B61BD505 for ; Tue, 6 Aug 2024 08:59:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.255 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934778; cv=none; b=aqjvPsmIUX0BXH3lzk9+mOrevYLKGPjCnhO4VEpF+lqSlTkzBCcPgSyWcfVDvOFt2OmJMHcjO27XiZfUiwThIeD0+bXaWFmSfxUuJ7Q0yZK2k5fE5RrKpwSC4c/XrPei2tSLxgXYKLZZnpMdPLjb/3J5Hhn/UR8WjZ5qQy5gSz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934778; c=relaxed/simple; bh=mc5+S4NfgglFHfOm/XvAZiQVzDyF8rqf6YaxmfrOUdY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=H2ScYmq504XkrCHO8WRopot5NgXyM0rmCJ3csf5AFenBicyb+a5nnfEp7TeBwds5i86dISE8t16YHmjePzSPLts7WHngsiQwNA/UkjitBHJYB9nXYm9Ui3FJ2tAJLxkeTXV9ZikpLy8eZp2UUXciMBm2HqjF7+U+knGabKJP79A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.255 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4WdS0f1f9Wz1L9tY; Tue, 6 Aug 2024 16:59:14 +0800 (CST) Received: from kwepemd200014.china.huawei.com (unknown [7.221.188.8]) by mail.maildlp.com (Postfix) with ESMTPS id 507E11400D8; Tue, 6 Aug 2024 16:59:33 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by kwepemd200014.china.huawei.com (7.221.188.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Tue, 6 Aug 2024 16:59:32 +0800 From: Yicong Yang To: , , , , , , , , , CC: , , , , , , , , , , , Subject: [PATCH v5 4/4] arm64: Kconfig: Enable HOTPLUG_SMT Date: Tue, 6 Aug 2024 16:53:20 +0800 Message-ID: <20240806085320.63514-5-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20240806085320.63514-1-yangyicong@huawei.com> References: <20240806085320.63514-1-yangyicong@huawei.com> 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-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd200014.china.huawei.com (7.221.188.8) Content-Type: text/plain; charset="utf-8" From: Yicong Yang Enable HOTPLUG_SMT for SMT control. Signed-off-by: Yicong Yang --- arch/arm64/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index a2f8ff354ca6..bd3bc2f5e0ec 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -238,6 +238,7 @@ config ARM64 select HAVE_KRETPROBES select HAVE_GENERIC_VDSO select HOTPLUG_CORE_SYNC_DEAD if HOTPLUG_CPU + select HOTPLUG_SMT if (SMP && HOTPLUG_CPU) select IRQ_DOMAIN select IRQ_FORCED_THREADING select KASAN_VMALLOC if KASAN --=20 2.24.0