78dfc77badd23ce3c10471ea73ddcb5a183bb138
[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 #endif /* AFS_PTHREAD_ENV */
57
58
59 #ifdef AFS_PTHREAD_ENV
60 struct rxkad_global_stats {
61     rxkad_stats_t * first;
62     rxkad_stats_t * last;
63 };
64
65 #include <pthread.h>
66 #include <assert.h>
67 extern pthread_mutex_t rxkad_global_stats_lock;
68 extern pthread_key_t rxkad_stats_key;
69
70 extern void rxkad_global_stats_init();
71 extern rxkad_stats_t * rxkad_thr_stats_init();
72 extern int rxkad_stats_agg(rxkad_stats_t *);
73
74 #ifndef BEGIN
75 #define BEGIN do {
76 #define END   } while(0)
77 #endif
78 #define RXKAD_GLOBAL_STATS_LOCK assert(pthread_mutex_lock(&rxkad_global_stats_lock)==0)
79 #define RXKAD_GLOBAL_STATS_UNLOCK assert(pthread_mutex_unlock(&rxkad_global_stats_lock)==0)
80 #define GET_RXKAD_STATS(stats) rxkad_stats_agg(stats)
81 #define GET_RXKAD_THR_STATS(rxkad_stats) \
82     BEGIN \
83         (rxkad_stats) = ((rxkad_stats_t*)pthread_getspecific(rxkad_stats_key)); \
84         if ((rxkad_stats) == NULL) { \
85             assert(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \
86         } \
87     END
88 #define INC_RXKAD_STATS(stats_elem) \
89     BEGIN \
90         rxkad_stats_t * rxkad_stats; \
91         rxkad_stats = ((rxkad_stats_t*)pthread_getspecific(rxkad_stats_key)); \
92         if (rxkad_stats == NULL) { \
93             assert(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \
94         } \
95         rxkad_stats->stats_elem++; \
96     END
97 #define DEC_RXKAD_STATS(stats_elem) \
98     BEGIN \
99         rxkad_stats_t * rxkad_stats; \
100         rxkad_stats = ((rxkad_stats_t*)pthread_getspecific(rxkad_stats_key)); \
101         if (rxkad_stats == NULL) { \
102             assert(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \
103         } \
104         rxkad_stats->stats_elem--; \
105     END
106 #define ADD_RXKAD_STATS(stats_elem, inc_value) \
107     BEGIN \
108         rxkad_stats_t * rxkad_stats; \
109         rxkad_stats = ((rxkad_stats_t*)pthread_getspecific(rxkad_stats_key)); \
110         if (rxkad_stats == NULL) { \
111             assert(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \
112         } \
113         rxkad_stats->stats_elem += inc_value; \
114     END
115 #define SUB_RXKAD_STATS(stats_elem, dec_value) \
116     BEGIN \
117         rxkad_stats_t * rxkad_stats; \
118         rxkad_stats = ((rxkad_stats_t*)pthread_getspecific(rxkad_stats_key)); \
119         if (rxkad_stats == NULL) { \
120             assert(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \
121         } \
122         rxkad_stats->stats_elem -= dec_value; \
123     END
124 #else /* AFS_PTHREAD_ENV */
125 #define INC_RXKAD_STATS(stats_elem) rxkad_stats.stats_elem++
126 #define DEC_RXKAD_STATS(stats_elem) rxkad_stats.stats_elem--
127 #define ADD_RXKAD_STATS(stats_elem, inc_value) rxkad_stats.stats_elem += (inc_value)
128 #define SUB_RXKAD_STATS(stats_elem, dec_value) rxkad_stats.stats_elem -= (dec_value)
129 #define GET_RXKAD_STATS(stats) memcpy((stats), &rxkad_stats, sizeof(rxkad_stats))
130 #endif /* AFS_PTHREAD_ENV */
131
132
133 #if defined(AFS_NT40_ENV) && defined(AFS_PTHREAD_ENV)
134 #ifndef RXKAD_STATS_DECLSPEC
135 #define RXKAD_STATS_DECLSPEC __declspec(dllimport) extern
136 #endif
137 #else
138 #define RXKAD_STATS_DECLSPEC extern
139 #endif
140
141 #ifdef AFS_PTHREAD_ENV
142 RXKAD_STATS_DECLSPEC struct rxkad_global_stats rxkad_global_stats;
143 #else /* AFS_PTHREAD_ENV */
144 RXKAD_STATS_DECLSPEC struct rxkad_stats rxkad_stats;
145 #endif
146
147
148 #endif /* OPENAFS_DES_STATS_H */