mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michael Ellerman <mpe@ellerman.id.au>
To: <linux-kernel@vger.kernel.org>
Cc: <linuxppc-dev@lists.ozlabs.org>, <linux-arch@vger.kernel.org>,
	<ldufour@linux.ibm.com>, <tglx@linutronix.de>,
	bp@alien8.de, dave.hansen@linux.intel.com, mingo@redhat.com,
	x86@kernel.org
Subject: [PATCH 3/9] cpu/SMT: Store the current/max number of threads
Date: Thu, 25 May 2023 01:56:24 +1000	[thread overview]
Message-ID: <20230524155630.794584-3-mpe@ellerman.id.au> (raw)
In-Reply-To: <20230524155630.794584-1-mpe@ellerman.id.au>

A subsequent patch will enable partial SMT states, ie. when not all SMT
threads are brought online.

To support that the SMT code needs to know the maximum number of SMT
threads, and also the currently configured number.

The arch code knows the max number of threads, so have the arch code
pass that value to cpu_smt_check_topology(). Note that although
topology_max_smt_threads() exists, it is not configured early enough to
be used here.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 arch/x86/kernel/cpu/bugs.c |  3 ++-
 include/linux/cpu_smt.h    |  6 ++++--
 kernel/cpu.c               | 12 +++++++++++-
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 182af64387d0..3406799c1e9d 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -34,6 +34,7 @@
 #include <asm/hypervisor.h>
 #include <asm/tlbflush.h>
 #include <asm/cpu.h>
+#include <asm/smp.h>
 
 #include "cpu.h"
 
@@ -133,7 +134,7 @@ void __init check_bugs(void)
 	 * identify_boot_cpu() initialized SMT support information, let the
 	 * core code know.
 	 */
-	cpu_smt_check_topology();
+	cpu_smt_check_topology(smp_num_siblings);
 
 	if (!IS_ENABLED(CONFIG_SMP)) {
 		pr_info("CPU: ");
diff --git a/include/linux/cpu_smt.h b/include/linux/cpu_smt.h
index 17e105b52d85..8d4ae26047c9 100644
--- a/include/linux/cpu_smt.h
+++ b/include/linux/cpu_smt.h
@@ -12,15 +12,17 @@ enum cpuhp_smt_control {
 
 #if defined(CONFIG_SMP) && defined(CONFIG_HOTPLUG_SMT)
 extern enum cpuhp_smt_control cpu_smt_control;
+extern unsigned int cpu_smt_num_threads;
 extern void cpu_smt_disable(bool force);
-extern void cpu_smt_check_topology(void);
+extern void cpu_smt_check_topology(unsigned int num_threads);
 extern bool cpu_smt_possible(void);
 extern int cpuhp_smt_enable(void);
 extern int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval);
 #else
 # define cpu_smt_control		(CPU_SMT_NOT_IMPLEMENTED)
+# define cpu_smt_num_threads 1
 static inline void cpu_smt_disable(bool force) { }
-static inline void cpu_smt_check_topology(void) { }
+static inline void cpu_smt_check_topology(unsigned int num_threads) { }
 static inline bool cpu_smt_possible(void) { return false; }
 static inline int cpuhp_smt_enable(void) { return 0; }
 static inline int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval) { return 0; }
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 01398ce3e131..a08dd8f93675 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -414,6 +414,8 @@ void __weak arch_smt_update(void) { }
 
 #ifdef CONFIG_HOTPLUG_SMT
 enum cpuhp_smt_control cpu_smt_control __read_mostly = CPU_SMT_ENABLED;
+static unsigned int cpu_smt_max_threads __ro_after_init;
+unsigned int cpu_smt_num_threads;
 
 void __init cpu_smt_disable(bool force)
 {
@@ -433,10 +435,18 @@ void __init cpu_smt_disable(bool force)
  * The decision whether SMT is supported can only be done after the full
  * CPU identification. Called from architecture code.
  */
-void __init cpu_smt_check_topology(void)
+void __init cpu_smt_check_topology(unsigned int num_threads)
 {
 	if (!topology_smt_supported())
 		cpu_smt_control = CPU_SMT_NOT_SUPPORTED;
+
+	cpu_smt_max_threads = num_threads;
+
+	// May already be disabled by nosmt command line parameter
+	if (cpu_smt_control != CPU_SMT_ENABLED)
+		cpu_smt_num_threads = 1;
+	else
+		cpu_smt_num_threads = num_threads;
 }
 
 static int __init smt_cmdline_disable(char *str)
-- 
2.40.1


  parent reply	other threads:[~2023-05-24 15:59 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-24 15:56 [PATCH 1/9] cpu/SMT: Move SMT prototypes into cpu_smt.h Michael Ellerman
2023-05-24 15:56 ` [PATCH 2/9] cpu/SMT: Move smt/control simple exit cases earlier Michael Ellerman
2023-05-24 15:56 ` Michael Ellerman [this message]
2023-06-10 21:26   ` [PATCH 3/9] cpu/SMT: Store the current/max number of threads Thomas Gleixner
2023-06-10 22:08     ` Thomas Gleixner
2023-06-13 17:16     ` Laurent Dufour
2023-06-13 18:53       ` Thomas Gleixner
2023-06-14 12:27         ` Laurent Dufour
2023-05-24 15:56 ` [PATCH 4/9] cpu/SMT: Create topology_smt_threads_supported() Michael Ellerman
2023-06-10 22:15   ` Thomas Gleixner
2023-05-24 15:56 ` [PATCH 5/9] cpu/SMT: Create topology_smt_thread_allowed() Michael Ellerman
2023-06-10 22:35   ` Thomas Gleixner
2023-05-24 15:56 ` [PATCH 6/9] cpu/SMT: Allow enabling partial SMT states via sysfs Michael Ellerman
2023-06-10 20:09   ` Thomas Gleixner
2023-06-10 20:13     ` Thomas Gleixner
2023-05-24 15:56 ` [PATCH 7/9] powerpc/pseries: Initialise CPU hotplug callbacks earlier Michael Ellerman
2023-05-24 15:56 ` [PATCH 8/9] powerpc: Add HOTPLUG_SMT support Michael Ellerman
2023-06-01 13:27   ` Laurent Dufour
2023-06-01 16:19     ` Laurent Dufour
2023-06-10 21:10       ` Thomas Gleixner
2023-06-12 15:20         ` Laurent Dufour
2023-06-12 16:34           ` Thomas Gleixner
2023-05-24 15:56 ` [PATCH 9/9] powerpc/pseries: Honour current SMT state when DLPAR onlining CPUs Michael Ellerman

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=20230524155630.794584-3-mpe@ellerman.id.au \
    --to=mpe@ellerman.id.au \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=ldufour@linux.ibm.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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®