diff mbox series

[v3,1/4] arch_topology: Support basic SMT control for the driver

Message ID 20231114040110.54590-2-yangyicong@huawei.com (mailing list archive)
State New, archived
Headers show
Series Support SMT control on arm64 | expand

Commit Message

Yicong Yang Nov. 14, 2023, 4:01 a.m. UTC
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
- record the allowed setting of SMT thread number by
  topology_smt_set_num_threads()
- update the SMT thread number for the framework after the topology
  enumerated on arm64

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  | 32 ++++++++++++++++++++++++++++++++
 include/linux/arch_topology.h |  9 +++++++++
 2 files changed, 41 insertions(+)

Comments

kernel test robot Nov. 14, 2023, 1:42 p.m. UTC | #1
Hi Yicong,

kernel test robot noticed the following build warnings:

[auto build test WARNING on arm64/for-next/core]
[also build test WARNING on driver-core/driver-core-testing driver-core/driver-core-next driver-core/driver-core-linus arm/for-next kvmarm/next soc/for-next linus/master arm/fixes v6.7-rc1 next-20231114]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Yicong-Yang/arch_topology-Support-basic-SMT-control-for-the-driver/20231114-120544
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
patch link:    https://lore.kernel.org/r/20231114040110.54590-2-yangyicong%40huawei.com
patch subject: [PATCH v3 1/4] arch_topology: Support basic SMT control for the driver
config: parisc-generic-64bit_defconfig (https://download.01.org/0day-ci/archive/20231114/202311142157.B3tyngmI-lkp@intel.com/config)
compiler: hppa-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231114/202311142157.B3tyngmI-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202311142157.B3tyngmI-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/base/arch_topology.c:32:12: warning: 'topology_smt_num_threads' defined but not used [-Wunused-variable]
      32 | static int topology_smt_num_threads = 1;
         |            ^~~~~~~~~~~~~~~~~~~~~~~~


vim +/topology_smt_num_threads +32 drivers/base/arch_topology.c

    30	
    31	/* Maximum threads number per-Core */
  > 32	static int topology_smt_num_threads = 1;
    33
kernel test robot Nov. 15, 2023, 3:23 p.m. UTC | #2
Hi Yicong,

kernel test robot noticed the following build warnings:

[auto build test WARNING on arm64/for-next/core]
[also build test WARNING on driver-core/driver-core-testing driver-core/driver-core-next driver-core/driver-core-linus arm/for-next kvmarm/next soc/for-next linus/master arm/fixes v6.7-rc1 next-20231115]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Yicong-Yang/arch_topology-Support-basic-SMT-control-for-the-driver/20231114-120544
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
patch link:    https://lore.kernel.org/r/20231114040110.54590-2-yangyicong%40huawei.com
patch subject: [PATCH v3 1/4] arch_topology: Support basic SMT control for the driver
config: arm-socfpga_defconfig (https://download.01.org/0day-ci/archive/20231115/202311152356.OWWDpFRB-lkp@intel.com/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231115/202311152356.OWWDpFRB-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202311152356.OWWDpFRB-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/base/arch_topology.c:32:12: warning: unused variable 'topology_smt_num_threads' [-Wunused-variable]
      32 | static int topology_smt_num_threads = 1;
         |            ^
   1 warning generated.


vim +/topology_smt_num_threads +32 drivers/base/arch_topology.c

    30	
    31	/* Maximum threads number per-Core */
  > 32	static int topology_smt_num_threads = 1;
    33
Yicong Yang Nov. 20, 2023, 3:29 a.m. UTC | #3
On 2023/11/15 23:23, kernel test robot wrote:
> Hi Yicong,
> 
> kernel test robot noticed the following build warnings:
> 
> [auto build test WARNING on arm64/for-next/core]
> [also build test WARNING on driver-core/driver-core-testing driver-core/driver-core-next driver-core/driver-core-linus arm/for-next kvmarm/next soc/for-next linus/master arm/fixes v6.7-rc1 next-20231115]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/Yicong-Yang/arch_topology-Support-basic-SMT-control-for-the-driver/20231114-120544
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
> patch link:    https://lore.kernel.org/r/20231114040110.54590-2-yangyicong%40huawei.com
> patch subject: [PATCH v3 1/4] arch_topology: Support basic SMT control for the driver
> config: arm-socfpga_defconfig (https://download.01.org/0day-ci/archive/20231115/202311152356.OWWDpFRB-lkp@intel.com/config)
> compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a)
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231115/202311152356.OWWDpFRB-lkp@intel.com/reproduce)
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202311152356.OWWDpFRB-lkp@intel.com/
> 
> All warnings (new ones prefixed by >>):
> 
>>> drivers/base/arch_topology.c:32:12: warning: unused variable 'topology_smt_num_threads' [-Wunused-variable]
>       32 | static int topology_smt_num_threads = 1;
>          |            ^
>    1 warning generated.
> 

This variable needs to be protected by CONFIG_HOTPLUG_SMT, otherwise it'll be unused
if architecture like arm/parisc selects CONFIG_GENERIC_ARCH_TOPOLOGY but not
CONFIG_HOTPLUG_SMT.

> 
> vim +/topology_smt_num_threads +32 drivers/base/arch_topology.c
> 
>     30	
>     31	/* Maximum threads number per-Core */
>   > 32	static int topology_smt_num_threads = 1;
>     33	
>
diff mbox series

Patch

diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
index b741b5ba82bd..7fb91f41d66d 100644
--- a/drivers/base/arch_topology.c
+++ b/drivers/base/arch_topology.c
@@ -28,6 +28,9 @@  static struct cpumask scale_freq_counters_mask;
 static bool scale_freq_invariant;
 static DEFINE_PER_CPU(u32, freq_factor) = 1;
 
+/* Maximum threads number per-Core */
+static int topology_smt_num_threads = 1;
+
 static bool supports_scale_freq_counters(const struct cpumask *cpus)
 {
 	return cpumask_subset(cpus, &scale_freq_counters_mask);
@@ -729,6 +732,28 @@  const struct cpumask *cpu_clustergroup_mask(int cpu)
 	return &cpu_topology[cpu].cluster_sibling;
 }
 
+#ifdef CONFIG_HOTPLUG_SMT
+
+void __init topology_smt_set_num_threads(unsigned int num_threads)
+{
+	topology_smt_num_threads = 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 +866,13 @@  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_num_threads, topology_smt_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..574942a12ae1 100644
--- a/include/linux/arch_topology.h
+++ b/include/linux/arch_topology.h
@@ -92,6 +92,15 @@  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);
+#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) { }
+#endif
+
 #endif
 
 #endif /* _LINUX_ARCH_TOPOLOGY_H_ */