Skip to content

Commit 380414b

Browse files
committed
x86/cpu/topology: Use topology logical mapping mechanism
Replace the logical package and die management functionality and retrieve the logical IDs from the topology bitmaps. Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Michael Kelley <[email protected]> Tested-by: Sohil Mehta <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent b7065f4 commit 380414b

File tree

4 files changed

+12
-131
lines changed

4 files changed

+12
-131
lines changed

arch/x86/include/asm/topology.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,13 @@ static inline int topology_get_logical_id(u32 apicid, enum x86_topology_domains
172172
#define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu))
173173
#define topology_sibling_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu))
174174

175+
176+
static inline int topology_phys_to_logical_pkg(unsigned int pkg)
177+
{
178+
return topology_get_logical_id(pkg << x86_topo_system.dom_shifts[TOPO_PKG_DOMAIN],
179+
TOPO_PKG_DOMAIN);
180+
}
181+
175182
extern int __max_smt_threads;
176183

177184
static inline int topology_max_smt_threads(void)
@@ -181,10 +188,6 @@ static inline int topology_max_smt_threads(void)
181188

182189
#include <linux/cpu_smt.h>
183190

184-
int topology_update_package_map(unsigned int apicid, unsigned int cpu);
185-
int topology_update_die_map(unsigned int dieid, unsigned int cpu);
186-
int topology_phys_to_logical_pkg(unsigned int pkg);
187-
188191
extern unsigned int __amd_nodes_per_pkg;
189192

190193
static inline unsigned int topology_amd_nodes_per_pkg(void)
@@ -205,10 +208,6 @@ static inline bool topology_is_primary_thread(unsigned int cpu)
205208
}
206209

207210
#else /* CONFIG_SMP */
208-
static inline int
209-
topology_update_package_map(unsigned int apicid, unsigned int cpu) { return 0; }
210-
static inline int
211-
topology_update_die_map(unsigned int dieid, unsigned int cpu) { return 0; }
212211
static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return 0; }
213212
static inline int topology_max_smt_threads(void) { return 1; }
214213
static inline bool topology_is_primary_thread(unsigned int cpu) { return true; }

arch/x86/kernel/cpu/common.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,18 +1719,6 @@ static void generic_identify(struct cpuinfo_x86 *c)
17191719
#endif
17201720
}
17211721

1722-
static void update_package_map(struct cpuinfo_x86 *c)
1723-
{
1724-
#ifdef CONFIG_SMP
1725-
unsigned int cpu = smp_processor_id();
1726-
1727-
BUG_ON(topology_update_package_map(c->topo.pkg_id, cpu));
1728-
BUG_ON(topology_update_die_map(c->topo.die_id, cpu));
1729-
#else
1730-
c->topo.logical_pkg_id = 0;
1731-
#endif
1732-
}
1733-
17341722
/*
17351723
* This does the hard work of actually picking apart the CPU stuff...
17361724
*/
@@ -1915,7 +1903,6 @@ void identify_secondary_cpu(struct cpuinfo_x86 *c)
19151903
#ifdef CONFIG_X86_32
19161904
enable_sep_cpu();
19171905
#endif
1918-
update_package_map(c);
19191906
x86_spec_ctrl_setup_ap();
19201907
update_srbds_msr();
19211908
if (boot_cpu_has_bug(X86_BUG_GDS))

arch/x86/kernel/cpu/topology_common.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "cpu.h"
1111

1212
struct x86_topology_system x86_topo_system __ro_after_init;
13+
EXPORT_SYMBOL_GPL(x86_topo_system);
1314

1415
unsigned int __amd_nodes_per_pkg __ro_after_init;
1516
EXPORT_SYMBOL_GPL(__amd_nodes_per_pkg);
@@ -147,6 +148,9 @@ static void topo_set_ids(struct topo_scan *tscan)
147148
c->topo.pkg_id = topo_shift_apicid(apicid, TOPO_PKG_DOMAIN);
148149
c->topo.die_id = topo_shift_apicid(apicid, TOPO_DIE_DOMAIN);
149150

151+
c->topo.logical_pkg_id = topology_get_logical_id(apicid, TOPO_PKG_DOMAIN);
152+
c->topo.logical_die_id = topology_get_logical_id(apicid, TOPO_DIE_DOMAIN);
153+
150154
/* Package relative core ID */
151155
c->topo.core_id = (apicid & topo_domain_mask(TOPO_PKG_DOMAIN)) >>
152156
x86_topo_system.dom_shifts[TOPO_SMT_DOMAIN];

arch/x86/kernel/smpboot.c

