mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yicong Yang <yangyicong@huawei.com>
To: <catalin.marinas@arm.com>, <will@kernel.org>,
	<sudeep.holla@arm.com>, <linux-arm-kernel@lists.infradead.org>
Cc: <dietmar.eggemann@arm.com>, <gregkh@linuxfoundation.org>,
	<rafael@kernel.org>, <jonathan.cameron@huawei.com>,
	<prime.zeng@hisilicon.com>, <linuxarm@huawei.com>,
	<yangyicong@hisilicon.com>, <linux-kernel@vger.kernel.org>
Subject: [PATCH v4 1/4] arch_topology: Support basic SMT control for the driver
Date: Tue, 21 Nov 2023 17:25:59 +0800	[thread overview]
Message-ID: <20231121092602.47792-2-yangyicong@huawei.com> (raw)
In-Reply-To: <20231121092602.47792-1-yangyicong@huawei.com>

From: Yicong Yang <yangyicong@hisilicon.com>

The core CPU control framework supports runtime SMT control which
is not yet supported by arch_topology driver and thus arch_topology
based architectures. This patch implements it in the following aspects:

- implement topology_is_primary_thread() to indicate the primary thread,
  required by the framework
- architecture code can get/set the SMT thread number by
  topology_smt_{get, set}_num_threads()
- update the SMT thread number for the framework after the topology
  enumerated on arm64, which is also required by the framework

For disabling SMT we'll offline all the secondary threads and
only leave the primary thread. Since we don't have restriction
for primary thread selection, the first thread is chosen as the
primary thread in this implementation.

This patch only implements the basic support for SMT control, which
needs to collabrate with ACPI/OF based topology building to fully
enable the feature. The SMT control will be enabled unless the
correct SMT thread number is set and HOTPLUG_SMT kconfig is selected.

Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
---
 drivers/base/arch_topology.c  | 38 +++++++++++++++++++++++++++++++++++
 include/linux/arch_topology.h | 14 +++++++++++++
 2 files changed, 52 insertions(+)

diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
index b741b5ba82bd..3ed6bdf9460e 100644
--- a/drivers/base/arch_topology.c
+++ b/drivers/base/arch_topology.c
@@ -729,6 +729,36 @@ const struct cpumask *cpu_clustergroup_mask(int cpu)
 	return &cpu_topology[cpu].cluster_sibling;
 }
 
+#ifdef CONFIG_HOTPLUG_SMT
+
+/* Maximum threads number per-Core */
+static unsigned int topology_smt_num_threads = 1;
+
+void __init topology_smt_set_num_threads(unsigned int num_threads)
+{
+	topology_smt_num_threads = num_threads;
+}
+
+unsigned int __init topology_smt_get_num_threads(void)
+{
+	return topology_smt_num_threads;
+}
+
+/*
+ * On SMT Hotplug the primary thread of the SMT won't be disabled. For x86 they
+ * seem to have a primary thread for special purpose. For other arthitectures
+ * like arm64 there's no such restriction for a primary thread, so make the
+ * first thread in the SMT as the primary thread.
+ */
+bool topology_is_primary_thread(unsigned int cpu)
+{
+	if (cpu == cpumask_first(topology_sibling_cpumask(cpu)))
+		return true;
+
+	return false;
+}
+#endif
+
 void update_siblings_masks(unsigned int cpuid)
 {
 	struct cpu_topology *cpu_topo, *cpuid_topo = &cpu_topology[cpuid];
@@ -841,6 +871,14 @@ void __init init_cpu_topology(void)
 		reset_cpu_topology();
 	}
 
+	/*
+	 * By this stage we get to know whether we support SMT or not, update
+	 * the information for the core. We don't support
+	 * CONFIG_SMT_NUM_THREADS_DYNAMIC so make the max_threads == num_threads.
+	 */
+	cpu_smt_set_num_threads(topology_smt_get_num_threads(),
+				topology_smt_get_num_threads());
+
 	for_each_possible_cpu(cpu) {
 		ret = fetch_cache_info(cpu);
 		if (!ret)
diff --git a/include/linux/arch_topology.h b/include/linux/arch_topology.h
index a07b510e7dc5..0367f3a61838 100644
--- a/include/linux/arch_topology.h
+++ b/include/linux/arch_topology.h
@@ -92,6 +92,20 @@ void update_siblings_masks(unsigned int cpu);
 void remove_cpu_topology(unsigned int cpuid);
 void reset_cpu_topology(void);
 int parse_acpi_topology(void);
+
+#ifdef CONFIG_HOTPLUG_SMT
+bool topology_is_primary_thread(unsigned int cpu);
+void topology_smt_set_num_threads(unsigned int num_threads);
+unsigned int topology_smt_get_num_threads(void);
+#else
+static inline bool topology_is_primary_thread(unsigned int cpu) { return false; }
+static inline void topology_smt_set_num_threads(unsigned int num_threads) { }
+static inline unsigned int topology_smt_get_num_threads(void)
+{
+	return 1;
+}
+#endif
+
 #endif
 
 #endif /* _LINUX_ARCH_TOPOLOGY_H_ */
-- 
2.24.0


  reply	other threads:[~2023-11-21  9:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-21  9:25 [PATCH v4 0/4] Support SMT control on arm64 Yicong Yang
2023-11-21  9:25 ` Yicong Yang [this message]
2023-11-21  9:26 ` [PATCH v4 2/4] arch_topology: Support SMT control for OF based system Yicong Yang
2023-11-21  9:26 ` [PATCH v4 3/4] arm64: topology: Support SMT control on ACPI " Yicong Yang
2023-11-21  9:26 ` [PATCH v4 4/4] arm64: Kconfig: Enable HOTPLUG_SMT Yicong Yang
2023-11-30  6:56 ` [PATCH v4 0/4] Support SMT control on arm64 Yicong Yang
2023-12-11 13:16 ` Will Deacon
2023-12-14 11:39   ` Yicong Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231121092602.47792-2-yangyicong@huawei.com \
    --to=yangyicong@huawei.com \
    --cc=catalin.marinas@arm.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jonathan.cameron@huawei.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=prime.zeng@hisilicon.com \
    --cc=rafael@kernel.org \
    --cc=sudeep.holla@arm.com \
    --cc=will@kernel.org \
    --cc=yangyicong@hisilicon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®