viced: Set HWHO_INPROGRESS in CheckHost_r
[openafs.git] / src / viced / fs_stats.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #ifndef __fs_stats_h
11 #define __fs_stats_h  1
12
13 /*------------------------------------------------------------------------
14  * fs_stats.h
15  *
16  * Definitions supporting call and performance information gathering for
17  * the FileServer xstat (extended statistics) interface.
18  *
19  *------------------------------------------------------------------------*/
20
21
22 #include <afs/param.h>          /*System configuration info */
23
24 /*
25  * Decide if we're keeping detailed File Server stats.
26  */
27 #define FS_STATS_DETAILED 1
28
29 /*
30  * Performance numbers.
31  */
32 struct afs_PerfStats {
33     afs_int32 numPerfCalls;     /*# of performance calls rcvd */
34
35     /*
36      * Vnode cache section.
37      */
38     afs_int32 vcache_L_Entries; /*Num entries in LARGE vnode cache */
39     afs_int32 vcache_L_Allocs;  /*# allocs, large */
40     afs_int32 vcache_L_Gets;    /*# gets, large */
41     afs_int32 vcache_L_Reads;   /*# reads, large */
42     afs_int32 vcache_L_Writes;  /*# writes, large */
43
44     afs_int32 vcache_S_Entries; /*Num entries in SMALL vnode cache */
45     afs_int32 vcache_S_Allocs;  /*# allocs, small */
46     afs_int32 vcache_S_Gets;    /*# gets, small */
47     afs_int32 vcache_S_Reads;   /*# reads, small */
48     afs_int32 vcache_S_Writes;  /*# writes, small */
49
50     afs_int32 vcache_H_Entries; /*Num entries in HEADER vnode cache */
51     afs_int32 vcache_H_Gets;    /*# gets */
52     afs_int32 vcache_H_Replacements;    /*# replacements */
53
54     /*
55      * Directory package section.
56      */
57     afs_int32 dir_Buffers;      /*Num buffers in use */
58     afs_int32 dir_Calls;        /*Num read calls made */
59     afs_int32 dir_IOs;          /*I/O ops performed */
60
61     /*
62      * Rx section.  These numbers represent the contents of the
63      * rx_stats structure maintained by Rx.  All other Rx info,
64      * including struct rx_debug and connection stuff is available
65      * via the rxdebug interface.
66      */
67     afs_int32 rx_packetRequests;        /*Packet alloc requests */
68     afs_int32 rx_noPackets_RcvClass;    /*Failed pkt requests, receives */
69     afs_int32 rx_noPackets_SendClass;   /*Ditto, sends */
70     afs_int32 rx_noPackets_SpecialClass;        /*Ditto, specials */
71     afs_int32 rx_socketGreedy;  /*Did SO_GREEDY succeed? */
72     afs_int32 rx_bogusPacketOnRead;     /*Short pkts rcvd */
73     afs_int32 rx_bogusHost;     /*Host addr from bogus pkts */
74     afs_int32 rx_noPacketOnRead;        /*Read pkts w/no packet there */
75     afs_int32 rx_noPacketBuffersOnRead; /*Pkts dropped from buff shortage */
76     afs_int32 rx_selects;       /*Selects waiting on pkt or timeout */
77     afs_int32 rx_sendSelects;   /*Selects forced upon sends */
78     afs_int32 rx_packetsRead_RcvClass;  /*Packets read, rcv class */
79     afs_int32 rx_packetsRead_SendClass; /*Packets read, send class */
80     afs_int32 rx_packetsRead_SpecialClass;      /*Packets read, special class */
81     afs_int32 rx_dataPacketsRead;       /*Uniq data packets read off wire */
82     afs_int32 rx_ackPacketsRead;        /*Ack packets read */
83     afs_int32 rx_dupPacketsRead;        /*Duplicate data packets read */
84     afs_int32 rx_spuriousPacketsRead;   /*Inappropriate packets read */
85     afs_int32 rx_packetsSent_RcvClass;  /*Packets sent, rcv class */
86     afs_int32 rx_packetsSent_SendClass; /*Packets sent, send class */
87     afs_int32 rx_packetsSent_SpecialClass;      /*Packets sent, special class */
88     afs_int32 rx_ackPacketsSent;        /*Ack packets sent */
89     afs_int32 rx_pingPacketsSent;       /*Ping packets sent */
90     afs_int32 rx_abortPacketsSent;      /*Abort packets sent */
91     afs_int32 rx_busyPacketsSent;       /*Busy packets sent */
92     afs_int32 rx_dataPacketsSent;       /*Unique data packets sent */
93     afs_int32 rx_dataPacketsReSent;     /*Retransmissions sent */
94     afs_int32 rx_dataPacketsPushed;     /*Retransmissions pushed by NACK */
95     afs_int32 rx_ignoreAckedPacket;     /*Packets w/acked flag on rxi_Start */
96     afs_int32 rx_totalRtt_Sec;  /*Ttl round trip time, secs */
97     afs_int32 rx_totalRtt_Usec; /*Ttl round trip time, usecs */
98     afs_int32 rx_minRtt_Sec;    /*Min round trip time, secs */
99     afs_int32 rx_minRtt_Usec;   /*Min round trip time, usecs */
100     afs_int32 rx_maxRtt_Sec;    /*Max round trip time, secs */
101     afs_int32 rx_maxRtt_Usec;   /*Max round trip time, usecs */
102     afs_int32 rx_nRttSamples;   /*Round trip samples */
103     afs_int32 rx_nServerConns;  /*Ttl server connections */
104     afs_int32 rx_nClientConns;  /*Ttl client connections */
105     afs_int32 rx_nPeerStructs;  /*Ttl peer structures */
106     afs_int32 rx_nCallStructs;  /*Ttl call structures */
107     afs_int32 rx_nFreeCallStructs;      /*Ttl free call structures */
108
109     /*
110      * Host module fields.
111      */
112     afs_int32 host_NumHostEntries;      /*Number of host entries */
113     afs_int32 host_HostBlocks;  /*Blocks in use for hosts */
114     afs_int32 host_NonDeletedHosts;     /*Non-deleted hosts */
115     afs_int32 host_HostsInSameNetOrSubnet;      /*" in same [sub]net as server */
116     afs_int32 host_HostsInDiffSubnet;   /*" in different subnet as server */
117     afs_int32 host_HostsInDiffNetwork;  /*" in different network as server */
118     afs_int32 host_NumClients;  /*Number of client entries */
119     afs_int32 host_ClientBlocks;        /*Blocks in use for clients */
120
121     /*
122      * Host systype
123      */
124     afs_int32 sysname_ID;       /*Unique hardware/OS identifier */
125
126     afs_int32 rx_nBusies;       /*Ttl VBUSYs sent to shed load */
127     afs_int32 fs_nBusies;       /*Ttl VBUSYs sent during restart/vol clone */
128
129     /*
130      * Can't count this as an RPC because it breaks the data structure
131      */
132     afs_int32 fs_nGetCaps;      /* Number of GetCapabilities calls */
133     /*
134      * Spares
135      */
136     afs_int32 spare[28];
137 };
138
139 #if FS_STATS_DETAILED
140 /*
141  * Assign each of the File Server's RPC interface routines an index.
142  */
143 #define FS_STATS_RPCIDX_FETCHDATA        0
144 #define FS_STATS_RPCIDX_FETCHACL         1
145 #define FS_STATS_RPCIDX_FETCHSTATUS      2
146 #define FS_STATS_RPCIDX_STOREDATA        3
147 #define FS_STATS_RPCIDX_STOREACL         4
148 #define FS_STATS_RPCIDX_STORESTATUS      5
149 #define FS_STATS_RPCIDX_REMOVEFILE       6
150 #define FS_STATS_RPCIDX_CREATEFILE       7
151 #define FS_STATS_RPCIDX_RENAME           8
152 #define FS_STATS_RPCIDX_SYMLINK          9
153 #define FS_STATS_RPCIDX_LINK            10
154 #define FS_STATS_RPCIDX_MAKEDIR         11
155 #define FS_STATS_RPCIDX_REMOVEDIR       12
156 #define FS_STATS_RPCIDX_SETLOCK         13
157 #define FS_STATS_RPCIDX_EXTENDLOCK      14
158 #define FS_STATS_RPCIDX_RELEASELOCK     15
159 #define FS_STATS_RPCIDX_GETSTATISTICS   16
160 #define FS_STATS_RPCIDX_GIVEUPCALLBACKS 17
161 #define FS_STATS_RPCIDX_GETVOLUMEINFO   18
162 #define FS_STATS_RPCIDX_GETVOLUMESTATUS 19
163 #define FS_STATS_RPCIDX_SETVOLUMESTATUS 20
164 #define FS_STATS_RPCIDX_GETROOTVOLUME   21
165 #define FS_STATS_RPCIDX_CHECKTOKEN      22
166 #define FS_STATS_RPCIDX_GETTIME         23
167 #define FS_STATS_RPCIDX_NGETVOLUMEINFO  24
168 #define FS_STATS_RPCIDX_BULKSTATUS      25
169 #define FS_STATS_RPCIDX_XSTATSVERSION   26
170 #define FS_STATS_RPCIDX_GETXSTATS       27
171
172 #define FS_STATS_NUM_RPC_OPS            28
173
174 /*
175  * Assign an index to each of the File Server's RPC interface routines
176  * that transfer any data to speak of.
177  */
178 #define FS_STATS_XFERIDX_FETCHDATA       0
179 #define FS_STATS_XFERIDX_STOREDATA       1
180
181 #define FS_STATS_NUM_XFER_OPS            2
182
183 /*
184  * Record to track timing numbers for each File Server RPC operation.
185  */
186 struct fs_stats_opTimingData {
187     afs_int32 numOps;           /*Number of operations executed */
188     afs_int32 numSuccesses;     /*Number of successful ops */
189     struct timeval sumTime;     /*Sum of sample timings */
190     struct timeval sqrTime;     /*Sum of squares of sample timings */
191     struct timeval minTime;     /*Minimum timing value observed */
192     struct timeval maxTime;     /*Minimum timing value observed */
193 };
194
195 /*
196  * We discriminate byte size transfers into this many buckets.
197  */
198 #define FS_STATS_NUM_XFER_BUCKETS       9
199
200 #define FS_STATS_MAXBYTES_BUCKET0     128
201 #define FS_STATS_MAXBYTES_BUCKET1    1024
202 #define FS_STATS_MAXBYTES_BUCKET2    8192
203 #define FS_STATS_MAXBYTES_BUCKET3   16384
204 #define FS_STATS_MAXBYTES_BUCKET4   32768
205 #define FS_STATS_MAXBYTES_BUCKET5  131072
206 #define FS_STATS_MAXBYTES_BUCKET6  524288
207 #define FS_STATS_MAXBYTES_BUCKET7 1048576
208
209
210 /*
211  * Record to track timings and byte sizes for data transfers.
212  */
213 struct fs_stats_xferData {
214     afs_int32 numXfers;         /*Number of xfers */
215     afs_int32 numSuccesses;     /*Number of successful xfers */
216     struct timeval sumTime;     /*Sum of timing values */
217     struct timeval sqrTime;     /*Sum of squares of timing values */
218     struct timeval minTime;     /*Minimum xfer time recorded */
219     struct timeval maxTime;     /*Maximum xfer time recorded */
220     afs_int32 sumBytes;         /*Sum of bytes transferred */
221     afs_int32 minBytes;         /*Minimum value observed */
222     afs_int32 maxBytes;         /*Maximum value observed */
223     afs_int32 count[FS_STATS_NUM_XFER_BUCKETS]; /*Tally for each range of bytes */
224 };
225
226 /*
227  * Macros to operate on time values.
228  *
229  * fs_stats_TimeLessThan(t1, t2)     Non-zero if t1 is less than t2
230  * fs_stats_TimeGreaterThan(t1, t2)  Non-zero if t1 is greater than t2
231  * fs_stats_GetDiff(t3, t1, t2)      Set t3 to the difference between
232  *                                      t1 and t2 (t1 is less than or
233  *                                      equal to t2).
234  * fs_stats_AddTo(t1, t2)            Add t2 to t1
235  * fs_stats_TimeAssign(t1, t2)       Assign time t2 to t1
236  * afs_stats_SquareAddTo(t1,t2)      Add square of t2 to t1
237  */
238 #define fs_stats_TimeLessThan(t1, t2)        \
239             ((t1.tv_sec  < t2.tv_sec)  ? 1 : \
240              (t1.tv_sec  > t2.tv_sec)  ? 0 : \
241              (t1.tv_usec < t2.tv_usec) ? 1 : \
242              0)
243
244 #define fs_stats_TimeGreaterThan(t1, t2)     \
245             ((t1.tv_sec  > t2.tv_sec)  ? 1 : \
246              (t1.tv_sec  < t2.tv_sec)  ? 0 : \
247              (t1.tv_usec > t2.tv_usec) ? 1 : \
248              0)
249
250 #define fs_stats_GetDiff(t3, t1, t2)                            \
251 {                                                               \
252     /*                                                          \
253      * If the microseconds of the later time are smaller than   \
254      * the earlier time, set up for proper subtraction (doing   \
255      * the carry).                                              \
256      */                                                         \
257     if (t2.tv_usec < t1.tv_usec) {                              \
258         t2.tv_usec += 1000000;                                  \
259         t2.tv_sec -= 1;                                         \
260     }                                                           \
261     t3.tv_sec  = t2.tv_sec  - t1.tv_sec;                        \
262     t3.tv_usec = t2.tv_usec - t1.tv_usec;                       \
263 }
264
265 #define fs_stats_AddTo(t1, t2)    \
266 {                                 \
267     t1.tv_sec  += t2.tv_sec;      \
268     t1.tv_usec += t2.tv_usec;     \
269     if (t1.tv_usec > 1000000) {   \
270         t1.tv_usec -= 1000000;    \
271         t1.tv_sec++;              \
272     }                             \
273 }
274
275 #define fs_stats_TimeAssign(t1, t2)     \
276 {                                       \
277     t1.tv_sec = t2.tv_sec;              \
278     t1.tv_usec = t2.tv_usec;            \
279 }
280
281 #define fs_stats_SquareAddTo(t1, t2)                         \
282 {                                                            \
283     if (t2.tv_sec > 0)                                       \
284       {                                                      \
285        t1.tv_sec += (int) (t2.tv_sec * t2.tv_sec                    \
286                     + (0.000002 * t2.tv_sec) * t2.tv_usec) ;  \
287        t1.tv_usec += (int) ((2 * t2.tv_sec * t2.tv_usec) % 1000000  \
288                     + (0.000001 * t2.tv_usec) * t2.tv_usec);  \
289       }                                                      \
290     else                                                     \
291       {                                                      \
292        t1.tv_usec += (int) ((0.000001 * t2.tv_usec) * t2.tv_usec);   \
293       }                                                      \
294     if (t1.tv_usec > 1000000) {                              \
295         t1.tv_usec -= 1000000;                               \
296         t1.tv_sec++;                                         \
297     }                                                        \
298 }
299
300 /*
301  * This is the detailed performance data collection for the File Server.
302  */
303 struct fs_stats_DetailedStats {
304     struct timeval epoch;       /*Time when data collection began */
305     struct fs_stats_opTimingData
306       rpcOpTimes[FS_STATS_NUM_RPC_OPS]; /*Individual RPC operation timings */
307     struct fs_stats_xferData
308       xferOpTimes[FS_STATS_NUM_XFER_OPS];       /*Byte info for certain ops */
309 };
310
311 /*
312  * This is all of the performance data, both overall and detailed.
313  */
314 struct fs_stats_FullPerfStats {
315     struct afs_PerfStats overall;
316     struct fs_stats_DetailedStats det;
317 };
318
319 /*
320  * This is the structure accessible by specifying the
321  * AFS_XSTATSCOLL_FULL_PERF_INFO collection to the xstat package.
322  */
323 extern struct fs_stats_FullPerfStats afs_FullPerfStats;
324 #endif /* FS_STATS_DETAILED */
325
326
327 /*
328  * This is the structure accessible by specifying the
329  * AFS_XSTATSCOLL_PERF_INFO collection to the xstat package.
330  */
331 extern struct afs_PerfStats afs_perfstats;
332
333 /*
334   * FileServer's name and IP address, both network byte order and
335   * host byte order.
336   */
337 extern char FS_HostName[];
338 extern afs_uint32 FS_HostAddr_NBO;
339 extern afs_uint32 FS_HostAddr_HBO;
340
341 #endif /* __fs_stats_h */