xfs: create global stats and stats_clear in sysfs
[linux-block.git] / fs / xfs / xfs_stats.h
1 /*
2  * Copyright (c) 2000,2005 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * 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.
13  *
14  * 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
17  */
18 #ifndef __XFS_STATS_H__
19 #define __XFS_STATS_H__
20
21 int xfs_stats_format(char *buf);
22 void xfs_stats_clearall(void);
23
24 #if defined(CONFIG_PROC_FS) && !defined(XFS_STATS_OFF)
25
26 #include <linux/percpu.h>
27
28 /*
29  * XFS global statistics
30  */
31 struct xfsstats {
32 # define XFSSTAT_END_EXTENT_ALLOC       4
33         __uint32_t              xs_allocx;
34         __uint32_t              xs_allocb;
35         __uint32_t              xs_freex;
36         __uint32_t              xs_freeb;
37 # define XFSSTAT_END_ALLOC_BTREE        (XFSSTAT_END_EXTENT_ALLOC+4)
38         __uint32_t              xs_abt_lookup;
39         __uint32_t              xs_abt_compare;
40         __uint32_t              xs_abt_insrec;
41         __uint32_t              xs_abt_delrec;
42 # define XFSSTAT_END_BLOCK_MAPPING      (XFSSTAT_END_ALLOC_BTREE+7)
43         __uint32_t              xs_blk_mapr;
44         __uint32_t              xs_blk_mapw;
45         __uint32_t              xs_blk_unmap;
46         __uint32_t              xs_add_exlist;
47         __uint32_t              xs_del_exlist;
48         __uint32_t              xs_look_exlist;
49         __uint32_t              xs_cmp_exlist;
50 # define XFSSTAT_END_BLOCK_MAP_BTREE    (XFSSTAT_END_BLOCK_MAPPING+4)
51         __uint32_t              xs_bmbt_lookup;
52         __uint32_t              xs_bmbt_compare;
53         __uint32_t              xs_bmbt_insrec;
54         __uint32_t              xs_bmbt_delrec;
55 # define XFSSTAT_END_DIRECTORY_OPS      (XFSSTAT_END_BLOCK_MAP_BTREE+4)
56         __uint32_t              xs_dir_lookup;
57         __uint32_t              xs_dir_create;
58         __uint32_t              xs_dir_remove;
59         __uint32_t              xs_dir_getdents;
60 # define XFSSTAT_END_TRANSACTIONS       (XFSSTAT_END_DIRECTORY_OPS+3)
61         __uint32_t              xs_trans_sync;
62         __uint32_t              xs_trans_async;
63         __uint32_t              xs_trans_empty;
64 # define XFSSTAT_END_INODE_OPS          (XFSSTAT_END_TRANSACTIONS+7)
65         __uint32_t              xs_ig_attempts;
66         __uint32_t              xs_ig_found;
67         __uint32_t              xs_ig_frecycle;
68         __uint32_t              xs_ig_missed;
69         __uint32_t              xs_ig_dup;
70         __uint32_t              xs_ig_reclaims;
71         __uint32_t              xs_ig_attrchg;
72 # define XFSSTAT_END_LOG_OPS            (XFSSTAT_END_INODE_OPS+5)
73         __uint32_t              xs_log_writes;
74         __uint32_t              xs_log_blocks;
75         __uint32_t              xs_log_noiclogs;
76         __uint32_t              xs_log_force;
77         __uint32_t              xs_log_force_sleep;
78 # define XFSSTAT_END_TAIL_PUSHING       (XFSSTAT_END_LOG_OPS+10)
79         __uint32_t              xs_try_logspace;
80         __uint32_t              xs_sleep_logspace;
81         __uint32_t              xs_push_ail;
82         __uint32_t              xs_push_ail_success;
83         __uint32_t              xs_push_ail_pushbuf;
84         __uint32_t              xs_push_ail_pinned;
85         __uint32_t              xs_push_ail_locked;
86         __uint32_t              xs_push_ail_flushing;
87         __uint32_t              xs_push_ail_restarts;
88         __uint32_t              xs_push_ail_flush;
89 # define XFSSTAT_END_WRITE_CONVERT      (XFSSTAT_END_TAIL_PUSHING+2)
90         __uint32_t              xs_xstrat_quick;
91         __uint32_t              xs_xstrat_split;
92 # define XFSSTAT_END_READ_WRITE_OPS     (XFSSTAT_END_WRITE_CONVERT+2)
93         __uint32_t              xs_write_calls;
94         __uint32_t              xs_read_calls;
95 # define XFSSTAT_END_ATTRIBUTE_OPS      (XFSSTAT_END_READ_WRITE_OPS+4)
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 # define XFSSTAT_END_INODE_CLUSTER      (XFSSTAT_END_ATTRIBUTE_OPS+3)
101         __uint32_t              xs_iflush_count;
102         __uint32_t              xs_icluster_flushcnt;
103         __uint32_t              xs_icluster_flushinode;
104 # define XFSSTAT_END_VNODE_OPS          (XFSSTAT_END_INODE_CLUSTER+8)
105         __uint32_t              vn_active;      /* # vnodes not on free lists */
106         __uint32_t              vn_alloc;       /* # times vn_alloc called */
107         __uint32_t              vn_get;         /* # times vn_get called */
108         __uint32_t              vn_hold;        /* # times vn_hold called */
109         __uint32_t              vn_rele;        /* # times vn_rele called */
110         __uint32_t              vn_reclaim;     /* # times vn_reclaim called */
111         __uint32_t              vn_remove;      /* # times vn_remove called */
112         __uint32_t              vn_free;        /* # times vn_free called */
113 #define XFSSTAT_END_BUF                 (XFSSTAT_END_VNODE_OPS+9)
114         __uint32_t              xb_get;
115         __uint32_t              xb_create;
116         __uint32_t              xb_get_locked;
117         __uint32_t              xb_get_locked_waited;
118         __uint32_t              xb_busy_locked;
119         __uint32_t              xb_miss_locked;
120         __uint32_t              xb_page_retries;
121         __uint32_t              xb_page_found;
122         __uint32_t              xb_get_read;
123 /* Version 2 btree counters */
124 #define XFSSTAT_END_ABTB_V2             (XFSSTAT_END_BUF+15)
125         __uint32_t              xs_abtb_2_lookup;
126         __uint32_t              xs_abtb_2_compare;
127         __uint32_t              xs_abtb_2_insrec;
128         __uint32_t              xs_abtb_2_delrec;
129         __uint32_t              xs_abtb_2_newroot;
130         __uint32_t              xs_abtb_2_killroot;
131         __uint32_t              xs_abtb_2_increment;
132         __uint32_t              xs_abtb_2_decrement;
133         __uint32_t              xs_abtb_2_lshift;
134         __uint32_t              xs_abtb_2_rshift;
135         __uint32_t              xs_abtb_2_split;
136         __uint32_t              xs_abtb_2_join;
137         __uint32_t              xs_abtb_2_alloc;
138         __uint32_t              xs_abtb_2_free;
139         __uint32_t              xs_abtb_2_moves;
140 #define XFSSTAT_END_ABTC_V2             (XFSSTAT_END_ABTB_V2+15)
141         __uint32_t              xs_abtc_2_lookup;
142         __uint32_t              xs_abtc_2_compare;
143         __uint32_t              xs_abtc_2_insrec;
144         __uint32_t              xs_abtc_2_delrec;
145         __uint32_t              xs_abtc_2_newroot;
146         __uint32_t              xs_abtc_2_killroot;
147         __uint32_t              xs_abtc_2_increment;
148         __uint32_t              xs_abtc_2_decrement;
149         __uint32_t              xs_abtc_2_lshift;
150         __uint32_t              xs_abtc_2_rshift;
151         __uint32_t              xs_abtc_2_split;
152         __uint32_t              xs_abtc_2_join;
153         __uint32_t              xs_abtc_2_alloc;
154         __uint32_t              xs_abtc_2_free;
155         __uint32_t              xs_abtc_2_moves;
156 #define XFSSTAT_END_BMBT_V2             (XFSSTAT_END_ABTC_V2+15)
157         __uint32_t              xs_bmbt_2_lookup;
158         __uint32_t              xs_bmbt_2_compare;
159         __uint32_t              xs_bmbt_2_insrec;
160         __uint32_t              xs_bmbt_2_delrec;
161         __uint32_t              xs_bmbt_2_newroot;
162         __uint32_t              xs_bmbt_2_killroot;
163         __uint32_t              xs_bmbt_2_increment;
164         __uint32_t              xs_bmbt_2_decrement;
165         __uint32_t              xs_bmbt_2_lshift;
166         __uint32_t              xs_bmbt_2_rshift;
167         __uint32_t              xs_bmbt_2_split;
168         __uint32_t              xs_bmbt_2_join;
169         __uint32_t              xs_bmbt_2_alloc;
170         __uint32_t              xs_bmbt_2_free;
171         __uint32_t              xs_bmbt_2_moves;
172 #define XFSSTAT_END_IBT_V2              (XFSSTAT_END_BMBT_V2+15)
173         __uint32_t              xs_ibt_2_lookup;
174         __uint32_t              xs_ibt_2_compare;
175         __uint32_t              xs_ibt_2_insrec;
176         __uint32_t              xs_ibt_2_delrec;
177         __uint32_t              xs_ibt_2_newroot;
178         __uint32_t              xs_ibt_2_killroot;
179         __uint32_t              xs_ibt_2_increment;
180         __uint32_t              xs_ibt_2_decrement;
181         __uint32_t              xs_ibt_2_lshift;
182         __uint32_t              xs_ibt_2_rshift;
183         __uint32_t              xs_ibt_2_split;
184         __uint32_t              xs_ibt_2_join;
185         __uint32_t              xs_ibt_2_alloc;
186         __uint32_t              xs_ibt_2_free;
187         __uint32_t              xs_ibt_2_moves;
188 #define XFSSTAT_END_FIBT_V2             (XFSSTAT_END_IBT_V2+15)
189         __uint32_t              xs_fibt_2_lookup;
190         __uint32_t              xs_fibt_2_compare;
191         __uint32_t              xs_fibt_2_insrec;
192         __uint32_t              xs_fibt_2_delrec;
193         __uint32_t              xs_fibt_2_newroot;
194         __uint32_t              xs_fibt_2_killroot;
195         __uint32_t              xs_fibt_2_increment;
196         __uint32_t              xs_fibt_2_decrement;
197         __uint32_t              xs_fibt_2_lshift;
198         __uint32_t              xs_fibt_2_rshift;
199         __uint32_t              xs_fibt_2_split;
200         __uint32_t              xs_fibt_2_join;
201         __uint32_t              xs_fibt_2_alloc;
202         __uint32_t              xs_fibt_2_free;
203         __uint32_t              xs_fibt_2_moves;
204 #define XFSSTAT_END_XQMSTAT             (XFSSTAT_END_FIBT_V2+6)
205         __uint32_t              xs_qm_dqreclaims;
206         __uint32_t              xs_qm_dqreclaim_misses;
207         __uint32_t              xs_qm_dquot_dups;
208         __uint32_t              xs_qm_dqcachemisses;
209         __uint32_t              xs_qm_dqcachehits;
210         __uint32_t              xs_qm_dqwants;
211 #define XFSSTAT_END_QM                  (XFSSTAT_END_XQMSTAT+2)
212         __uint32_t              xs_qm_dquot;
213         __uint32_t              xs_qm_dquot_unused;
214 /* Extra precision counters */
215         __uint64_t              xs_xstrat_bytes;
216         __uint64_t              xs_write_bytes;
217         __uint64_t              xs_read_bytes;
218 };
219
220 DECLARE_PER_CPU(struct xfsstats, xfsstats);
221
222 /*
223  * We don't disable preempt, not too worried about poking the
224  * wrong CPU's stat for now (also aggregated before reporting).
225  */
226 #define XFS_STATS_INC(v)        (per_cpu(xfsstats, current_cpu()).v++)
227 #define XFS_STATS_DEC(v)        (per_cpu(xfsstats, current_cpu()).v--)
228 #define XFS_STATS_ADD(v, inc)   (per_cpu(xfsstats, current_cpu()).v += (inc))
229
230 extern int xfs_init_procfs(void);
231 extern void xfs_cleanup_procfs(void);
232
233
234 #else   /* !CONFIG_PROC_FS */
235
236 # define XFS_STATS_INC(count)
237 # define XFS_STATS_DEC(count)
238 # define XFS_STATS_ADD(count, inc)
239
240 static inline int xfs_init_procfs(void)
241 {
242         return 0;
243 }
244
245 static inline void xfs_cleanup_procfs(void)
246 {
247 }
248
249 #endif  /* !CONFIG_PROC_FS */
250
251 #endif /* __XFS_STATS_H__ */