blob: 34d704f703d25e07ab8af65f9ed0205a9ab6e655 [file] [log] [blame]
Dave Chinner0b61f8a2018-06-05 19:42:14 -07001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Nathan Scott7b718762005-11-02 14:58:39 +11003 * Copyright (c) 2000,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6#ifndef __XFS_STATS_H__
7#define __XFS_STATS_H__
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10#include <linux/percpu.h>
11
12/*
Dave Chinner11ef38a2016-12-05 14:38:58 +110013 * 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 */
20enum {
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 Torvalds1da177e2005-04-16 15:20:36 -070041 * XFS global statistics
42 */
Dave Chinner11ef38a2016-12-05 14:38:58 +110043struct __xfsstats {
Darrick J. Wongc8ce5402017-06-16 11:00:05 -070044 uint32_t xs_allocx;
45 uint32_t xs_allocb;
46 uint32_t xs_freex;
47 uint32_t xs_freeb;
Darrick J. Wongc8ce5402017-06-16 11:00:05 -070048 uint32_t xs_abt_lookup;
49 uint32_t xs_abt_compare;
50 uint32_t xs_abt_insrec;
51 uint32_t xs_abt_delrec;
Darrick J. Wongc8ce5402017-06-16 11:00:05 -070052 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;
Darrick J. Wongc8ce5402017-06-16 11:00:05 -070059 uint32_t xs_bmbt_lookup;
60 uint32_t xs_bmbt_compare;
61 uint32_t xs_bmbt_insrec;
62 uint32_t xs_bmbt_delrec;
Darrick J. Wongc8ce5402017-06-16 11:00:05 -070063 uint32_t xs_dir_lookup;
64 uint32_t xs_dir_create;
65 uint32_t xs_dir_remove;
66 uint32_t xs_dir_getdents;
Darrick J. Wongc8ce5402017-06-16 11:00:05 -070067 uint32_t xs_trans_sync;
68 uint32_t xs_trans_async;
69 uint32_t xs_trans_empty;
Darrick J. Wongc8ce5402017-06-16 11:00:05 -070070 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;
Darrick J. Wongc8ce5402017-06-16 11:00:05 -070077 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;
Darrick J. Wongc8ce5402017-06-16 11:00:05 -070082 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;
Darrick J. Wongc8ce5402017-06-16 11:00:05 -070092 uint32_t xs_xstrat_quick;
93 uint32_t xs_xstrat_split;
Darrick J. Wongc8ce5402017-06-16 11:00:05 -070094 uint32_t xs_write_calls;
95 uint32_t xs_read_calls;
Darrick J. Wongc8ce5402017-06-16 11:00:05 -070096 uint32_t xs_attr_get;
97 uint32_t xs_attr_set;
98 uint32_t xs_attr_remove;
99 uint32_t xs_attr_list;
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700100 uint32_t xs_iflush_count;
101 uint32_t xs_icluster_flushcnt;
102 uint32_t xs_icluster_flushinode;
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700103 uint32_t vn_active; /* # vnodes not on free lists */
104 uint32_t vn_alloc; /* # times vn_alloc called */
105 uint32_t vn_get; /* # times vn_get called */
106 uint32_t vn_hold; /* # times vn_hold called */
107 uint32_t vn_rele; /* # times vn_rele called */
108 uint32_t vn_reclaim; /* # times vn_reclaim called */
109 uint32_t vn_remove; /* # times vn_remove called */
110 uint32_t vn_free; /* # times vn_free called */
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700111 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;
David Chinner854929f2008-10-30 16:55:03 +1100120/* Version 2 btree counters */
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700121 uint32_t xs_abtb_2[__XBTS_MAX];
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700122 uint32_t xs_abtc_2[__XBTS_MAX];
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700123 uint32_t xs_bmbt_2[__XBTS_MAX];
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700124 uint32_t xs_ibt_2[__XBTS_MAX];
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700125 uint32_t xs_fibt_2[__XBTS_MAX];
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700126 uint32_t xs_rmap_2[__XBTS_MAX];
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700127 uint32_t xs_refcbt_2[__XBTS_MAX];
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700128 uint32_t xs_qm_dqreclaims;
129 uint32_t xs_qm_dqreclaim_misses;
130 uint32_t xs_qm_dquot_dups;
131 uint32_t xs_qm_dqcachemisses;
132 uint32_t xs_qm_dqcachehits;
133 uint32_t xs_qm_dqwants;
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700134 uint32_t xs_qm_dquot;
135 uint32_t xs_qm_dquot_unused;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136/* Extra precision counters */
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700137 uint64_t xs_xstrat_bytes;
138 uint64_t xs_write_bytes;
139 uint64_t xs_read_bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140};
141
Carlos Maiolino26ca3902018-10-18 17:21:39 +1100142#define xfsstats_offset(f) (offsetof(struct __xfsstats, f)/sizeof(uint32_t))
143
Dave Chinner11ef38a2016-12-05 14:38:58 +1100144struct xfsstats {
145 union {
146 struct __xfsstats s;
Carlos Maiolino26ca3902018-10-18 17:21:39 +1100147 uint32_t a[xfsstats_offset(xs_qm_dquot)];
Dave Chinner11ef38a2016-12-05 14:38:58 +1100148 };
149};
150
151/*
152 * simple wrapper for getting the array index of s struct member offset
153 */
154#define XFS_STATS_CALC_INDEX(member) \
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700155 (offsetof(struct __xfsstats, member) / (int)sizeof(uint32_t))
Dave Chinner11ef38a2016-12-05 14:38:58 +1100156
157
Bill O'Donnell80529c42015-10-12 05:19:45 +1100158int xfs_stats_format(struct xfsstats __percpu *stats, char *buf);
159void xfs_stats_clearall(struct xfsstats __percpu *stats);
160extern struct xstats xfsstats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Bill O'Donnellff6d6af2015-10-12 18:21:22 +1100162#define XFS_STATS_INC(mp, v) \
163do { \
Dave Chinner11ef38a2016-12-05 14:38:58 +1100164 per_cpu_ptr(xfsstats.xs_stats, current_cpu())->s.v++; \
165 per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->s.v++; \
Bill O'Donnellff6d6af2015-10-12 18:21:22 +1100166} while (0)
Bill O'Donnell80529c42015-10-12 05:19:45 +1100167
Bill O'Donnellff6d6af2015-10-12 18:21:22 +1100168#define XFS_STATS_DEC(mp, v) \
169do { \
Dave Chinner11ef38a2016-12-05 14:38:58 +1100170 per_cpu_ptr(xfsstats.xs_stats, current_cpu())->s.v--; \
171 per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->s.v--; \
Bill O'Donnellff6d6af2015-10-12 18:21:22 +1100172} while (0)
Bill O'Donnell80529c42015-10-12 05:19:45 +1100173
Bill O'Donnellff6d6af2015-10-12 18:21:22 +1100174#define XFS_STATS_ADD(mp, v, inc) \
175do { \
Dave Chinner11ef38a2016-12-05 14:38:58 +1100176 per_cpu_ptr(xfsstats.xs_stats, current_cpu())->s.v += (inc); \
177 per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->s.v += (inc); \
178} while (0)
179
180#define XFS_STATS_INC_OFF(mp, off) \
181do { \
182 per_cpu_ptr(xfsstats.xs_stats, current_cpu())->a[off]++; \
183 per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->a[off]++; \
184} while (0)
185
186#define XFS_STATS_DEC_OFF(mp, off) \
187do { \
188 per_cpu_ptr(xfsstats.xs_stats, current_cpu())->a[off]; \
189 per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->a[off]; \
190} while (0)
191
192#define XFS_STATS_ADD_OFF(mp, off, inc) \
193do { \
194 per_cpu_ptr(xfsstats.xs_stats, current_cpu())->a[off] += (inc); \
195 per_cpu_ptr(mp->m_stats.xs_stats, current_cpu())->a[off] += (inc); \
Bill O'Donnellff6d6af2015-10-12 18:21:22 +1100196} while (0)
197
198#if defined(CONFIG_PROC_FS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Christoph Hellwig9f8868f2008-07-18 17:11:46 +1000200extern int xfs_init_procfs(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201extern void xfs_cleanup_procfs(void);
202
203
204#else /* !CONFIG_PROC_FS */
205
Christoph Hellwig9f8868f2008-07-18 17:11:46 +1000206static inline int xfs_init_procfs(void)
207{
Christoph Hellwig766b0922008-07-18 17:12:50 +1000208 return 0;
209}
210
Christoph Hellwig9f8868f2008-07-18 17:11:46 +1000211static inline void xfs_cleanup_procfs(void)
212{
Christoph Hellwig766b0922008-07-18 17:12:50 +1000213}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215#endif /* !CONFIG_PROC_FS */
216
217#endif /* __XFS_STATS_H__ */