Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / rxkad / 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 AFS_SRC_RXKAD_STATS_H
14 #define AFS_SRC_RXKAD_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 #if defined(AFS_PTHREAD_ENV) && !defined(KERNEL)
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 #if defined(AFS_PTHREAD_ENV) && !defined(KERNEL)
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 && !KERNEL */
55 };
56 #ifdef AFS_NT40_ENV
57 struct rxkad_stats rxkad_stats; /* put this here for convenience */
58 #endif
59 #endif /* AFS_PTHREAD_ENV && !KERNEL*/
60
61
62 #if defined(AFS_PTHREAD_ENV) && !defined(KERNEL)
63 struct rxkad_global_stats {
64 rxkad_stats_t * first;
65 rxkad_stats_t * last;
66 };
67
68 #include <pthread.h>
69 extern pthread_mutex_t rxkad_global_stats_lock;
70 extern pthread_key_t rxkad_stats_key;
71
72 extern rxkad_stats_t * rxkad_thr_stats_init(void);
73 extern int rxkad_stats_agg(rxkad_stats_t *);
74
75 #ifndef BEGIN
76 #define BEGIN do {
77 #define END } while(0)
78 #endif
79 #define RXKAD_GLOBAL_STATS_LOCK opr_Verify(pthread_mutex_lock(&rxkad_global_stats_lock)==0)
80 #define RXKAD_GLOBAL_STATS_UNLOCK opr_Verify(pthread_mutex_unlock(&rxkad_global_stats_lock)==0)
81 #define GET_RXKAD_STATS(stats) rxkad_stats_agg(stats)
82 #define GET_RXKAD_THR_STATS(rxkad_stats) \
83 BEGIN \
84 (rxkad_stats) = ((rxkad_stats_t*)pthread_getspecific(rxkad_stats_key)); \
85 if ((rxkad_stats) == NULL) { \
86 opr_Verify(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \
87 } \
88 END
89 #define INC_RXKAD_STATS(stats_elem) \
90 BEGIN \
91 rxkad_stats_t * rxkad_stats; \
92 rxkad_stats = ((rxkad_stats_t*)pthread_getspecific(rxkad_stats_key)); \
93 if (rxkad_stats == NULL) { \
94 opr_Verify(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \
95 } \
96 rxkad_stats->stats_elem++; \
97 END
98 #define DEC_RXKAD_STATS(stats_elem) \
99 BEGIN \
100 rxkad_stats_t * rxkad_stats; \
101 rxkad_stats = ((rxkad_stats_t*)pthread_getspecific(rxkad_stats_key)); \
102 if (rxkad_stats == NULL) { \
103 opr_Verify(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \
104 } \
105 rxkad_stats->stats_elem--; \
106 END
107 #ifndef AFS_OBSD38_ENV
108 #define ADD_RXKAD_STATS(stats_elem, inc_value) \
109 BEGIN \
110 rxkad_stats_t * rxkad_stats; \
111 rxkad_stats = ((rxkad_stats_t*)pthread_getspecific(rxkad_stats_key)); \
112 if (rxkad_stats == NULL) { \
113 opr_Verify(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \
114 } \
115 rxkad_stats->stats_elem += inc_value; \
116 END
117 #define SUB_RXKAD_STATS(stats_elem, dec_value) \
118 BEGIN \
119 rxkad_stats_t * rxkad_stats; \
120 rxkad_stats = ((rxkad_stats_t*)pthread_getspecific(rxkad_stats_key)); \
121 if (rxkad_stats == NULL) { \
122 opr_Verify(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \
123 } \
124 rxkad_stats->stats_elem -= dec_value; \
125 END
126 #else /* AFS_OBSD38_ENV */
127 /* segfaults but we don't know why */
128 #define ADD_RXKAD_STATS(stats_elem, inc_value)
129 #define SUB_RXKAD_STATS(stats_elem, dec_value)
130 #endif /* AFS_OBSD38_ENV */
131 #else /* AFS_PTHREAD_ENV && !KERNEL*/
132 #define INC_RXKAD_STATS(stats_elem) rxkad_stats.stats_elem++
133 #define DEC_RXKAD_STATS(stats_elem) rxkad_stats.stats_elem--
134 #define ADD_RXKAD_STATS(stats_elem, inc_value) rxkad_stats.stats_elem += (inc_value)
135 #define SUB_RXKAD_STATS(stats_elem, dec_value) rxkad_stats.stats_elem -= (dec_value)
136 #define GET_RXKAD_STATS(stats) memcpy((stats), &rxkad_stats, sizeof(rxkad_stats))
137 #endif /* AFS_PTHREAD_ENV && !KERNEL */
138
139
140 #if defined(AFS_NT40_ENV) && defined(AFS_PTHREAD_ENV)
141 #ifndef RXKAD_STATS_DECLSPEC
142 #define RXKAD_STATS_DECLSPEC __declspec(dllimport) extern
143 #endif
144 #else
145 #define RXKAD_STATS_DECLSPEC extern
146 #endif
147
148 #if defined(AFS_PTHREAD_ENV) && !defined(KERNEL)
149 RXKAD_STATS_DECLSPEC struct rxkad_global_stats rxkad_global_stats;
150 #else /* AFS_PTHREAD_ENV && !KERNEL */
151 RXKAD_STATS_DECLSPEC struct rxkad_stats rxkad_stats;
152 #endif
153
154
155 #endif /* AFS_SRC_DES_STATS_H */