Dave Chinner | 0b61f8a | 2018-06-05 19:42:14 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 3 | * Copyright (c) 2000,2005 Silicon Graphics, Inc. |
| 4 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
| 6 | #ifndef __XFS_STATS_H__ |
| 7 | #define __XFS_STATS_H__ |
| 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
| 10 | #include <linux/percpu.h> |
| 11 | |
| 12 | /* |
Dave Chinner | 11ef38a | 2016-12-05 14:38:58 +1100 | [diff] [blame] | 13 | * The btree stats arrays have fixed offsets for the different stats. We |
| 14 | * store the base index in the btree cursor via XFS_STATS_CALC_INDEX() and |
| 15 | * that allows us to use fixed offsets into the stats array for each btree |
| 16 | * stat. These index offsets are defined in the order they will be emitted |
| 17 | * in the stats files, so it is possible to add new btree stat types by |
| 18 | * appending to the enum list below. |
| 19 | */ |
| 20 | enum { |
| 21 | __XBTS_lookup = 0, |
| 22 | __XBTS_compare = 1, |
| 23 | __XBTS_insrec = 2, |
| 24 | __XBTS_delrec = 3, |
| 25 | __XBTS_newroot = 4, |
| 26 | __XBTS_killroot = 5, |
| 27 | __XBTS_increment = 6, |
| 28 | __XBTS_decrement = 7, |
| 29 | __XBTS_lshift = 8, |
| 30 | __XBTS_rshift = 9, |
| 31 | __XBTS_split = 10, |
| 32 | __XBTS_join = 11, |
| 33 | __XBTS_alloc = 12, |
| 34 | __XBTS_free = 13, |
| 35 | __XBTS_moves = 14, |
| 36 | |
| 37 | __XBTS_MAX = 15, |
| 38 | }; |
| 39 | |
| 40 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | * XFS global statistics |
| 42 | */ |
Dave Chinner | 11ef38a | 2016-12-05 14:38:58 +1100 | [diff] [blame] | 43 | struct __xfsstats { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | # define XFSSTAT_END_EXTENT_ALLOC 4 |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 45 | uint32_t xs_allocx; |
| 46 | uint32_t xs_allocb; |
| 47 | uint32_t xs_freex; |
| 48 | uint32_t xs_freeb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | # define XFSSTAT_END_ALLOC_BTREE (XFSSTAT_END_EXTENT_ALLOC+4) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 50 | uint32_t xs_abt_lookup; |
| 51 | uint32_t xs_abt_compare; |
| 52 | uint32_t xs_abt_insrec; |
| 53 | uint32_t xs_abt_delrec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | # define XFSSTAT_END_BLOCK_MAPPING (XFSSTAT_END_ALLOC_BTREE+7) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 55 | uint32_t xs_blk_mapr; |
| 56 | uint32_t xs_blk_mapw; |
| 57 | uint32_t xs_blk_unmap; |
| 58 | uint32_t xs_add_exlist; |
| 59 | uint32_t xs_del_exlist; |
| 60 | uint32_t xs_look_exlist; |
| 61 | uint32_t xs_cmp_exlist; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | # define XFSSTAT_END_BLOCK_MAP_BTREE (XFSSTAT_END_BLOCK_MAPPING+4) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 63 | uint32_t xs_bmbt_lookup; |
| 64 | uint32_t xs_bmbt_compare; |
| 65 | uint32_t xs_bmbt_insrec; |
| 66 | uint32_t xs_bmbt_delrec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | # define XFSSTAT_END_DIRECTORY_OPS (XFSSTAT_END_BLOCK_MAP_BTREE+4) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 68 | uint32_t xs_dir_lookup; |
| 69 | uint32_t xs_dir_create; |
| 70 | uint32_t xs_dir_remove; |
| 71 | uint32_t xs_dir_getdents; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | # define XFSSTAT_END_TRANSACTIONS (XFSSTAT_END_DIRECTORY_OPS+3) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 73 | uint32_t xs_trans_sync; |
| 74 | uint32_t xs_trans_async; |
| 75 | uint32_t xs_trans_empty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | # define XFSSTAT_END_INODE_OPS (XFSSTAT_END_TRANSACTIONS+7) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 77 | uint32_t xs_ig_attempts; |
| 78 | uint32_t xs_ig_found; |
| 79 | uint32_t xs_ig_frecycle; |
| 80 | uint32_t xs_ig_missed; |
| 81 | uint32_t xs_ig_dup; |
| 82 | uint32_t xs_ig_reclaims; |
| 83 | uint32_t xs_ig_attrchg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | # define XFSSTAT_END_LOG_OPS (XFSSTAT_END_INODE_OPS+5) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 85 | uint32_t xs_log_writes; |
| 86 | uint32_t xs_log_blocks; |
| 87 | uint32_t xs_log_noiclogs; |
| 88 | uint32_t xs_log_force; |
| 89 | uint32_t xs_log_force_sleep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | # define XFSSTAT_END_TAIL_PUSHING (XFSSTAT_END_LOG_OPS+10) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 91 | uint32_t xs_try_logspace; |
| 92 | uint32_t xs_sleep_logspace; |
| 93 | uint32_t xs_push_ail; |
| 94 | uint32_t xs_push_ail_success; |
| 95 | uint32_t xs_push_ail_pushbuf; |
| 96 | uint32_t xs_push_ail_pinned; |
| 97 | uint32_t xs_push_ail_locked; |
| 98 | uint32_t xs_push_ail_flushing; |
| 99 | uint32_t xs_push_ail_restarts; |
| 100 | uint32_t xs_push_ail_flush; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | # define XFSSTAT_END_WRITE_CONVERT (XFSSTAT_END_TAIL_PUSHING+2) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 102 | uint32_t xs_xstrat_quick; |
| 103 | uint32_t xs_xstrat_split; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | # define XFSSTAT_END_READ_WRITE_OPS (XFSSTAT_END_WRITE_CONVERT+2) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 105 | uint32_t xs_write_calls; |
| 106 | uint32_t xs_read_calls; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | # define XFSSTAT_END_ATTRIBUTE_OPS (XFSSTAT_END_READ_WRITE_OPS+4) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 108 | uint32_t xs_attr_get; |
| 109 | uint32_t xs_attr_set; |
| 110 | uint32_t xs_attr_remove; |
| 111 | uint32_t xs_attr_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | # define XFSSTAT_END_INODE_CLUSTER (XFSSTAT_END_ATTRIBUTE_OPS+3) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 113 | uint32_t xs_iflush_count; |
| 114 | uint32_t xs_icluster_flushcnt; |
| 115 | uint32_t xs_icluster_flushinode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | # define XFSSTAT_END_VNODE_OPS (XFSSTAT_END_INODE_CLUSTER+8) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 117 | uint32_t vn_active; /* # vnodes not on free lists */ |
| 118 | uint32_t vn_alloc; /* # times vn_alloc called */ |
| 119 | uint32_t vn_get; /* # times vn_get called */ |
| 120 | uint32_t vn_hold; /* # times vn_hold called */ |
| 121 | uint32_t vn_rele; /* # times vn_rele called */ |
| 122 | uint32_t vn_reclaim; /* # times vn_reclaim called */ |
| 123 | uint32_t vn_remove; /* # times vn_remove called */ |
| 124 | uint32_t vn_free; /* # times vn_free called */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | #define XFSSTAT_END_BUF (XFSSTAT_END_VNODE_OPS+9) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 126 | uint32_t xb_get; |
| 127 | uint32_t xb_create; |
| 128 | uint32_t xb_get_locked; |
| 129 | uint32_t xb_get_locked_waited; |
| 130 | uint32_t xb_busy_locked; |
| 131 | uint32_t xb_miss_locked; |
| 132 | uint32_t xb_page_retries; |
| 133 | uint32_t xb_page_found; |
| 134 | uint32_t xb_get_read; |
David Chinner | 854929f | 2008-10-30 16:55:03 +1100 | [diff] [blame] | 135 | /* Version 2 btree counters */ |
Dave Chinner | 11ef38a | 2016-12-05 14:38:58 +1100 | [diff] [blame] | 136 | #define XFSSTAT_END_ABTB_V2 (XFSSTAT_END_BUF + __XBTS_MAX) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 137 | uint32_t xs_abtb_2[__XBTS_MAX]; |
Dave Chinner | 11ef38a | 2016-12-05 14:38:58 +1100 | [diff] [blame] | 138 | #define XFSSTAT_END_ABTC_V2 (XFSSTAT_END_ABTB_V2 + __XBTS_MAX) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 139 | uint32_t xs_abtc_2[__XBTS_MAX]; |
Dave Chinner | 11ef38a | 2016-12-05 14:38:58 +1100 | [diff] [blame] | 140 | #define XFSSTAT_END_BMBT_V2 (XFSSTAT_END_ABTC_V2 + __XBTS_MAX) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 141 | uint32_t xs_bmbt_2[__XBTS_MAX]; |
Dave Chinner | 11ef38a | 2016-12-05 14:38:58 +1100 | [diff] [blame] | 142 | #define XFSSTAT_END_IBT_V2 (XFSSTAT_END_BMBT_V2 + __XBTS_MAX) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 143 | uint32_t xs_ibt_2[__XBTS_MAX]; |
Dave Chinner | 11ef38a | 2016-12-05 14:38:58 +1100 | [diff] [blame] | 144 | #define XFSSTAT_END_FIBT_V2 (XFSSTAT_END_IBT_V2 + __XBTS_MAX) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 145 | uint32_t xs_fibt_2[__XBTS_MAX]; |
Dave Chinner | 11ef38a | 2016-12-05 14:38:58 +1100 | [diff] [blame] | 146 | #define XFSSTAT_END_RMAP_V2 (XFSSTAT_END_FIBT_V2 + __XBTS_MAX) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 147 | uint32_t xs_rmap_2[__XBTS_MAX]; |
Dave Chinner | 11ef38a | 2016-12-05 14:38:58 +1100 | [diff] [blame] | 148 | #define XFSSTAT_END_REFCOUNT (XFSSTAT_END_RMAP_V2 + __XBTS_MAX) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 149 | uint32_t xs_refcbt_2[__XBTS_MAX]; |
Darrick J. Wong | 46eeb52 | 2016-10-03 09:11:16 -0700 | [diff] [blame] | 150 | #define XFSSTAT_END_XQMSTAT (XFSSTAT_END_REFCOUNT + 6) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 151 | uint32_t xs_qm_dqreclaims; |
| 152 | uint32_t xs_qm_dqreclaim_misses; |
| 153 | uint32_t xs_qm_dquot_dups; |
| 154 | uint32_t xs_qm_dqcachemisses; |
| 155 | uint32_t xs_qm_dqcachehits; |
| 156 | uint32_t xs_qm_dqwants; |
Christoph Hellwig | 48776fd | 2012-03-13 08:52:33 +0000 | [diff] [blame] | 157 | #define XFSSTAT_END_QM (XFSSTAT_END_XQMSTAT+2) |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 158 | uint32_t xs_qm_dquot; |
| 159 | uint32_t xs_qm_dquot_unused; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | /* Extra precision counters */ |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 161 | uint64_t xs_xstrat_bytes; |
| 162 | uint64_t xs_write_bytes; |
| 163 | uint64_t xs_read_bytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | }; |
| 165 | |
Dave Chinner | 11ef38a | 2016-12-05 14:38:58 +1100 | [diff] [blame] | 166 | struct xfsstats { |
| 167 | union { |
| 168 | struct __xfsstats s; |
| 169 | uint32_t a[XFSSTAT_END_XQMSTAT]; |
| 170 | }; |
| 171 | }; |
| 172 | |
| 173 | /* |
| 174 | * simple wrapper for getting the array index of s struct member offset |
| 175 | */ |
| 176 | #define XFS_STATS_CALC_INDEX(member) \ |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 177 | (offsetof(struct __xfsstats, member) / (int)sizeof(uint32_t)) |
Dave Chinner | 11ef38a | 2016-12-05 14:38:58 +1100 | [diff] [blame] | 178 | |
| 179 | |
Bill O'Donnell | 80529c4 | 2015-10-12 05:19:45 +1100 | [diff] [blame] | 180 | int xfs_stats_format(struct xfsstats __percpu *stats, char *buf); |
| 181 | void xfs_stats_clearall(struct xfsstats __percpu *stats); |
| 182 | extern struct xstats xfsstats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
Bill O'Donnell | ff6d6af | 2015-10-12 18:21:22 +1100 | [diff] [blame] | 184 | #define XFS_STATS_INC(mp, v) \ |
| 185 | do { \ |
Dave Chinner | 11ef38a | 2016-12-05 14:38:58 +1100 | [diff] [blame] | 186 | per_cpu_ptr(xfsstats.xs_stats, current_cpu())->s.v++; \ |
| 187 | per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->s.v++; \ |
Bill O'Donnell | ff6d6af | 2015-10-12 18:21:22 +1100 | [diff] [blame] | 188 | } while (0) |
Bill O'Donnell | 80529c4 | 2015-10-12 05:19:45 +1100 | [diff] [blame] | 189 | |
Bill O'Donnell | ff6d6af | 2015-10-12 18:21:22 +1100 | [diff] [blame] | 190 | #define XFS_STATS_DEC(mp, v) \ |
| 191 | do { \ |
Dave Chinner | 11ef38a | 2016-12-05 14:38:58 +1100 | [diff] [blame] | 192 | per_cpu_ptr(xfsstats.xs_stats, current_cpu())->s.v--; \ |
| 193 | per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->s.v--; \ |
Bill O'Donnell | ff6d6af | 2015-10-12 18:21:22 +1100 | [diff] [blame] | 194 | } while (0) |
Bill O'Donnell | 80529c4 | 2015-10-12 05:19:45 +1100 | [diff] [blame] | 195 | |
Bill O'Donnell | ff6d6af | 2015-10-12 18:21:22 +1100 | [diff] [blame] | 196 | #define XFS_STATS_ADD(mp, v, inc) \ |
| 197 | do { \ |
Dave Chinner | 11ef38a | 2016-12-05 14:38:58 +1100 | [diff] [blame] | 198 | per_cpu_ptr(xfsstats.xs_stats, current_cpu())->s.v += (inc); \ |
| 199 | per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->s.v += (inc); \ |
| 200 | } while (0) |
| 201 | |
| 202 | #define XFS_STATS_INC_OFF(mp, off) \ |
| 203 | do { \ |
| 204 | per_cpu_ptr(xfsstats.xs_stats, current_cpu())->a[off]++; \ |
| 205 | per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->a[off]++; \ |
| 206 | } while (0) |
| 207 | |
| 208 | #define XFS_STATS_DEC_OFF(mp, off) \ |
| 209 | do { \ |
| 210 | per_cpu_ptr(xfsstats.xs_stats, current_cpu())->a[off]; \ |
| 211 | per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->a[off]; \ |
| 212 | } while (0) |
| 213 | |
| 214 | #define XFS_STATS_ADD_OFF(mp, off, inc) \ |
| 215 | do { \ |
| 216 | per_cpu_ptr(xfsstats.xs_stats, current_cpu())->a[off] += (inc); \ |
| 217 | per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->a[off] += (inc); \ |
Bill O'Donnell | ff6d6af | 2015-10-12 18:21:22 +1100 | [diff] [blame] | 218 | } while (0) |
| 219 | |
| 220 | #if defined(CONFIG_PROC_FS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 222 | extern int xfs_init_procfs(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | extern void xfs_cleanup_procfs(void); |
| 224 | |
| 225 | |
| 226 | #else /* !CONFIG_PROC_FS */ |
| 227 | |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 228 | static inline int xfs_init_procfs(void) |
| 229 | { |
Christoph Hellwig | 766b092 | 2008-07-18 17:12:50 +1000 | [diff] [blame] | 230 | return 0; |
| 231 | } |
| 232 | |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 233 | static inline void xfs_cleanup_procfs(void) |
| 234 | { |
Christoph Hellwig | 766b092 | 2008-07-18 17:12:50 +1000 | [diff] [blame] | 235 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
| 237 | #endif /* !CONFIG_PROC_FS */ |
| 238 | |
| 239 | #endif /* __XFS_STATS_H__ */ |