xfs_stats.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. struct xstats xfsstats;
  8. static int counter_val(struct xfsstats __percpu *stats, int idx)
  9. {
  10. int val = 0, cpu;
  11. for_each_possible_cpu(cpu)
  12. val += *(((__u32 *)per_cpu_ptr(stats, cpu) + idx));
  13. return val;
  14. }
  15. int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
  16. {
  17. int i, j;
  18. int len = 0;
  19. uint64_t xs_xstrat_bytes = 0;
  20. uint64_t xs_write_bytes = 0;
  21. uint64_t xs_read_bytes = 0;
  22. uint64_t defer_relog = 0;
  23. static const struct xstats_entry {
  24. char *desc;
  25. int endpoint;
  26. } xstats[] = {
  27. { "extent_alloc", xfsstats_offset(xs_abt_lookup) },
  28. { "abt", xfsstats_offset(xs_blk_mapr) },
  29. { "blk_map", xfsstats_offset(xs_bmbt_lookup) },
  30. { "bmbt", xfsstats_offset(xs_dir_lookup) },
  31. { "dir", xfsstats_offset(xs_trans_sync) },
  32. { "trans", xfsstats_offset(xs_ig_attempts) },
  33. { "ig", xfsstats_offset(xs_log_writes) },
  34. { "log", xfsstats_offset(xs_try_logspace)},
  35. { "push_ail", xfsstats_offset(xs_xstrat_quick)},
  36. { "xstrat", xfsstats_offset(xs_write_calls) },
  37. { "rw", xfsstats_offset(xs_attr_get) },
  38. { "attr", xfsstats_offset(xs_iflush_count)},
  39. { "icluster", xfsstats_offset(vn_active) },
  40. { "vnodes", xfsstats_offset(xb_get) },
  41. { "buf", xfsstats_offset(xs_abtb_2) },
  42. { "abtb2", xfsstats_offset(xs_abtc_2) },
  43. { "abtc2", xfsstats_offset(xs_bmbt_2) },
  44. { "bmbt2", xfsstats_offset(xs_ibt_2) },
  45. { "ibt2", xfsstats_offset(xs_fibt_2) },
  46. { "fibt2", xfsstats_offset(xs_rmap_2) },
  47. { "rmapbt", xfsstats_offset(xs_refcbt_2) },
  48. { "refcntbt", xfsstats_offset(xs_qm_dqreclaims)},
  49. /* we print both series of quota information together */
  50. { "qm", xfsstats_offset(xs_xstrat_bytes)},
  51. };
  52. /* Loop over all stats groups */
  53. for (i = j = 0; i < ARRAY_SIZE(xstats); i++) {
  54. len += scnprintf(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 += scnprintf(buf + len, PATH_MAX - len, " %u",
  59. counter_val(stats, j));
  60. len += scnprintf(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. defer_relog += per_cpu_ptr(stats, i)->s.defer_relog;
  68. }
  69. len += scnprintf(buf + len, PATH_MAX-len, "xpc %Lu %Lu %Lu\n",
  70. xs_xstrat_bytes, xs_write_bytes, xs_read_bytes);
  71. len += scnprintf(buf + len, PATH_MAX-len, "defer_relog %llu\n",
  72. defer_relog);
  73. len += scnprintf(buf + len, PATH_MAX-len, "debug %u\n",
  74. #if defined(DEBUG)
  75. 1);
  76. #else
  77. 0);
  78. #endif
  79. return len;
  80. }
  81. void xfs_stats_clearall(struct xfsstats __percpu *stats)
  82. {
  83. int c;
  84. uint32_t vn_active;
  85. xfs_notice(NULL, "Clearing xfsstats");
  86. for_each_possible_cpu(c) {
  87. preempt_disable();
  88. /* save vn_active, it's a universal truth! */
  89. vn_active = per_cpu_ptr(stats, c)->s.vn_active;
  90. memset(per_cpu_ptr(stats, c), 0, sizeof(*stats));
  91. per_cpu_ptr(stats, c)->s.vn_active = vn_active;
  92. preempt_enable();
  93. }
  94. }
  95. #ifdef CONFIG_PROC_FS
  96. /* legacy quota interfaces */
  97. #ifdef CONFIG_XFS_QUOTA
  98. #define XFSSTAT_START_XQMSTAT xfsstats_offset(xs_qm_dqreclaims)
  99. #define XFSSTAT_END_XQMSTAT xfsstats_offset(xs_qm_dquot)
  100. static int xqm_proc_show(struct seq_file *m, void *v)
  101. {
  102. /* maximum; incore; ratio free to inuse; freelist */
  103. seq_printf(m, "%d\t%d\t%d\t%u\n",
  104. 0, counter_val(xfsstats.xs_stats, XFSSTAT_END_XQMSTAT),
  105. 0, counter_val(xfsstats.xs_stats, XFSSTAT_END_XQMSTAT + 1));
  106. return 0;
  107. }
  108. /* legacy quota stats interface no 2 */
  109. static int xqmstat_proc_show(struct seq_file *m, void *v)
  110. {
  111. int j;
  112. seq_printf(m, "qm");
  113. for (j = XFSSTAT_START_XQMSTAT; j < XFSSTAT_END_XQMSTAT; j++)
  114. seq_printf(m, " %u", counter_val(xfsstats.xs_stats, j));
  115. seq_putc(m, '\n');
  116. return 0;
  117. }
  118. #endif /* CONFIG_XFS_QUOTA */
  119. int
  120. xfs_init_procfs(void)
  121. {
  122. if (!proc_mkdir("fs/xfs", NULL))
  123. return -ENOMEM;
  124. if (!proc_symlink("fs/xfs/stat", NULL,
  125. "/sys/fs/xfs/stats/stats"))
  126. goto out;
  127. #ifdef CONFIG_XFS_QUOTA
  128. if (!proc_create_single("fs/xfs/xqmstat", 0, NULL, xqmstat_proc_show))
  129. goto out;
  130. if (!proc_create_single("fs/xfs/xqm", 0, NULL, xqm_proc_show))
  131. goto out;
  132. #endif
  133. return 0;
  134. out:
  135. remove_proc_subtree("fs/xfs", NULL);
  136. return -ENOMEM;
  137. }
  138. void
  139. xfs_cleanup_procfs(void)
  140. {
  141. remove_proc_subtree("fs/xfs", NULL);
  142. }
  143. #endif /* CONFIG_PROC_FS */