source: gpfs_3.1_ker2.6.20/lpp/mmfs/src/include/cxi/cxiVFSStats.h @ 195

Last change on this file since 195 was 16, checked in by rock, 17 years ago
File size: 11.7 KB
Line 
1/***************************************************************************
2 *
3 * Copyright (C) 2001 International Business Machines
4 * All rights reserved.
5 *
6 * This file is part of the GPFS mmfslinux kernel module.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 *  1. Redistributions of source code must retain the above copyright notice,
13 *     this list of conditions and the following disclaimer.
14 *  2. Redistributions in binary form must reproduce the above copyright
15 *     notice, this list of conditions and the following disclaimer in the
16 *     documentation and/or other materials provided with the distribution.
17 *  3. The name of the author may not be used to endorse or promote products
18 *     derived from this software without specific prior written
19 *     permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 *************************************************************************** */
33/* @(#)47       1.12  src/avs/fs/mmfs/ts/kernext/ibm-kxi/cxiVFSStats.h, mmfs, avs_rgpfs24, rgpfs240610b 1/12/05 11:14:56 */
34#ifndef _h_cxiVFSStats
35#define _h_cxiVFSStats
36
37/*
38 * Gather statistics for VFS operations:
39 *
40 * Usage:
41 *  - Placing an instance of the VFS_STAT_START macro at the begining
42 *    of a function and VFS_STAT_STOP macro at the end of a function
43 *    will keep a count of how many times the function is called as well
44 *    as the total amount of time spent in the function (elapsed time
45 *    between entering and leaving the function).
46 *  - Placing an instance of the VFS_INC macro inside a function will
47 *    update a call count, but not keep any time statistics.
48 *  - Use the command "mmfsadm vfsstats ..." to control and display
49 *    vfs statistics:
50 *       mmfsadm vfsstats enable    - turn on statistics gathering
51 *       mmfsadm vfsstats disable   - turn off statistics gathering
52 *       mmfsadm vfsstats reset     - reset all statistics counters
53 *       mmfsadm vfsstats show      - display statistics
54 *
55 */
56
57#include <cxiVFSStats-plat.h>
58
59/* Enumeration of all calls for which we keep vfs statistics.  Except as
60   noted, the enum value named xxxCall represents calls to the vnode or
61   vfs operation named xxx. */
62enum VFSStatItem
63{
64  // special value indicating statistics disabled
65  nullCall             = -1,
66
67  // vnode ops
68  accessCall           = 0,
69  closeCall            = 1,
70  createCall           = 2,
71  fclearCall           = 3,
72  fsyncCall            = 4,
73  fsync_rangeCall      = 5,
74  ftruncCall           = 6,
75  getattrCall          = 7,
76  linkCall             = 8,
77  lockctlCall          = 9,
78  lookupCall           = 10,
79  map_lloffCall        = 11,
80  mkdirCall            = 12,
81  mknodCall            = 13,
82  openCall             = 14,
83  readCall             = 15, // mmfs_rdwr with op == UIO_READ
84  writeCall            = 16, // mmfs_rdwr with op != UIO_READ
85  mmapReadCall         = 17, // mmap kproc read
86  mmapWriteCall        = 18, // mmap kproc write
87  readdirCall          = 19,
88  readlinkCall         = 20,
89  readpageCall         = 21,
90  removeCall           = 22,
91  renameCall           = 23,
92  rmdirCall            = 24,
93  setaclCall           = 25,
94  setattrCall          = 26,
95  symlinkCall          = 27,
96  unmapCall            = 28,
97  writepageCall        = 29,
98  tsfattrCall          = 30,
99  tsfsattrCall         = 31,
100  flockCall            = 32,
101  setxattrCall         = 33,
102  getxattrCall         = 34,
103  listxattrCall        = 35,
104  removexattrCall      = 36,
105  fsLocationCall       = 37,
106
107  //export ops
108  encode_fhCall        = 38,
109  decode_fhCall        = 39,
110  get_dentryCall       = 40,
111  get_parentCall       = 41,
112
113  // vfs ops
114  mountCall            = 42,
115  statfsCall           = 43,
116  syncCall             = 44,
117  vgetCall             = 45,
118
119  // other counters
120  startIOCall          = 46, // number of I/Os started
121  fastOpenCount        = 47, // no of mmfs_open calls that use fast open
122  fastCloseCount       = 48, // no of mmfs_close calls that use fast close
123  fastLookupCount      = 49, // no of mmfs_lookup calls that use fast lookup
124  fastReadCount        = 50, // no of mmfs_rdwr calls that use fast read
125  fastWriteCount       = 51, // no of mmfs_rdwr calls that use fast write
126  revalidateCount      = 52, // number of revalidate calls
127  nSyncWrites          = 53, // total number of synchronous write calls
128  nAvoidedFsyncs       = 54, // number of syncs avoided due to fsync coalescing
129  nYieldSyncWriters    = 55, // number of times yield in fsync coalescing worked
130
131  // histogram of numbers of coalesced fsyncs
132  nFSync_1             = 56, // These must be contiguous
133  nFSync_2             = 57,
134  nFSync_3             = 58,
135  nFSync_4             = 59,
136  nFSync_5             = 60,
137  nFSync_6             = 61,
138  nFSync_7             = 62,
139  nFSync_8             = 63,
140
141  // total number of stat items; add new items above!
142  nVFSStatItems = 64
143};
144
145#ifdef INCLUDE_VFSSTATITEMNAMESPP
146/* printable names for VFSStatItem enum values */
147const char *VFSStatItemNamesPP[] =
148{
149  "access",               // 0
150  "close",                // 1
151  "create",               // 2
152  "fclear",               // 3
153  "fsync",                // 4
154  "fsync_range",          // 5
155  "ftrunc",               // 6
156  "getattr",              // 7
157  "link",                 // 8
158  "lockctl",              // 9
159  "lookup",               // 10
160  "map_lloff",            // 11
161  "mkdir",                // 12
162  "mknod",                // 13
163  "open",                 // 14
164  "read",                 // 15
165  "write",                // 16
166  "mmapRead",             // 17
167  "mmapWrite",            // 18
168  "readdir",              // 19
169  "readlink",             // 20
170  "readpage",             // 21
171  "remove",               // 22
172  "rename",               // 23
173  "rmdir",                // 24
174  "setacl",               // 25
175  "setattr",              // 26
176  "symlink",              // 27
177  "unmap",                // 28
178  "writepage",            // 29
179  "tsfattr",              // 30
180  "tsfsattr",             // 31
181  "flock",                // 32
182  "setxattr",             // 33
183  "getxattr",             // 34
184  "listxattr",            // 35
185  "removexattr",          // 36
186  "NOT_USED",             // 37
187
188  //export ops
189  "encode_fh",            // 38
190  "decode_fh",            // 39
191  "get_dentry",           // 40
192  "get_parent",           // 41
193
194  // vfs ops
195  "mount",                // 42
196  "statfs",               // 43
197  "sync",                 // 44
198  "vget",                 // 45
199
200  // other counters
201  "startIO",              // 46
202  "fastOpen",             // 47
203  "fastClose",            // 48
204  "fastLookup",           // 49
205  "fastRead",             // 40
206  "fastWrite",            // 51
207  "revalidate",           // 52
208  "nSyncWrites",          // 53
209  "nAvoidedFsyncs",       // 54
210  "nYieldSyncWriters",    // 55
211
212  // histogram of number of coalesced fsyncs
213  "coalesce fsync 1",     // 56
214  "coalesce fsync 2",     // 57
215  "coalesce fsync 3",     // 58
216  "coalesce fsync 4",     // 69
217  "coalesce fsync 5",     // 60
218  "coalesce fsync 6",     // 61
219  "coalesce fsync 7",     // 62
220  "coalesce fsync >= 8",  // 63
221};
222#else
223extern const char *VFSStatItemNamesPP[];
224#endif
225
226/* Statistics about a vfs call */
227typedef struct VFSStatData
228{
229  UInt32 cnt;                // total no of calls
230  cxiTimeStruc_t totalTime;  // total amount of time in call
231} VFSStatData_t;
232
233
234typedef struct VFSStats
235{
236  /* Statistics updated by kernel operations.  These are always updated by
237     using the VFS_STAT_START(xxxCall) and VFS_STAT_STOP macro pair, where
238     xxxCall is one of the enum VFSStatItem values.  If NO_VFS_STATS is
239     defined, the VFS_STAT macro will not generate any code. */
240  VFSStatData_t data[nVFSStatItems];
241
242  /* Flag indicating whether statistic gathering is currently enabled.
243     Use enable/disable methods to set or clear this flag. */
244  Boolean enabled;
245
246  /* Time period over which statistics were gathered:
247     startTime is the absolute time at which statistic gathering were last
248     started or reset by a call to enable() or reset(), and endTime is the
249     absolute time at which statistic gathering was last disabled.  If still
250     enabled, endTime will be zero. */
251  cxiTimeStruc_t startTime;  // absolute time in nanoseconds
252  cxiTimeStruc_t endTime;    // absolute time in nanoseconds
253
254} VFSStats_t;
255
256/* Enable/disable statistic gathering.  Set or clears the enabled flag and
257   updates startTime/endTime values accordingly.  The reset() method resets
258   all statistics data but leaves the enabled flag unchanged. */
259EXTERNC void VFSStats_enable(VFSStats_t *objPtr);
260EXTERNC void VFSStats_disable(VFSStats_t *objPtr);
261EXTERNC void VFSStats_reset(VFSStats_t *objPtr);
262
263/* Kernel extension interface to enable, disable, reset, and/or retrieve vfs
264   statistics, as indicated by the 'cmd' parameter (see #define's below).
265   The 'bufP' parameter is used to return statistics to the caller. */
266
267EXTERNC int kxVFSStatCtl(int cmd, void *bufP, int bufSize);
268
269#define VSTAT_ENABLE  0x01  // enable statistics gathering
270#define VSTAT_DISABLE 0x02  // disable statistics gathering
271#define VSTAT_RESET   0x04  // reset statistics
272#define VSTAT_GET     0x08  // copy statistics from kernel to bufP in user
273                            //   space; bufSize must be >= sizeof(VFSStats)
274
275#ifdef _KERNEL
276
277/* Instance of VFSStats class in the kernel */
278#ifdef DEFINE_VFSSTATS_GBL_VARS
279VFSStats_t vfsStats;
280#else
281extern VFSStats_t vfsStats;
282#endif
283
284/* Class to update vfs statistics on entering and exiting a vfs or vnode op.
285   If statistic gathering is enabled, the VFSStatPoint constructor will record
286   the current time; the destructor will calculate how much time has elapsed
287   since the constructor was called and update VFSStats accordingly.  The
288   intended use is that each function for which statistics are to be gathered
289   will have a variable of type VFSStatPoint declared at the very top of
290   the function (using the VFS_STAT_START macro defined below).  This way the
291   VFSStatPoint constructor will be called when the function is entered and
292   the destructor will be called before returning from the function
293   using the VFS_STAT_STOP macro. */
294typedef struct VFSStatPoint
295{
296  enum VFSStatItem statItem;
297  cxiTimeStruc_t beginTime;
298} VFSStatPoint_t;
299
300/* OS dependent functions in implementation layer */
301EXTERNC void VFSStatPoint_begin(VFSStatPoint_t *objPtr, enum VFSStatItem i);
302EXTERNC void VFSStatPoint_end(VFSStatPoint_t *objPtr);
303
304/* Psuedo constructor and destructor.  */
305static inline void VFSStatPoint_create(VFSStatPoint_t *objPtr, enum VFSStatItem i)
306{ if (vfsStats.enabled)
307    VFSStatPoint_begin(objPtr, i);
308  else objPtr->statItem = nullCall;
309}
310static inline void VFSStatPoint_destroy(VFSStatPoint_t *objPtr)
311{ if (vfsStats.enabled)
312    VFSStatPoint_end(objPtr);
313}
314
315#ifdef NO_VFS_STATS
316#define VFS_STAT_START(i) NOOP
317#define VFS_STAT_STOP NOOP
318#define VFS_INC(i)  NOOP
319#else
320#define VFS_STAT_START(i) VFSStatPoint_t vsp; VFSStatPoint_create(&vsp,i);
321#define VFS_STAT_STOP VFSStatPoint_destroy(&vsp);
322#define VFS_INC(i)  if (vfsStats.enabled) vfsStats.data[i].cnt++; else NOOP
323#endif
324
325#endif // _KERNEL
326
327#endif // _h_cxiVFSStats
Note: See TracBrowser for help on using the repository browser.