proc.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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: %s\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. c->wp_works_ok ? "yes" : "no");
  40. }
  41. #else
  42. static void show_cpuinfo_misc(struct seq_file *m, struct cpuinfo_x86 *c)
  43. {
  44. seq_printf(m,
  45. "fpu\t\t: yes\n"
  46. "fpu_exception\t: yes\n"
  47. "cpuid level\t: %d\n"
  48. "wp\t\t: yes\n",
  49. c->cpuid_level);
  50. }
  51. #endif
  52. static int show_cpuinfo(struct seq_file *m, void *v)
  53. {
  54. struct cpuinfo_x86 *c = v;
  55. unsigned int cpu;
  56. int i;
  57. cpu = c->cpu_index;
  58. seq_printf(m, "processor\t: %u\n"
  59. "vendor_id\t: %s\n"
  60. "cpu family\t: %d\n"
  61. "model\t\t: %u\n"
  62. "model name\t: %s\n",
  63. cpu,
  64. c->x86_vendor_id[0] ? c->x86_vendor_id : "unknown",
  65. c->x86,
  66. c->x86_model,
  67. c->x86_model_id[0] ? c->x86_model_id : "unknown");
  68. if (c->x86_mask || c->cpuid_level >= 0)
  69. seq_printf(m, "stepping\t: %d\n", c->x86_mask);
  70. else
  71. seq_puts(m, "stepping\t: unknown\n");
  72. if (c->microcode)
  73. seq_printf(m, "microcode\t: 0x%x\n", c->microcode);
  74. if (cpu_has(c, X86_FEATURE_TSC)) {
  75. unsigned int freq = cpufreq_quick_get(cpu);
  76. if (!freq)
  77. freq = cpu_khz;
  78. seq_printf(m, "cpu MHz\t\t: %u.%03u\n",
  79. freq / 1000, (freq % 1000));
  80. }
  81. /* Cache size */
  82. if (c->x86_cache_size)
  83. seq_printf(m, "cache size\t: %u KB\n", c->x86_cache_size);
  84. show_cpuinfo_core(m, c, cpu);
  85. show_cpuinfo_misc(m, c);
  86. seq_puts(m, "flags\t\t:");
  87. for (i = 0; i < 32*NCAPINTS; i++)
  88. if (cpu_has(c, i) && x86_cap_flags[i] != NULL)
  89. seq_printf(m, " %s", x86_cap_flags[i]);
  90. seq_puts(m, "\nbugs\t\t:");
  91. for (i = 0; i < 32*NBUGINTS; i++) {
  92. unsigned int bug_bit = 32*NCAPINTS + i;
  93. if (cpu_has_bug(c, bug_bit) && x86_bug_flags[i])
  94. seq_printf(m, " %s", x86_bug_flags[i]);
  95. }
  96. seq_printf(m, "\nbogomips\t: %lu.%02lu\n",
  97. c->loops_per_jiffy/(500000/HZ),
  98. (c->loops_per_jiffy/(5000/HZ)) % 100);
  99. #ifdef CONFIG_X86_64
  100. if (c->x86_tlbsize > 0)
  101. seq_printf(m, "TLB size\t: %d 4K pages\n", c->x86_tlbsize);
  102. #endif
  103. seq_printf(m, "clflush size\t: %u\n", c->x86_clflush_size);
  104. seq_printf(m, "cache_alignment\t: %d\n", c->x86_cache_alignment);
  105. seq_printf(m, "address sizes\t: %u bits physical, %u bits virtual\n",
  106. c->x86_phys_bits, c->x86_virt_bits);
  107. seq_puts(m, "power management:");
  108. for (i = 0; i < 32; i++) {
  109. if (c->x86_power & (1 << i)) {
  110. if (i < ARRAY_SIZE(x86_power_flags) &&
  111. x86_power_flags[i])
  112. seq_printf(m, "%s%s",
  113. x86_power_flags[i][0] ? " " : "",
  114. x86_power_flags[i]);
  115. else
  116. seq_printf(m, " [%d]", i);
  117. }
  118. }
  119. seq_puts(m, "\n\n");
  120. return 0;
  121. }
  122. static void *c_start(struct seq_file *m, loff_t *pos)
  123. {
  124. *pos = cpumask_next(*pos - 1, cpu_online_mask);
  125. if ((*pos) < nr_cpu_ids)
  126. return &cpu_data(*pos);
  127. return NULL;
  128. }
  129. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  130. {
  131. (*pos)++;
  132. return c_start(m, pos);
  133. }
  134. static void c_stop(struct seq_file *m, void *v)
  135. {
  136. }
  137. const struct seq_operations cpuinfo_op = {
  138. .start = c_start,
  139. .next = c_next,
  140. .stop = c_stop,
  141. .show = show_cpuinfo,
  142. };