sysinfo.c 14 KB

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