proc.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. if (c->x86_max_cores * smp_num_siblings > 1) {
  14. seq_printf(m, "physical id\t: %d\n", c->phys_proc_id);
  15. seq_printf(m, "siblings\t: %d\n",
  16. cpumask_weight(cpu_core_mask(cpu)));
  17. seq_printf(m, "core id\t\t: %d\n", c->cpu_core_id);
  18. seq_printf(m, "cpu cores\t: %d\n", c->booted_cores);
  19. seq_printf(m, "apicid\t\t: %d\n", c->apicid);
  20. seq_printf(m, "initial apicid\t: %d\n", c->initial_apicid);
  21. }
  22. #endif
  23. }
  24. #ifdef CONFIG_X86_32
  25. static void show_cpuinfo_misc(struct seq_file *m, struct cpuinfo_x86 *c)
  26. {
  27. seq_printf(m,
  28. "fdiv_bug\t: %s\n"
  29. "hlt_bug\t\t: %s\n"
  30. "f00f_bug\t: %s\n"
  31. "coma_bug\t: %s\n"
  32. "fpu\t\t: %s\n"
  33. "fpu_exception\t: %s\n"
  34. "cpuid level\t: %d\n"
  35. "wp\t\t: %s\n",
  36. c->fdiv_bug ? "yes" : "no",
  37. c->hlt_works_ok ? "no" : "yes",
  38. c->f00f_bug ? "yes" : "no",
  39. c->coma_bug ? "yes" : "no",
  40. c->hard_math ? "yes" : "no",
  41. c->hard_math ? "yes" : "no",
  42. c->cpuid_level,
  43. c->wp_works_ok ? "yes" : "no");
  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_mask || c->cpuid_level >= 0)
  73. seq_printf(m, "stepping\t: %d\n", c->x86_mask);
  74. else
  75. seq_printf(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 = cpufreq_quick_get(cpu);
  80. if (!freq)
  81. freq = cpu_khz;
  82. seq_printf(m, "cpu MHz\t\t: %u.%03u\n",
  83. freq / 1000, (freq % 1000));
  84. }
  85. /* Cache size */
  86. if (c->x86_cache_size >= 0)
  87. seq_printf(m, "cache size\t: %d KB\n", c->x86_cache_size);
  88. show_cpuinfo_core(m, c, cpu);
  89. show_cpuinfo_misc(m, c);
  90. seq_printf(m, "flags\t\t:");
  91. for (i = 0; i < 32*NCAPINTS; i++)
  92. if (cpu_has(c, i) && x86_cap_flags[i] != NULL)
  93. seq_printf(m, " %s", x86_cap_flags[i]);
  94. seq_printf(m, "\nbogomips\t: %lu.%02lu\n",
  95. c->loops_per_jiffy/(500000/HZ),
  96. (c->loops_per_jiffy/(5000/HZ)) % 100);
  97. #ifdef CONFIG_X86_64
  98. if (c->x86_tlbsize > 0)
  99. seq_printf(m, "TLB size\t: %d 4K pages\n", c->x86_tlbsize);
  100. #endif
  101. seq_printf(m, "clflush size\t: %u\n", c->x86_clflush_size);
  102. seq_printf(m, "cache_alignment\t: %d\n", c->x86_cache_alignment);
  103. seq_printf(m, "address sizes\t: %u bits physical, %u bits virtual\n",
  104. c->x86_phys_bits, c->x86_virt_bits);
  105. seq_printf(m, "power management:");
  106. for (i = 0; i < 32; i++) {
  107. if (c->x86_power & (1 << i)) {
  108. if (i < ARRAY_SIZE(x86_power_flags) &&
  109. x86_power_flags[i])
  110. seq_printf(m, "%s%s",
  111. x86_power_flags[i][0] ? " " : "",
  112. x86_power_flags[i]);
  113. else
  114. seq_printf(m, " [%d]", i);
  115. }
  116. }
  117. seq_printf(m, "\n\n");
  118. return 0;
  119. }
  120. static void *c_start(struct seq_file *m, loff_t *pos)
  121. {
  122. *pos = cpumask_next(*pos - 1, cpu_online_mask);
  123. if ((*pos) < nr_cpu_ids)
  124. return &cpu_data(*pos);
  125. return NULL;
  126. }
  127. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  128. {
  129. (*pos)++;
  130. return c_start(m, pos);
  131. }
  132. static void c_stop(struct seq_file *m, void *v)
  133. {
  134. }
  135. const struct seq_operations cpuinfo_op = {
  136. .start = c_start,
  137. .next = c_next,
  138. .stop = c_stop,
  139. .show = show_cpuinfo,
  140. };