Skip to content

Commit 89b0f15

Browse files
committed
x86/cpu/topology: Get rid of cpuinfo::x86_max_cores
Now that __num_cores_per_package and __num_threads_per_package are available, cpuinfo::x86_max_cores and the related math all over the place can be replaced with the ready to consume data. 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.176147806@linutronix.de
1 parent fd43b8a commit 89b0f15

File tree

14 files changed

+31
-43
lines changed

14 files changed

+31
-43
lines changed

Documentation/arch/x86/topology.rst

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,21 @@ AMD nomenclature for package is 'Node'.
4747

4848
Package-related topology information in the kernel:
4949

50-
- cpuinfo_x86.x86_max_cores:
50+
- topology_num_threads_per_package()
5151

52-
The number of cores in a package. This information is retrieved via CPUID.
52+
The number of threads in a package.
5353

54-
- cpuinfo_x86.x86_max_dies:
54+
- topology_num_cores_per_package()
5555

56-
The number of dies in a package. This information is retrieved via CPUID.
56+
The number of cores in a package.
57+
58+
- topology_max_dies_per_package()
59+
60+
The maximum number of dies in a package.
5761

5862
- cpuinfo_x86.topo.die_id:
5963

60-
The physical ID of the die. This information is retrieved via CPUID.
64+
The physical ID of the die.
6165

6266
- cpuinfo_x86.topo.pkg_id:
6367

@@ -96,16 +100,6 @@ are SMT- or CMT-type threads.
96100
AMDs nomenclature for a CMT core is "Compute Unit". The kernel always uses
97101
"core".
98102

99-
Core-related topology information in the kernel:
100-
101-
- smp_num_siblings:
102-
103-
The number of threads in a core. The number of threads in a package can be
104-
calculated by::
105-
106-
threads_per_package = cpuinfo_x86.x86_max_cores * smp_num_siblings
107-
108-
109103
Threads
110104
=======
111105
A thread is a single scheduling unit. It's the equivalent to a logical Linux

arch/x86/events/intel/uncore_nhmex.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,8 +1221,8 @@ void nhmex_uncore_cpu_init(void)
12211221
uncore_nhmex = true;
12221222
else
12231223
nhmex_uncore_mbox.event_descs = wsmex_uncore_mbox_events;
1224-
if (nhmex_uncore_cbox.num_boxes > boot_cpu_data.x86_max_cores)
1225-
nhmex_uncore_cbox.num_boxes = boot_cpu_data.x86_max_cores;
1224+
if (nhmex_uncore_cbox.num_boxes > topology_num_cores_per_package())
1225+
nhmex_uncore_cbox.num_boxes = topology_num_cores_per_package();
12261226
uncore_msr_uncores = nhmex_msr_uncores;
12271227
}
12281228
/* end of Nehalem-EX uncore support */

