Skip to content

Commit 90781f0

Browse files
committed
x86/cpu/topology: Cure the abuse of cpuinfo for persisting logical ids
Per CPU cpuinfo is used to persist the logical package and die IDs. That's really not the right place simply because cpuinfo is subject to be reinitialized when a CPU goes through an offline/online cycle. This works by chance today, but that's far from correct and neither obvious nor documented. Add a per cpu datastructure which persists those logical IDs, which allows to cleanup the CPUID evaluation code. This is a temporary workaround until the larger topology management is in place, which makes all of this logical management mechanics obsolete. Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Juergen Gross <[email protected]> Tested-by: Sohil Mehta <[email protected]> Tested-by: Michael Kelley <[email protected]> Tested-by: Peter Zijlstra (Intel) <[email protected]> Tested-by: Zhang Rui <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent db4a408 commit 90781f0

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

arch/x86/kernel/smpboot.c

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,20 @@ struct mwait_cpu_dead {
124124
*/
125125
static DEFINE_PER_CPU_ALIGNED(struct mwait_cpu_dead, mwait_cpu_dead);
126126

127-
/* Logical package management. We might want to allocate that dynamically */
127+
/* Logical package management. */
128+
struct logical_maps {
129+
u32 phys_pkg_id;
130+
u32 phys_die_id;
131+
u32 logical_pkg_id;
132+
u32 logical_die_id;
133+
};
134+
135+
/* Temporary workaround until the full topology mechanics is in place */
136+
static DEFINE_PER_CPU_READ_MOSTLY(struct logical_maps, logical_maps) = {
137+
.phys_pkg_id = U32_MAX,
138+
.phys_die_id = U32_MAX,
139+
};
140+
128141
unsigned int __max_logical_packages __read_mostly;
129142
EXPORT_SYMBOL(__max_logical_packages);
130143
static unsigned int logical_packages __read_mostly;
@@ -337,10 +350,8 @@ int topology_phys_to_logical_pkg(unsigned int phys_pkg)
337350
int cpu;
338351

339352
for_each_possible_cpu(cpu) {
340-
struct cpuinfo_x86 *c = &cpu_data(cpu);
341-
342-
if (c->initialized && c->topo.pkg_id == phys_pkg)
343-
return c->topo.logical_pkg_id;
353+
if (per_cpu(logical_maps.phys_pkg_id, cpu) == phys_pkg)
354+
return per_cpu(logical_maps.logical_pkg_id, cpu);
344355
}
345356
return -1;
346357
}
@@ -358,11 +369,9 @@ static int topology_phys_to_logical_die(unsigned int die_id, unsigned int cur_cp
358369
int cpu, proc_id = cpu_data(cur_cpu).topo.pkg_id;
359370

360371
for_each_possible_cpu(cpu) {
361-
struct cpuinfo_x86 *c = &cpu_data(cpu);
362-
363-
if (c->initialized && c->topo.die_id == die_id &&
364-
c->topo.pkg_id == proc_id)
365-
return c->topo.logical_die_id;
372+
if (per_cpu(logical_maps.phys_pkg_id, cpu) == proc_id &&
373+
per_cpu(logical_maps.phys_die_id, cpu) == die_id)
374+
return per_cpu(logical_maps.logical_die_id, cpu);
366375
}
367376
return -1;
368377
}
@@ -387,6 +396,8 @@ int topology_update_package_map(unsigned int pkg, unsigned int cpu)
387396
cpu, pkg, new);
388397
}
389398
found:
399+
per_cpu(logical_maps.phys_pkg_id, cpu) = pkg;
400+
per_cpu(logical_maps.logical_pkg_id, cpu) = new;
390401
cpu_data(cpu).topo.logical_pkg_id = new;
391402
return 0;
392403
}
@@ -410,6 +421,8 @@ int topology_update_die_map(unsigned int die, unsigned int cpu)
410421
cpu, die, new);
411422
}
412423
found:
424+
per_cpu(logical_maps.phys_die_id, cpu) = die;
425+
per_cpu(logical_maps.logical_die_id, cpu) = new;
413426
cpu_data(cpu).topo.logical_die_id = new;
414427
return 0;
415428
}

0 commit comments

Comments
 (0)