proc.c 4.4 KB

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