processor.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Copyright IBM Corp. 2008
  3. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
  4. */
  5. #define KMSG_COMPONENT "cpu"
  6. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  7. #include <linux/cpufeature.h>
  8. #include <linux/bitops.h>
  9. #include <linux/kernel.h>
  10. #include <linux/sched/mm.h>
  11. #include <linux/init.h>
  12. #include <linux/seq_file.h>
  13. #include <linux/mm_types.h>
  14. #include <linux/delay.h>
  15. #include <linux/cpu.h>
  16. #include <asm/diag.h>
  17. #include <asm/facility.h>
  18. #include <asm/elf.h>
  19. #include <asm/lowcore.h>
  20. #include <asm/param.h>
  21. #include <asm/smp.h>
  22. struct cpu_info {
  23. unsigned int cpu_mhz_dynamic;
  24. unsigned int cpu_mhz_static;
  25. struct cpuid cpu_id;
  26. };
  27. static DEFINE_PER_CPU(struct cpu_info, cpu_info);
  28. static bool machine_has_cpu_mhz;
  29. void __init cpu_detect_mhz_feature(void)
  30. {
  31. if (test_facility(34) && __ecag(ECAG_CPU_ATTRIBUTE, 0) != -1UL)
  32. machine_has_cpu_mhz = true;
  33. }
  34. static void update_cpu_mhz(void *arg)
  35. {
  36. unsigned long mhz;
  37. struct cpu_info *c;
  38. mhz = __ecag(ECAG_CPU_ATTRIBUTE, 0);
  39. c = this_cpu_ptr(&cpu_info);
  40. c->cpu_mhz_dynamic = mhz >> 32;
  41. c->cpu_mhz_static = mhz & 0xffffffff;
  42. }
  43. void s390_update_cpu_mhz(void)
  44. {
  45. s390_adjust_jiffies();
  46. if (machine_has_cpu_mhz)
  47. on_each_cpu(update_cpu_mhz, NULL, 0);
  48. }
  49. void notrace cpu_relax_yield(void)
  50. {
  51. if (!smp_cpu_mtid && MACHINE_HAS_DIAG44) {
  52. diag_stat_inc(DIAG_STAT_X044);
  53. asm volatile("diag 0,0,0x44");
  54. }
  55. barrier();
  56. }
  57. EXPORT_SYMBOL(cpu_relax_yield);
  58. /*
  59. * cpu_init - initializes state that is per-CPU.
  60. */
  61. void cpu_init(void)
  62. {
  63. struct cpuid *id = this_cpu_ptr(&cpu_info.cpu_id);
  64. get_cpu_id(id);
  65. if (machine_has_cpu_mhz)
  66. update_cpu_mhz(NULL);
  67. mmgrab(&init_mm);
  68. current->active_mm = &init_mm;
  69. BUG_ON(current->mm);
  70. enter_lazy_tlb(&init_mm, current);
  71. }
  72. /*
  73. * cpu_have_feature - Test CPU features on module initialization
  74. */
  75. int cpu_have_feature(unsigned int num)
  76. {
  77. return elf_hwcap & (1UL << num);
  78. }
  79. EXPORT_SYMBOL(cpu_have_feature);
  80. static void show_facilities(struct seq_file *m)
  81. {
  82. unsigned int bit;
  83. long *facilities;
  84. facilities = (long *)&S390_lowcore.stfle_fac_list;
  85. seq_puts(m, "facilities :");
  86. for_each_set_bit_inv(bit, facilities, MAX_FACILITY_BIT)
  87. seq_printf(m, " %d", bit);
  88. seq_putc(m, '\n');
  89. }
  90. static void show_cpu_summary(struct seq_file *m, void *v)
  91. {
  92. static const char *hwcap_str[] = {
  93. "esan3", "zarch", "stfle", "msa", "ldisp", "eimm", "dfp",
  94. "edat", "etf3eh", "highgprs", "te", "vx", "vxd", "vxe", "gs"
  95. };
  96. static const char * const int_hwcap_str[] = {
  97. "sie"
  98. };
  99. int i, cpu;
  100. seq_printf(m, "vendor_id : IBM/S390\n"
  101. "# processors : %i\n"
  102. "bogomips per cpu: %lu.%02lu\n",
  103. num_online_cpus(), loops_per_jiffy/(500000/HZ),
  104. (loops_per_jiffy/(5000/HZ))%100);
  105. seq_printf(m, "max thread id : %d\n", smp_cpu_mtid);
  106. seq_puts(m, "features\t: ");
  107. for (i = 0; i < ARRAY_SIZE(hwcap_str); i++)
  108. if (hwcap_str[i] && (elf_hwcap & (1UL << i)))
  109. seq_printf(m, "%s ", hwcap_str[i]);
  110. for (i = 0; i < ARRAY_SIZE(int_hwcap_str); i++)
  111. if (int_hwcap_str[i] && (int_hwcap & (1UL << i)))
  112. seq_printf(m, "%s ", int_hwcap_str[i]);
  113. seq_puts(m, "\n");
  114. show_facilities(m);
  115. show_cacheinfo(m);
  116. for_each_online_cpu(cpu) {
  117. struct cpuid *id = &per_cpu(cpu_info.cpu_id, cpu);
  118. seq_printf(m, "processor %d: "
  119. "version = %02X, "
  120. "identification = %06X, "
  121. "machine = %04X\n",
  122. cpu, id->version, id->ident, id->machine);
  123. }
  124. }
  125. static void show_cpu_mhz(struct seq_file *m, unsigned long n)
  126. {
  127. struct cpu_info *c = per_cpu_ptr(&cpu_info, n);
  128. seq_printf(m, "cpu MHz dynamic : %d\n", c->cpu_mhz_dynamic);
  129. seq_printf(m, "cpu MHz static : %d\n", c->cpu_mhz_static);
  130. }
  131. /*
  132. * show_cpuinfo - Get information on one CPU for use by procfs.
  133. */
  134. static int show_cpuinfo(struct seq_file *m, void *v)
  135. {
  136. unsigned long n = (unsigned long) v - 1;
  137. if (!n)
  138. show_cpu_summary(m, v);
  139. if (!machine_has_cpu_mhz)
  140. return 0;
  141. seq_printf(m, "\ncpu number : %ld\n", n);
  142. show_cpu_mhz(m, n);
  143. return 0;
  144. }
  145. static inline void *c_update(loff_t *pos)
  146. {
  147. if (*pos)
  148. *pos = cpumask_next(*pos - 1, cpu_online_mask);
  149. return *pos < nr_cpu_ids ? (void *)*pos + 1 : NULL;
  150. }
  151. static void *c_start(struct seq_file *m, loff_t *pos)
  152. {
  153. get_online_cpus();
  154. return c_update(pos);
  155. }
  156. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  157. {
  158. ++*pos;
  159. return c_update(pos);
  160. }
  161. static void c_stop(struct seq_file *m, void *v)
  162. {
  163. put_online_cpus();
  164. }
  165. const struct seq_operations cpuinfo_op = {
  166. .start = c_start,
  167. .next = c_next,
  168. .stop = c_stop,
  169. .show = show_cpuinfo,
  170. };