xfs_stats.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. { "rmapbt", XFSSTAT_END_RMAP_V2 },
  60. { "refcntbt", XFSSTAT_END_REFCOUNT },
  61. /* we print both series of quota information together */
  62. { "qm", XFSSTAT_END_QM },
  63. };
  64. /* Loop over all stats groups */
  65. for (i = j = 0; i < ARRAY_SIZE(xstats); i++) {
  66. len += snprintf(buf + len, PATH_MAX - len, "%s",
  67. xstats[i].desc);
  68. /* inner loop does each group */
  69. for (; j < xstats[i].endpoint; j++)
  70. len += snprintf(buf + len, PATH_MAX - len, " %u",
  71. counter_val(stats, j));
  72. len += snprintf(buf + len, PATH_MAX - len, "\n");
  73. }
  74. /* extra precision counters */
  75. for_each_possible_cpu(i) {
  76. xs_xstrat_bytes += per_cpu_ptr(stats, i)->xs_xstrat_bytes;
  77. xs_write_bytes += per_cpu_ptr(stats, i)->xs_write_bytes;
  78. xs_read_bytes += per_cpu_ptr(stats, i)->xs_read_bytes;
  79. }
  80. len += snprintf(buf + len, PATH_MAX-len, "xpc %Lu %Lu %Lu\n",
  81. xs_xstrat_bytes, xs_write_bytes, xs_read_bytes);
  82. len += snprintf(buf + len, PATH_MAX-len, "debug %u\n",
  83. #if defined(DEBUG)
  84. 1);
  85. #else
  86. 0);
  87. #endif
  88. return len;
  89. }
  90. void xfs_stats_clearall(struct xfsstats __percpu *stats)
  91. {
  92. int c;
  93. __uint32_t vn_active;
  94. xfs_notice(NULL, "Clearing xfsstats");
  95. for_each_possible_cpu(c) {
  96. preempt_disable();
  97. /* save vn_active, it's a universal truth! */
  98. vn_active = per_cpu_ptr(stats, c)->vn_active;
  99. memset(per_cpu_ptr(stats, c), 0, sizeof(*stats));
  100. per_cpu_ptr(stats, c)->vn_active = vn_active;
  101. preempt_enable();
  102. }
  103. }
  104. /* legacy quota interfaces */
  105. #ifdef CONFIG_XFS_QUOTA
  106. static int xqm_proc_show(struct seq_file *m, void *v)
  107. {
  108. /* maximum; incore; ratio free to inuse; freelist */
  109. seq_printf(m, "%d\t%d\t%d\t%u\n",
  110. 0, counter_val(xfsstats.xs_stats, XFSSTAT_END_XQMSTAT),
  111. 0, counter_val(xfsstats.xs_stats, XFSSTAT_END_XQMSTAT + 1));
  112. return 0;
  113. }
  114. static int xqm_proc_open(struct inode *inode, struct file *file)
  115. {
  116. return single_open(file, xqm_proc_show, NULL);
  117. }
  118. static const struct file_operations xqm_proc_fops = {
  119. .open = xqm_proc_open,
  120. .read = seq_read,
  121. .llseek = seq_lseek,
  122. .release = single_release,
  123. };
  124. /* legacy quota stats interface no 2 */
  125. static int xqmstat_proc_show(struct seq_file *m, void *v)
  126. {
  127. int j;
  128. seq_printf(m, "qm");
  129. for (j = XFSSTAT_END_IBT_V2; j < XFSSTAT_END_XQMSTAT; j++)
  130. seq_printf(m, " %u", counter_val(xfsstats.xs_stats, j));
  131. seq_putc(m, '\n');
  132. return 0;
  133. }
  134. static int xqmstat_proc_open(struct inode *inode, struct file *file)
  135. {
  136. return single_open(file, xqmstat_proc_show, NULL);
  137. }
  138. static const struct file_operations xqmstat_proc_fops = {
  139. .owner = THIS_MODULE,
  140. .open = xqmstat_proc_open,
  141. .read = seq_read,
  142. .llseek = seq_lseek,
  143. .release = single_release,
  144. };
  145. #endif /* CONFIG_XFS_QUOTA */
  146. #ifdef CONFIG_PROC_FS
  147. int
  148. xfs_init_procfs(void)
  149. {
  150. if (!proc_mkdir("fs/xfs", NULL))
  151. return -ENOMEM;
  152. if (!proc_symlink("fs/xfs/stat", NULL,
  153. "/sys/fs/xfs/stats/stats"))
  154. goto out;
  155. #ifdef CONFIG_XFS_QUOTA
  156. if (!proc_create("fs/xfs/xqmstat", 0, NULL,
  157. &xqmstat_proc_fops))
  158. goto out;
  159. if (!proc_create("fs/xfs/xqm", 0, NULL,
  160. &xqm_proc_fops))
  161. goto out;
  162. #endif
  163. return 0;
  164. out:
  165. remove_proc_subtree("fs/xfs", NULL);
  166. return -ENOMEM;
  167. }
  168. void
  169. xfs_cleanup_procfs(void)
  170. {
  171. remove_proc_subtree("fs/xfs", NULL);
  172. }
  173. #endif /* CONFIG_PROC_FS */