Skip to content

Commit fd43b8a

Browse files
committed
x86/cpu/topology: Provide __num_[cores|threads]_per_package
Expose properly accounted information and accessors so the fiddling with other topology variables can be replaced. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Michael Kelley <mhklinux@outlook.com> Tested-by: Sohil Mehta <sohil.mehta@intel.com> Link: https://lore.kernel.org/r/20240213210253.120958987@linutronix.de
1 parent bd745d1 commit fd43b8a

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

arch/x86/include/asm/topology.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ extern const struct cpumask *cpu_clustergroup_mask(int cpu);
146146
extern unsigned int __max_dies_per_package;
147147
extern unsigned int __max_logical_packages;
148148
extern unsigned int __max_threads_per_core;
149+
extern unsigned int __num_threads_per_package;
150+
extern unsigned int __num_cores_per_package;
149151

150152
static inline unsigned int topology_max_packages(void)
151153
{
@@ -157,6 +159,16 @@ static inline unsigned int topology_max_dies_per_package(void)
157159
return __max_dies_per_package;
158160
}
159161

162+
static inline unsigned int topology_num_cores_per_package(void)
163+
{
164+
return __num_cores_per_package;
165+
}
166+
167+
static inline unsigned int topology_num_threads_per_package(void)
168+
{
169+
return __num_threads_per_package;
170+
}
171+
160172
#ifdef CONFIG_X86_LOCAL_APIC
161173
int topology_get_logical_id(u32 apicid, enum x86_topology_domains at_level);
162174
#else

arch/x86/kernel/cpu/common.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ EXPORT_SYMBOL(__max_dies_per_package);
8282
unsigned int __max_logical_packages __ro_after_init = 1;
8383
EXPORT_SYMBOL(__max_logical_packages);
8484

85+
unsigned int __num_cores_per_package __ro_after_init = 1;
86+
EXPORT_SYMBOL(__num_cores_per_package);
87+
88+
unsigned int __num_threads_per_package __ro_after_init = 1;
89+
EXPORT_SYMBOL(__num_threads_per_package);
90+
8591
static struct ppin_info {
8692
int feature;
8793
int msr_ppin_ctl;

arch/x86/kernel/cpu/topology.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ void __init topology_init_possible_cpus(void)
392392
unsigned int disabled = topo_info.nr_disabled_cpus;
393393
unsigned int cnta, cntb, cpu, allowed = 1;
394394
unsigned int total = assigned + disabled;
395-
u32 apicid;
395+
u32 apicid, firstid;
396396

397397
if (!restrict_to_up()) {
398398
if (WARN_ON_ONCE(assigned > nr_cpu_ids)) {
@@ -432,6 +432,12 @@ void __init topology_init_possible_cpus(void)
432432
__max_threads_per_core = DIV_ROUND_UP(cntb, cnta);
433433
pr_info("Max. threads per core: %3u\n", __max_threads_per_core);
434434

435+
firstid = find_first_bit(apic_maps[TOPO_SMT_DOMAIN].map, MAX_LOCAL_APIC);
436+
__num_cores_per_package = topology_unit_count(firstid, TOPO_CORE_DOMAIN, TOPO_PKG_DOMAIN);
437+
pr_info("Num. cores per package: %3u\n", __num_cores_per_package);
438+
__num_threads_per_package = topology_unit_count(firstid, TOPO_SMT_DOMAIN, TOPO_PKG_DOMAIN);
439+
pr_info("Num. threads per package: %3u\n", __num_threads_per_package);
440+
435441
pr_info("Allowing %u present CPUs plus %u hotplug CPUs\n", assigned, disabled);
436442
if (topo_info.nr_rejected_cpus)
437443
pr_info("Rejected CPUs %u\n", topo_info.nr_rejected_cpus);

0 commit comments

Comments
 (0)