dasd_proc.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
  4. * Horst Hummel <Horst.Hummel@de.ibm.com>
  5. * Carsten Otte <Cotte@de.ibm.com>
  6. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  7. * Bugreports.to..: <Linux390@de.ibm.com>
  8. * Copyright IBM Corp. 1999, 2002
  9. *
  10. * /proc interface for the dasd driver.
  11. *
  12. */
  13. #include <linux/ctype.h>
  14. #include <linux/slab.h>
  15. #include <linux/string.h>
  16. #include <linux/seq_file.h>
  17. #include <linux/vmalloc.h>
  18. #include <linux/proc_fs.h>
  19. #include <asm/debug.h>
  20. #include <linux/uaccess.h>
  21. #include "dasd_int.h"
  22. static struct proc_dir_entry *dasd_proc_root_entry = NULL;
  23. static struct proc_dir_entry *dasd_devices_entry = NULL;
  24. static struct proc_dir_entry *dasd_statistics_entry = NULL;
  25. static int
  26. dasd_devices_show(struct seq_file *m, void *v)
  27. {
  28. struct dasd_device *device;
  29. struct dasd_block *block;
  30. char *substr;
  31. device = dasd_device_from_devindex((unsigned long) v - 1);
  32. if (IS_ERR(device))
  33. return 0;
  34. if (device->block)
  35. block = device->block;
  36. else {
  37. dasd_put_device(device);
  38. return 0;
  39. }
  40. /* Print device number. */
  41. seq_printf(m, "%s", dev_name(&device->cdev->dev));
  42. /* Print discipline string. */
  43. if (device->discipline != NULL)
  44. seq_printf(m, "(%s)", device->discipline->name);
  45. else
  46. seq_printf(m, "(none)");
  47. /* Print kdev. */
  48. if (block->gdp)
  49. seq_printf(m, " at (%3d:%6d)",
  50. MAJOR(disk_devt(block->gdp)),
  51. MINOR(disk_devt(block->gdp)));
  52. else
  53. seq_printf(m, " at (???:??????)");
  54. /* Print device name. */
  55. if (block->gdp)
  56. seq_printf(m, " is %-8s", block->gdp->disk_name);
  57. else
  58. seq_printf(m, " is ????????");
  59. /* Print devices features. */
  60. substr = (device->features & DASD_FEATURE_READONLY) ? "(ro)" : " ";
  61. seq_printf(m, "%4s: ", substr);
  62. /* Print device status information. */
  63. switch (device->state) {
  64. case DASD_STATE_NEW:
  65. seq_printf(m, "new");
  66. break;
  67. case DASD_STATE_KNOWN:
  68. seq_printf(m, "detected");
  69. break;
  70. case DASD_STATE_BASIC:
  71. seq_printf(m, "basic");
  72. break;
  73. case DASD_STATE_UNFMT:
  74. seq_printf(m, "unformatted");
  75. break;
  76. case DASD_STATE_READY:
  77. case DASD_STATE_ONLINE:
  78. seq_printf(m, "active ");
  79. if (dasd_check_blocksize(block->bp_block))
  80. seq_printf(m, "n/f ");
  81. else
  82. seq_printf(m,
  83. "at blocksize: %u, %lu blocks, %lu MB",
  84. block->bp_block, block->blocks,
  85. ((block->bp_block >> 9) *
  86. block->blocks) >> 11);
  87. break;
  88. default:
  89. seq_printf(m, "no stat");
  90. break;
  91. }
  92. dasd_put_device(device);
  93. if (dasd_probeonly)
  94. seq_printf(m, "(probeonly)");
  95. seq_printf(m, "\n");
  96. return 0;
  97. }
  98. static void *dasd_devices_start(struct seq_file *m, loff_t *pos)
  99. {
  100. if (*pos >= dasd_max_devindex)
  101. return NULL;
  102. return (void *)((unsigned long) *pos + 1);
  103. }
  104. static void *dasd_devices_next(struct seq_file *m, void *v, loff_t *pos)
  105. {
  106. ++*pos;
  107. return dasd_devices_start(m, pos);
  108. }
  109. static void dasd_devices_stop(struct seq_file *m, void *v)
  110. {
  111. }
  112. static const struct seq_operations dasd_devices_seq_ops = {
  113. .start = dasd_devices_start,
  114. .next = dasd_devices_next,
  115. .stop = dasd_devices_stop,
  116. .show = dasd_devices_show,
  117. };
  118. #ifdef CONFIG_DASD_PROFILE
  119. static int dasd_stats_all_block_on(void)
  120. {
  121. int i, rc;
  122. struct dasd_device *device;
  123. rc = 0;
  124. for (i = 0; i < dasd_max_devindex; ++i) {
  125. device = dasd_device_from_devindex(i);
  126. if (IS_ERR(device))
  127. continue;
  128. if (device->block)
  129. rc = dasd_profile_on(&device->block->profile);
  130. dasd_put_device(device);
  131. if (rc)
  132. return rc;
  133. }
  134. return 0;
  135. }
  136. static void dasd_stats_all_block_off(void)
  137. {
  138. int i;
  139. struct dasd_device *device;
  140. for (i = 0; i < dasd_max_devindex; ++i) {
  141. device = dasd_device_from_devindex(i);
  142. if (IS_ERR(device))
  143. continue;
  144. if (device->block)
  145. dasd_profile_off(&device->block->profile);
  146. dasd_put_device(device);
  147. }
  148. }
  149. static void dasd_stats_all_block_reset(void)
  150. {
  151. int i;
  152. struct dasd_device *device;
  153. for (i = 0; i < dasd_max_devindex; ++i) {
  154. device = dasd_device_from_devindex(i);
  155. if (IS_ERR(device))
  156. continue;
  157. if (device->block)
  158. dasd_profile_reset(&device->block->profile);
  159. dasd_put_device(device);
  160. }
  161. }
  162. static void dasd_statistics_array(struct seq_file *m, unsigned int *array, int factor)
  163. {
  164. int i;
  165. for (i = 0; i < 32; i++) {
  166. seq_printf(m, "%7d ", array[i] / factor);
  167. if (i == 15)
  168. seq_putc(m, '\n');
  169. }
  170. seq_putc(m, '\n');
  171. }
  172. #endif /* CONFIG_DASD_PROFILE */
  173. static int dasd_stats_proc_show(struct seq_file *m, void *v)
  174. {
  175. #ifdef CONFIG_DASD_PROFILE
  176. struct dasd_profile_info *prof;
  177. int factor;
  178. spin_lock_bh(&dasd_global_profile.lock);
  179. prof = dasd_global_profile.data;
  180. if (!prof) {
  181. spin_unlock_bh(&dasd_global_profile.lock);
  182. seq_printf(m, "Statistics are off - they might be "
  183. "switched on using 'echo set on > "
  184. "/proc/dasd/statistics'\n");
  185. return 0;
  186. }
  187. /* prevent counter 'overflow' on output */
  188. for (factor = 1; (prof->dasd_io_reqs / factor) > 9999999;
  189. factor *= 10);
  190. seq_printf(m, "%d dasd I/O requests\n", prof->dasd_io_reqs);
  191. seq_printf(m, "with %u sectors(512B each)\n",
  192. prof->dasd_io_sects);
  193. seq_printf(m, "Scale Factor is %d\n", factor);
  194. seq_printf(m,
  195. " __<4 ___8 __16 __32 __64 _128 "
  196. " _256 _512 __1k __2k __4k __8k "
  197. " _16k _32k _64k 128k\n");
  198. seq_printf(m,
  199. " _256 _512 __1M __2M __4M __8M "
  200. " _16M _32M _64M 128M 256M 512M "
  201. " __1G __2G __4G " " _>4G\n");
  202. seq_printf(m, "Histogram of sizes (512B secs)\n");
  203. dasd_statistics_array(m, prof->dasd_io_secs, factor);
  204. seq_printf(m, "Histogram of I/O times (microseconds)\n");
  205. dasd_statistics_array(m, prof->dasd_io_times, factor);
  206. seq_printf(m, "Histogram of I/O times per sector\n");
  207. dasd_statistics_array(m, prof->dasd_io_timps, factor);
  208. seq_printf(m, "Histogram of I/O time till ssch\n");
  209. dasd_statistics_array(m, prof->dasd_io_time1, factor);
  210. seq_printf(m, "Histogram of I/O time between ssch and irq\n");
  211. dasd_statistics_array(m, prof->dasd_io_time2, factor);
  212. seq_printf(m, "Histogram of I/O time between ssch "
  213. "and irq per sector\n");
  214. dasd_statistics_array(m, prof->dasd_io_time2ps, factor);
  215. seq_printf(m, "Histogram of I/O time between irq and end\n");
  216. dasd_statistics_array(m, prof->dasd_io_time3, factor);
  217. seq_printf(m, "# of req in chanq at enqueuing (1..32) \n");
  218. dasd_statistics_array(m, prof->dasd_io_nr_req, factor);
  219. spin_unlock_bh(&dasd_global_profile.lock);
  220. #else
  221. seq_printf(m, "Statistics are not activated in this kernel\n");
  222. #endif
  223. return 0;
  224. }
  225. static int dasd_stats_proc_open(struct inode *inode, struct file *file)
  226. {
  227. return single_open(file, dasd_stats_proc_show, NULL);
  228. }
  229. static ssize_t dasd_stats_proc_write(struct file *file,
  230. const char __user *user_buf, size_t user_len, loff_t *pos)
  231. {
  232. #ifdef CONFIG_DASD_PROFILE
  233. char *buffer, *str;
  234. int rc;
  235. if (user_len > 65536)
  236. user_len = 65536;
  237. buffer = dasd_get_user_string(user_buf, user_len);
  238. if (IS_ERR(buffer))
  239. return PTR_ERR(buffer);
  240. /* check for valid verbs */
  241. str = skip_spaces(buffer);
  242. if (strncmp(str, "set", 3) == 0 && isspace(str[3])) {
  243. /* 'set xxx' was given */
  244. str = skip_spaces(str + 4);
  245. if (strcmp(str, "on") == 0) {
  246. /* switch on statistics profiling */
  247. rc = dasd_stats_all_block_on();
  248. if (rc) {
  249. dasd_stats_all_block_off();
  250. goto out_error;
  251. }
  252. rc = dasd_profile_on(&dasd_global_profile);
  253. if (rc) {
  254. dasd_stats_all_block_off();
  255. goto out_error;
  256. }
  257. dasd_profile_reset(&dasd_global_profile);
  258. dasd_global_profile_level = DASD_PROFILE_ON;
  259. pr_info("The statistics feature has been switched "
  260. "on\n");
  261. } else if (strcmp(str, "off") == 0) {
  262. /* switch off statistics profiling */
  263. dasd_global_profile_level = DASD_PROFILE_OFF;
  264. dasd_profile_off(&dasd_global_profile);
  265. dasd_stats_all_block_off();
  266. pr_info("The statistics feature has been switched "
  267. "off\n");
  268. } else
  269. goto out_parse_error;
  270. } else if (strncmp(str, "reset", 5) == 0) {
  271. /* reset the statistics */
  272. dasd_profile_reset(&dasd_global_profile);
  273. dasd_stats_all_block_reset();
  274. pr_info("The statistics have been reset\n");
  275. } else
  276. goto out_parse_error;
  277. vfree(buffer);
  278. return user_len;
  279. out_parse_error:
  280. rc = -EINVAL;
  281. pr_warn("%s is not a supported value for /proc/dasd/statistics\n", str);
  282. out_error:
  283. vfree(buffer);
  284. return rc;
  285. #else
  286. pr_warn("/proc/dasd/statistics: is not activated in this kernel\n");
  287. return user_len;
  288. #endif /* CONFIG_DASD_PROFILE */
  289. }
  290. static const struct proc_ops dasd_stats_proc_ops = {
  291. .proc_open = dasd_stats_proc_open,
  292. .proc_read = seq_read,
  293. .proc_lseek = seq_lseek,
  294. .proc_release = single_release,
  295. .proc_write = dasd_stats_proc_write,
  296. };
  297. /*
  298. * Create dasd proc-fs entries.
  299. * In case creation failed, cleanup and return -ENOENT.
  300. */
  301. int
  302. dasd_proc_init(void)
  303. {
  304. dasd_proc_root_entry = proc_mkdir("dasd", NULL);
  305. if (!dasd_proc_root_entry)
  306. goto out_nodasd;
  307. dasd_devices_entry = proc_create_seq("devices", 0444,
  308. dasd_proc_root_entry,
  309. &dasd_devices_seq_ops);
  310. if (!dasd_devices_entry)
  311. goto out_nodevices;
  312. dasd_statistics_entry = proc_create("statistics",
  313. S_IFREG | S_IRUGO | S_IWUSR,
  314. dasd_proc_root_entry,
  315. &dasd_stats_proc_ops);
  316. if (!dasd_statistics_entry)
  317. goto out_nostatistics;
  318. return 0;
  319. out_nostatistics:
  320. remove_proc_entry("devices", dasd_proc_root_entry);
  321. out_nodevices:
  322. remove_proc_entry("dasd", NULL);
  323. out_nodasd:
  324. return -ENOENT;
  325. }
  326. void
  327. dasd_proc_exit(void)
  328. {
  329. remove_proc_entry("devices", dasd_proc_root_entry);
  330. remove_proc_entry("statistics", dasd_proc_root_entry);
  331. remove_proc_entry("dasd", NULL);
  332. }