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 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 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) }, 53*4787fc80SDarrick J. Wong { "refcntbt", xfsstats_offset(xs_rmap_mem_2) }, 54*4787fc80SDarrick J. Wong { "rmapbt_mem", xfsstats_offset(xs_qm_dqreclaims)}, 55bb230c12SBill O'Donnell /* we print both series of quota information together */ 5626ca3901SCarlos Maiolino { "qm", xfsstats_offset(xs_xstrat_bytes)}, 57bb230c12SBill O'Donnell }; 58bb230c12SBill O'Donnell 59bb230c12SBill O'Donnell /* Loop over all stats groups */ 60bb230c12SBill O'Donnell 61bb230c12SBill O'Donnell for (i = j = 0; i < ARRAY_SIZE(xstats); i++) { 6217bb60b7STakashi Iwai len += scnprintf(buf + len, PATH_MAX - len, "%s", 63bb230c12SBill O'Donnell xstats[i].desc); 64bb230c12SBill O'Donnell /* inner loop does each group */ 65bb230c12SBill O'Donnell for (; j < xstats[i].endpoint; j++) 6617bb60b7STakashi Iwai len += scnprintf(buf + len, PATH_MAX - len, " %u", 6780529c45SBill O'Donnell counter_val(stats, j)); 6817bb60b7STakashi Iwai len += scnprintf(buf + len, PATH_MAX - len, "\n"); 69bb230c12SBill O'Donnell } 70bb230c12SBill O'Donnell /* extra precision counters */ 71bb230c12SBill O'Donnell for_each_possible_cpu(i) { 7211ef38afSDave Chinner xs_xstrat_bytes += per_cpu_ptr(stats, i)->s.xs_xstrat_bytes; 7311ef38afSDave Chinner xs_write_bytes += per_cpu_ptr(stats, i)->s.xs_write_bytes; 7411ef38afSDave Chinner xs_read_bytes += per_cpu_ptr(stats, i)->s.xs_read_bytes; 754e919af7SDarrick J. Wong defer_relog += per_cpu_ptr(stats, i)->s.defer_relog; 76bb230c12SBill O'Donnell } 77bb230c12SBill O'Donnell 7878b0f58bSZeng Heng len += scnprintf(buf + len, PATH_MAX-len, "xpc %llu %llu %llu\n", 79bb230c12SBill O'Donnell xs_xstrat_bytes, xs_write_bytes, xs_read_bytes); 804e919af7SDarrick J. Wong len += scnprintf(buf + len, PATH_MAX-len, "defer_relog %llu\n", 814e919af7SDarrick J. Wong defer_relog); 8217bb60b7STakashi Iwai len += scnprintf(buf + len, PATH_MAX-len, "debug %u\n", 83bb230c12SBill O'Donnell #if defined(DEBUG) 84bb230c12SBill O'Donnell 1); 85bb230c12SBill O'Donnell #else 86bb230c12SBill O'Donnell 0); 87bb230c12SBill O'Donnell #endif 88bb230c12SBill O'Donnell 89bb230c12SBill O'Donnell return len; 90bb230c12SBill O'Donnell } 91bb230c12SBill O'Donnell 9280529c45SBill O'Donnell void xfs_stats_clearall(struct xfsstats __percpu *stats) 93bb230c12SBill O'Donnell { 94bb230c12SBill O'Donnell int c; 95c8ce540dSDarrick J. Wong uint32_t vn_active; 96bb230c12SBill O'Donnell 97bb230c12SBill O'Donnell xfs_notice(NULL, "Clearing xfsstats"); 98bb230c12SBill O'Donnell for_each_possible_cpu(c) { 99bb230c12SBill O'Donnell preempt_disable(); 100bb230c12SBill O'Donnell /* save vn_active, it's a universal truth! */ 10111ef38afSDave Chinner vn_active = per_cpu_ptr(stats, c)->s.vn_active; 10280529c45SBill O'Donnell memset(per_cpu_ptr(stats, c), 0, sizeof(*stats)); 10311ef38afSDave Chinner per_cpu_ptr(stats, c)->s.vn_active = vn_active; 104bb230c12SBill O'Donnell preempt_enable(); 105bb230c12SBill O'Donnell } 106bb230c12SBill O'Donnell } 107bb230c12SBill O'Donnell 1085ef03dbdSArnd Bergmann #ifdef CONFIG_PROC_FS 10948776fd2SChristoph Hellwig /* legacy quota interfaces */ 11048776fd2SChristoph Hellwig #ifdef CONFIG_XFS_QUOTA 11126ca3901SCarlos Maiolino 11226ca3901SCarlos Maiolino #define XFSSTAT_START_XQMSTAT xfsstats_offset(xs_qm_dqreclaims) 11326ca3901SCarlos Maiolino #define XFSSTAT_END_XQMSTAT xfsstats_offset(xs_qm_dquot) 11426ca3901SCarlos Maiolino 11548776fd2SChristoph Hellwig static int xqm_proc_show(struct seq_file *m, void *v) 11648776fd2SChristoph Hellwig { 11748776fd2SChristoph Hellwig /* maximum; incore; ratio free to inuse; freelist */ 11848776fd2SChristoph Hellwig seq_printf(m, "%d\t%d\t%d\t%u\n", 11980529c45SBill O'Donnell 0, counter_val(xfsstats.xs_stats, XFSSTAT_END_XQMSTAT), 12080529c45SBill O'Donnell 0, counter_val(xfsstats.xs_stats, XFSSTAT_END_XQMSTAT + 1)); 12148776fd2SChristoph Hellwig return 0; 12248776fd2SChristoph Hellwig } 12348776fd2SChristoph Hellwig 12448776fd2SChristoph Hellwig /* legacy quota stats interface no 2 */ 12548776fd2SChristoph Hellwig static int xqmstat_proc_show(struct seq_file *m, void *v) 12648776fd2SChristoph Hellwig { 12748776fd2SChristoph Hellwig int j; 12848776fd2SChristoph Hellwig 12992b40768SZeng Heng seq_puts(m, "qm"); 13026ca3901SCarlos Maiolino for (j = XFSSTAT_START_XQMSTAT; j < XFSSTAT_END_XQMSTAT; j++) 13180529c45SBill O'Donnell seq_printf(m, " %u", counter_val(xfsstats.xs_stats, j)); 13248776fd2SChristoph Hellwig seq_putc(m, '\n'); 13348776fd2SChristoph Hellwig return 0; 13448776fd2SChristoph Hellwig } 13548776fd2SChristoph Hellwig #endif /* CONFIG_XFS_QUOTA */ 13648776fd2SChristoph Hellwig 137c59d87c4SChristoph Hellwig int 138c59d87c4SChristoph Hellwig xfs_init_procfs(void) 139c59d87c4SChristoph Hellwig { 140c59d87c4SChristoph Hellwig if (!proc_mkdir("fs/xfs", NULL)) 1419e92054eSEric Sandeen return -ENOMEM; 142c59d87c4SChristoph Hellwig 14332f0ea05SBill O'Donnell if (!proc_symlink("fs/xfs/stat", NULL, 14432f0ea05SBill O'Donnell "/sys/fs/xfs/stats/stats")) 1459e92054eSEric Sandeen goto out; 14632f0ea05SBill O'Donnell 14748776fd2SChristoph Hellwig #ifdef CONFIG_XFS_QUOTA 1483f3942acSChristoph Hellwig if (!proc_create_single("fs/xfs/xqmstat", 0, NULL, xqmstat_proc_show)) 1499e92054eSEric Sandeen goto out; 1503f3942acSChristoph Hellwig if (!proc_create_single("fs/xfs/xqm", 0, NULL, xqm_proc_show)) 1519e92054eSEric Sandeen goto out; 15248776fd2SChristoph Hellwig #endif 153c59d87c4SChristoph Hellwig return 0; 154c59d87c4SChristoph Hellwig 155c59d87c4SChristoph Hellwig out: 1569e92054eSEric Sandeen remove_proc_subtree("fs/xfs", NULL); 157c59d87c4SChristoph Hellwig return -ENOMEM; 158c59d87c4SChristoph Hellwig } 159c59d87c4SChristoph Hellwig 160c59d87c4SChristoph Hellwig void 161c59d87c4SChristoph Hellwig xfs_cleanup_procfs(void) 162c59d87c4SChristoph Hellwig { 1639e92054eSEric Sandeen remove_proc_subtree("fs/xfs", NULL); 164c59d87c4SChristoph Hellwig } 165985ef4dcSDave Chinner #endif /* CONFIG_PROC_FS */ 166