blob: f64d0ae345c4d7b5dd3759fc2340572373a71743 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
18#ifndef __XFS_STATS_H__
19#define __XFS_STATS_H__
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#include <linux/percpu.h>
23
24/*
Dave Chinner11ef38a2016-12-05 14:38:58 +110025 * The btree stats arrays have fixed offsets for the different stats. We
26 * store the base index in the btree cursor via XFS_STATS_CALC_INDEX() and
27 * that allows us to use fixed offsets into the stats array for each btree
28 * stat. These index offsets are defined in the order they will be emitted
29 * in the stats files, so it is possible to add new btree stat types by
30 * appending to the enum list below.
31 */
32enum {
33 __XBTS_lookup = 0,
34 __XBTS_compare = 1,
35 __XBTS_insrec = 2,
36 __XBTS_delrec = 3,
37 __XBTS_newroot = 4,
38 __XBTS_killroot = 5,
39 __XBTS_increment = 6,
40 __XBTS_decrement = 7,
41 __XBTS_lshift = 8,
42 __XBTS_rshift = 9,
43 __XBTS_split = 10,
44 __XBTS_join = 11,
45 __XBTS_alloc = 12,
46 __XBTS_free = 13,
47 __XBTS_moves = 14,
48
49 __XBTS_MAX = 15,
50};
51
52/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 * XFS global statistics
54 */
Dave Chinner11ef38a2016-12-05 14:38:58 +110055struct __xfsstats {
Linus Torvalds1da177e2005-04-16 15:20:36 -070056# define XFSSTAT_END_EXTENT_ALLOC 4
Darrick J. Wongc8ce5402017-06-16 11:00:05 -070057 uint32_t xs_allocx;
58 uint32_t xs_allocb;
59 uint32_t xs_freex;
60 uint32_t xs_freeb;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061# define XFSSTAT_END_ALLOC_BTREE (XFSSTAT_END_EXTENT_ALLOC+4)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -070062 uint32_t xs_abt_lookup;
63 uint32_t xs_abt_compare;
64 uint32_t xs_abt_insrec;
65 uint32_t xs_abt_delrec;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066# define XFSSTAT_END_BLOCK_MAPPING (XFSSTAT_END_ALLOC_BTREE+7)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -070067 uint32_t xs_blk_mapr;
68 uint32_t xs_blk_mapw;
69 uint32_t xs_blk_unmap;
70 uint32_t xs_add_exlist;
71 uint32_t xs_del_exlist;
72 uint32_t xs_look_exlist;
73 uint32_t xs_cmp_exlist;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074# define XFSSTAT_END_BLOCK_MAP_BTREE (XFSSTAT_END_BLOCK_MAPPING+4)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -070075 uint32_t xs_bmbt_lookup;
76 uint32_t xs_bmbt_compare;
77 uint32_t xs_bmbt_insrec;
78 uint32_t xs_bmbt_delrec;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079# define XFSSTAT_END_DIRECTORY_OPS (XFSSTAT_END_BLOCK_MAP_BTREE+4)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -070080 uint32_t xs_dir_lookup;
81 uint32_t xs_dir_create;
82 uint32_t xs_dir_remove;
83 uint32_t xs_dir_getdents;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084# define XFSSTAT_END_TRANSACTIONS (XFSSTAT_END_DIRECTORY_OPS+3)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -070085 uint32_t xs_trans_sync;
86 uint32_t xs_trans_async;
87 uint32_t xs_trans_empty;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088# define XFSSTAT_END_INODE_OPS (XFSSTAT_END_TRANSACTIONS+7)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -070089 uint32_t xs_ig_attempts;
90 uint32_t xs_ig_found;
91 uint32_t xs_ig_frecycle;
92 uint32_t xs_ig_missed;
93 uint32_t xs_ig_dup;
94 uint32_t xs_ig_reclaims;
95 uint32_t xs_ig_attrchg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096# define XFSSTAT_END_LOG_OPS (XFSSTAT_END_INODE_OPS+5)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -070097 uint32_t xs_log_writes;
98 uint32_t xs_log_blocks;
99 uint32_t xs_log_noiclogs;
100 uint32_t xs_log_force;
101 uint32_t xs_log_force_sleep;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102# define XFSSTAT_END_TAIL_PUSHING (XFSSTAT_END_LOG_OPS+10)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700103 uint32_t xs_try_logspace;
104 uint32_t xs_sleep_logspace;
105 uint32_t xs_push_ail;
106 uint32_t xs_push_ail_success;
107 uint32_t xs_push_ail_pushbuf;
108 uint32_t xs_push_ail_pinned;
109 uint32_t xs_push_ail_locked;
110 uint32_t xs_push_ail_flushing;
111 uint32_t xs_push_ail_restarts;
112 uint32_t xs_push_ail_flush;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113# define XFSSTAT_END_WRITE_CONVERT (XFSSTAT_END_TAIL_PUSHING+2)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700114 uint32_t xs_xstrat_quick;
115 uint32_t xs_xstrat_split;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116# define XFSSTAT_END_READ_WRITE_OPS (XFSSTAT_END_WRITE_CONVERT+2)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700117 uint32_t xs_write_calls;
118 uint32_t xs_read_calls;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119# define XFSSTAT_END_ATTRIBUTE_OPS (XFSSTAT_END_READ_WRITE_OPS+4)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700120 uint32_t xs_attr_get;
121 uint32_t xs_attr_set;
122 uint32_t xs_attr_remove;
123 uint32_t xs_attr_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124# define XFSSTAT_END_INODE_CLUSTER (XFSSTAT_END_ATTRIBUTE_OPS+3)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700125 uint32_t xs_iflush_count;
126 uint32_t xs_icluster_flushcnt;
127 uint32_t xs_icluster_flushinode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128# define XFSSTAT_END_VNODE_OPS (XFSSTAT_END_INODE_CLUSTER+8)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700129 uint32_t vn_active; /* # vnodes not on free lists */
130 uint32_t vn_alloc; /* # times vn_alloc called */
131 uint32_t vn_get; /* # times vn_get called */
132 uint32_t vn_hold; /* # times vn_hold called */
133 uint32_t vn_rele; /* # times vn_rele called */
134 uint32_t vn_reclaim; /* # times vn_reclaim called */
135 uint32_t vn_remove; /* # times vn_remove called */
136 uint32_t vn_free; /* # times vn_free called */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#define XFSSTAT_END_BUF (XFSSTAT_END_VNODE_OPS+9)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700138 uint32_t xb_get;
139 uint32_t xb_create;
140 uint32_t xb_get_locked;
141 uint32_t xb_get_locked_waited;
142 uint32_t xb_busy_locked;
143 uint32_t xb_miss_locked;
144 uint32_t xb_page_retries;
145 uint32_t xb_page_found;
146 uint32_t xb_get_read;
David Chinner854929f2008-10-30 16:55:03 +1100147/* Version 2 btree counters */
Dave Chinner11ef38a2016-12-05 14:38:58 +1100148#define XFSSTAT_END_ABTB_V2 (XFSSTAT_END_BUF + __XBTS_MAX)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700149 uint32_t xs_abtb_2[__XBTS_MAX];
Dave Chinner11ef38a2016-12-05 14:38:58 +1100150#define XFSSTAT_END_ABTC_V2 (XFSSTAT_END_ABTB_V2 + __XBTS_MAX)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700151 uint32_t xs_abtc_2[__XBTS_MAX];
Dave Chinner11ef38a2016-12-05 14:38:58 +1100152#define XFSSTAT_END_BMBT_V2 (XFSSTAT_END_ABTC_V2 + __XBTS_MAX)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700153 uint32_t xs_bmbt_2[__XBTS_MAX];
Dave Chinner11ef38a2016-12-05 14:38:58 +1100154#define XFSSTAT_END_IBT_V2 (XFSSTAT_END_BMBT_V2 + __XBTS_MAX)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700155 uint32_t xs_ibt_2[__XBTS_MAX];
Dave Chinner11ef38a2016-12-05 14:38:58 +1100156#define XFSSTAT_END_FIBT_V2 (XFSSTAT_END_IBT_V2 + __XBTS_MAX)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700157 uint32_t xs_fibt_2[__XBTS_MAX];
Dave Chinner11ef38a2016-12-05 14:38:58 +1100158#define XFSSTAT_END_RMAP_V2 (XFSSTAT_END_FIBT_V2 + __XBTS_MAX)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700159 uint32_t xs_rmap_2[__XBTS_MAX];
Dave Chinner11ef38a2016-12-05 14:38:58 +1100160#define XFSSTAT_END_REFCOUNT (XFSSTAT_END_RMAP_V2 + __XBTS_MAX)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700161 uint32_t xs_refcbt_2[__XBTS_MAX];
Darrick J. Wong46eeb522016-10-03 09:11:16 -0700162#define XFSSTAT_END_XQMSTAT (XFSSTAT_END_REFCOUNT + 6)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700163 uint32_t xs_qm_dqreclaims;
164 uint32_t xs_qm_dqreclaim_misses;
165 uint32_t xs_qm_dquot_dups;
166 uint32_t xs_qm_dqcachemisses;
167 uint32_t xs_qm_dqcachehits;
168 uint32_t xs_qm_dqwants;
Christoph Hellwig48776fd2012-03-13 08:52:33 +0000169#define XFSSTAT_END_QM (XFSSTAT_END_XQMSTAT+2)
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700170 uint32_t xs_qm_dquot;
171 uint32_t xs_qm_dquot_unused;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172/* Extra precision counters */
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700173 uint64_t xs_xstrat_bytes;
174 uint64_t xs_write_bytes;
175 uint64_t xs_read_bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176};
177
Dave Chinner11ef38a2016-12-05 14:38:58 +1100178struct xfsstats {
179 union {
180 struct __xfsstats s;
181 uint32_t a[XFSSTAT_END_XQMSTAT];
182 };
183};
184
185/*
186 * simple wrapper for getting the array index of s struct member offset
187 */
188#define XFS_STATS_CALC_INDEX(member) \
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700189 (offsetof(struct __xfsstats, member) / (int)sizeof(uint32_t))
Dave Chinner11ef38a2016-12-05 14:38:58 +1100190
191
Bill O'Donnell80529c42015-10-12 05:19:45 +1100192int xfs_stats_format(struct xfsstats __percpu *stats, char *buf);
193void xfs_stats_clearall(struct xfsstats __percpu *stats);
194extern struct xstats xfsstats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Bill O'Donnellff6d6af2015-10-12 18:21:22 +1100196#define XFS_STATS_INC(mp, v) \
197do { \
Dave Chinner11ef38a2016-12-05 14:38:58 +1100198 per_cpu_ptr(xfsstats.xs_stats, current_cpu())->s.v++; \
199 per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->s.v++; \
Bill O'Donnellff6d6af2015-10-12 18:21:22 +1100200} while (0)
Bill O'Donnell80529c42015-10-12 05:19:45 +1100201
Bill O'Donnellff6d6af2015-10-12 18:21:22 +1100202#define XFS_STATS_DEC(mp, v) \
203do { \
Dave Chinner11ef38a2016-12-05 14:38:58 +1100204 per_cpu_ptr(xfsstats.xs_stats, current_cpu())->s.v--; \
205 per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->s.v--; \
Bill O'Donnellff6d6af2015-10-12 18:21:22 +1100206} while (0)
Bill O'Donnell80529c42015-10-12 05:19:45 +1100207
Bill O'Donnellff6d6af2015-10-12 18:21:22 +1100208#define XFS_STATS_ADD(mp, v, inc) \
209do { \
Dave Chinner11ef38a2016-12-05 14:38:58 +1100210 per_cpu_ptr(xfsstats.xs_stats, current_cpu())->s.v += (inc); \
211 per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->s.v += (inc); \
212} while (0)
213
214#define XFS_STATS_INC_OFF(mp, off) \
215do { \
216 per_cpu_ptr(xfsstats.xs_stats, current_cpu())->a[off]++; \
217 per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->a[off]++; \
218} while (0)
219
220#define XFS_STATS_DEC_OFF(mp, off) \
221do { \
222 per_cpu_ptr(xfsstats.xs_stats, current_cpu())->a[off]; \
223 per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->a[off]; \
224} while (0)
225
226#define XFS_STATS_ADD_OFF(mp, off, inc) \
227do { \
228 per_cpu_ptr(xfsstats.xs_stats, current_cpu())->a[off] += (inc); \
229 per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->a[off] += (inc); \
Bill O'Donnellff6d6af2015-10-12 18:21:22 +1100230} while (0)
231
232#if defined(CONFIG_PROC_FS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
Christoph Hellwig9f8868f2008-07-18 17:11:46 +1000234extern int xfs_init_procfs(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235extern void xfs_cleanup_procfs(void);
236
237
238#else /* !CONFIG_PROC_FS */
239
Christoph Hellwig9f8868f2008-07-18 17:11:46 +1000240static inline int xfs_init_procfs(void)
241{
Christoph Hellwig766b0922008-07-18 17:12:50 +1000242 return 0;
243}
244
Christoph Hellwig9f8868f2008-07-18 17:11:46 +1000245static inline void xfs_cleanup_procfs(void)
246{
Christoph Hellwig766b0922008-07-18 17:12:50 +1000247}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249#endif /* !CONFIG_PROC_FS */
250
251#endif /* __XFS_STATS_H__ */