arch/x86/events/intel/uncore_snb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ static struct intel_uncore_type *snb_msr_uncores[] = {
364364
void snb_uncore_cpu_init(void)
365365
{
366366
uncore_msr_uncores = snb_msr_uncores;
367-
if (snb_uncore_cbox.num_boxes > boot_cpu_data.x86_max_cores)
368-
snb_uncore_cbox.num_boxes = boot_cpu_data.x86_max_cores;
367+
if (snb_uncore_cbox.num_boxes > topology_num_cores_per_package())
368+
snb_uncore_cbox.num_boxes = topology_num_cores_per_package();
369369
}
370370

371371
static void skl_uncore_msr_init_box(struct intel_uncore_box *box)
@@ -428,8 +428,8 @@ static struct intel_uncore_type *skl_msr_uncores[] = {
428428
void skl_uncore_cpu_init(void)
429429
{
430430
uncore_msr_uncores = skl_msr_uncores;
431-
if (skl_uncore_cbox.num_boxes > boot_cpu_data.x86_max_cores)
432-
skl_uncore_cbox.num_boxes = boot_cpu_data.x86_max_cores;
431+
if (skl_uncore_cbox.num_boxes > topology_num_cores_per_package())
432+
skl_uncore_cbox.num_boxes = topology_num_cores_per_package();
433433
snb_uncore_arb.ops = &skl_uncore_msr_ops;
434434
}
435435

arch/x86/events/intel/uncore_snbep.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,8 +1172,8 @@ static struct intel_uncore_type *snbep_msr_uncores[] = {
11721172

11731173
void snbep_uncore_cpu_init(void)
11741174
{
1175-
if (snbep_uncore_cbox.num_boxes > boot_cpu_data.x86_max_cores)
1176-
snbep_uncore_cbox.num_boxes = boot_cpu_data.x86_max_cores;
1175+
if (snbep_uncore_cbox.num_boxes > topology_num_cores_per_package())
1176+
snbep_uncore_cbox.num_boxes = topology_num_cores_per_package();
11771177
uncore_msr_uncores = snbep_msr_uncores;
11781178
}
11791179

@@ -1845,8 +1845,8 @@ static struct intel_uncore_type *ivbep_msr_uncores[] = {
18451845

18461846
void ivbep_uncore_cpu_init(void)
18471847
{
1848-
if (ivbep_uncore_cbox.num_boxes > boot_cpu_data.x86_max_cores)
1849-
ivbep_uncore_cbox.num_boxes = boot_cpu_data.x86_max_cores;
1848+
if (ivbep_uncore_cbox.num_boxes > topology_num_cores_per_package())
1849+
ivbep_uncore_cbox.num_boxes = topology_num_cores_per_package();
18501850
uncore_msr_uncores = ivbep_msr_uncores;
18511851
}
18521852

@@ -2917,8 +2917,8 @@ static bool hswep_has_limit_sbox(unsigned int device)
29172917

29182918
void hswep_uncore_cpu_init(void)
29192919
{
2920-
if (hswep_uncore_cbox.num_boxes > boot_cpu_data.x86_max_cores)
2921-
hswep_uncore_cbox.num_boxes = boot_cpu_data.x86_max_cores;
2920+
if (hswep_uncore_cbox.num_boxes > topology_num_cores_per_package())
2921+
hswep_uncore_cbox.num_boxes = topology_num_cores_per_package();
29222922

29232923
/* Detect 6-8 core systems with only two SBOXes */
29242924
if (hswep_has_limit_sbox(HSWEP_PCU_DID))
@@ -3280,8 +3280,8 @@ static struct event_constraint bdx_uncore_pcu_constraints[] = {
32803280

32813281
void bdx_uncore_cpu_init(void)
32823282
{
3283-
if (bdx_uncore_cbox.num_boxes > boot_cpu_data.x86_max_cores)
3284-
bdx_uncore_cbox.num_boxes = boot_cpu_data.x86_max_cores;
3283+
if (bdx_uncore_cbox.num_boxes > topology_num_cores_per_package())
3284+
bdx_uncore_cbox.num_boxes = topology_num_cores_per_package();
32853285
uncore_msr_uncores = bdx_msr_uncores;
32863286

32873287
/* Detect systems with no SBOXes */

arch/x86/include/asm/processor.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ struct cpuinfo_x86 {
149149
unsigned long loops_per_jiffy;
150150
/* protected processor identification number */
151151
u64 ppin;
152-
/* cpuid returned max cores value: */
153-
u16 x86_max_cores;
154152
u16 x86_clflush_size;
155153
/* number of cores as seen by the OS: */
156154
u16 booted_cores;

arch/x86/kernel/cpu/cacheinfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ amd_cpuid4(int leaf, union _cpuid4_leaf_eax *eax,
301301
eax->split.type = types[leaf];
302302
eax->split.level = levels[leaf];
303303
eax->split.num_threads_sharing = 0;
304-
eax->split.num_cores_on_die = __this_cpu_read(cpu_info.x86_max_cores) - 1;
304+
eax->split.num_cores_on_die = topology_num_cores_per_package();
305305

306306

307307
if (assoc == 0xffff)

arch/x86/kernel/cpu/common.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1738,7 +1738,6 @@ static void identify_cpu(struct cpuinfo_x86 *c)
17381738
c->x86_model = c->x86_stepping = 0; /* So far unknown... */
17391739
c->x86_vendor_id[0] = '\0'; /* Unset */
17401740
c->x86_model_id[0] = '\0'; /* Unset */
1741-
c->x86_max_cores = 1;
17421741
#ifdef CONFIG_X86_64
17431742
c->x86_clflush_size = 64;
17441743
c->x86_phys_bits = 36;

arch/x86/kernel/cpu/debugfs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ static int cpu_debug_show(struct seq_file *m, void *p)
2828
seq_printf(m, "l2c_id: %u\n", c->topo.l2c_id);
2929
seq_printf(m, "amd_node_id: %u\n", c->topo.amd_node_id);
3030
seq_printf(m, "amd_nodes_per_pkg: %u\n", topology_amd_nodes_per_pkg());
31-
seq_printf(m, "max_cores: %u\n", c->x86_max_cores);
31+
seq_printf(m, "num_threads: %u\n", __num_threads_per_package);
32+
seq_printf(m, "num_cores: %u\n", __num_cores_per_package);
3233
seq_printf(m, "max_dies_per_pkg: %u\n", __max_dies_per_package);
3334
seq_printf(m, "max_threads_per_core:%u\n", __max_threads_per_core);
3435
return 0;

arch/x86/kernel/cpu/mce/inject.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,9 @@ static void trigger_thr_int(void *info)
430430

431431
static u32 get_nbc_for_node(int node_id)
432432
{
433-
struct cpuinfo_x86 *c = &boot_cpu_data;
434433
u32 cores_per_node;
435434

436-
cores_per_node = (c->x86_max_cores * __max_threads_per_core) / topology_amd_nodes_per_pkg();
435+
cores_per_node = topology_num_threads_per_package() / topology_amd_nodes_per_pkg();
437436
return cores_per_node * node_id;
438437
}
439438

arch/x86/kernel/cpu/microcode/intel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ static __init void calc_llc_size_per_core(struct cpuinfo_x86 *c)
641641
{
642642
u64 llc_size = c->x86_cache_size * 1024ULL;
643643

644-
do_div(llc_size, c->x86_max_cores);
644+
do_div(llc_size, topology_num_cores_per_package());
645645
llc_size_per_core = (unsigned int)llc_size;
646646
}
647647

0 commit comments

Comments
 (0)