86de544cdb14cfaa72092011436160b6e97835a7
[sfrench/cifs-2.6.git] / arch / x86 / kernel / cpu / debugfs.c
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 #include "cpu.h"
9
10 static int cpu_debug_show(struct seq_file *m, void *p)
11 {
12         unsigned long cpu = (unsigned long)m->private;
13         struct cpuinfo_x86 *c = per_cpu_ptr(&cpu_info, cpu);
14
15         seq_printf(m, "online:              %d\n", cpu_online(cpu));
16         if (!c->initialized)
17                 return 0;
18
19         seq_printf(m, "initial_apicid:      %x\n", c->topo.initial_apicid);
20         seq_printf(m, "apicid:              %x\n", c->topo.apicid);
21         seq_printf(m, "pkg_id:              %u\n", c->topo.pkg_id);
22         seq_printf(m, "die_id:              %u\n", c->topo.die_id);
23         seq_printf(m, "cu_id:               %u\n", c->topo.cu_id);
24         seq_printf(m, "core_id:             %u\n", c->topo.core_id);
25         seq_printf(m, "logical_pkg_id:      %u\n", c->topo.logical_pkg_id);
26         seq_printf(m, "logical_die_id:      %u\n", c->topo.logical_die_id);
27         seq_printf(m, "llc_id:              %u\n", c->topo.llc_id);
28         seq_printf(m, "l2c_id:              %u\n", c->topo.l2c_id);
29         seq_printf(m, "amd_node_id:         %u\n", c->topo.amd_node_id);
30         seq_printf(m, "amd_nodes_per_pkg:   %u\n", topology_amd_nodes_per_pkg());
31         seq_printf(m, "max_cores:           %u\n", c->x86_max_cores);
32         seq_printf(m, "max_die_per_pkg:     %u\n", __max_die_per_package);
33         seq_printf(m, "smp_num_siblings:    %u\n", smp_num_siblings);
34         return 0;
35 }
36
37 static int cpu_debug_open(struct inode *inode, struct file *file)
38 {
39         return single_open(file, cpu_debug_show, inode->i_private);
40 }
41
42 static const struct file_operations dfs_cpu_ops = {
43         .open           = cpu_debug_open,
44         .read           = seq_read,
45         .llseek         = seq_lseek,
46         .release        = single_release,
47 };
48
49 static int dom_debug_show(struct seq_file *m, void *p)
50 {
51         static const char *domain_names[TOPO_MAX_DOMAIN] = {
52                 [TOPO_SMT_DOMAIN]       = "Thread",
53                 [TOPO_CORE_DOMAIN]      = "Core",
54                 [TOPO_MODULE_DOMAIN]    = "Module",
55                 [TOPO_TILE_DOMAIN]      = "Tile",
56                 [TOPO_DIE_DOMAIN]       = "Die",
57                 [TOPO_DIEGRP_DOMAIN]    = "DieGrp",
58                 [TOPO_PKG_DOMAIN]       = "Package",
59         };
60         unsigned int dom, nthreads = 1;
61
62         for (dom = 0; dom < TOPO_MAX_DOMAIN; dom++) {
63                 nthreads *= x86_topo_system.dom_size[dom];
64                 seq_printf(m, "domain: %-10s shift: %u dom_size: %5u max_threads: %5u\n",
65                            domain_names[dom], x86_topo_system.dom_shifts[dom],
66                            x86_topo_system.dom_size[dom], nthreads);
67         }
68         return 0;
69 }
70
71 static int dom_debug_open(struct inode *inode, struct file *file)
72 {
73         return single_open(file, dom_debug_show, inode->i_private);
74 }
75
76 static const struct file_operations dfs_dom_ops = {
77         .open           = dom_debug_open,
78         .read           = seq_read,
79         .llseek         = seq_lseek,
80         .release        = single_release,
81 };
82
83 static __init int cpu_init_debugfs(void)
84 {
85         struct dentry *dir, *base = debugfs_create_dir("topo", arch_debugfs_dir);
86         unsigned long id;
87         char name[24];
88
89         debugfs_create_file("domains", 0444, base, NULL, &dfs_dom_ops);
90
91         dir = debugfs_create_dir("cpus", base);
92         for_each_possible_cpu(id) {
93                 sprintf(name, "%lu", id);
94                 debugfs_create_file(name, 0444, dir, (void *)id, &dfs_cpu_ops);
95         }
96         return 0;
97 }
98 late_initcall(cpu_init_debugfs);