10b61f8a4SDave Chinner // SPDX-License-Identifier: GPL-2.0
2c59d87c4SChristoph Hellwig /*
3c59d87c4SChristoph Hellwig * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
4c59d87c4SChristoph Hellwig * All Rights Reserved.
5c59d87c4SChristoph Hellwig */
6c59d87c4SChristoph Hellwig #include "xfs.h"
7c59d87c4SChristoph Hellwig
880529c45SBill O'Donnell struct xstats xfsstats;
9c59d87c4SChristoph Hellwig
counter_val(struct xfsstats __percpu * stats,int idx)1080529c45SBill O'Donnell static int counter_val(struct xfsstats __percpu *stats, int idx)
1148776fd2SChristoph Hellwig {
1248776fd2SChristoph Hellwig int val = 0, cpu;
1348776fd2SChristoph Hellwig
1448776fd2SChristoph Hellwig for_each_possible_cpu(cpu)
1580529c45SBill O'Donnell val += *(((__u32 *)per_cpu_ptr(stats, cpu) + idx));
1648776fd2SChristoph Hellwig return val;
1748776fd2SChristoph Hellwig }
1848776fd2SChristoph Hellwig
xfs_stats_format(struct xfsstats __percpu * stats,char * buf)1980529c45SBill O'Donnell int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
20bb230c12SBill O'Donnell {
21bb230c12SBill O'Donnell int i, j;
22bb230c12SBill O'Donnell int len = 0;
23c8ce540dSDarrick J. Wong uint64_t xs_xstrat_bytes = 0;
24c8ce540dSDarrick J. Wong uint64_t xs_write_bytes = 0;
25c8ce540dSDarrick J. Wong uint64_t xs_read_bytes = 0;
264e919af7SDarrick J. Wong uint64_t defer_relog = 0;
27bb230c12SBill O'Donnell
28bb230c12SBill O'Donnell static const struct xstats_entry {
29bb230c12SBill O'Donnell char *desc;
30bb230c12SBill O'Donnell int endpoint;
31bb230c12SBill O'Donnell } xstats[] = {
3226ca3901SCarlos Maiolino { "extent_alloc", xfsstats_offset(xs_abt_lookup) },
3326ca3901SCarlos Maiolino { "abt", xfsstats_offset(xs_blk_mapr) },
3426ca3901SCarlos Maiolino { "blk_map", xfsstats_offset(xs_bmbt_lookup) },
3526ca3901SCarlos Maiolino { "bmbt", xfsstats_offset(xs_dir_lookup) },
3626ca3901SCarlos Maiolino { "dir", xfsstats_offset(xs_trans_sync) },
3726ca3901SCarlos Maiolino { "trans", xfsstats_offset(xs_ig_attempts) },
3826ca3901SCarlos Maiolino { "ig", xfsstats_offset(xs_log_writes) },
3926ca3901SCarlos Maiolino { "log", xfsstats_offset(xs_try_logspace)},
4026ca3901SCarlos Maiolino { "push_ail", xfsstats_offset(xs_xstrat_quick)},
4126ca3901SCarlos Maiolino { "xstrat", xfsstats_offset(xs_write_calls) },
4226ca3901SCarlos Maiolino { "rw", xfsstats_offset(xs_attr_get) },
4326ca3901SCarlos Maiolino { "attr", xfsstats_offset(xs_iflush_count)},
4426ca3901SCarlos Maiolino { "icluster", xfsstats_offset(vn_active) },
4526ca3901SCarlos Maiolino { "vnodes", xfsstats_offset(xb_get) },
4626ca3901SCarlos Maiolino { "buf", xfsstats_offset(xs_abtb_2) },
4726ca3901SCarlos Maiolino { "abtb2", xfsstats_offset(xs_abtc_2) },
4826ca3901SCarlos Maiolino { "abtc2", xfsstats_offset(xs_bmbt_2) },
4926ca3901SCarlos Maiolino { "bmbt2", xfsstats_offset(xs_ibt_2) },
5026ca3901SCarlos Maiolino { "ibt2", xfsstats_offset(xs_fibt_2) },
5126ca3901SCarlos Maiolino { "fibt2", xfsstats_offset(xs_rmap_2) },
5226ca3901SCarlos Maiolino { "rmapbt", xfsstats_offset(xs_refcbt_2) },
534787fc80SDarrick J. Wong { "refcntbt", xfsstats_offset(xs_rmap_mem_2) },
54*18a1e644SDarrick J. Wong { "rmapbt_mem", xfsstats_offset(xs_rcbag_2) },
55*18a1e644SDarrick J. Wong { "rcbagbt", xfsstats_offset(xs_qm_dqreclaims)},
56bb230c12SBill O'Donnell /* we print both series of quota information together */
5726ca3901SCarlos Maiolino { "qm", xfsstats_offset(xs_xstrat_bytes)},
58bb230c12SBill O'Donnell };
59bb230c12SBill O'Donnell
60bb230c12SBill O'Donnell /* Loop over all stats groups */
61bb230c12SBill O'Donnell
62bb230c12SBill O'Donnell for (i = j = 0; i < ARRAY_SIZE(xstats); i++) {
6317bb60b7STakashi Iwai len += scnprintf(buf + len, PATH_MAX - len, "%s",
64bb230c12SBill O'Donnell xstats[i].desc);
65bb230c12SBill O'Donnell /* inner loop does each group */
66bb230c12SBill O'Donnell for (; j < xstats[i].endpoint; j++)
6717bb60b7STakashi Iwai len += scnprintf(buf + len, PATH_MAX - len, " %u",
6880529c45SBill O'Donnell counter_val(stats, j));
6917bb60b7STakashi Iwai len += scnprintf(buf + len, PATH_MAX - len, "\n");
70bb230c12SBill O'Donnell }
71bb230c12SBill O'Donnell /* extra precision counters */
72bb230c12SBill O'Donnell for_each_possible_cpu(i) {
7311ef38afSDave Chinner xs_xstrat_bytes += per_cpu_ptr(stats, i)->s.xs_xstrat_bytes;
7411ef38afSDave Chinner xs_write_bytes += per_cpu_ptr(stats, i)->s.xs_write_bytes;
7511ef38afSDave Chinner xs_read_bytes += per_cpu_ptr(stats, i)->s.xs_read_bytes;
764e919af7SDarrick J. Wong defer_relog += per_cpu_ptr(stats, i)->s.defer_relog;
77bb230c12SBill O'Donnell }
78bb230c12SBill O'Donnell
7978b0f58bSZeng Heng len += scnprintf(buf + len, PATH_MAX-len, "xpc %llu %llu %llu\n",
80bb230c12SBill O'Donnell xs_xstrat_bytes, xs_write_bytes, xs_read_bytes);
814e919af7SDarrick J. Wong len += scnprintf(buf + len, PATH_MAX-len, "defer_relog %llu\n",
824e919af7SDarrick J. Wong defer_relog);
8317bb60b7STakashi Iwai len += scnprintf(buf + len, PATH_MAX-len, "debug %u\n",
84bb230c12SBill O'Donnell #if defined(DEBUG)
85bb230c12SBill O'Donnell 1);
86bb230c12SBill O'Donnell #else
87bb230c12SBill O'Donnell 0);
88bb230c12SBill O'Donnell #endif
89bb230c12SBill O'Donnell
90bb230c12SBill O'Donnell return len;
91bb230c12SBill O'Donnell }
92bb230c12SBill O'Donnell
xfs_stats_clearall(struct xfsstats __percpu * stats)9380529c45SBill O'Donnell void xfs_stats_clearall(struct xfsstats __percpu *stats)
94bb230c12SBill O'Donnell {
95bb230c12SBill O'Donnell int c;
96c8ce540dSDarrick J. Wong uint32_t vn_active;
97bb230c12SBill O'Donnell
98bb230c12SBill O'Donnell xfs_notice(NULL, "Clearing xfsstats");
99bb230c12SBill O'Donnell for_each_possible_cpu(c) {
100bb230c12SBill O'Donnell preempt_disable();
101bb230c12SBill O'Donnell /* save vn_active, it's a universal truth! */
10211ef38afSDave Chinner vn_active = per_cpu_ptr(stats, c)->s.vn_active;
10380529c45SBill O'Donnell memset(per_cpu_ptr(stats, c), 0, sizeof(*stats));
10411ef38afSDave Chinner per_cpu_ptr(stats, c)->s.vn_active = vn_active;
105bb230c12SBill O'Donnell preempt_enable();
106bb230c12SBill O'Donnell }
107bb230c12SBill O'Donnell }
108bb230c12SBill O'Donnell
1095ef03dbdSArnd Bergmann #ifdef CONFIG_PROC_FS
11048776fd2SChristoph Hellwig /* legacy quota interfaces */
11148776fd2SChristoph Hellwig #ifdef CONFIG_XFS_QUOTA
11226ca3901SCarlos Maiolino
11326ca3901SCarlos Maiolino #define XFSSTAT_START_XQMSTAT xfsstats_offset(xs_qm_dqreclaims)
11426ca3901SCarlos Maiolino #define XFSSTAT_END_XQMSTAT xfsstats_offset(xs_qm_dquot)
11526ca3901SCarlos Maiolino
xqm_proc_show(struct seq_file * m,void * v)11648776fd2SChristoph Hellwig static int xqm_proc_show(struct seq_file *m, void *v)
11748776fd2SChristoph Hellwig {
11848776fd2SChristoph Hellwig /* maximum; incore; ratio free to inuse; freelist */
11948776fd2SChristoph Hellwig seq_printf(m, "%d\t%d\t%d\t%u\n",
12080529c45SBill O'Donnell 0, counter_val(xfsstats.xs_stats, XFSSTAT_END_XQMSTAT),
12180529c45SBill O'Donnell 0, counter_val(xfsstats.xs_stats, XFSSTAT_END_XQMSTAT + 1));
12248776fd2SChristoph Hellwig return 0;
12348776fd2SChristoph Hellwig }
12448776fd2SChristoph Hellwig
12548776fd2SChristoph Hellwig /* legacy quota stats interface no 2 */
xqmstat_proc_show(struct seq_file * m,void * v)12648776fd2SChristoph Hellwig static int xqmstat_proc_show(struct seq_file *m, void *v)
12748776fd2SChristoph Hellwig {
12848776fd2SChristoph Hellwig int j;
12948776fd2SChristoph Hellwig
13092b40768SZeng Heng seq_puts(m, "qm");
13126ca3901SCarlos Maiolino for (j = XFSSTAT_START_XQMSTAT; j < XFSSTAT_END_XQMSTAT; j++)
13280529c45SBill O'Donnell seq_printf(m, " %u", counter_val(xfsstats.xs_stats, j));
13348776fd2SChristoph Hellwig seq_putc(m, '\n');
13448776fd2SChristoph Hellwig return 0;
13548776fd2SChristoph Hellwig }
13648776fd2SChristoph Hellwig #endif /* CONFIG_XFS_QUOTA */
13748776fd2SChristoph Hellwig
138c59d87c4SChristoph Hellwig int
xfs_init_procfs(void)139c59d87c4SChristoph Hellwig xfs_init_procfs(void)
140c59d87c4SChristoph Hellwig {
141c59d87c4SChristoph Hellwig if (!proc_mkdir("fs/xfs", NULL))
1429e92054eSEric Sandeen return -ENOMEM;
143c59d87c4SChristoph Hellwig
14432f0ea05SBill O'Donnell if (!proc_symlink("fs/xfs/stat", NULL,
14532f0ea05SBill O'Donnell "/sys/fs/xfs/stats/stats"))
1469e92054eSEric Sandeen goto out;
14732f0ea05SBill O'Donnell
14848776fd2SChristoph Hellwig #ifdef CONFIG_XFS_QUOTA
1493f3942acSChristoph Hellwig if (!proc_create_single("fs/xfs/xqmstat", 0, NULL, xqmstat_proc_show))
1509e92054eSEric Sandeen goto out;
1513f3942acSChristoph Hellwig if (!proc_create_single("fs/xfs/xqm", 0, NULL, xqm_proc_show))
1529e92054eSEric Sandeen goto out;
15348776fd2SChristoph Hellwig #endif
154c59d87c4SChristoph Hellwig return 0;
155c59d87c4SChristoph Hellwig
156c59d87c4SChristoph Hellwig out:
1579e92054eSEric Sandeen remove_proc_subtree("fs/xfs", NULL);
158c59d87c4SChristoph Hellwig return -ENOMEM;
159c59d87c4SChristoph Hellwig }
160c59d87c4SChristoph Hellwig
161c59d87c4SChristoph Hellwig void
xfs_cleanup_procfs(void)162c59d87c4SChristoph Hellwig xfs_cleanup_procfs(void)
163c59d87c4SChristoph Hellwig {
1649e92054eSEric Sandeen remove_proc_subtree("fs/xfs", NULL);
165c59d87c4SChristoph Hellwig }
166985ef4dcSDave Chinner #endif /* CONFIG_PROC_FS */
167