proc.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/smp.h>
  3. #include <linux/timex.h>
  4. #include <linux/string.h>
  5. #include <linux/seq_file.h>
  6. #include <linux/cpufreq.h>
  7. #include "cpu.h"
  8. /*
  9. * Get CPU information for use by the procfs.
  10. */
  11. static void show_cpuinfo_core(struct seq_file *m, struct cpuinfo_x86 *c,
  12. unsigned int cpu)
  13. {
  14. #ifdef CONFIG_SMP
  15. seq_printf(m, "physical id\t: %d\n", c->phys_proc_id);
  16. seq_printf(m, "siblings\t: %d\n",
  17. cpumask_weight(topology_core_cpumask(cpu)));
  18. seq_printf(m, "core id\t\t: %d\n", c->cpu_core_id);
  19. seq_printf(m, "cpu cores\t: %d\n", c->booted_cores);
  20. seq_printf(m, "apicid\t\t: %d\n", c->apicid);
  21. seq_printf(m, "initial apicid\t: %d\n", c->initial_apicid);
  22. #endif
  23. }
  24. #ifdef CONFIG_X86_32
  25. static void show_cpuinfo_misc(struct seq_file *m, struct cpuinfo_x86 *c)
  26. {
  27. seq_printf(m,
  28. "fdiv_bug\t: %s\n"
  29. "f00f_bug\t: %s\n"
  30. "coma_bug\t: %s\n"
  31. "fpu\t\t: %s\n"
  32. "fpu_exception\t: %s\n"
  33. "cpuid level\t: %d\n"
  34. "wp\t\t: yes\n",
  35. static_cpu_has_bug(X86_BUG_FDIV) ? "yes" : "no",
  36. static_cpu_has_bug(X86_BUG_F00F) ? "yes" : "no",
  37. static_cpu_has_bug(X86_BUG_COMA) ? "yes" : "no",
  38. static_cpu_has(X86_FEATURE_FPU) ? "yes" : "no",
  39. static_cpu_has(X86_FEATURE_FPU) ? "yes" : "no",
  40. c->cpuid_level);
  41. }
  42. #else
  43. static void show_cpuinfo_misc(struct seq_file *m, struct cpuinfo_x86 *c)
  44. {
  45. seq_printf(m,
  46. "fpu\t\t: yes\n"
  47. "fpu_exception\t: yes\n"
  48. "cpuid level\t: %d\n"
  49. "wp\t\t: yes\n",
  50. c->cpuid_level);
  51. }
  52. #endif
  53. static int show_cpuinfo(struct seq_file *m, void *v)
  54. {
  55. struct cpuinfo_x86 *c = v;
  56. unsigned int cpu;
  57. int i;
  58. cpu = c->cpu_index;
  59. seq_printf(m, "processor\t: %u\n"
  60. "vendor_id\t: %s\n"
  61. "cpu family\t: %d\n"
  62. "model\t\t: %u\n"
  63. "model name\t: %s\n",
  64. cpu,
  65. c->x86_vendor_id[0] ? c->x86_vendor_id : "unknown",
  66. c->x86,
  67. c->x86_model,
  68. c->x86_model_id[0] ? c->x86_model_id : "unknown");
  69. if (c->x86_stepping || c->cpuid_level >= 0)
  70. seq_printf(m, "stepping\t: %d\n", c->x86_stepping);
  71. else
  72. seq_puts(m, "stepping\t: unknown\n");
  73. if (c->microcode)
  74. seq_printf(m, "microcode\t: 0x%x\n", c->microcode);
  75. if (cpu_has(c, X86_FEATURE_TSC)) {
  76. unsigned int freq = aperfmperf_get_khz(cpu);
  77. if (!freq)
  78. freq = cpufreq_quick_get(cpu);
  79. if (!freq)
  80. freq = cpu_khz;
  81. seq_printf(m, "cpu MHz\t\t: %u.%03u\n",
  82. freq / 1000, (freq % 1000));
  83. }
  84. /* Cache size */
  85. if (c->x86_cache_size)
  86. seq_printf(m, "cache size\t: %u KB\n", c->x86_cache_size);
  87. show_cpuinfo_core(m, c, cpu);
  88. show_cpuinfo_misc(m, c);
  89. seq_puts(m, "flags\t\t:");
  90. for (i = 0; i < 32*NCAPINTS; i++)
  91. if (cpu_has(c, i) && x86_cap_flags[i] != NULL)
  92. seq_printf(m, " %s", x86_cap_flags[i]);
  93. seq_puts(m, "\nbugs\t\t:");
  94. for (i = 0; i < 32*NBUGINTS; i++) {
  95. unsigned int bug_bit = 32*NCAPINTS + i;
  96. if (cpu_has_bug(c, bug_bit) && x86_bug_flags[i])
  97. seq_printf(m, " %s", x86_bug_flags[i]);
  98. }
  99. seq_printf(m, "\nbogomips\t: %lu.%02lu\n",
  100. c->loops_per_jiffy/(500000/HZ),
  101. (c->loops_per_jiffy/(5000/HZ)) % 100);
  102. #ifdef CONFIG_X86_64
  103. if (c->x86_tlbsize > 0)
  104. seq_printf(m, "TLB size\t: %d 4K pages\n", c->x86_tlbsize);
  105. #endif
  106. seq_printf(m, "clflush size\t: %u\n", c->x86_clflush_size);
  107. seq_printf(m, "cache_alignment\t: %d\n", c->x86_cache_alignment);
  108. seq_printf(m, "address sizes\t: %u bits physical, %u bits virtual\n",
  109. c->x86_phys_bits, c->x86_virt_bits);
  110. seq_puts(m, "power management:");
  111. for (i = 0; i < 32; i++) {
  112. if (c->x86_power & (1 << i)) {
  113. if (i < ARRAY_SIZE(x86_power_flags) &&
  114. x86_power_flags[i])
  115. seq_printf(m, "%s%s",
  116. x86_power_flags[i][0] ? " " : "",
  117. x86_power_flags[i]);
  118. else
  119. seq_printf(m, " [%d]", i);
  120. }
  121. }
  122. seq_puts(m, "\n\n");
  123. return 0;
  124. }
  125. static void *c_start(struct seq_file *m, loff_t *pos)
  126. {
  127. *pos = cpumask_next(*pos - 1, cpu_online_mask);
  128. if ((*pos) < nr_cpu_ids)
  129. return &cpu_data(*pos);
  130. return NULL;
  131. }
  132. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  133. {
  134. (*pos)++;
  135. return c_start(m, pos);
  136. }
  137. static void c_stop(struct seq_file *m, void *v)
  138. {
  139. }
  140. const struct seq_operations cpuinfo_op = {
  141. .start = c_start,
  142. .next = c_next,
  143. .stop = c_stop,
  144. .show = show_cpuinfo,
  145. };