148525fd1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0
248525fd1SThomas Gleixner
348525fd1SThomas Gleixner #include <linux/debugfs.h>
448525fd1SThomas Gleixner
548525fd1SThomas Gleixner #include <asm/apic.h>
648525fd1SThomas Gleixner #include <asm/processor.h>
748525fd1SThomas Gleixner
8ebdb2036SThomas Gleixner #include "cpu.h"
9ebdb2036SThomas Gleixner
cpu_debug_show(struct seq_file * m,void * p)1048525fd1SThomas Gleixner static int cpu_debug_show(struct seq_file *m, void *p)
1148525fd1SThomas Gleixner {
1248525fd1SThomas Gleixner unsigned long cpu = (unsigned long)m->private;
1348525fd1SThomas Gleixner struct cpuinfo_x86 *c = per_cpu_ptr(&cpu_info, cpu);
1448525fd1SThomas Gleixner
1548525fd1SThomas Gleixner seq_printf(m, "online: %d\n", cpu_online(cpu));
1648525fd1SThomas Gleixner if (!c->initialized)
1748525fd1SThomas Gleixner return 0;
1848525fd1SThomas Gleixner
19*4a412c70SPawan Gupta seq_printf(m, "initial_apicid: 0x%x\n", c->topo.initial_apicid);
20*4a412c70SPawan Gupta seq_printf(m, "apicid: 0x%x\n", c->topo.apicid);
2148525fd1SThomas Gleixner seq_printf(m, "pkg_id: %u\n", c->topo.pkg_id);
2248525fd1SThomas Gleixner seq_printf(m, "die_id: %u\n", c->topo.die_id);
2348525fd1SThomas Gleixner seq_printf(m, "cu_id: %u\n", c->topo.cu_id);
2448525fd1SThomas Gleixner seq_printf(m, "core_id: %u\n", c->topo.core_id);
2545239ba3SPawan Gupta seq_printf(m, "cpu_type: %s\n", get_topology_cpu_type_name(c));
2648525fd1SThomas Gleixner seq_printf(m, "logical_pkg_id: %u\n", c->topo.logical_pkg_id);
2748525fd1SThomas Gleixner seq_printf(m, "logical_die_id: %u\n", c->topo.logical_die_id);
28e4b44434SK Prateek Nayak seq_printf(m, "logical_core_id: %u\n", c->topo.logical_core_id);
2948525fd1SThomas Gleixner seq_printf(m, "llc_id: %u\n", c->topo.llc_id);
3048525fd1SThomas Gleixner seq_printf(m, "l2c_id: %u\n", c->topo.l2c_id);
31f7fb3b2dSThomas Gleixner seq_printf(m, "amd_node_id: %u\n", c->topo.amd_node_id);
32f7fb3b2dSThomas Gleixner seq_printf(m, "amd_nodes_per_pkg: %u\n", topology_amd_nodes_per_pkg());
3389b0f15fSThomas Gleixner seq_printf(m, "num_threads: %u\n", __num_threads_per_package);
3489b0f15fSThomas Gleixner seq_printf(m, "num_cores: %u\n", __num_cores_per_package);
35090610baSThomas Gleixner seq_printf(m, "max_dies_per_pkg: %u\n", __max_dies_per_package);
368078f4d6SThomas Gleixner seq_printf(m, "max_threads_per_core:%u\n", __max_threads_per_core);
3748525fd1SThomas Gleixner return 0;
3848525fd1SThomas Gleixner }
3948525fd1SThomas Gleixner
cpu_debug_open(struct inode * inode,struct file * file)4048525fd1SThomas Gleixner static int cpu_debug_open(struct inode *inode, struct file *file)
4148525fd1SThomas Gleixner {
4248525fd1SThomas Gleixner return single_open(file, cpu_debug_show, inode->i_private);
4348525fd1SThomas Gleixner }
4448525fd1SThomas Gleixner
4548525fd1SThomas Gleixner static const struct file_operations dfs_cpu_ops = {
4648525fd1SThomas Gleixner .open = cpu_debug_open,
4748525fd1SThomas Gleixner .read = seq_read,
4848525fd1SThomas Gleixner .llseek = seq_lseek,
4948525fd1SThomas Gleixner .release = single_release,
5048525fd1SThomas Gleixner };
5148525fd1SThomas Gleixner
dom_debug_show(struct seq_file * m,void * p)52ebdb2036SThomas Gleixner static int dom_debug_show(struct seq_file *m, void *p)
53ebdb2036SThomas Gleixner {
54ebdb2036SThomas Gleixner static const char *domain_names[TOPO_MAX_DOMAIN] = {
55ebdb2036SThomas Gleixner [TOPO_SMT_DOMAIN] = "Thread",
56ebdb2036SThomas Gleixner [TOPO_CORE_DOMAIN] = "Core",
57ebdb2036SThomas Gleixner [TOPO_MODULE_DOMAIN] = "Module",
58ebdb2036SThomas Gleixner [TOPO_TILE_DOMAIN] = "Tile",
59ebdb2036SThomas Gleixner [TOPO_DIE_DOMAIN] = "Die",
60ebdb2036SThomas Gleixner [TOPO_DIEGRP_DOMAIN] = "DieGrp",
61ebdb2036SThomas Gleixner [TOPO_PKG_DOMAIN] = "Package",
62ebdb2036SThomas Gleixner };
63ebdb2036SThomas Gleixner unsigned int dom, nthreads = 1;
64ebdb2036SThomas Gleixner
65ebdb2036SThomas Gleixner for (dom = 0; dom < TOPO_MAX_DOMAIN; dom++) {
66ebdb2036SThomas Gleixner nthreads *= x86_topo_system.dom_size[dom];
67ebdb2036SThomas Gleixner seq_printf(m, "domain: %-10s shift: %u dom_size: %5u max_threads: %5u\n",
68ebdb2036SThomas Gleixner domain_names[dom], x86_topo_system.dom_shifts[dom],
69ebdb2036SThomas Gleixner x86_topo_system.dom_size[dom], nthreads);
70ebdb2036SThomas Gleixner }
71ebdb2036SThomas Gleixner return 0;
72ebdb2036SThomas Gleixner }
73ebdb2036SThomas Gleixner
dom_debug_open(struct inode * inode,struct file * file)74ebdb2036SThomas Gleixner static int dom_debug_open(struct inode *inode, struct file *file)
75ebdb2036SThomas Gleixner {
76ebdb2036SThomas Gleixner return single_open(file, dom_debug_show, inode->i_private);
77ebdb2036SThomas Gleixner }
78ebdb2036SThomas Gleixner
79ebdb2036SThomas Gleixner static const struct file_operations dfs_dom_ops = {
80ebdb2036SThomas Gleixner .open = dom_debug_open,
81ebdb2036SThomas Gleixner .read = seq_read,
82ebdb2036SThomas Gleixner .llseek = seq_lseek,
83ebdb2036SThomas Gleixner .release = single_release,
84ebdb2036SThomas Gleixner };
85ebdb2036SThomas Gleixner
cpu_init_debugfs(void)8648525fd1SThomas Gleixner static __init int cpu_init_debugfs(void)
8748525fd1SThomas Gleixner {
8848525fd1SThomas Gleixner struct dentry *dir, *base = debugfs_create_dir("topo", arch_debugfs_dir);
8948525fd1SThomas Gleixner unsigned long id;
9048525fd1SThomas Gleixner char name[24];
9148525fd1SThomas Gleixner
92ebdb2036SThomas Gleixner debugfs_create_file("domains", 0444, base, NULL, &dfs_dom_ops);
93ebdb2036SThomas Gleixner
9448525fd1SThomas Gleixner dir = debugfs_create_dir("cpus", base);
9548525fd1SThomas Gleixner for_each_possible_cpu(id) {
9648525fd1SThomas Gleixner sprintf(name, "%lu", id);
9748525fd1SThomas Gleixner debugfs_create_file(name, 0444, dir, (void *)id, &dfs_cpu_ops);
9848525fd1SThomas Gleixner }
9948525fd1SThomas Gleixner return 0;
10048525fd1SThomas Gleixner }
10148525fd1SThomas Gleixner late_initcall(cpu_init_debugfs);
102