Skip to content

Commit 212bf4f

Browse files
lenbKAGA-KOKO
authored andcommitted
x86/topology: Define topology_logical_die_id()
Define topology_logical_die_id() ala existing topology_logical_package_id() Signed-off-by: Len Brown <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Zhang Rui <[email protected]> Reviewed-by: Ingo Molnar <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/2f3526e25ae14fbeff26fb26e877d159df8946d9.1557769318.git.len.brown@intel.com
1 parent 306a0de commit 212bf4f

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

arch/x86/include/asm/processor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ struct cpuinfo_x86 {
118118
/* Core id: */
119119
u16 cpu_core_id;
120120
u16 cpu_die_id;
121+
u16 logical_die_id;
121122
/* Index into per_cpu list: */
122123
u16 cpu_index;
123124
u32 microcode;

arch/x86/include/asm/topology.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ extern const struct cpumask *cpu_coregroup_mask(int cpu);
106106

107107
#define topology_logical_package_id(cpu) (cpu_data(cpu).logical_proc_id)
108108
#define topology_physical_package_id(cpu) (cpu_data(cpu).phys_proc_id)
109+
#define topology_logical_die_id(cpu) (cpu_data(cpu).logical_die_id)
109110
#define topology_die_id(cpu) (cpu_data(cpu).cpu_die_id)
110111
#define topology_core_id(cpu) (cpu_data(cpu).cpu_core_id)
111112

@@ -131,13 +132,17 @@ static inline int topology_max_smt_threads(void)
131132
}
132133

133134
int topology_update_package_map(unsigned int apicid, unsigned int cpu);
135+
int topology_update_die_map(unsigned int dieid, unsigned int cpu);
134136
int topology_phys_to_logical_pkg(unsigned int pkg);
137+
int topology_phys_to_logical_die(unsigned int die, unsigned int cpu);
135138
bool topology_is_primary_thread(unsigned int cpu);
136139
bool topology_smt_supported(void);
137140
#else
138141
#define topology_max_packages() (1)
139142
static inline int
140143
topology_update_package_map(unsigned int apicid, unsigned int cpu) { return 0; }
144+
static inline int
145+
topology_update_die_map(unsigned int dieid, unsigned int cpu) { return 0; }
141146
static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return 0; }
142147
static inline int topology_phys_to_logical_die(unsigned int die,
143148
unsigned int cpu) { return 0; }

arch/x86/kernel/cpu/common.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,7 @@ static void validate_apic_and_package_id(struct cpuinfo_x86 *c)
12981298
cpu, apicid, c->initial_apicid);
12991299
}
13001300
BUG_ON(topology_update_package_map(c->phys_proc_id, cpu));
1301+
BUG_ON(topology_update_die_map(c->cpu_die_id, cpu));
13011302
#else
13021303
c->logical_proc_id = 0;
13031304
#endif

arch/x86/kernel/smpboot.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ EXPORT_PER_CPU_SYMBOL(cpu_info);
101101
unsigned int __max_logical_packages __read_mostly;
102102
EXPORT_SYMBOL(__max_logical_packages);
103103
static unsigned int logical_packages __read_mostly;
104+
static unsigned int logical_die __read_mostly;
104105

105106
/* Maximum number of SMT threads on any online core */
106107
int __read_mostly __max_smt_threads = 1;
@@ -302,6 +303,26 @@ int topology_phys_to_logical_pkg(unsigned int phys_pkg)
302303
return -1;
303304
}
304305
EXPORT_SYMBOL(topology_phys_to_logical_pkg);
306+
/**
307+
* topology_phys_to_logical_die - Map a physical die id to logical
308+
*
309+
* Returns logical die id or -1 if not found
310+
*/
311+
int topology_phys_to_logical_die(unsigned int die_id, unsigned int cur_cpu)
312+
{
313+
int cpu;
314+
int proc_id = cpu_data(cur_cpu).phys_proc_id;
315+
316+
for_each_possible_cpu(cpu) {
317+
struct cpuinfo_x86 *c = &cpu_data(cpu);
318+
319+
if (c->initialized && c->cpu_die_id == die_id &&
320+
c->phys_proc_id == proc_id)
321+
return c->logical_die_id;
322+
}
323+
return -1;
324+
}
325+
EXPORT_SYMBOL(topology_phys_to_logical_die);
305326

306327
/**
307328
* topology_update_package_map - Update the physical to logical package map
@@ -326,6 +347,29 @@ int topology_update_package_map(unsigned int pkg, unsigned int cpu)
326347
cpu_data(cpu).logical_proc_id = new;
327348
return 0;
328349
}
350+
/**
351+
* topology_update_die_map - Update the physical to logical die map
352+
* @die: The die id as retrieved via CPUID
353+
* @cpu: The cpu for which this is updated
354+
*/
355+
int topology_update_die_map(unsigned int die, unsigned int cpu)
356+
{
357+
int new;
358+
359+
/* Already available somewhere? */
360+
new = topology_phys_to_logical_die(die, cpu);
361+
if (new >= 0)
362+
goto found;
363+
364+
new = logical_die++;
365+
if (new != die) {
366+
pr_info("CPU %u Converting physical %u to logical die %u\n",
367+
cpu, die, new);
368+
}
369+
found:
370+
cpu_data(cpu).logical_die_id = new;
371+
return 0;
372+
}
329373

330374
void __init smp_store_boot_cpu_info(void)
331375
{
@@ -335,6 +379,7 @@ void __init smp_store_boot_cpu_info(void)
335379
*c = boot_cpu_data;
336380
c->cpu_index = id;
337381
topology_update_package_map(c->phys_proc_id, id);
382+
topology_update_die_map(c->cpu_die_id, id);
338383
c->initialized = true;
339384
}
340385

0 commit comments

Comments
 (0)