sysinfo.c 13 KB

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