debugfs.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/debugfs.h>
  3. #include <asm/apic.h>
  4. #include <asm/processor.h>
  5. #include "cpu.h"
  6. static int cpu_debug_show(struct seq_file *m, void *p)
  7. {
  8. unsigned long cpu = (unsigned long)m->private;
  9. struct cpuinfo_x86 *c = per_cpu_ptr(&cpu_info, cpu);
  10. seq_printf(m, "online: %d\n", cpu_online(cpu));
  11. if (!c->initialized)
  12. return 0;
  13. seq_printf(m, "initial_apicid: %x\n", c->topo.initial_apicid);
  14. seq_printf(m, "apicid: %x\n", c->topo.apicid);
  15. seq_printf(m, "pkg_id: %u\n", c->topo.pkg_id);
  16. seq_printf(m, "die_id: %u\n", c->topo.die_id);
  17. seq_printf(m, "cu_id: %u\n", c->topo.cu_id);
  18. seq_printf(m, "core_id: %u\n", c->topo.core_id);
  19. seq_printf(m, "logical_pkg_id: %u\n", c->topo.logical_pkg_id);
  20. seq_printf(m, "logical_die_id: %u\n", c->topo.logical_die_id);
  21. seq_printf(m, "llc_id: %u\n", c->topo.llc_id);
  22. seq_printf(m, "l2c_id: %u\n", c->topo.l2c_id);
  23. seq_printf(m, "amd_node_id: %u\n", c->topo.amd_node_id);
  24. seq_printf(m, "amd_nodes_per_pkg: %u\n", topology_amd_nodes_per_pkg());
  25. seq_printf(m, "num_threads: %u\n", __num_threads_per_package);
  26. seq_printf(m, "num_cores: %u\n", __num_cores_per_package);
  27. seq_printf(m, "max_dies_per_pkg: %u\n", __max_dies_per_package);
  28. seq_printf(m, "max_threads_per_core:%u\n", __max_threads_per_core);
  29. return 0;
  30. }
  31. static int cpu_debug_open(struct inode *inode, struct file *file)
  32. {
  33. return single_open(file, cpu_debug_show, inode->i_private);
  34. }
  35. static const struct file_operations dfs_cpu_ops = {
  36. .open = cpu_debug_open,
  37. .read = seq_read,
  38. .llseek = seq_lseek,
  39. .release = single_release,
  40. };
  41. static int dom_debug_show(struct seq_file *m, void *p)
  42. {
  43. static const char *domain_names[TOPO_MAX_DOMAIN] = {
  44. [TOPO_SMT_DOMAIN] = "Thread",
  45. [TOPO_CORE_DOMAIN] = "Core",
  46. [TOPO_MODULE_DOMAIN] = "Module",
  47. [TOPO_TILE_DOMAIN] = "Tile",
  48. [TOPO_DIE_DOMAIN] = "Die",
  49. [TOPO_DIEGRP_DOMAIN] = "DieGrp",
  50. [TOPO_PKG_DOMAIN] = "Package",
  51. };
  52. unsigned int dom, nthreads = 1;
  53. for (dom = 0; dom < TOPO_MAX_DOMAIN; dom++) {
  54. nthreads *= x86_topo_system.dom_size[dom];
  55. seq_printf(m, "domain: %-10s shift: %u dom_size: %5u max_threads: %5u\n",
  56. domain_names[dom], x86_topo_system.dom_shifts[dom],
  57. x86_topo_system.dom_size[dom], nthreads);
  58. }
  59. return 0;
  60. }
  61. static int dom_debug_open(struct inode *inode, struct file *file)
  62. {
  63. return single_open(file, dom_debug_show, inode->i_private);
  64. }
  65. static const struct file_operations dfs_dom_ops = {
  66. .open = dom_debug_open,
  67. .read = seq_read,
  68. .llseek = seq_lseek,
  69. .release = single_release,
  70. };
  71. static __init int cpu_init_debugfs(void)
  72. {
  73. struct dentry *dir, *base = debugfs_create_dir("topo", arch_debugfs_dir);
  74. unsigned long id;
  75. char name[24];
  76. debugfs_create_file("domains", 0444, base, NULL, &dfs_dom_ops);
  77. dir = debugfs_create_dir("cpus", base);
  78. for_each_possible_cpu(id) {
  79. sprintf(name, "%lu", id);
  80. debugfs_create_file(name, 0444, dir, (void *)id, &dfs_cpu_ops);
  81. }
  82. return 0;
  83. }
  84. late_initcall(cpu_init_debugfs);