xref: /openbmc/linux/fs/xfs/xfs_stats.h (revision cbecf716ca618fd44feda6bd9a64a8179d031fc5)
10b61f8a4SDave Chinner // SPDX-License-Identifier: GPL-2.0
2c59d87c4SChristoph Hellwig /*
3c59d87c4SChristoph Hellwig  * Copyright (c) 2000,2005 Silicon Graphics, Inc.
4c59d87c4SChristoph Hellwig  * All Rights Reserved.
5c59d87c4SChristoph Hellwig  */
6c59d87c4SChristoph Hellwig #ifndef __XFS_STATS_H__
7c59d87c4SChristoph Hellwig #define __XFS_STATS_H__
8c59d87c4SChristoph Hellwig 
9c59d87c4SChristoph Hellwig 
10c59d87c4SChristoph Hellwig #include <linux/percpu.h>
11c59d87c4SChristoph Hellwig 
12c59d87c4SChristoph Hellwig /*
1311ef38afSDave Chinner  * The btree stats arrays have fixed offsets for the different stats. We
1411ef38afSDave Chinner  * store the base index in the btree cursor via XFS_STATS_CALC_INDEX() and
1511ef38afSDave Chinner  * that allows us to use fixed offsets into the stats array for each btree
1611ef38afSDave Chinner  * stat. These index offsets are defined in the order they will be emitted
1711ef38afSDave Chinner  * in the stats files, so it is possible to add new btree stat types by
1811ef38afSDave Chinner  * appending to the enum list below.
1911ef38afSDave Chinner  */
2011ef38afSDave Chinner enum {
2111ef38afSDave Chinner 	__XBTS_lookup = 0,
2211ef38afSDave Chinner 	__XBTS_compare = 1,
2311ef38afSDave Chinner 	__XBTS_insrec = 2,
2411ef38afSDave Chinner 	__XBTS_delrec = 3,
2511ef38afSDave Chinner 	__XBTS_newroot = 4,
2611ef38afSDave Chinner 	__XBTS_killroot = 5,
2711ef38afSDave Chinner 	__XBTS_increment = 6,
2811ef38afSDave Chinner 	__XBTS_decrement = 7,
2911ef38afSDave Chinner 	__XBTS_lshift = 8,
3011ef38afSDave Chinner 	__XBTS_rshift = 9,
3111ef38afSDave Chinner 	__XBTS_split = 10,
3211ef38afSDave Chinner 	__XBTS_join = 11,
3311ef38afSDave Chinner 	__XBTS_alloc = 12,
3411ef38afSDave Chinner 	__XBTS_free = 13,
3511ef38afSDave Chinner 	__XBTS_moves = 14,
3611ef38afSDave Chinner 
3711ef38afSDave Chinner 	__XBTS_MAX = 15,
3811ef38afSDave Chinner };
3911ef38afSDave Chinner 
4011ef38afSDave Chinner /*
41c59d87c4SChristoph Hellwig  * XFS global statistics
42c59d87c4SChristoph Hellwig  */
4311ef38afSDave Chinner struct __xfsstats {
44c8ce540dSDarrick J. Wong 	uint32_t		xs_allocx;
45c8ce540dSDarrick J. Wong 	uint32_t		xs_allocb;
46c8ce540dSDarrick J. Wong 	uint32_t		xs_freex;
47c8ce540dSDarrick J. Wong 	uint32_t		xs_freeb;
48c8ce540dSDarrick J. Wong 	uint32_t		xs_abt_lookup;
49c8ce540dSDarrick J. Wong 	uint32_t		xs_abt_compare;
50c8ce540dSDarrick J. Wong 	uint32_t		xs_abt_insrec;
51c8ce540dSDarrick J. Wong 	uint32_t		xs_abt_delrec;
52c8ce540dSDarrick J. Wong 	uint32_t		xs_blk_mapr;
53c8ce540dSDarrick J. Wong 	uint32_t		xs_blk_mapw;
54c8ce540dSDarrick J. Wong 	uint32_t		xs_blk_unmap;
55c8ce540dSDarrick J. Wong 	uint32_t		xs_add_exlist;
56c8ce540dSDarrick J. Wong 	uint32_t		xs_del_exlist;
57c8ce540dSDarrick J. Wong 	uint32_t		xs_look_exlist;
58c8ce540dSDarrick J. Wong 	uint32_t		xs_cmp_exlist;
59c8ce540dSDarrick J. Wong 	uint32_t		xs_bmbt_lookup;
60c8ce540dSDarrick J. Wong 	uint32_t		xs_bmbt_compare;
61c8ce540dSDarrick J. Wong 	uint32_t		xs_bmbt_insrec;
62c8ce540dSDarrick J. Wong 	uint32_t		xs_bmbt_delrec;
63c8ce540dSDarrick J. Wong 	uint32_t		xs_dir_lookup;
64c8ce540dSDarrick J. Wong 	uint32_t		xs_dir_create;
65c8ce540dSDarrick J. Wong 	uint32_t		xs_dir_remove;
66c8ce540dSDarrick J. Wong 	uint32_t		xs_dir_getdents;
67c8ce540dSDarrick J. Wong 	uint32_t		xs_trans_sync;
68c8ce540dSDarrick J. Wong 	uint32_t		xs_trans_async;
69c8ce540dSDarrick J. Wong 	uint32_t		xs_trans_empty;
70c8ce540dSDarrick J. Wong 	uint32_t		xs_ig_attempts;
71c8ce540dSDarrick J. Wong 	uint32_t		xs_ig_found;
72c8ce540dSDarrick J. Wong 	uint32_t		xs_ig_frecycle;
73c8ce540dSDarrick J. Wong 	uint32_t		xs_ig_missed;
74c8ce540dSDarrick J. Wong 	uint32_t		xs_ig_dup;
75c8ce540dSDarrick J. Wong 	uint32_t		xs_ig_reclaims;
76c8ce540dSDarrick J. Wong 	uint32_t		xs_ig_attrchg;
77c8ce540dSDarrick J. Wong 	uint32_t		xs_log_writes;
78c8ce540dSDarrick J. Wong 	uint32_t		xs_log_blocks;
79c8ce540dSDarrick J. Wong 	uint32_t		xs_log_noiclogs;
80c8ce540dSDarrick J. Wong 	uint32_t		xs_log_force;
81c8ce540dSDarrick J. Wong 	uint32_t		xs_log_force_sleep;
82c8ce540dSDarrick J. Wong 	uint32_t		xs_try_logspace;
83c8ce540dSDarrick J. Wong 	uint32_t		xs_sleep_logspace;
84c8ce540dSDarrick J. Wong 	uint32_t		xs_push_ail;
85c8ce540dSDarrick J. Wong 	uint32_t		xs_push_ail_success;
86c8ce540dSDarrick J. Wong 	uint32_t		xs_push_ail_pushbuf;
87c8ce540dSDarrick J. Wong 	uint32_t		xs_push_ail_pinned;
88c8ce540dSDarrick J. Wong 	uint32_t		xs_push_ail_locked;
89c8ce540dSDarrick J. Wong 	uint32_t		xs_push_ail_flushing;
90c8ce540dSDarrick J. Wong 	uint32_t		xs_push_ail_restarts;
91c8ce540dSDarrick J. Wong 	uint32_t		xs_push_ail_flush;
92c8ce540dSDarrick J. Wong 	uint32_t		xs_xstrat_quick;
93c8ce540dSDarrick J. Wong 	uint32_t		xs_xstrat_split;
94c8ce540dSDarrick J. Wong 	uint32_t		xs_write_calls;
95c8ce540dSDarrick J. Wong 	uint32_t		xs_read_calls;
96c8ce540dSDarrick J. Wong 	uint32_t		xs_attr_get;
97c8ce540dSDarrick J. Wong 	uint32_t		xs_attr_set;
98c8ce540dSDarrick J. Wong 	uint32_t		xs_attr_remove;
99c8ce540dSDarrick J. Wong 	uint32_t		xs_attr_list;
100c8ce540dSDarrick J. Wong 	uint32_t		xs_iflush_count;
101c8ce540dSDarrick J. Wong 	uint32_t		xs_icluster_flushcnt;
102c8ce540dSDarrick J. Wong 	uint32_t		xs_icluster_flushinode;
103c8ce540dSDarrick J. Wong 	uint32_t		vn_active;	/* # vnodes not on free lists */
104c8ce540dSDarrick J. Wong 	uint32_t		vn_alloc;	/* # times vn_alloc called */
105c8ce540dSDarrick J. Wong 	uint32_t		vn_get;		/* # times vn_get called */
106c8ce540dSDarrick J. Wong 	uint32_t		vn_hold;	/* # times vn_hold called */
107c8ce540dSDarrick J. Wong 	uint32_t		vn_rele;	/* # times vn_rele called */
108c8ce540dSDarrick J. Wong 	uint32_t		vn_reclaim;	/* # times vn_reclaim called */
109c8ce540dSDarrick J. Wong 	uint32_t		vn_remove;	/* # times vn_remove called */
110c8ce540dSDarrick J. Wong 	uint32_t		vn_free;	/* # times vn_free called */
111c8ce540dSDarrick J. Wong 	uint32_t		xb_get;
112c8ce540dSDarrick J. Wong 	uint32_t		xb_create;
113c8ce540dSDarrick J. Wong 	uint32_t		xb_get_locked;
114c8ce540dSDarrick J. Wong 	uint32_t		xb_get_locked_waited;
115c8ce540dSDarrick J. Wong 	uint32_t		xb_busy_locked;
116c8ce540dSDarrick J. Wong 	uint32_t		xb_miss_locked;
117c8ce540dSDarrick J. Wong 	uint32_t		xb_page_retries;
118c8ce540dSDarrick J. Wong 	uint32_t		xb_page_found;
119c8ce540dSDarrick J. Wong 	uint32_t		xb_get_read;
120c59d87c4SChristoph Hellwig /* Version 2 btree counters */
121c8ce540dSDarrick J. Wong 	uint32_t		xs_abtb_2[__XBTS_MAX];
122c8ce540dSDarrick J. Wong 	uint32_t		xs_abtc_2[__XBTS_MAX];
123c8ce540dSDarrick J. Wong 	uint32_t		xs_bmbt_2[__XBTS_MAX];
124c8ce540dSDarrick J. Wong 	uint32_t		xs_ibt_2[__XBTS_MAX];
125c8ce540dSDarrick J. Wong 	uint32_t		xs_fibt_2[__XBTS_MAX];
126c8ce540dSDarrick J. Wong 	uint32_t		xs_rmap_2[__XBTS_MAX];
127c8ce540dSDarrick J. Wong 	uint32_t		xs_refcbt_2[__XBTS_MAX];
128c8ce540dSDarrick J. Wong 	uint32_t		xs_qm_dqreclaims;
129c8ce540dSDarrick J. Wong 	uint32_t		xs_qm_dqreclaim_misses;
130c8ce540dSDarrick J. Wong 	uint32_t		xs_qm_dquot_dups;
131c8ce540dSDarrick J. Wong 	uint32_t		xs_qm_dqcachemisses;
132c8ce540dSDarrick J. Wong 	uint32_t		xs_qm_dqcachehits;
133c8ce540dSDarrick J. Wong 	uint32_t		xs_qm_dqwants;
134c8ce540dSDarrick J. Wong 	uint32_t		xs_qm_dquot;
135c8ce540dSDarrick J. Wong 	uint32_t		xs_qm_dquot_unused;
136c59d87c4SChristoph Hellwig /* Extra precision counters */
137c8ce540dSDarrick J. Wong 	uint64_t		xs_xstrat_bytes;
138c8ce540dSDarrick J. Wong 	uint64_t		xs_write_bytes;
139c8ce540dSDarrick J. Wong 	uint64_t		xs_read_bytes;
140*4e919af7SDarrick J. Wong 	uint64_t		defer_relog;
141c59d87c4SChristoph Hellwig };
142c59d87c4SChristoph Hellwig 
14326ca3901SCarlos Maiolino #define	xfsstats_offset(f)	(offsetof(struct __xfsstats, f)/sizeof(uint32_t))
14426ca3901SCarlos Maiolino 
14511ef38afSDave Chinner struct xfsstats {
14611ef38afSDave Chinner 	union {
14711ef38afSDave Chinner 		struct __xfsstats	s;
14826ca3901SCarlos Maiolino 		uint32_t		a[xfsstats_offset(xs_qm_dquot)];
14911ef38afSDave Chinner 	};
15011ef38afSDave Chinner };
15111ef38afSDave Chinner 
15211ef38afSDave Chinner /*
15311ef38afSDave Chinner  * simple wrapper for getting the array index of s struct member offset
15411ef38afSDave Chinner  */
15511ef38afSDave Chinner #define XFS_STATS_CALC_INDEX(member)	\
156c8ce540dSDarrick J. Wong 	(offsetof(struct __xfsstats, member) / (int)sizeof(uint32_t))
15711ef38afSDave Chinner 
15811ef38afSDave Chinner 
15980529c45SBill O'Donnell int xfs_stats_format(struct xfsstats __percpu *stats, char *buf);
16080529c45SBill O'Donnell void xfs_stats_clearall(struct xfsstats __percpu *stats);
16180529c45SBill O'Donnell extern struct xstats xfsstats;
162c59d87c4SChristoph Hellwig 
163ff6d6af2SBill O'Donnell #define XFS_STATS_INC(mp, v)					\
164ff6d6af2SBill O'Donnell do {								\
16511ef38afSDave Chinner 	per_cpu_ptr(xfsstats.xs_stats, current_cpu())->s.v++;	\
16611ef38afSDave Chinner 	per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->s.v++;	\
167ff6d6af2SBill O'Donnell } while (0)
16880529c45SBill O'Donnell 
169ff6d6af2SBill O'Donnell #define XFS_STATS_DEC(mp, v)					\
170ff6d6af2SBill O'Donnell do {								\
17111ef38afSDave Chinner 	per_cpu_ptr(xfsstats.xs_stats, current_cpu())->s.v--;	\
17211ef38afSDave Chinner 	per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->s.v--;	\
173ff6d6af2SBill O'Donnell } while (0)
17480529c45SBill O'Donnell 
175ff6d6af2SBill O'Donnell #define XFS_STATS_ADD(mp, v, inc)					\
176ff6d6af2SBill O'Donnell do {									\
17711ef38afSDave Chinner 	per_cpu_ptr(xfsstats.xs_stats, current_cpu())->s.v += (inc);	\
17811ef38afSDave Chinner 	per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->s.v += (inc);	\
17911ef38afSDave Chinner } while (0)
18011ef38afSDave Chinner 
18111ef38afSDave Chinner #define XFS_STATS_INC_OFF(mp, off)				\
18211ef38afSDave Chinner do {								\
18311ef38afSDave Chinner 	per_cpu_ptr(xfsstats.xs_stats, current_cpu())->a[off]++;	\
18411ef38afSDave Chinner 	per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->a[off]++;	\
18511ef38afSDave Chinner } while (0)
18611ef38afSDave Chinner 
18711ef38afSDave Chinner #define XFS_STATS_DEC_OFF(mp, off)					\
18811ef38afSDave Chinner do {								\
18911ef38afSDave Chinner 	per_cpu_ptr(xfsstats.xs_stats, current_cpu())->a[off];	\
19011ef38afSDave Chinner 	per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->a[off];	\
19111ef38afSDave Chinner } while (0)
19211ef38afSDave Chinner 
19311ef38afSDave Chinner #define XFS_STATS_ADD_OFF(mp, off, inc)					\
19411ef38afSDave Chinner do {									\
19511ef38afSDave Chinner 	per_cpu_ptr(xfsstats.xs_stats, current_cpu())->a[off] += (inc);	\
19611ef38afSDave Chinner 	per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->a[off] += (inc);	\
197ff6d6af2SBill O'Donnell } while (0)
198ff6d6af2SBill O'Donnell 
199ff6d6af2SBill O'Donnell #if defined(CONFIG_PROC_FS)
200c59d87c4SChristoph Hellwig 
201c59d87c4SChristoph Hellwig extern int xfs_init_procfs(void);
202c59d87c4SChristoph Hellwig extern void xfs_cleanup_procfs(void);
203c59d87c4SChristoph Hellwig 
204c59d87c4SChristoph Hellwig 
205c59d87c4SChristoph Hellwig #else	/* !CONFIG_PROC_FS */
206c59d87c4SChristoph Hellwig 
xfs_init_procfs(void)207c59d87c4SChristoph Hellwig static inline int xfs_init_procfs(void)
208c59d87c4SChristoph Hellwig {
209c59d87c4SChristoph Hellwig 	return 0;
210c59d87c4SChristoph Hellwig }
211c59d87c4SChristoph Hellwig 
xfs_cleanup_procfs(void)212c59d87c4SChristoph Hellwig static inline void xfs_cleanup_procfs(void)
213c59d87c4SChristoph Hellwig {
214c59d87c4SChristoph Hellwig }
215c59d87c4SChristoph Hellwig 
216c59d87c4SChristoph Hellwig #endif	/* !CONFIG_PROC_FS */
217c59d87c4SChristoph Hellwig 
218c59d87c4SChristoph Hellwig #endif /* __XFS_STATS_H__ */
219