proc.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #include <linux/smp.h>
  2. #include <linux/timex.h>
  3. #include <linux/string.h>
  4. #include <asm/semaphore.h>
  5. #include <linux/seq_file.h>
  6. #include <linux/cpufreq.h>
  7. /*
  8. * Get CPU information for use by the procfs.
  9. */
  10. #ifdef CONFIG_X86_32
  11. static void show_cpuinfo_core(struct seq_file *m, struct cpuinfo_x86 *c,
  12. unsigned int cpu)
  13. {
  14. #ifdef CONFIG_X86_HT
  15. if (c->x86_max_cores * smp_num_siblings > 1) {
  16. seq_printf(m, "physical id\t: %d\n", c->phys_proc_id);
  17. seq_printf(m, "siblings\t: %d\n",
  18. cpus_weight(per_cpu(cpu_core_map, cpu)));
  19. seq_printf(m, "core id\t\t: %d\n", c->cpu_core_id);
  20. seq_printf(m, "cpu cores\t: %d\n", c->booted_cores);
  21. }
  22. #endif
  23. }
  24. static void show_cpuinfo_misc(struct seq_file *m, struct cpuinfo_x86 *c)
  25. {
  26. /*
  27. * We use exception 16 if we have hardware math and we've either seen
  28. * it or the CPU claims it is internal
  29. */
  30. int fpu_exception = c->hard_math && (ignore_fpu_irq || cpu_has_fpu);
  31. seq_printf(m,
  32. "fdiv_bug\t: %s\n"
  33. "hlt_bug\t\t: %s\n"
  34. "f00f_bug\t: %s\n"
  35. "coma_bug\t: %s\n"
  36. "fpu\t\t: %s\n"
  37. "fpu_exception\t: %s\n"
  38. "cpuid level\t: %d\n"
  39. "wp\t\t: %s\n",
  40. c->fdiv_bug ? "yes" : "no",
  41. c->hlt_works_ok ? "no" : "yes",
  42. c->f00f_bug ? "yes" : "no",
  43. c->coma_bug ? "yes" : "no",
  44. c->hard_math ? "yes" : "no",
  45. fpu_exception ? "yes" : "no",
  46. c->cpuid_level,
  47. c->wp_works_ok ? "yes" : "no");
  48. }
  49. #else
  50. static void show_cpuinfo_core(struct seq_file *m, struct cpuinfo_x86 *c,
  51. unsigned int cpu)
  52. {
  53. #ifdef CONFIG_SMP
  54. if (c->x86_max_cores * smp_num_siblings > 1) {
  55. seq_printf(m, "physical id\t: %d\n", c->phys_proc_id);
  56. seq_printf(m, "siblings\t: %d\n",
  57. cpus_weight(per_cpu(cpu_core_map, cpu)));
  58. seq_printf(m, "core id\t\t: %d\n", c->cpu_core_id);
  59. seq_printf(m, "cpu cores\t: %d\n", c->booted_cores);
  60. }
  61. #endif
  62. }
  63. static void show_cpuinfo_misc(struct seq_file *m, struct cpuinfo_x86 *c)
  64. {
  65. seq_printf(m,
  66. "fpu\t\t: yes\n"
  67. "fpu_exception\t: yes\n"
  68. "cpuid level\t: %d\n"
  69. "wp\t\t: yes\n",
  70. c->cpuid_level);
  71. }
  72. #endif
  73. static int show_cpuinfo(struct seq_file *m, void *v)
  74. {
  75. struct cpuinfo_x86 *c = v;
  76. unsigned int cpu = 0;
  77. int i;
  78. #ifdef CONFIG_SMP
  79. cpu = c->cpu_index;
  80. #endif
  81. seq_printf(m, "processor\t: %u\n"
  82. "vendor_id\t: %s\n"
  83. "cpu family\t: %d\n"
  84. "model\t\t: %u\n"
  85. "model name\t: %s\n",
  86. cpu,
  87. c->x86_vendor_id[0] ? c->x86_vendor_id : "unknown",
  88. c->x86,
  89. c->x86_model,
  90. c->x86_model_id[0] ? c->x86_model_id : "unknown");
  91. if (c->x86_mask || c->cpuid_level >= 0)
  92. seq_printf(m, "stepping\t: %d\n", c->x86_mask);
  93. else
  94. seq_printf(m, "stepping\t: unknown\n");
  95. if (cpu_has(c, X86_FEATURE_TSC)) {
  96. unsigned int freq = cpufreq_quick_get(cpu);
  97. if (!freq)
  98. freq = cpu_khz;
  99. seq_printf(m, "cpu MHz\t\t: %u.%03u\n",
  100. freq / 1000, (freq % 1000));
  101. }
  102. /* Cache size */
  103. if (c->x86_cache_size >= 0)
  104. seq_printf(m, "cache size\t: %d KB\n", c->x86_cache_size);
  105. show_cpuinfo_core(m, c, cpu);
  106. show_cpuinfo_misc(m, c);
  107. seq_printf(m, "flags\t\t:");
  108. for (i = 0; i < 32*NCAPINTS; i++)
  109. if (cpu_has(c, i) && x86_cap_flags[i] != NULL)
  110. seq_printf(m, " %s", x86_cap_flags[i]);
  111. seq_printf(m, "\nbogomips\t: %lu.%02lu\n",
  112. c->loops_per_jiffy/(500000/HZ),
  113. (c->loops_per_jiffy/(5000/HZ)) % 100);
  114. #ifdef CONFIG_X86_64
  115. if (c->x86_tlbsize > 0)
  116. seq_printf(m, "TLB size\t: %d 4K pages\n", c->x86_tlbsize);
  117. #endif
  118. seq_printf(m, "clflush size\t: %u\n", c->x86_clflush_size);
  119. #ifdef CONFIG_X86_64
  120. seq_printf(m, "cache_alignment\t: %d\n", c->x86_cache_alignment);
  121. seq_printf(m, "address sizes\t: %u bits physical, %u bits virtual\n",
  122. c->x86_phys_bits, c->x86_virt_bits);
  123. #endif
  124. seq_printf(m, "power management:");
  125. for (i = 0; i < 32; i++) {
  126. if (c->x86_power & (1 << i)) {
  127. if (i < ARRAY_SIZE(x86_power_flags) &&
  128. x86_power_flags[i])
  129. seq_printf(m, "%s%s",
  130. x86_power_flags[i][0]?" ":"",
  131. x86_power_flags[i]);
  132. else
  133. seq_printf(m, " [%d]", i);
  134. }
  135. }
  136. seq_printf(m, "\n\n");
  137. return 0;
  138. }
  139. static void *c_start(struct seq_file *m, loff_t *pos)
  140. {
  141. if (*pos == 0) /* just in case, cpu 0 is not the first */
  142. *pos = first_cpu(cpu_online_map);
  143. if ((*pos) < NR_CPUS && cpu_online(*pos))
  144. return &cpu_data(*pos);
  145. return NULL;
  146. }
  147. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  148. {
  149. *pos = next_cpu(*pos, cpu_online_map);
  150. return c_start(m, pos);
  151. }
  152. static void c_stop(struct seq_file *m, void *v)
  153. {
  154. }
  155. const struct seq_operations cpuinfo_op = {
  156. .start = c_start,
  157. .next = c_next,
  158. .stop = c_stop,
  159. .show = show_cpuinfo,
  160. };