xfs_stats.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "xfs.h"
  19. #include <linux/proc_fs.h>
  20. struct xstats xfsstats;
  21. static int counter_val(struct xfsstats __percpu *stats, int idx)
  22. {
  23. int val = 0, cpu;
  24. for_each_possible_cpu(cpu)
  25. val += *(((__u32 *)per_cpu_ptr(stats, cpu) + idx));
  26. return val;
  27. }
  28. int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
  29. {
  30. int i, j;
  31. int len = 0;
  32. __uint64_t xs_xstrat_bytes = 0;
  33. __uint64_t xs_write_bytes = 0;
  34. __uint64_t xs_read_bytes = 0;
  35. static const struct xstats_entry {
  36. char *desc;
  37. int endpoint;
  38. } xstats[] = {
  39. { "extent_alloc", XFSSTAT_END_EXTENT_ALLOC },
  40. { "abt", XFSSTAT_END_ALLOC_BTREE },
  41. { "blk_map", XFSSTAT_END_BLOCK_MAPPING },
  42. { "bmbt", XFSSTAT_END_BLOCK_MAP_BTREE },
  43. { "dir", XFSSTAT_END_DIRECTORY_OPS },
  44. { "trans", XFSSTAT_END_TRANSACTIONS },
  45. { "ig", XFSSTAT_END_INODE_OPS },
  46. { "log", XFSSTAT_END_LOG_OPS },
  47. { "push_ail", XFSSTAT_END_TAIL_PUSHING },
  48. { "xstrat", XFSSTAT_END_WRITE_CONVERT },
  49. { "rw", XFSSTAT_END_READ_WRITE_OPS },
  50. { "attr", XFSSTAT_END_ATTRIBUTE_OPS },
  51. { "icluster", XFSSTAT_END_INODE_CLUSTER },
  52. { "vnodes", XFSSTAT_END_VNODE_OPS },
  53. { "buf", XFSSTAT_END_BUF },
  54. { "abtb2", XFSSTAT_END_ABTB_V2 },
  55. { "abtc2", XFSSTAT_END_ABTC_V2 },
  56. { "bmbt2", XFSSTAT_END_BMBT_V2 },
  57. { "ibt2", XFSSTAT_END_IBT_V2 },
  58. { "fibt2", XFSSTAT_END_FIBT_V2 },
  59. /* we print both series of quota information together */
  60. { "qm", XFSSTAT_END_QM },
  61. };
  62. /* Loop over all stats groups */
  63. for (i = j = 0; i < ARRAY_SIZE(xstats); i++) {
  64. len += snprintf(buf + len, PATH_MAX - len, "%s",
  65. xstats[i].desc);
  66. /* inner loop does each group */
  67. for (; j < xstats[i].endpoint; j++)
  68. len += snprintf(buf + len, PATH_MAX - len, " %u",
  69. counter_val(stats, j));
  70. len += snprintf(buf + len, PATH_MAX - len, "\n");
  71. }
  72. /* extra precision counters */
  73. for_each_possible_cpu(i) {
  74. xs_xstrat_bytes += per_cpu_ptr(stats, i)->xs_xstrat_bytes;
  75. xs_write_bytes += per_cpu_ptr(stats, i)->xs_write_bytes;
  76. xs_read_bytes += per_cpu_ptr(stats, i)->xs_read_bytes;
  77. }
  78. len += snprintf(buf + len, PATH_MAX-len, "xpc %Lu %Lu %Lu\n",
  79. xs_xstrat_bytes, xs_write_bytes, xs_read_bytes);
  80. len += snprintf(buf + len, PATH_MAX-len, "debug %u\n",
  81. #if defined(DEBUG)
  82. 1);
  83. #else
  84. 0);
  85. #endif
  86. return len;
  87. }
  88. void xfs_stats_clearall(struct xfsstats __percpu *stats)
  89. {
  90. int c;
  91. __uint32_t vn_active;
  92. xfs_notice(NULL, "Clearing xfsstats");
  93. for_each_possible_cpu(c) {
  94. preempt_disable();
  95. /* save vn_active, it's a universal truth! */
  96. vn_active = per_cpu_ptr(stats, c)->vn_active;
  97. memset(per_cpu_ptr(stats, c), 0, sizeof(*stats));
  98. per_cpu_ptr(stats, c)->vn_active = vn_active;
  99. preempt_enable();
  100. }
  101. }
  102. /* legacy quota interfaces */
  103. #ifdef CONFIG_XFS_QUOTA
  104. static int xqm_proc_show(struct seq_file *m, void *v)
  105. {
  106. /* maximum; incore; ratio free to inuse; freelist */
  107. seq_printf(m, "%d\t%d\t%d\t%u\n",
  108. 0, counter_val(xfsstats.xs_stats, XFSSTAT_END_XQMSTAT),
  109. 0, counter_val(xfsstats.xs_stats, XFSSTAT_END_XQMSTAT + 1));
  110. return 0;
  111. }
  112. static int xqm_proc_open(struct inode *inode, struct file *file)
  113. {
  114. return single_open(file, xqm_proc_show, NULL);
  115. }
  116. static const struct file_operations xqm_proc_fops = {
  117. .owner = THIS_MODULE,
  118. .open = xqm_proc_open,
  119. .read = seq_read,
  120. .llseek = seq_lseek,
  121. .release = single_release,
  122. };
  123. /* legacy quota stats interface no 2 */
  124. static int xqmstat_proc_show(struct seq_file *m, void *v)
  125. {
  126. int j;
  127. seq_printf(m, "qm");
  128. for (j = XFSSTAT_END_IBT_V2; j < XFSSTAT_END_XQMSTAT; j++)
  129. seq_printf(m, " %u", counter_val(xfsstats.xs_stats, j));
  130. seq_putc(m, '\n');
  131. return 0;
  132. }
  133. static int xqmstat_proc_open(struct inode *inode, struct file *file)
  134. {
  135. return single_open(file, xqmstat_proc_show, NULL);
  136. }
  137. static const struct file_operations xqmstat_proc_fops = {
  138. .owner = THIS_MODULE,
  139. .open = xqmstat_proc_open,
  140. .read = seq_read,
  141. .llseek = seq_lseek,
  142. .release = single_release,
  143. };
  144. #endif /* CONFIG_XFS_QUOTA */
  145. #ifdef CONFIG_PROC_FS
  146. int
  147. xfs_init_procfs(void)
  148. {
  149. if (!proc_mkdir("fs/xfs", NULL))
  150. return -ENOMEM;
  151. if (!proc_symlink("fs/xfs/stat", NULL,
  152. "/sys/fs/xfs/stats/stats"))
  153. goto out;
  154. #ifdef CONFIG_XFS_QUOTA
  155. if (!proc_create("fs/xfs/xqmstat", 0, NULL,
  156. &xqmstat_proc_fops))
  157. goto out;
  158. if (!proc_create("fs/xfs/xqm", 0, NULL,
  159. &xqm_proc_fops))
  160. goto out;
  161. #endif
  162. return 0;
  163. out:
  164. remove_proc_subtree("fs/xfs", NULL);
  165. return -ENOMEM;
  166. }
  167. void
  168. xfs_cleanup_procfs(void)
  169. {
  170. remove_proc_subtree("fs/xfs", NULL);
  171. }
  172. #endif /* CONFIG_PROC_FS */