public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [Patch v2 1/2] smp: Add helper function to mark possible bad package number
@ 2023-06-13  5:25 Feng Tang
  2023-06-13  5:25 ` [Patch v2 2/2] x86/tsc: use logical_packages as a better estimation of socket numbers Feng Tang
  0 siblings, 1 reply; 23+ messages in thread
From: Feng Tang @ 2023-06-13  5:25 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	H . Peter Anvin, Peter Zijlstra, David Woodhouse,
	Paul E . McKenney, x86, linux-kernel
  Cc: rui.zhang, tim.c.chen, Feng Tang

For some architecture like x86, it calculates processor package number
in the process of bringing up all CPUs. The 'nr_cpus=' and 'maxcpus='
cmdline parameter setup may reduce the number of CPUs which actually
get brought up, and make the package number inaccurate (less than the
real number).

Add a general helper function arch_mark_bad_package_count() to enable
affected architectures to mark the possible unreliable package
estimation. Also implement the support in x86 to leverage it.

Suggested-by: Dave Hansen <dave.hansen@linux.intel.com>
Signed-off-by: Feng Tang <feng.tang@intel.com>
---
 arch/x86/kernel/smpboot.c |  9 +++++++++
 include/linux/smp.h       | 13 +++++++++++++
 kernel/smp.c              | 10 +++++++++-
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 352f0ce1ece4..b78770b0c43d 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -1274,6 +1274,15 @@ void arch_disable_smp_support(void)
 	disable_ioapic_support();
 }
 
+void arch_mark_bad_package_count(char *reason)
+{
+	if (package_count_unreliable)
+		return;
+
+	package_count_unreliable = true;
+	pr_warn("Processor package count may be unreliable due to: %s\n", reason);
+}
+
 /*
  * Fall back to non SMP mode after errors.
  *
diff --git a/include/linux/smp.h b/include/linux/smp.h
index 91ea4a67f8ca..25bfdc73cc78 100644
--- a/include/linux/smp.h
+++ b/include/linux/smp.h
@@ -188,6 +188,13 @@ static inline int get_boot_cpu_id(void)
 	return __boot_cpu_id;
 }
 
+extern bool package_count_unreliable;
+
+static inline bool is_package_count_reliable(void)
+{
+	 return !package_count_unreliable;
+}
+
 #else /* !SMP */
 
 static inline void smp_send_stop(void) { }
@@ -230,6 +237,10 @@ static inline int get_boot_cpu_id(void)
 	return 0;
 }
 
+static inline bool is_package_count_reliable(void)
+{
+	return true;
+}
 #endif /* !SMP */
 
 /**
@@ -283,6 +294,8 @@ extern void arch_disable_smp_support(void);
 extern void arch_thaw_secondary_cpus_begin(void);
 extern void arch_thaw_secondary_cpus_end(void);
 
+extern void arch_mark_bad_package_count(char *reason);
+
 void smp_setup_processor_id(void);
 
 int smp_call_on_cpu(unsigned int cpu, int (*func)(void *), void *par,
diff --git a/kernel/smp.c b/kernel/smp.c
index ab3e5dad6cfe..494288bedd9b 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -904,13 +904,20 @@ static int __init nosmp(char *str)
 
 early_param("nosmp", nosmp);
 
+bool package_count_unreliable;
+
+void __weak arch_mark_bad_package_count(char *reason) { }
+
 /* this is hard limit */
 static int __init nrcpus(char *str)
 {
 	int nr_cpus;
 
-	if (get_option(&str, &nr_cpus) && nr_cpus > 0 && nr_cpus < nr_cpu_ids)
+	if (get_option(&str, &nr_cpus) && nr_cpus > 0 &&
+		nr_cpus < nr_cpu_ids) {
 		set_nr_cpu_ids(nr_cpus);
+		arch_mark_bad_package_count("'nr_cpus' setup");
+	}
 
 	return 0;
 }
@@ -923,6 +930,7 @@ static int __init maxcpus(char *str)
 	if (setup_max_cpus == 0)
 		arch_disable_smp_support();
 
+	arch_mark_bad_package_count("'maxcpus' setup");
 	return 0;
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2023-07-27  1:33 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-13  5:25 [Patch v2 1/2] smp: Add helper function to mark possible bad package number Feng Tang
2023-06-13  5:25 ` [Patch v2 2/2] x86/tsc: use logical_packages as a better estimation of socket numbers Feng Tang
2023-06-15  9:20   ` Peter Zijlstra
2023-06-16  6:53     ` Zhang, Rui
2023-06-16  8:02       ` Peter Zijlstra
2023-06-16  8:10         ` Peter Zijlstra
2023-06-16  9:19           ` Zhang, Rui
2023-06-16  9:42             ` Peter Zijlstra
2023-06-16 11:23               ` Zhang, Rui
2023-06-16 11:47                 ` Feng Tang
2023-06-16  8:22         ` Peter Zijlstra
2023-06-19 10:42         ` Feng Tang
2023-06-16  7:18     ` Feng Tang
2023-06-22 14:27       ` Thomas Gleixner
2023-06-22 23:07         ` Thomas Gleixner
2023-06-23 15:49           ` Zhang, Rui
     [not found]           ` <ZJW0gi5oQQbxf8Df@feng-clx>
2023-06-25 14:51             ` Feng Tang
2023-06-27 11:14               ` Thomas Gleixner
2023-06-29 13:27                 ` Feng Tang
2023-07-17 13:38                   ` Feng Tang
2023-07-26 19:37                     ` Thomas Gleixner
2023-07-27  1:24                       ` Feng Tang
2023-06-23 15:36         ` Zhang, Rui

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox