proc.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 int show_cpuinfo(struct seq_file *m, void *v)
  11. {
  12. /*
  13. * These flag bits must match the definitions in <asm/cpufeature.h>.
  14. * NULL means this bit is undefined or reserved; either way it doesn't
  15. * have meaning as far as Linux is concerned. Note that it's important
  16. * to realize there is a difference between this table and CPUID -- if
  17. * applications want to get the raw CPUID data, they should access
  18. * /dev/cpu/<cpu_nr>/cpuid instead.
  19. */
  20. static char *x86_cap_flags[] = {
  21. /* Intel-defined */
  22. "fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
  23. "cx8", "apic", NULL, "sep", "mtrr", "pge", "mca", "cmov",
  24. "pat", "pse36", "pn", "clflush", NULL, "dts", "acpi", "mmx",
  25. "fxsr", "sse", "sse2", "ss", "ht", "tm", "ia64", "pbe",
  26. /* AMD-defined */
  27. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  28. NULL, NULL, NULL, "syscall", NULL, NULL, NULL, NULL,
  29. NULL, NULL, NULL, "mp", "nx", NULL, "mmxext", NULL,
  30. NULL, "fxsr_opt", NULL, NULL, NULL, "lm", "3dnowext", "3dnow",
  31. /* Transmeta-defined */
  32. "recovery", "longrun", NULL, "lrti", NULL, NULL, NULL, NULL,
  33. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  34. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  35. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  36. /* Other (Linux-defined) */
  37. "cxmmx", "k6_mtrr", "cyrix_arr", "centaur_mcr",
  38. NULL, NULL, NULL, NULL,
  39. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  40. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  41. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  42. /* Intel-defined (#2) */
  43. "pni", NULL, NULL, "monitor", "ds_cpl", "vmx", NULL, "est",
  44. "tm2", NULL, "cid", NULL, NULL, "cx16", "xtpr", NULL,
  45. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  46. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  47. /* VIA/Cyrix/Centaur-defined */
  48. NULL, NULL, "rng", "rng_en", NULL, NULL, "ace", "ace_en",
  49. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  50. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  51. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  52. /* AMD-defined (#2) */
  53. "lahf_lm", "cmp_legacy", NULL, NULL, NULL, NULL, NULL, NULL,
  54. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  55. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  56. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  57. };
  58. struct cpuinfo_x86 *c = v;
  59. int i, n = c - cpu_data;
  60. int fpu_exception;
  61. #ifdef CONFIG_SMP
  62. if (!cpu_online(n))
  63. return 0;
  64. #endif
  65. seq_printf(m, "processor\t: %d\n"
  66. "vendor_id\t: %s\n"
  67. "cpu family\t: %d\n"
  68. "model\t\t: %d\n"
  69. "model name\t: %s\n",
  70. n,
  71. c->x86_vendor_id[0] ? c->x86_vendor_id : "unknown",
  72. c->x86,
  73. c->x86_model,
  74. c->x86_model_id[0] ? c->x86_model_id : "unknown");
  75. if (c->x86_mask || c->cpuid_level >= 0)
  76. seq_printf(m, "stepping\t: %d\n", c->x86_mask);
  77. else
  78. seq_printf(m, "stepping\t: unknown\n");
  79. if ( cpu_has(c, X86_FEATURE_TSC) ) {
  80. unsigned int freq = cpufreq_quick_get(n);
  81. if (!freq)
  82. freq = cpu_khz;
  83. seq_printf(m, "cpu MHz\t\t: %u.%03u\n",
  84. freq / 1000, (freq % 1000));
  85. }
  86. /* Cache size */
  87. if (c->x86_cache_size >= 0)
  88. seq_printf(m, "cache size\t: %d KB\n", c->x86_cache_size);
  89. #ifdef CONFIG_X86_HT
  90. if (c->x86_max_cores * smp_num_siblings > 1) {
  91. seq_printf(m, "physical id\t: %d\n", phys_proc_id[n]);
  92. seq_printf(m, "siblings\t: %d\n", cpus_weight(cpu_core_map[n]));
  93. seq_printf(m, "core id\t\t: %d\n", cpu_core_id[n]);
  94. seq_printf(m, "cpu cores\t: %d\n", c->booted_cores);
  95. }
  96. #endif
  97. /* We use exception 16 if we have hardware math and we've either seen it or the CPU claims it is internal */
  98. fpu_exception = c->hard_math && (ignore_fpu_irq || cpu_has_fpu);
  99. seq_printf(m, "fdiv_bug\t: %s\n"
  100. "hlt_bug\t\t: %s\n"
  101. "f00f_bug\t: %s\n"
  102. "coma_bug\t: %s\n"
  103. "fpu\t\t: %s\n"
  104. "fpu_exception\t: %s\n"
  105. "cpuid level\t: %d\n"
  106. "wp\t\t: %s\n"
  107. "flags\t\t:",
  108. c->fdiv_bug ? "yes" : "no",
  109. c->hlt_works_ok ? "no" : "yes",
  110. c->f00f_bug ? "yes" : "no",
  111. c->coma_bug ? "yes" : "no",
  112. c->hard_math ? "yes" : "no",
  113. fpu_exception ? "yes" : "no",
  114. c->cpuid_level,
  115. c->wp_works_ok ? "yes" : "no");
  116. for ( i = 0 ; i < 32*NCAPINTS ; i++ )
  117. if ( test_bit(i, c->x86_capability) &&
  118. x86_cap_flags[i] != NULL )
  119. seq_printf(m, " %s", x86_cap_flags[i]);
  120. seq_printf(m, "\nbogomips\t: %lu.%02lu\n\n",
  121. c->loops_per_jiffy/(500000/HZ),
  122. (c->loops_per_jiffy/(5000/HZ)) % 100);
  123. return 0;
  124. }
  125. static void *c_start(struct seq_file *m, loff_t *pos)
  126. {
  127. return *pos < NR_CPUS ? cpu_data + *pos : 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. struct seq_operations cpuinfo_op = {
  138. .start = c_start,
  139. .next = c_next,
  140. .stop = c_stop,
  141. .show = show_cpuinfo,
  142. };