xfs_stats.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
  4. * All Rights Reserved.
  5. */
  6. #include "xfs.h"
  7. #include <linux/proc_fs.h>
  8. struct xstats xfsstats;
  9. static int counter_val(struct xfsstats __percpu *stats, int idx)
  10. {
  11. int val = 0, cpu;
  12. for_each_possible_cpu(cpu)
  13. val += *(((__u32 *)per_cpu_ptr(stats, cpu) + idx));
  14. return val;
  15. }
  16. int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
  17. {
  18. int i, j;
  19. int len = 0;
  20. uint64_t xs_xstrat_bytes = 0;
  21. uint64_t xs_write_bytes = 0;
  22. uint64_t xs_read_bytes = 0;
  23. static const struct xstats_entry {
  24. char *desc;
  25. int endpoint;
  26. } xstats[] = {
  27. { "extent_alloc", XFSSTAT_END_EXTENT_ALLOC },
  28. { "abt", XFSSTAT_END_ALLOC_BTREE },
  29. { "blk_map", XFSSTAT_END_BLOCK_MAPPING },
  30. { "bmbt", XFSSTAT_END_BLOCK_MAP_BTREE },
  31. { "dir", XFSSTAT_END_DIRECTORY_OPS },
  32. { "trans", XFSSTAT_END_TRANSACTIONS },
  33. { "ig", XFSSTAT_END_INODE_OPS },
  34. { "log", XFSSTAT_END_LOG_OPS },
  35. { "push_ail", XFSSTAT_END_TAIL_PUSHING },
  36. { "xstrat", XFSSTAT_END_WRITE_CONVERT },
  37. { "rw", XFSSTAT_END_READ_WRITE_OPS },
  38. { "attr", XFSSTAT_END_ATTRIBUTE_OPS },
  39. { "icluster", XFSSTAT_END_INODE_CLUSTER },
  40. { "vnodes", XFSSTAT_END_VNODE_OPS },
  41. { "buf", XFSSTAT_END_BUF },
  42. { "abtb2", XFSSTAT_END_ABTB_V2 },
  43. { "abtc2", XFSSTAT_END_ABTC_V2 },
  44. { "bmbt2", XFSSTAT_END_BMBT_V2 },
  45. { "ibt2", XFSSTAT_END_IBT_V2 },
  46. { "fibt2", XFSSTAT_END_FIBT_V2 },
  47. { "rmapbt", XFSSTAT_END_RMAP_V2 },
  48. { "refcntbt", XFSSTAT_END_REFCOUNT },
  49. /* we print both series of quota information together */
  50. { "qm", XFSSTAT_END_QM },
  51. };
  52. /* Loop over all stats groups */
  53. for (i = j = 0; i < ARRAY_SIZE(xstats); i++) {
  54. len += snprintf(buf + len, PATH_MAX - len, "%s",
  55. xstats[i].desc);
  56. /* inner loop does each group */
  57. for (; j < xstats[i].endpoint; j++)
  58. len += snprintf(buf + len, PATH_MAX - len, " %u",
  59. counter_val(stats, j));
  60. len += snprintf(buf + len, PATH_MAX - len, "\n");
  61. }
  62. /* extra precision counters */
  63. for_each_possible_cpu(i) {
  64. xs_xstrat_bytes += per_cpu_ptr(stats, i)->s.xs_xstrat_bytes;
  65. xs_write_bytes += per_cpu_ptr(stats, i)->s.xs_write_bytes;
  66. xs_read_bytes += per_cpu_ptr(stats, i)->s.xs_read_bytes;
  67. }
  68. len += snprintf(buf + len, PATH_MAX-len, "xpc %Lu %Lu %Lu\n",
  69. xs_xstrat_bytes, xs_write_bytes, xs_read_bytes);
  70. len += snprintf(buf + len, PATH_MAX-len, "debug %u\n",
  71. #if defined(DEBUG)
  72. 1);
  73. #else
  74. 0);
  75. #endif
  76. return len;
  77. }
  78. void xfs_stats_clearall(struct xfsstats __percpu *stats)
  79. {
  80. int c;
  81. uint32_t vn_active;
  82. xfs_notice(NULL, "Clearing xfsstats");
  83. for_each_possible_cpu(c) {
  84. preempt_disable();
  85. /* save vn_active, it's a universal truth! */
  86. vn_active = per_cpu_ptr(stats, c)->s.vn_active;
  87. memset(per_cpu_ptr(stats, c), 0, sizeof(*stats));
  88. per_cpu_ptr(stats, c)->s.vn_active = vn_active;
  89. preempt_enable();
  90. }
  91. }
  92. #ifdef CONFIG_PROC_FS
  93. /* legacy quota interfaces */
  94. #ifdef CONFIG_XFS_QUOTA
  95. static int xqm_proc_show(struct seq_file *m, void *v)
  96. {
  97. /* maximum; incore; ratio free to inuse; freelist */
  98. seq_printf(m, "%d\t%d\t%d\t%u\n",
  99. 0, counter_val(xfsstats.xs_stats, XFSSTAT_END_XQMSTAT),
  100. 0, counter_val(xfsstats.xs_stats, XFSSTAT_END_XQMSTAT + 1));
  101. return 0;
  102. }
  103. /* legacy quota stats interface no 2 */
  104. static int xqmstat_proc_show(struct seq_file *m, void *v)
  105. {
  106. int j;
  107. seq_printf(m, "qm");
  108. for (j = XFSSTAT_END_REFCOUNT; j < XFSSTAT_END_XQMSTAT; j++)
  109. seq_printf(m, " %u", counter_val(xfsstats.xs_stats, j));
  110. seq_putc(m, '\n');
  111. return 0;
  112. }
  113. #endif /* CONFIG_XFS_QUOTA */
  114. int
  115. xfs_init_procfs(void)
  116. {
  117. if (!proc_mkdir("fs/xfs", NULL))
  118. return -ENOMEM;
  119. if (!proc_symlink("fs/xfs/stat", NULL,
  120. "/sys/fs/xfs/stats/stats"))
  121. goto out;
  122. #ifdef CONFIG_XFS_QUOTA
  123. if (!proc_create_single("fs/xfs/xqmstat", 0, NULL, xqmstat_proc_show))
  124. goto out;
  125. if (!proc_create_single("fs/xfs/xqm", 0, NULL, xqm_proc_show))
  126. goto out;
  127. #endif
  128. return 0;
  129. out:
  130. remove_proc_subtree("fs/xfs", NULL);
  131. return -ENOMEM;
  132. }
  133. void
  134. xfs_cleanup_procfs(void)
  135. {
  136. remove_proc_subtree("fs/xfs", NULL);
  137. }
  138. #endif /* CONFIG_PROC_FS */