Skip to content

Commit ae6730f

Browse files
author
Peter Zijlstra
committed
x86/topo: Add topology_num_nodes_per_package()
Use the MADT and SRAT table data to compute __num_nodes_per_package. Specifically, SRAT has already been parsed in x86_numa_init(), which is called before acpi_boot_init() which parses MADT. So both are available in topology_init_possible_cpus(). This number is useful to divinate the various Intel CoD/SNC and AMD NPS modes, since the platforms are failing to provide this otherwise. Doing it this way is independent of the number of online CPUs and other such shenanigans. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Ingo Molnar <mingo@kernel.org> Tested-by: Tony Luck <tony.luck@intel.com> Tested-by: K Prateek Nayak <kprateek.nayak@amd.com> Tested-by: Zhang Rui <rui.zhang@intel.com> Tested-by: Chen Yu <yu.c.chen@intel.com> Tested-by: Kyle Meyer <kyle.meyer@hpe.com> Link: https://patch.msgid.link/20260303110100.004091624@infradead.org
1 parent 48084cc commit ae6730f

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

arch/x86/include/asm/topology.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ extern unsigned int __max_logical_packages;
155155
extern unsigned int __max_threads_per_core;
156156
extern unsigned int __num_threads_per_package;
157157
extern unsigned int __num_cores_per_package;
158+
extern unsigned int __num_nodes_per_package;
158159

159160
const char *get_topology_cpu_type_name(struct cpuinfo_x86 *c);
160161
enum x86_topology_cpu_type get_topology_cpu_type(struct cpuinfo_x86 *c);
@@ -179,6 +180,11 @@ static inline unsigned int topology_num_threads_per_package(void)
179180
return __num_threads_per_package;
180181
}
181182

183+
static inline unsigned int topology_num_nodes_per_package(void)
184+
{
185+
return __num_nodes_per_package;
186+
}
187+
182188
#ifdef CONFIG_X86_LOCAL_APIC
183189
int topology_get_logical_id(u32 apicid, enum x86_topology_domains at_level);
184190
#else

arch/x86/kernel/cpu/common.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ EXPORT_SYMBOL(__max_dies_per_package);
9595
unsigned int __max_logical_packages __ro_after_init = 1;
9696
EXPORT_SYMBOL(__max_logical_packages);
9797

98+
unsigned int __num_nodes_per_package __ro_after_init = 1;
99+
EXPORT_SYMBOL(__num_nodes_per_package);
100+
98101
unsigned int __num_cores_per_package __ro_after_init = 1;
99102
EXPORT_SYMBOL(__num_cores_per_package);
100103

arch/x86/kernel/cpu/topology.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <asm/mpspec.h>
3232
#include <asm/msr.h>
3333
#include <asm/smp.h>
34+
#include <asm/numa.h>
3435

3536
#include "cpu.h"
3637

@@ -492,11 +493,19 @@ void __init topology_init_possible_cpus(void)
492493
set_nr_cpu_ids(allowed);
493494

494495
cnta = domain_weight(TOPO_PKG_DOMAIN);
495-
cntb = domain_weight(TOPO_DIE_DOMAIN);
496496
__max_logical_packages = cnta;
497+
498+
pr_info("Max. logical packages: %3u\n", __max_logical_packages);
499+
500+
cntb = num_phys_nodes();
501+
__num_nodes_per_package = DIV_ROUND_UP(cntb, cnta);
502+
503+
pr_info("Max. logical nodes: %3u\n", cntb);
504+
pr_info("Num. nodes per package:%3u\n", __num_nodes_per_package);
505+
506+
cntb = domain_weight(TOPO_DIE_DOMAIN);
497507
__max_dies_per_package = 1U << (get_count_order(cntb) - get_count_order(cnta));
498508

499-
pr_info("Max. logical packages: %3u\n", cnta);
500509
pr_info("Max. logical dies: %3u\n", cntb);
501510
pr_info("Max. dies per package: %3u\n", __max_dies_per_package);
502511

0 commit comments

Comments
 (0)