Lines changed: 1 addition & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,6 @@ struct mwait_cpu_dead {
125125
*/
126126
static DEFINE_PER_CPU_ALIGNED(struct mwait_cpu_dead, mwait_cpu_dead);
127127

128-
/* Logical package management. */
129-
struct logical_maps {
130-
u32 phys_pkg_id;
131-
u32 phys_die_id;
132-
u32 logical_pkg_id;
133-
u32 logical_die_id;
134-
};
135-
136-
/* Temporary workaround until the full topology mechanics is in place */
137-
static DEFINE_PER_CPU_READ_MOSTLY(struct logical_maps, logical_maps) = {
138-
.phys_pkg_id = U32_MAX,
139-
.phys_die_id = U32_MAX,
140-
};
141-
142-
static unsigned int logical_packages __read_mostly;
143-
static unsigned int logical_die __read_mostly;
144-
145128
/* Maximum number of SMT threads on any online core */
146129
int __read_mostly __max_smt_threads = 1;
147130

@@ -334,103 +317,11 @@ static void notrace start_secondary(void *unused)
334317
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
335318
}
336319

337-
/**
338-
* topology_phys_to_logical_pkg - Map a physical package id to a logical
339-
* @phys_pkg: The physical package id to map
340-
*
341-
* Returns logical package id or -1 if not found
342-
*/
343-
int topology_phys_to_logical_pkg(unsigned int phys_pkg)
344-
{
345-
int cpu;
346-
347-
for_each_possible_cpu(cpu) {
348-
if (per_cpu(logical_maps.phys_pkg_id, cpu) == phys_pkg)
349-
return per_cpu(logical_maps.logical_pkg_id, cpu);
350-
}
351-
return -1;
352-
}
353-
EXPORT_SYMBOL(topology_phys_to_logical_pkg);
354-
355-
/**
356-
* topology_phys_to_logical_die - Map a physical die id to logical
357-
* @die_id: The physical die id to map
358-
* @cur_cpu: The CPU for which the mapping is done
359-
*
360-
* Returns logical die id or -1 if not found
361-
*/
362-
static int topology_phys_to_logical_die(unsigned int die_id, unsigned int cur_cpu)
363-
{
364-
int cpu, proc_id = cpu_data(cur_cpu).topo.pkg_id;
365-
366-
for_each_possible_cpu(cpu) {
367-
if (per_cpu(logical_maps.phys_pkg_id, cpu) == proc_id &&
368-
per_cpu(logical_maps.phys_die_id, cpu) == die_id)
369-
return per_cpu(logical_maps.logical_die_id, cpu);
370-
}
371-
return -1;
372-
}
373-
374-
/**
375-
* topology_update_package_map - Update the physical to logical package map
376-
* @pkg: The physical package id as retrieved via CPUID
377-
* @cpu: The cpu for which this is updated
378-
*/
379-
int topology_update_package_map(unsigned int pkg, unsigned int cpu)
380-
{
381-
int new;
382-
383-
/* Already available somewhere? */
384-
new = topology_phys_to_logical_pkg(pkg);
385-
if (new >= 0)
386-
goto found;
387-
388-
new = logical_packages++;
389-
if (new != pkg) {
390-
pr_info("CPU %u Converting physical %u to logical package %u\n",
391-
cpu, pkg, new);
392-
}
393-
found:
394-
per_cpu(logical_maps.phys_pkg_id, cpu) = pkg;
395-
per_cpu(logical_maps.logical_pkg_id, cpu) = new;
396-
cpu_data(cpu).topo.logical_pkg_id = new;
397-
return 0;
398-
}
399-
/**
400-
* topology_update_die_map - Update the physical to logical die map
401-
* @die: The die id as retrieved via CPUID
402-
* @cpu: The cpu for which this is updated
403-
*/
404-
int topology_update_die_map(unsigned int die, unsigned int cpu)
405-
{
406-
int new;
407-
408-
/* Already available somewhere? */
409-
new = topology_phys_to_logical_die(die, cpu);
410-
if (new >= 0)
411-
goto found;
412-
413-
new = logical_die++;
414-
if (new != die) {
415-
pr_info("CPU %u Converting physical %u to logical die %u\n",
416-
cpu, die, new);
417-
}
418-
found:
419-
per_cpu(logical_maps.phys_die_id, cpu) = die;
420-
per_cpu(logical_maps.logical_die_id, cpu) = new;
421-
cpu_data(cpu).topo.logical_die_id = new;
422-
return 0;
423-
}
424-
425320
static void __init smp_store_boot_cpu_info(void)
426321
{
427-
int id = 0; /* CPU 0 */
428-
struct cpuinfo_x86 *c = &cpu_data(id);
322+
struct cpuinfo_x86 *c = &cpu_data(0);
429323

430324
*c = boot_cpu_data;
431-
c->cpu_index = id;
432-
topology_update_package_map(c->topo.pkg_id, id);
433-
topology_update_die_map(c->topo.die_id, id);
434325
c->initialized = true;
435326
}
436327

0 commit comments

Comments
 (0)