sysinfo.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. /*
  2. * Copyright IBM Corp. 2001, 2009
  3. * Author(s): Ulrich Weigand <Ulrich.Weigand@de.ibm.com>,
  4. * Martin Schwidefsky <schwidefsky@de.ibm.com>,
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/mm.h>
  8. #include <linux/proc_fs.h>
  9. #include <linux/seq_file.h>
  10. #include <linux/init.h>
  11. #include <linux/delay.h>
  12. #include <linux/module.h>
  13. #include <linux/slab.h>
  14. #include <asm/ebcdic.h>
  15. #include <asm/sysinfo.h>
  16. #include <asm/cpcmd.h>
  17. #include <asm/topology.h>
  18. /* Sigh, math-emu. Don't ask. */
  19. #include <asm/sfp-util.h>
  20. #include <math-emu/soft-fp.h>
  21. #include <math-emu/single.h>
  22. static inline int stsi_0(void)
  23. {
  24. int rc = stsi(NULL, 0, 0, 0);
  25. return rc == -ENOSYS ? rc : (((unsigned int) rc) >> 28);
  26. }
  27. static void stsi_1_1_1(struct seq_file *m, struct sysinfo_1_1_1 *info)
  28. {
  29. int i;
  30. if (stsi(info, 1, 1, 1) == -ENOSYS)
  31. return;
  32. EBCASC(info->manufacturer, sizeof(info->manufacturer));
  33. EBCASC(info->type, sizeof(info->type));
  34. EBCASC(info->model, sizeof(info->model));
  35. EBCASC(info->sequence, sizeof(info->sequence));
  36. EBCASC(info->plant, sizeof(info->plant));
  37. EBCASC(info->model_capacity, sizeof(info->model_capacity));
  38. EBCASC(info->model_perm_cap, sizeof(info->model_perm_cap));
  39. EBCASC(info->model_temp_cap, sizeof(info->model_temp_cap));
  40. seq_printf(m, "Manufacturer: %-16.16s\n", info->manufacturer);
  41. seq_printf(m, "Type: %-4.4s\n", info->type);
  42. /*
  43. * Sigh: the model field has been renamed with System z9
  44. * to model_capacity and a new model field has been added
  45. * after the plant field. To avoid confusing older programs
  46. * the "Model:" prints "model_capacity model" or just
  47. * "model_capacity" if the model string is empty .
  48. */
  49. seq_printf(m, "Model: %-16.16s", info->model_capacity);
  50. if (info->model[0] != '\0')
  51. seq_printf(m, " %-16.16s", info->model);
  52. seq_putc(m, '\n');
  53. seq_printf(m, "Sequence Code: %-16.16s\n", info->sequence);
  54. seq_printf(m, "Plant: %-4.4s\n", info->plant);
  55. seq_printf(m, "Model Capacity: %-16.16s %08u\n",
  56. info->model_capacity, info->model_cap_rating);
  57. if (info->model_perm_cap_rating)
  58. seq_printf(m, "Model Perm. Capacity: %-16.16s %08u\n",
  59. info->model_perm_cap,
  60. info->model_perm_cap_rating);
  61. if (info->model_temp_cap_rating)
  62. seq_printf(m, "Model Temp. Capacity: %-16.16s %08u\n",
  63. info->model_temp_cap,
  64. info->model_temp_cap_rating);
  65. if (info->ncr)
  66. seq_printf(m, "Nominal Cap. Rating: %08u\n", info->ncr);
  67. if (info->npr)
  68. seq_printf(m, "Nominal Perm. Rating: %08u\n", info->npr);
  69. if (info->ntr)
  70. seq_printf(m, "Nominal Temp. Rating: %08u\n", info->ntr);
  71. if (info->cai) {
  72. seq_printf(m, "Capacity Adj. Ind.: %d\n", info->cai);
  73. seq_printf(m, "Capacity Ch. Reason: %d\n", info->ccr);
  74. seq_printf(m, "Capacity Transient: %d\n", info->t);
  75. }
  76. if (info->p) {
  77. for (i = 1; i <= ARRAY_SIZE(info->typepct); i++) {
  78. seq_printf(m, "Type %d Percentage: %d\n",
  79. i, info->typepct[i - 1]);
  80. }
  81. }
  82. }
  83. static void stsi_15_1_x(struct seq_file *m, struct sysinfo_15_1_x *info)
  84. {
  85. static int max_mnest;
  86. int i, rc;
  87. seq_putc(m, '\n');
  88. if (!MACHINE_HAS_TOPOLOGY)
  89. return;
  90. if (max_mnest) {
  91. stsi(info, 15, 1, max_mnest);
  92. } else {
  93. for (max_mnest = 6; max_mnest > 1; max_mnest--) {
  94. rc = stsi(info, 15, 1, max_mnest);
  95. if (rc != -ENOSYS)
  96. break;
  97. }
  98. }
  99. seq_printf(m, "CPU Topology HW: ");
  100. for (i = 0; i < TOPOLOGY_NR_MAG; i++)
  101. seq_printf(m, " %d", info->mag[i]);
  102. seq_putc(m, '\n');
  103. #ifdef CONFIG_SCHED_MC
  104. store_topology(info);
  105. seq_printf(m, "CPU Topology SW: ");
  106. for (i = 0; i < TOPOLOGY_NR_MAG; i++)
  107. seq_printf(m, " %d", info->mag[i]);
  108. seq_putc(m, '\n');
  109. #endif
  110. }
  111. static void stsi_1_2_2(struct seq_file *m, struct sysinfo_1_2_2 *info)
  112. {
  113. struct sysinfo_1_2_2_extension *ext;
  114. int i;
  115. if (stsi(info, 1, 2, 2) == -ENOSYS)
  116. return;
  117. ext = (struct sysinfo_1_2_2_extension *)
  118. ((unsigned long) info + info->acc_offset);
  119. seq_printf(m, "CPUs Total: %d\n", info->cpus_total);
  120. seq_printf(m, "CPUs Configured: %d\n", info->cpus_configured);
  121. seq_printf(m, "CPUs Standby: %d\n", info->cpus_standby);
  122. seq_printf(m, "CPUs Reserved: %d\n", info->cpus_reserved);
  123. /*
  124. * Sigh 2. According to the specification the alternate
  125. * capability field is a 32 bit floating point number
  126. * if the higher order 8 bits are not zero. Printing
  127. * a floating point number in the kernel is a no-no,
  128. * always print the number as 32 bit unsigned integer.
  129. * The user-space needs to know about the strange
  130. * encoding of the alternate cpu capability.
  131. */
  132. seq_printf(m, "Capability: %u", info->capability);
  133. if (info->format == 1)
  134. seq_printf(m, " %u", ext->alt_capability);
  135. seq_putc(m, '\n');
  136. if (info->nominal_cap)
  137. seq_printf(m, "Nominal Capability: %d\n", info->nominal_cap);
  138. if (info->secondary_cap)
  139. seq_printf(m, "Secondary Capability: %d\n", info->secondary_cap);
  140. for (i = 2; i <= info->cpus_total; i++) {
  141. seq_printf(m, "Adjustment %02d-way: %u",
  142. i, info->adjustment[i-2]);
  143. if (info->format == 1)
  144. seq_printf(m, " %u", ext->alt_adjustment[i-2]);
  145. seq_putc(m, '\n');
  146. }
  147. }
  148. static void stsi_2_2_2(struct seq_file *m, struct sysinfo_2_2_2 *info)
  149. {
  150. if (stsi(info, 2, 2, 2) == -ENOSYS)
  151. return;
  152. EBCASC(info->name, sizeof(info->name));
  153. seq_putc(m, '\n');
  154. seq_printf(m, "LPAR Number: %d\n", info->lpar_number);
  155. seq_printf(m, "LPAR Characteristics: ");
  156. if (info->characteristics & LPAR_CHAR_DEDICATED)
  157. seq_printf(m, "Dedicated ");
  158. if (info->characteristics & LPAR_CHAR_SHARED)
  159. seq_printf(m, "Shared ");
  160. if (info->characteristics & LPAR_CHAR_LIMITED)
  161. seq_printf(m, "Limited ");
  162. seq_putc(m, '\n');
  163. seq_printf(m, "LPAR Name: %-8.8s\n", info->name);
  164. seq_printf(m, "LPAR Adjustment: %d\n", info->caf);
  165. seq_printf(m, "LPAR CPUs Total: %d\n", info->cpus_total);
  166. seq_printf(m, "LPAR CPUs Configured: %d\n", info->cpus_configured);
  167. seq_printf(m, "LPAR CPUs Standby: %d\n", info->cpus_standby);
  168. seq_printf(m, "LPAR CPUs Reserved: %d\n", info->cpus_reserved);
  169. seq_printf(m, "LPAR CPUs Dedicated: %d\n", info->cpus_dedicated);
  170. seq_printf(m, "LPAR CPUs Shared: %d\n", info->cpus_shared);
  171. }
  172. static void stsi_3_2_2(struct seq_file *m, struct sysinfo_3_2_2 *info)
  173. {
  174. int i;
  175. if (stsi(info, 3, 2, 2) == -ENOSYS)
  176. return;
  177. for (i = 0; i < info->count; i++) {
  178. EBCASC(info->vm[i].name, sizeof(info->vm[i].name));
  179. EBCASC(info->vm[i].cpi, sizeof(info->vm[i].cpi));
  180. seq_putc(m, '\n');
  181. seq_printf(m, "VM%02d Name: %-8.8s\n", i, info->vm[i].name);
  182. seq_printf(m, "VM%02d Control Program: %-16.16s\n", i, info->vm[i].cpi);
  183. seq_printf(m, "VM%02d Adjustment: %d\n", i, info->vm[i].caf);
  184. seq_printf(m, "VM%02d CPUs Total: %d\n", i, info->vm[i].cpus_total);
  185. seq_printf(m, "VM%02d CPUs Configured: %d\n", i, info->vm[i].cpus_configured);
  186. seq_printf(m, "VM%02d CPUs Standby: %d\n", i, info->vm[i].cpus_standby);
  187. seq_printf(m, "VM%02d CPUs Reserved: %d\n", i, info->vm[i].cpus_reserved);
  188. }
  189. }
  190. static int sysinfo_show(struct seq_file *m, void *v)
  191. {
  192. void *info = (void *)get_zeroed_page(GFP_KERNEL);
  193. int level;
  194. if (!info)
  195. return 0;
  196. level = stsi_0();
  197. if (level >= 1)
  198. stsi_1_1_1(m, info);
  199. if (level >= 1)
  200. stsi_15_1_x(m, info);
  201. if (level >= 1)
  202. stsi_1_2_2(m, info);
  203. if (level >= 2)
  204. stsi_2_2_2(m, info);
  205. if (level >= 3)
  206. stsi_3_2_2(m, info);
  207. free_page((unsigned long)info);
  208. return 0;
  209. }
  210. static int sysinfo_open(struct inode *inode, struct file *file)
  211. {
  212. return single_open(file, sysinfo_show, NULL);
  213. }
  214. static const struct file_operations sysinfo_fops = {
  215. .open = sysinfo_open,
  216. .read = seq_read,
  217. .llseek = seq_lseek,
  218. .release = single_release,
  219. };
  220. static int __init sysinfo_create_proc(void)
  221. {
  222. proc_create("sysinfo", 0444, NULL, &sysinfo_fops);
  223. return 0;
  224. }
  225. device_initcall(sysinfo_create_proc);
  226. /*
  227. * Service levels interface.
  228. */
  229. static DECLARE_RWSEM(service_level_sem);
  230. static LIST_HEAD(service_level_list);
  231. int register_service_level(struct service_level *slr)
  232. {
  233. struct service_level *ptr;
  234. down_write(&service_level_sem);
  235. list_for_each_entry(ptr, &service_level_list, list)
  236. if (ptr == slr) {
  237. up_write(&service_level_sem);
  238. return -EEXIST;
  239. }
  240. list_add_tail(&slr->list, &service_level_list);
  241. up_write(&service_level_sem);
  242. return 0;
  243. }
  244. EXPORT_SYMBOL(register_service_level);
  245. int unregister_service_level(struct service_level *slr)
  246. {
  247. struct service_level *ptr, *next;
  248. int rc = -ENOENT;
  249. down_write(&service_level_sem);
  250. list_for_each_entry_safe(ptr, next, &service_level_list, list) {
  251. if (ptr != slr)
  252. continue;
  253. list_del(&ptr->list);
  254. rc = 0;
  255. break;
  256. }
  257. up_write(&service_level_sem);
  258. return rc;
  259. }
  260. EXPORT_SYMBOL(unregister_service_level);
  261. static void *service_level_start(struct seq_file *m, loff_t *pos)
  262. {
  263. down_read(&service_level_sem);
  264. return seq_list_start(&service_level_list, *pos);
  265. }
  266. static void *service_level_next(struct seq_file *m, void *p, loff_t *pos)
  267. {
  268. return seq_list_next(p, &service_level_list, pos);
  269. }
  270. static void service_level_stop(struct seq_file *m, void *p)
  271. {
  272. up_read(&service_level_sem);
  273. }
  274. static int service_level_show(struct seq_file *m, void *p)
  275. {
  276. struct service_level *slr;
  277. slr = list_entry(p, struct service_level, list);
  278. slr->seq_print(m, slr);
  279. return 0;
  280. }
  281. static const struct seq_operations service_level_seq_ops = {
  282. .start = service_level_start,
  283. .next = service_level_next,
  284. .stop = service_level_stop,
  285. .show = service_level_show
  286. };
  287. static int service_level_open(struct inode *inode, struct file *file)
  288. {
  289. return seq_open(file, &service_level_seq_ops);
  290. }
  291. static const struct file_operations service_level_ops = {
  292. .open = service_level_open,
  293. .read = seq_read,
  294. .llseek = seq_lseek,
  295. .release = seq_release
  296. };
  297. static void service_level_vm_print(struct seq_file *m,
  298. struct service_level *slr)
  299. {
  300. char *query_buffer, *str;
  301. query_buffer = kmalloc(1024, GFP_KERNEL | GFP_DMA);
  302. if (!query_buffer)
  303. return;
  304. cpcmd("QUERY CPLEVEL", query_buffer, 1024, NULL);
  305. str = strchr(query_buffer, '\n');
  306. if (str)
  307. *str = 0;
  308. seq_printf(m, "VM: %s\n", query_buffer);
  309. kfree(query_buffer);
  310. }
  311. static struct service_level service_level_vm = {
  312. .seq_print = service_level_vm_print
  313. };
  314. static __init int create_proc_service_level(void)
  315. {
  316. proc_create("service_levels", 0, NULL, &service_level_ops);
  317. if (MACHINE_IS_VM)
  318. register_service_level(&service_level_vm);
  319. return 0;
  320. }
  321. subsys_initcall(create_proc_service_level);
  322. /*
  323. * CPU capability might have changed. Therefore recalculate loops_per_jiffy.
  324. */
  325. void s390_adjust_jiffies(void)
  326. {
  327. struct sysinfo_1_2_2 *info;
  328. const unsigned int fmil = 0x4b189680; /* 1e7 as 32-bit float. */
  329. FP_DECL_S(SA); FP_DECL_S(SB); FP_DECL_S(SR);
  330. FP_DECL_EX;
  331. unsigned int capability;
  332. info = (void *) get_zeroed_page(GFP_KERNEL);
  333. if (!info)
  334. return;
  335. if (stsi(info, 1, 2, 2) != -ENOSYS) {
  336. /*
  337. * Major sigh. The cpu capability encoding is "special".
  338. * If the first 9 bits of info->capability are 0 then it
  339. * is a 32 bit unsigned integer in the range 0 .. 2^23.
  340. * If the first 9 bits are != 0 then it is a 32 bit float.
  341. * In addition a lower value indicates a proportionally
  342. * higher cpu capacity. Bogomips are the other way round.
  343. * To get to a halfway suitable number we divide 1e7
  344. * by the cpu capability number. Yes, that means a floating
  345. * point division .. math-emu here we come :-)
  346. */
  347. FP_UNPACK_SP(SA, &fmil);
  348. if ((info->capability >> 23) == 0)
  349. FP_FROM_INT_S(SB, (long) info->capability, 64, long);
  350. else
  351. FP_UNPACK_SP(SB, &info->capability);
  352. FP_DIV_S(SR, SA, SB);
  353. FP_TO_INT_S(capability, SR, 32, 0);
  354. } else
  355. /*
  356. * Really old machine without stsi block for basic
  357. * cpu information. Report 42.0 bogomips.
  358. */
  359. capability = 42;
  360. loops_per_jiffy = capability * (500000/HZ);
  361. free_page((unsigned long) info);
  362. }
  363. /*
  364. * calibrate the delay loop
  365. */
  366. void __cpuinit calibrate_delay(void)
  367. {
  368. s390_adjust_jiffies();
  369. /* Print the good old Bogomips line .. */
  370. printk(KERN_DEBUG "Calibrating delay loop (skipped)... "
  371. "%lu.%02lu BogoMIPS preset\n", loops_per_jiffy/(500000/HZ),
  372. (loops_per_jiffy/(5000/HZ)) % 100);
  373. }