dasd_proc.c 9.7 KB

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