proc.c 4.0 KB

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