proc.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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", cpumask_weight(cpu_core_mask(cpu)));
  15. seq_printf(m, "core id\t\t: %d\n", c->cpu_core_id);
  16. seq_printf(m, "cpu cores\t: %d\n", c->booted_cores);
  17. seq_printf(m, "apicid\t\t: %d\n", c->apicid);
  18. seq_printf(m, "initial apicid\t: %d\n", c->initial_apicid);
  19. #endif
  20. }
  21. #ifdef CONFIG_X86_32
  22. static void show_cpuinfo_misc(struct seq_file *m, struct cpuinfo_x86 *c)
  23. {
  24. seq_printf(m,
  25. "fdiv_bug\t: %s\n"
  26. "f00f_bug\t: %s\n"
  27. "coma_bug\t: %s\n"
  28. "fpu\t\t: %s\n"
  29. "fpu_exception\t: %s\n"
  30. "cpuid level\t: %d\n"
  31. "wp\t\t: %s\n",
  32. static_cpu_has_bug(X86_BUG_FDIV) ? "yes" : "no",
  33. static_cpu_has_bug(X86_BUG_F00F) ? "yes" : "no",
  34. static_cpu_has_bug(X86_BUG_COMA) ? "yes" : "no",
  35. static_cpu_has(X86_FEATURE_FPU) ? "yes" : "no",
  36. static_cpu_has(X86_FEATURE_FPU) ? "yes" : "no",
  37. c->cpuid_level,
  38. c->wp_works_ok ? "yes" : "no");
  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_printf(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_printf(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_printf(m, "\nbogomips\t: %lu.%02lu\n",
  90. c->loops_per_jiffy/(500000/HZ),
  91. (c->loops_per_jiffy/(5000/HZ)) % 100);
  92. #ifdef CONFIG_X86_64
  93. if (c->x86_tlbsize > 0)
  94. seq_printf(m, "TLB size\t: %d 4K pages\n", c->x86_tlbsize);
  95. #endif
  96. seq_printf(m, "clflush size\t: %u\n", c->x86_clflush_size);
  97. seq_printf(m, "cache_alignment\t: %d\n", c->x86_cache_alignment);
  98. seq_printf(m, "address sizes\t: %u bits physical, %u bits virtual\n",
  99. c->x86_phys_bits, c->x86_virt_bits);
  100. seq_printf(m, "power management:");
  101. for (i = 0; i < 32; i++) {
  102. if (c->x86_power & (1 << i)) {
  103. if (i < ARRAY_SIZE(x86_power_flags) &&
  104. x86_power_flags[i])
  105. seq_printf(m, "%s%s",
  106. x86_power_flags[i][0] ? " " : "",
  107. x86_power_flags[i]);
  108. else
  109. seq_printf(m, " [%d]", i);
  110. }
  111. }
  112. seq_printf(m, "\n\n");
  113. return 0;
  114. }
  115. static void *c_start(struct seq_file *m, loff_t *pos)
  116. {
  117. *pos = cpumask_next(*pos - 1, cpu_online_mask);
  118. if ((*pos) < nr_cpu_ids)
  119. return &cpu_data(*pos);
  120. return NULL;
  121. }
  122. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  123. {
  124. (*pos)++;
  125. return c_start(m, pos);
  126. }
  127. static void c_stop(struct seq_file *m, void *v)
  128. {
  129. }
  130. const struct seq_operations cpuinfo_op = {
  131. .start = c_start,
  132. .next = c_next,
  133. .stop = c_stop,
  134. .show = show_cpuinfo,
  135. };