proc.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. static void show_cpuinfo_core(struct seq_file *m, struct cpuinfo_x86 *c,
  11. unsigned int cpu)
  12. {
  13. #ifdef CONFIG_X86_HT
  14. if (c->x86_max_cores * smp_num_siblings > 1) {
  15. seq_printf(m, "physical id\t: %d\n", c->phys_proc_id);
  16. seq_printf(m, "siblings\t: %d\n",
  17. cpus_weight(per_cpu(cpu_core_map, cpu)));
  18. seq_printf(m, "core id\t\t: %d\n", c->cpu_core_id);
  19. seq_printf(m, "cpu cores\t: %d\n", c->booted_cores);
  20. }
  21. #endif
  22. }
  23. static void show_cpuinfo_misc(struct seq_file *m, struct cpuinfo_x86 *c)
  24. {
  25. /*
  26. * We use exception 16 if we have hardware math and we've either seen
  27. * it or the CPU claims it is internal
  28. */
  29. int fpu_exception = c->hard_math && (ignore_fpu_irq || cpu_has_fpu);
  30. seq_printf(m,
  31. "fdiv_bug\t: %s\n"
  32. "hlt_bug\t\t: %s\n"
  33. "f00f_bug\t: %s\n"
  34. "coma_bug\t: %s\n"
  35. "fpu\t\t: %s\n"
  36. "fpu_exception\t: %s\n"
  37. "cpuid level\t: %d\n"
  38. "wp\t\t: %s\n",
  39. c->fdiv_bug ? "yes" : "no",
  40. c->hlt_works_ok ? "no" : "yes",
  41. c->f00f_bug ? "yes" : "no",
  42. c->coma_bug ? "yes" : "no",
  43. c->hard_math ? "yes" : "no",
  44. fpu_exception ? "yes" : "no",
  45. c->cpuid_level,
  46. c->wp_works_ok ? "yes" : "no");
  47. }
  48. static int show_cpuinfo(struct seq_file *m, void *v)
  49. {
  50. struct cpuinfo_x86 *c = v;
  51. unsigned int cpu = 0;
  52. int i;
  53. #ifdef CONFIG_SMP
  54. cpu = c->cpu_index;
  55. #endif
  56. seq_printf(m, "processor\t: %u\n"
  57. "vendor_id\t: %s\n"
  58. "cpu family\t: %d\n"
  59. "model\t\t: %u\n"
  60. "model name\t: %s\n",
  61. cpu,
  62. c->x86_vendor_id[0] ? c->x86_vendor_id : "unknown",
  63. c->x86,
  64. c->x86_model,
  65. c->x86_model_id[0] ? c->x86_model_id : "unknown");
  66. if (c->x86_mask || c->cpuid_level >= 0)
  67. seq_printf(m, "stepping\t: %d\n", c->x86_mask);
  68. else
  69. seq_printf(m, "stepping\t: unknown\n");
  70. if (cpu_has(c, X86_FEATURE_TSC)) {
  71. unsigned int freq = cpufreq_quick_get(cpu);
  72. if (!freq)
  73. freq = cpu_khz;
  74. seq_printf(m, "cpu MHz\t\t: %u.%03u\n",
  75. freq / 1000, (freq % 1000));
  76. }
  77. /* Cache size */
  78. if (c->x86_cache_size >= 0)
  79. seq_printf(m, "cache size\t: %d KB\n", c->x86_cache_size);
  80. show_cpuinfo_core(m, c, cpu);
  81. show_cpuinfo_misc(m, c);
  82. seq_printf(m, "flags\t\t:");
  83. for (i = 0; i < 32*NCAPINTS; i++)
  84. if (cpu_has(c, i) && x86_cap_flags[i] != NULL)
  85. seq_printf(m, " %s", x86_cap_flags[i]);
  86. seq_printf(m, "\nbogomips\t: %lu.%02lu\n",
  87. c->loops_per_jiffy/(500000/HZ),
  88. (c->loops_per_jiffy/(5000/HZ)) % 100);
  89. seq_printf(m, "clflush size\t: %u\n", c->x86_clflush_size);
  90. seq_printf(m, "power management:");
  91. for (i = 0; i < 32; i++) {
  92. if (c->x86_power & (1 << i)) {
  93. if (i < ARRAY_SIZE(x86_power_flags) &&
  94. x86_power_flags[i])
  95. seq_printf(m, "%s%s",
  96. x86_power_flags[i][0]?" ":"",
  97. x86_power_flags[i]);
  98. else
  99. seq_printf(m, " [%d]", i);
  100. }
  101. }
  102. seq_printf(m, "\n\n");
  103. return 0;
  104. }
  105. static void *c_start(struct seq_file *m, loff_t *pos)
  106. {
  107. if (*pos == 0) /* just in case, cpu 0 is not the first */
  108. *pos = first_cpu(cpu_online_map);
  109. if ((*pos) < NR_CPUS && cpu_online(*pos))
  110. return &cpu_data(*pos);
  111. return NULL;
  112. }
  113. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  114. {
  115. *pos = next_cpu(*pos, cpu_online_map);
  116. return c_start(m, pos);
  117. }
  118. static void c_stop(struct seq_file *m, void *v)
  119. {
  120. }
  121. const struct seq_operations cpuinfo_op = {
  122. .start = c_start,
  123. .next = c_next,
  124. .stop = c_stop,
  125. .show = show_cpuinfo,
  126. };