xref: /linux/arch/x86/kernel/cpu/debugfs.c (revision 3652117f854819a148ff0fbe4492587d3520b5e5)
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);
59