rx-stats-calls-waited-ever-20040917
[openafs.git] / src / rx / rx_globals.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 /* RX:  Globals for internal use, basically */
11
12 #ifdef  KERNEL
13 #include "rx/rx.h"
14 #else /* KERNEL */
15 # include "rx.h"
16 #endif /* KERNEL */
17
18 #ifndef INIT
19 #define INIT(x)
20 #if defined(AFS_NT40_ENV) && defined(AFS_PTHREAD_ENV)
21 #define EXT __declspec(dllimport) extern
22 #else
23 #define EXT extern
24 #endif
25 #endif
26
27 /* Basic socket for client requests; other sockets (for receiving server requests) are in the service structures */
28 EXT osi_socket rx_socket;
29
30 /* The array of installed services.  Null terminated. */
31 EXT struct rx_service *rx_services[RX_MAX_SERVICES + 1];
32 #ifdef RX_ENABLE_LOCKS
33 /* Protects nRequestsRunning as well as pool allocation variables. */
34 EXT afs_kmutex_t rx_serverPool_lock;
35 #endif /* RX_ENABLE_LOCKS */
36
37 /* Incoming calls wait on this queue when there are no available server processes */
38 EXT struct rx_queue rx_incomingCallQueue;
39
40 /* Server processes wait on this queue when there are no appropriate calls to process */
41 EXT struct rx_queue rx_idleServerQueue;
42
43 /* Constant delay time before sending an acknowledge of the last packet received.  This is to avoid sending an extra acknowledge when the client is about to make another call, anyway, or the server is about to respond. */
44 EXT struct clock rx_lastAckDelay;
45
46 /* Constant delay time before sending a hard ack if the receiver consumes
47  * a packet while no delayed ack event is scheduled. Ensures that the
48  * sender is able to advance its window when the receiver consumes a packet
49  * after the sender has exhausted its transmit window.
50  */
51 EXT struct clock rx_hardAckDelay;
52
53 /* Constant delay time before sending a soft ack when none was requested.
54  * This is to make sure we send soft acks before the sender times out,
55  * Normally we wait and send a hard ack when the receiver consumes the packet */
56 EXT struct clock rx_softAckDelay;
57
58 /* Variable to allow introduction of network unreliability */
59 #ifdef RXDEBUG
60 EXT int rx_intentionallyDroppedPacketsPer100 INIT(0);   /* Dropped on Send */
61 #endif
62
63 /* extra packets to add to the quota */
64 EXT int rx_extraQuota INIT(0);
65 /* extra packets to alloc (2 windows by deflt) */
66 EXT int rx_extraPackets INIT(32);
67
68 EXT int rx_stackSize INIT(RX_DEFAULT_STACK_SIZE);
69
70 /* Time until an unresponsive connection is declared dead */
71 EXT int rx_connDeadTime INIT(12);
72 /* Set rx default connection dead time; set on both services and connections at creation time */
73 #define rx_SetRxDeadTime(seconds)   (rx_connDeadTime = (seconds))
74
75 /* Time until we toss an idle connection */
76 EXT int rx_idleConnectionTime INIT(700);
77 /* Time until we toss a peer structure, after all connections using are gone */
78 EXT int rx_idlePeerTime INIT(60);
79
80 /* The file server is temporarily salvaging */
81 EXT int rx_tranquil INIT(0);
82
83 /* UDP rcv buffer size */
84 EXT int rx_UdpBufSize INIT(64 * 1024);
85 #define rx_GetMinUdpBufSize()   (64*1024)
86 #define rx_SetUdpBufSize(x)     (((x)>rx_GetMinUdpBufSize()) ? (rx_UdpBufSize = (x)):0)
87
88 /*
89  * Variables to control RX overload management. When the number of calls
90  * waiting for a thread exceed the threshold, new calls are aborted
91  * with the busy error. 
92  */
93 EXT int rx_BusyThreshold INIT(-1);      /* default is disabled */
94 EXT int rx_BusyError INIT(-1);
95
96 /* These definitions should be in one place */
97 #ifdef  AFS_SUN5_ENV
98 #define RX_CBUF_TIME    180     /* Check for packet deficit */
99 #define RX_REAP_TIME    90      /* Check for tossable connections every 90 seconds */
100 #else
101 #define RX_CBUF_TIME    120     /* Check for packet deficit */
102 #define RX_REAP_TIME    60      /* Check for tossable connections every 60 seconds */
103 #endif
104
105 #define RX_FAST_ACK_RATE 1      /* as of 3.4, ask for an ack every 
106                                  * other packet. */
107
108 EXT int rx_minWindow INIT(1);
109 EXT int rx_initReceiveWindow INIT(16);  /* how much to accept */
110 EXT int rx_maxReceiveWindow INIT(32);   /* how much to accept */
111 EXT int rx_initSendWindow INIT(8);
112 EXT int rx_maxSendWindow INIT(32);
113 EXT int rx_nackThreshold INIT(3);       /* Number NACKS to trigger congestion recovery */
114 EXT int rx_nDgramThreshold INIT(4);     /* Number of packets before increasing
115                                          * packets per datagram */
116 #define RX_MAX_FRAGS 4
117 EXT int rxi_nSendFrags INIT(RX_MAX_FRAGS);      /* max fragments in a datagram */
118 EXT int rxi_nRecvFrags INIT(RX_MAX_FRAGS);
119 EXT int rxi_OrphanFragSize INIT(512);
120
121 #define RX_MAX_DGRAM_PACKETS 6  /* max packets per jumbogram */
122
123 EXT int rxi_nDgramPackets INIT(RX_MAX_DGRAM_PACKETS);
124 /* allow n packets between soft acks - must be power of 2 -1, else change
125  * macro below */
126 EXT int rxi_SoftAckRate INIT(RX_FAST_ACK_RATE);
127 /* consume n packets before sending hard ack, should be larger than above,
128    but not absolutely necessary.  If it's smaller, than fast receivers will
129    send a soft ack, immediately followed by a hard ack. */
130 EXT int rxi_HardAckRate INIT(RX_FAST_ACK_RATE + 1);
131
132 /* EXT int rx_maxWindow INIT(15);   Temporary HACK:  transmit/receive window */
133
134 /* If window sizes become very variable (in terms of #packets), be
135  * sure that the sender can get back a hard acks without having to wait for
136  * some kind of timer event first (like a keep-alive, for instance).
137  * It might be kind of tricky, so it might be better to shrink the
138  * window size by reducing the packet size below the "natural" MTU. */
139
140 #define ACKHACK(p,r) { if (((p)->header.seq & (rxi_SoftAckRate))==0) (p)->header.flags |= RX_REQUEST_ACK; }
141
142 EXT int rx_nPackets INIT(100);  /* obsolete; use rx_extraPackets now */
143
144 /* List of free packets */
145 EXT struct rx_queue rx_freePacketQueue;
146 #ifdef RX_ENABLE_LOCKS
147 EXT afs_kmutex_t rx_freePktQ_lock;
148 #endif
149
150 /* Number of free packets */
151 EXT int rx_nFreePackets INIT(0);
152 EXT int rxi_NeedMorePackets INIT(0);
153 EXT int rx_nWaiting INIT(0);
154 EXT int rx_nWaited INIT(0);
155 EXT int rx_packetReclaims INIT(0);
156
157 /* largest packet which we can safely receive, initialized to AFS 3.2 value
158  * This is provided for backward compatibility with peers which may be unable
159  * to swallow anything larger. THIS MUST NEVER DECREASE WHILE AN APPLICATION
160  * IS RUNNING! */
161 EXT afs_uint32 rx_maxReceiveSize INIT(OLD_MAX_PACKET_SIZE * RX_MAX_FRAGS +
162                                       UDP_HDR_SIZE * (RX_MAX_FRAGS - 1));
163
164 /* this is the maximum packet size that the user wants us to receive */
165 /* this is set by rxTune if required */
166 EXT afs_uint32 rx_maxReceiveSizeUser INIT(0xffffffff);
167
168 /* rx_MyMaxSendSize is the size of the largest packet we will send,
169  * including the RX header. Just as rx_maxReceiveSize is the
170  * max we will receive, including the rx header.
171  */
172 EXT afs_uint32 rx_MyMaxSendSize INIT(8588);
173
174 /* Maximum size of a jumbo datagram we can receive */
175 EXT afs_uint32 rx_maxJumboRecvSize INIT(RX_MAX_PACKET_SIZE);
176
177 /* need this to permit progs to run on AIX systems */
178 EXT int (*rxi_syscallp) (afs_uint32 a3, afs_uint32 a4, void *a5)INIT(0);
179
180 /* List of free queue entries */
181 EXT struct rx_serverQueueEntry *rx_FreeSQEList INIT(0);
182 #ifdef  RX_ENABLE_LOCKS
183 EXT afs_kmutex_t freeSQEList_lock;
184 #endif
185
186 /* List of free call structures */
187 EXT struct rx_queue rx_freeCallQueue;
188 #ifdef  RX_ENABLE_LOCKS
189 EXT afs_kmutex_t rx_freeCallQueue_lock;
190 #endif
191 EXT afs_int32 rxi_nCalls INIT(0);
192
193 /* Port requested at rx_Init.  If this is zero, the actual port used will be different--but it will only be used for client operations.  If non-zero, server provided services may use the same port. */
194 EXT u_short rx_port;
195
196 #if !defined(KERNEL) && !defined(AFS_PTHREAD_ENV)
197 /* 32-bit select Mask for rx_Listener. */
198 EXT fd_set rx_selectMask;
199 EXT int rx_maxSocketNumber;     /* Maximum socket number in the select mask. */
200 /* Minumum socket number in the select mask. */
201 EXT int rx_minSocketNumber INIT(0x7fffffff);
202 #endif
203
204 /* This is actually the minimum number of packets that must remain free,
205     overall, immediately after a packet of the requested class has been
206     allocated.  *WARNING* These must be assigned with a great deal of care.
207     In order, these are receive quota, send quota, special quota, receive
208     continuation quota, and send continuation quota. */
209 #define RX_PACKET_QUOTAS {1, 10, 0, 1, 10}
210 /* value large enough to guarantee that no allocation fails due to RX_PACKET_QUOTAS.
211    Make it a little bigger, just for fun */
212 #define RX_MAX_QUOTA    15      /* part of min packet computation */
213 EXT int rx_packetQuota[RX_N_PACKET_CLASSES] INIT(RX_PACKET_QUOTAS);
214 EXT int meltdown_1pkt INIT(1);  /* prefer to schedule single-packet calls */
215 EXT int rxi_doreclaim INIT(1);  /* if discard one packet, discard all */
216 EXT int rxi_md2cnt INIT(0);     /* counter of skipped calls */
217 EXT int rxi_2dchoice INIT(1);   /* keep track of another call to schedule */
218
219 /* quota system: each attached server process must be able to make
220     progress to avoid system deadlock, so we ensure that we can always
221     handle the arrival of the next unacknowledged data packet for an
222     attached call.  rxi_dataQuota gives the max # of packets that must be
223     reserved for active calls for them to be able to make progress, which is
224     essentially enough to queue up a window-full of packets (the first packet
225     may be missing, so these may not get read) + the # of packets the thread
226     may use before reading all of its input (# free must be one more than send
227     packet quota).  Thus, each thread allocates rx_maxReceiveWindow+1 (max
228     queued packets) + an extra for sending data.  The system also reserves
229     RX_MAX_QUOTA (must be more than RX_PACKET_QUOTA[i], which is 10), so that
230     the extra packet can be sent (must be under the system-wide send packet
231     quota to send any packets) */
232 /* # to reserve so that thread with input can still make calls (send packets)
233    without blocking */
234 EXT int rxi_dataQuota INIT(RX_MAX_QUOTA);       /* packets to reserve for active threads */
235
236 EXT afs_int32 rxi_availProcs INIT(0);   /* number of threads in the pool */
237 EXT afs_int32 rxi_totalMin INIT(0);     /* Sum(minProcs) forall services */
238 EXT afs_int32 rxi_minDeficit INIT(0);   /* number of procs needed to handle all minProcs */
239
240 EXT int rx_nextCid;             /* Next connection call id */
241 EXT int rx_epoch;               /* Initialization time of rx */
242 #ifdef  RX_ENABLE_LOCKS
243 EXT afs_kcondvar_t rx_waitingForPackets_cv;
244 #endif
245 EXT char rx_waitingForPackets;  /* Processes set and wait on this variable when waiting for packet buffers */
246
247 EXT struct rx_stats rx_stats;
248
249 EXT struct rx_peer **rx_peerHashTable;
250 EXT struct rx_connection **rx_connHashTable;
251 EXT struct rx_connection *rx_connCleanup_list INIT(0);
252 EXT afs_uint32 rx_hashTableSize INIT(256);      /* Power of 2 */
253 EXT afs_uint32 rx_hashTableMask INIT(255);      /* One less than rx_hashTableSize */
254 #ifdef RX_ENABLE_LOCKS
255 EXT afs_kmutex_t rx_peerHashTable_lock;
256 EXT afs_kmutex_t rx_connHashTable_lock;
257 #endif /* RX_ENABLE_LOCKS */
258
259 #define CONN_HASH(host, port, cid, epoch, type) ((((cid)>>RX_CIDSHIFT)&rx_hashTableMask))
260
261 #define PEER_HASH(host, port)  ((host ^ port) & rx_hashTableMask)
262
263 /* Forward definitions of internal procedures */
264 #define rxi_ChallengeOff(conn)  rxevent_Cancel((conn)->challengeEvent, (struct rx_call*)0, 0);
265 #define rxi_KeepAliveOff(call) rxevent_Cancel((call)->keepAliveEvent, call, RX_CALL_REFCOUNT_ALIVE)
266
267 #define rxi_AllocSecurityObject() (struct rx_securityClass *) rxi_Alloc(sizeof(struct rx_securityClass))
268 #define rxi_FreeSecurityObject(obj) rxi_Free(obj, sizeof(struct rx_securityClass))
269 #define rxi_AllocService()      (struct rx_service *) rxi_Alloc(sizeof(struct rx_service))
270 #define rxi_FreeService(obj)    rxi_Free(obj, sizeof(struct rx_service))
271 #define rxi_AllocPeer()         (struct rx_peer *) rxi_Alloc(sizeof(struct rx_peer))
272 #define rxi_FreePeer(peer)      rxi_Free(peer, sizeof(struct rx_peer))
273 #define rxi_AllocConnection()   (struct rx_connection *) rxi_Alloc(sizeof(struct rx_connection))
274 #define rxi_FreeConnection(conn) (rxi_Free(conn, sizeof(struct rx_connection)))
275
276 #ifdef RXDEBUG
277 /* Some debugging stuff */
278 EXT FILE *rx_debugFile;         /* Set by the user to a stdio file for debugging output */
279 EXT FILE *rxevent_debugFile;    /* Set to an stdio descriptor for event logging to that file */
280
281 #define rx_Log rx_debugFile
282 #define dpf(args) if (rx_debugFile) rxi_DebugPrint args; else
283 #define rx_Log_event rxevent_debugFile
284
285 EXT char *rx_packetTypes[RX_N_PACKET_TYPES] INIT(RX_PACKET_TYPES);      /* Strings defined in rx.h */
286
287 #ifndef KERNEL
288 /*
289  * Counter used to implement connection specific data
290  */
291 EXT int rxi_keyCreate_counter INIT(0);
292 /*
293  * Array of function pointers used to destory connection specific data
294  */
295 EXT rx_destructor_t *rxi_keyCreate_destructor INIT(NULL);
296 #ifdef RX_ENABLE_LOCKS
297 EXT afs_kmutex_t rxi_keyCreate_lock;
298 #endif /* RX_ENABLE_LOCKS */
299 #endif /* !KERNEL */
300
301 #else
302 #define dpf(args)
303 #endif /* RXDEBUG */
304
305 /*
306  * SERVER ONLY: Threshholds used to throttle error replies to looping
307  * clients. When consecutive calls are aborting with the same error, the
308  * server throttles the client by waiting before sending error messages.
309  * Disabled if abort thresholds are zero.
310  */
311 EXT int rxi_connAbortThreshhold INIT(0);
312 EXT int rxi_connAbortDelay INIT(3000);
313 EXT int rxi_callAbortThreshhold INIT(0);
314 EXT int rxi_callAbortDelay INIT(3000);
315
316 /*
317  * Thread specific thread ID used to implement LWP_Index().
318  */
319
320 #if defined(AFS_PTHREAD_ENV)
321 EXT int rxi_fcfs_thread_num INIT(0);
322 EXT pthread_key_t rx_thread_id_key;
323 /* keep track of pthread numbers - protected by rx_stats_mutex, 
324    except in rx_Init() before mutex exists! */
325 EXT int rxi_pthread_hinum INIT(0);
326 #else
327 #define rxi_fcfs_thread_num (0)
328 #endif
329
330 #if defined(RX_ENABLE_LOCKS)
331 EXT afs_kmutex_t rx_stats_mutex;        /* used to activate stats gathering */
332 #endif
333
334 EXT int rx_enable_stats INIT(0);
335
336 /*
337  * Set this flag to enable the listener thread to trade places with an idle
338  * worker thread to move the context switch from listener to worker out of
339  * the request path.
340  */
341 EXT int rx_enable_hot_thread INIT(0);