Skip to content

Commit 48525fd

Browse files
committed
x86/cpu: Provide debug interface
Provide debug files which dump the topology related information of cpuinfo_x86. This is useful to validate the upcoming conversion of the topology evaluation for correctness or bug compatibility. 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 90781f0 commit 48525fd

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

arch/x86/kernel/cpu/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ obj-$(CONFIG_X86_LOCAL_APIC) += perfctr-watchdog.o
5454
obj-$(CONFIG_HYPERVISOR_GUEST) += vmware.o hypervisor.o mshyperv.o
5555
obj-$(CONFIG_ACRN_GUEST) += acrn.o
5656

57+
obj-$(CONFIG_DEBUG_FS) += debugfs.o
58+
5759
quiet_cmd_mkcapflags = MKCAP $@
5860
cmd_mkcapflags = $(CONFIG_SHELL) $(srctree)/$(src)/mkcapflags.sh $@ $^
5961

arch/x86/kernel/cpu/debugfs.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/debugfs.h>
4+
5+
#include <asm/apic.h>
6+
#include <asm/processor.h>
7+
8+
static int cpu_debug_show(struct seq_file *m, void *p)
9+
{
10+
unsigned long cpu = (unsigned long)m->private;
11+
struct cpuinfo_x86 *c = per_cpu_ptr(&cpu_info, cpu);
12+
13+
seq_printf(m, "online: %d\n", cpu_online(cpu));
14+
if (!c->initialized)
15+
return 0;
16+
17+
seq_printf(m, "initial_apicid: %x\n", c->topo.initial_apicid);
18+
seq_printf(m, "apicid: %x\n", c->topo.apicid);
19+
seq_printf(m, "pkg_id: %u\n", c->topo.pkg_id);
20+
seq_printf(m, "die_id: %u\n", c->topo.die_id);
21+
seq_printf(m, "cu_id: %u\n", c->topo.cu_id);
22+
seq_printf(m, "core_id: %u\n", c->topo.core_id);
23+
seq_printf(m, "logical_pkg_id: %u\n", c->topo.logical_pkg_id);
24+
seq_printf(m, "logical_die_id: %u\n", c->topo.logical_die_id);
25+
seq_printf(m, "llc_id: %u\n", c->topo.llc_id);
26+
seq_printf(m, "l2c_id: %u\n", c->topo.l2c_id);
27+
seq_printf(m, "max_cores: %u\n", c->x86_max_cores);
28+
seq_printf(m, "max_die_per_pkg: %u\n", __max_die_per_package);
29+
seq_printf(m, "smp_num_siblings: %u\n", smp_num_siblings);
30+
return 0;
31+
}
32+
33+
static int cpu_debug_open(struct inode *inode, struct file *file)
34+
{
35+
return single_open(file, cpu_debug_show, inode->i_private);
36+
}
37+
38+
static const struct file_operations dfs_cpu_ops = {
39+
.open = cpu_debug_open,
40+
.read = seq_read,
41+
.llseek = seq_lseek,
42+
.release = single_release,
43+
};
44+
45+
static __init int cpu_init_debugfs(void)
46+
{
47+
struct dentry *dir, *base = debugfs_create_dir("topo", arch_debugfs_dir);
48+
unsigned long id;
49+
char name[24];
50+
51+
dir = debugfs_create_dir("cpus", base);
52+
for_each_possible_cpu(id) {
53+
sprintf(name, "%lu", id);
54+
debugfs_create_file(name, 0444, dir, (void *)id, &dfs_cpu_ops);
55+
}
56+
return 0;
57+
}
58+
late_initcall(cpu_init_debugfs);

0 commit comments

Comments
 (0)