dasd_proc.c 9.6 KB

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