sysinfo.c 13 KB

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