1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2000,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6 #ifndef __XFS_STATS_H__
7 #define __XFS_STATS_H__
8
9
10 #include <linux/percpu.h>
11
12 /*
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 /*
41 * XFS global statistics
42 */
43 struct __xfsstats {
44 uint32_t xs_allocx;
45 uint32_t xs_allocb;
46 uint32_t xs_freex;
47 uint32_t xs_freeb;
48 uint32_t xs_abt_lookup;
49 uint32_t xs_abt_compare;
50 uint32_t xs_abt_insrec;
51 uint32_t xs_abt_delrec;
52 uint32_t xs_blk_mapr;
53 uint32_t xs_blk_mapw;
54 uint32_t xs_blk_unmap;
55 uint32_t xs_add_exlist;
56 uint32_t xs_del_exlist;
57 uint32_t xs_look_exlist;
58 uint32_t xs_cmp_exlist;
59 uint32_t xs_bmbt_lookup;
60 uint32_t xs_bmbt_compare;
61 uint32_t xs_bmbt_insrec;
62 uint32_t xs_bmbt_delrec;
63 uint32_t xs_dir_lookup;
64 uint32_t xs_dir_create;
65 uint32_t xs_dir_remove;
66 uint32_t xs_dir_getdents;
67 uint32_t xs_trans_sync;
68 uint32_t xs_trans_async;
69 uint32_t xs_trans_empty;
70 uint32_t xs_ig_attempts;
71 uint32_t xs_ig_found;
72 uint32_t xs_ig_frecycle;
73 uint32_t xs_ig_missed;
74 uint32_t xs_ig_dup;
75 uint32_t xs_ig_reclaims;
76 uint32_t xs_ig_attrchg;
77 uint32_t xs_log_writes;
78 uint32_t xs_log_blocks;
79 uint32_t xs_log_noiclogs;
80 uint32_t xs_log_force;
81 uint32_t xs_log_force_sleep;
82 uint32_t xs_try_logspace;
83 uint32_t xs_sleep_logspace;
84 uint32_t xs_push_ail;
85 uint32_t xs_push_ail_success;
86 uint32_t xs_push_ail_pushbuf;
87 uint32_t xs_push_ail_pinned;
88 uint32_t xs_push_ail_locked;
89 uint32_t xs_push_ail_flushing;
90 uint32_t xs_push_ail_restarts;
91 uint32_t xs_push_ail_flush;
92 uint32_t xs_xstrat_quick;
93 uint32_t xs_xstrat_split;
94 uint32_t xs_write_calls;
95 uint32_t xs_read_calls;
96 uint32_t xs_attr_get;
97 uint32_t xs_attr_set;
98 uint32_t xs_attr_remove;
99 uint32_t xs_attr_list;
100 uint32_t xs_iflush_count;
101 uint32_t xs_icluster_flushcnt;
102 uint32_t xs_icluster_flushinode;
103 uint32_t xs_inodes_active;
104 uint32_t __unused_vn_alloc;
105 uint32_t __unused_vn_get;
106 uint32_t __unused_vn_hold;
107 uint32_t xs_inode_destroy;
108 uint32_t xs_inode_destroy2; /* same as xs_inode_destroy */
109 uint32_t xs_inode_mark_reclaimable;
110 uint32_t __unused_vn_free;
111 uint32_t xb_get;
112 uint32_t xb_create;
113 uint32_t xb_get_locked;
114 uint32_t xb_get_locked_waited;
115 uint32_t xb_busy_locked;
116 uint32_t xb_miss_locked;
117 uint32_t xb_page_retries;
118 uint32_t xb_page_found;
119 uint32_t xb_get_read;
120 /* Version 2 btree counters */
121 uint32_t xs_abtb_2[__XBTS_MAX];
122 uint32_t xs_abtc_2[__XBTS_MAX];
123 uint32_t xs_bmbt_2[__XBTS_MAX];
124 uint32_t xs_ibt_2[__XBTS_MAX];
125 uint32_t xs_fibt_2[__XBTS_MAX];
126 uint32_t xs_rmap_2[__XBTS_MAX];
127 uint32_t xs_refcbt_2[__XBTS_MAX];
128 uint32_t xs_rmap_mem_2[__XBTS_MAX];
129 uint32_t xs_rcbag_2[__XBTS_MAX];
130 uint32_t xs_rtrmap_2[__XBTS_MAX];
131 uint32_t xs_rtrmap_mem_2[__XBTS_MAX];
132 uint32_t xs_rtrefcbt_2[__XBTS_MAX];
133 uint32_t xs_qm_dqreclaims;
134 uint32_t xs_qm_dqreclaim_misses;
135 uint32_t xs_qm_dquot_dups;
136 uint32_t xs_qm_dqcachemisses;
137 uint32_t xs_qm_dqcachehits;
138 uint32_t xs_qm_dqwants;
139 uint32_t xs_qm_dquot;
140 uint32_t xs_qm_dquot_unused;
141 /* Zone GC counters */
142 uint32_t xs_gc_read_calls;
143 uint32_t xs_gc_write_calls;
144 uint32_t xs_gc_zone_reset_calls;
145 /* Metafile counters */
146 uint32_t xs_inodes_meta;
147 /* Extra precision counters */
148 uint64_t xs_xstrat_bytes;
149 uint64_t xs_write_bytes;
150 uint64_t xs_read_bytes;
151 uint64_t xs_defer_relog;
152 uint64_t xs_gc_bytes;
153 };
154
155 #define xfsstats_offset(f) (offsetof(struct __xfsstats, f)/sizeof(uint32_t))
156
157 struct xfsstats {
158 union {
159 struct __xfsstats s;
160 uint32_t a[xfsstats_offset(xs_qm_dquot)];
161 };
162 };
163
164 /*
165 * simple wrapper for getting the array index of s struct member offset
166 */
167 #define XFS_STATS_CALC_INDEX(member) \
168 (offsetof(struct __xfsstats, member) / (int)sizeof(uint32_t))
169
170
171 int xfs_stats_format(struct xfsstats __percpu *stats, char *buf);
172 void xfs_stats_clearall(struct xfsstats __percpu *stats);
173 extern struct xstats xfsstats;
174
175 #define XFS_STATS_INC(mp, v) \
176 do { \
177 per_cpu_ptr(xfsstats.xs_stats, current_cpu())->s.v++; \
178 per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->s.v++; \
179 } while (0)
180
181 #define XFS_STATS_DEC(mp, v) \
182 do { \
183 per_cpu_ptr(xfsstats.xs_stats, current_cpu())->s.v--; \
184 per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->s.v--; \
185 } while (0)
186
187 #define XFS_STATS_ADD(mp, v, inc) \
188 do { \
189 per_cpu_ptr(xfsstats.xs_stats, current_cpu())->s.v += (inc); \
190 per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->s.v += (inc); \
191 } while (0)
192
193 #define XFS_STATS_INC_OFF(mp, off) \
194 do { \
195 per_cpu_ptr(xfsstats.xs_stats, current_cpu())->a[off]++; \
196 per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->a[off]++; \
197 } while (0)
198
199 #define XFS_STATS_DEC_OFF(mp, off) \
200 do { \
201 per_cpu_ptr(xfsstats.xs_stats, current_cpu())->a[off]; \
202 per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->a[off]; \
203 } while (0)
204
205 #define XFS_STATS_ADD_OFF(mp, off, inc) \
206 do { \
207 per_cpu_ptr(xfsstats.xs_stats, current_cpu())->a[off] += (inc); \
208 per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->a[off] += (inc); \
209 } while (0)
210
211 #if defined(CONFIG_PROC_FS)
212
213 extern int xfs_init_procfs(void);
214 extern void xfs_cleanup_procfs(void);
215
216
217 #else /* !CONFIG_PROC_FS */
218
xfs_init_procfs(void)219 static inline int xfs_init_procfs(void)
220 {
221 return 0;
222 }
223
xfs_cleanup_procfs(void)224 static inline void xfs_cleanup_procfs(void)
225 {
226 }
227
228 #endif /* !CONFIG_PROC_FS */
229
230 #endif /* __XFS_STATS_H__ */
231