windows-des-stats-20050531
[openafs.git] / src / des / 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 /* Some Cheap statistics which should be shared with the rxkad definitions, but
11  * aren't.  The layout should match the layout in rxkad/rxkad.p.h. */
12
13 #ifndef OPENAFS_DES_STATS_H
14 #define OPENAFS_DES_STATS_H
15
16
17 /* this is an optimization for pthreads environments.  Instead of having global
18    rxkad statistics, make them thread-specific, and only perform aggregation on
19    the stats structures when necessary.  Furthermore, don't do any locking, and
20    live with the nearly accurate aggregation (e.g. you might miss a few increments,
21    but the resulting aggregation should be almost correct). */
22
23 #ifdef AFS_PTHREAD_ENV
24 typedef struct rxkad_stats_t {
25 #else
26 struct rxkad_stats {
27 #endif
28     afs_uint32 connections[3];  /* client side only */
29     afs_uint32 destroyObject;   /* client security objects */
30     afs_uint32 destroyClient;   /* client connections */
31     afs_uint32 destroyUnused;   /* unused server conn */
32     afs_uint32 destroyUnauth;   /* unauthenticated server conn */
33     afs_uint32 destroyConn[3];  /* server conn per level */
34     afs_uint32 expired;         /* server packets rejected */
35     afs_uint32 challengesSent;  /* server challenges sent */
36     afs_uint32 challenges[3];   /* challenges seen by client */
37     afs_uint32 responses[3];    /* responses seen by server */
38     afs_uint32 preparePackets[6];
39     afs_uint32 checkPackets[6];
40     afs_uint32 bytesEncrypted[2];       /* index just by type */
41     afs_uint32 bytesDecrypted[2];
42     afs_uint32 fc_encrypts[2];  /* DECRYPT==0, ENCRYPT==1 */
43     afs_uint32 fc_key_scheds;   /* key schedule creations */
44     afs_uint32 des_encrypts[2]; /* DECRYPT==0, ENCRYPT==1 */
45     afs_uint32 des_key_scheds;  /* key schedule creations */
46     afs_uint32 des_randoms;     /* random blocks generated */
47     afs_uint32 clientObjects;
48     afs_uint32 serverObjects;
49     long spares[8];
50 #ifdef AFS_PTHREAD_ENV
51     struct rxkad_stats_t * next;
52     struct rxkad_stats_t * prev;
53 } rxkad_stats_t;                        /* put these here for convenience */
54 #else /* AFS_PTHREAD_ENV */
55 };
56 #ifdef AFS_NT40_ENV
57 struct rxkad_stats rxkad_stats;         /* put this here for convenience */
58 #endif 
59 #endif /* AFS_PTHREAD_ENV */
60
61
62 #ifdef AFS_PTHREAD_ENV
63 struct rxkad_global_stats {
64     rxkad_stats_t * first;
65     rxkad_stats_t * last;
66 };
67
68 #include <pthread.h>
69 #include <assert.h>
70 extern pthread_mutex_t rxkad_global_stats_lock;
71 extern pthread_key_t rxkad_stats_key;
72
73 extern void rxkad_global_stats_init();
74 extern rxkad_stats_t * rxkad_thr_stats_init();
75 extern int rxkad_stats_agg(rxkad_stats_t *);
76
77 #ifndef BEGIN
78 #define BEGIN do {
79 #define END   } while(0)
80 #endif
81 #define RXKAD_GLOBAL_STATS_LOCK assert(pthread_mutex_lock(&rxkad_global_stats_lock)==0)
82 #define RXKAD_GLOBAL_STATS_UNLOCK assert(pthread_mutex_unlock(&rxkad_global_stats_lock)==0)
83 #define GET_RXKAD_STATS(stats) rxkad_stats_agg(stats)
84 #define GET_RXKAD_THR_STATS(rxkad_stats) \
85     BEGIN \
86         (rxkad_stats) = ((rxkad_stats_t*)pthread_getspecific(rxkad_stats_key)); \
87         if ((rxkad_stats) == NULL) { \
88             assert(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \
89         } \
90     END
91 #define INC_RXKAD_STATS(stats_elem) \
92     BEGIN \
93         rxkad_stats_t * rxkad_stats; \
94         rxkad_stats = ((rxkad_stats_t*)pthread_getspecific(rxkad_stats_key)); \
95         if (rxkad_stats == NULL) { \
96             assert(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \
97         } \
98         rxkad_stats->stats_elem++; \
99     END
100 #define DEC_RXKAD_STATS(stats_elem) \
101     BEGIN \
102         rxkad_stats_t * rxkad_stats; \
103         rxkad_stats = ((rxkad_stats_t*)pthread_getspecific(rxkad_stats_key)); \
104         if (rxkad_stats == NULL) { \
105             assert(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \
106         } \
107         rxkad_stats->stats_elem--; \
108     END
109 #define ADD_RXKAD_STATS(stats_elem, inc_value) \
110     BEGIN \
111         rxkad_stats_t * rxkad_stats; \
112         rxkad_stats = ((rxkad_stats_t*)pthread_getspecific(rxkad_stats_key)); \
113         if (rxkad_stats == NULL) { \
114             assert(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \
115         } \
116         rxkad_stats->stats_elem += inc_value; \
117     END
118 #define SUB_RXKAD_STATS(stats_elem, dec_value) \
119     BEGIN \
120         rxkad_stats_t * rxkad_stats; \
121         rxkad_stats = ((rxkad_stats_t*)pthread_getspecific(rxkad_stats_key)); \
122         if (rxkad_stats == NULL) { \
123             assert(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \
124         } \
125         rxkad_stats->stats_elem -= dec_value; \
126     END
127 #else /* AFS_PTHREAD_ENV */
128 #define INC_RXKAD_STATS(stats_elem) rxkad_stats.stats_elem++
129 #define DEC_RXKAD_STATS(stats_elem) rxkad_stats.stats_elem--
130 #define ADD_RXKAD_STATS(stats_elem, inc_value) rxkad_stats.stats_elem += (inc_value)
131 #define SUB_RXKAD_STATS(stats_elem, dec_value) rxkad_stats.stats_elem -= (dec_value)
132 #define GET_RXKAD_STATS(stats) memcpy((stats), &rxkad_stats, sizeof(rxkad_stats))
133 #endif /* AFS_PTHREAD_ENV */
134
135
136 #if defined(AFS_NT40_ENV) && defined(AFS_PTHREAD_ENV)
137 #ifndef RXKAD_STATS_DECLSPEC
138 #define RXKAD_STATS_DECLSPEC __declspec(dllimport) extern
139 #endif
140 #else
141 #define RXKAD_STATS_DECLSPEC extern
142 #endif
143
144 #ifdef AFS_PTHREAD_ENV
145 RXKAD_STATS_DECLSPEC struct rxkad_global_stats rxkad_global_stats;
146 #else /* AFS_PTHREAD_ENV */
147 RXKAD_STATS_DECLSPEC struct rxkad_stats rxkad_stats;
148 #endif
149
150
151 #endif /* OPENAFS_DES_STATS_H */