sysinfo.c 12 KB

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