taking-rx-back-into-the-20th-century-20061228
[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 #ifndef AFS_RX_GLOBALS_H
13 #define AFS_RX_GLOBALS_H
14
15
16 #ifdef  KERNEL
17 #include "rx/rx.h"
18 #else /* KERNEL */
19 # include "rx.h"
20 #endif /* KERNEL */
21
22 #ifndef GLOBALSINIT
23 #define GLOBALSINIT(x)
24 #if defined(AFS_NT40_ENV)
25 #if defined(AFS_PTHREAD_ENV)
26 #define EXT __declspec(dllimport) extern
27 #else
28 #define EXT extern
29 #endif
30 #define EXT2 __declspec(dllimport) extern
31 #else
32 #define EXT2 extern
33 #define EXT extern
34 #endif
35 #endif /* !GLOBALSINIT */
36
37 /* Basic socket for client requests; other sockets (for receiving server requests) are in the service structures */
38 EXT osi_socket rx_socket;
39
40 /* The array of installed services.  Null terminated. */
41 EXT struct rx_service *rx_services[RX_MAX_SERVICES + 1];
42 #ifdef RX_ENABLE_LOCKS
43 /* Protects nRequestsRunning as well as pool allocation variables. */
44 EXT afs_kmutex_t rx_serverPool_lock;
45 #endif /* RX_ENABLE_LOCKS */
46
47 /* Incoming calls wait on this queue when there are no available server processes */
48 EXT struct rx_queue rx_incomingCallQueue;
49
50 /* Server processes wait on this queue when there are no appropriate calls to process */
51 EXT struct rx_queue rx_idleServerQueue;
52
53 /* 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. */
54 EXT struct clock rx_lastAckDelay;
55
56 /* Constant delay time before sending a hard ack if the receiver consumes
57  * a packet while no delayed ack event is scheduled. Ensures that the
58  * sender is able to advance its window when the receiver consumes a packet
59  * after the sender has exhausted its transmit window.
60  */
61 EXT struct clock rx_hardAckDelay;
62
63 /* Constant delay time before sending a soft ack when none was requested.
64  * This is to make sure we send soft acks before the sender times out,
65  * Normally we wait and send a hard ack when the receiver consumes the packet */
66 EXT struct clock rx_softAckDelay;
67
68 /* Variable to allow introduction of network unreliability */
69 #ifdef RXDEBUG
70 EXT int rx_intentionallyDroppedPacketsPer100 GLOBALSINIT(0);    /* Dropped on Send */
71 EXT int rx_intentionallyDroppedOnReadPer100  GLOBALSINIT(0);    /* Dropped on Read */
72 #endif
73
74 /* extra packets to add to the quota */
75 EXT int rx_extraQuota GLOBALSINIT(0);
76 /* extra packets to alloc (2 windows by deflt) */
77 EXT int rx_extraPackets GLOBALSINIT(32);
78
79 EXT int rx_stackSize GLOBALSINIT(RX_DEFAULT_STACK_SIZE);
80
81 /* Time until an unresponsive connection is declared dead */
82 EXT int rx_connDeadTime GLOBALSINIT(12);
83 /* Set rx default connection dead time; set on both services and connections at creation time */
84 #define rx_SetRxDeadTime(seconds)   (rx_connDeadTime = (seconds))
85
86 /* Time until we toss an idle connection */
87 EXT int rx_idleConnectionTime GLOBALSINIT(700);
88 /* Time until we toss a peer structure, after all connections using are gone */
89 EXT int rx_idlePeerTime GLOBALSINIT(60);
90
91 /* The file server is temporarily salvaging */
92 EXT int rx_tranquil GLOBALSINIT(0);
93
94 /* UDP rcv buffer size */
95 EXT int rx_UdpBufSize GLOBALSINIT(64 * 1024);
96 #define rx_GetMinUdpBufSize()   (64*1024)
97 #define rx_SetUdpBufSize(x)     (((x)>rx_GetMinUdpBufSize()) ? (rx_UdpBufSize = (x)):0)
98
99 /*
100  * Variables to control RX overload management. When the number of calls
101  * waiting for a thread exceed the threshold, new calls are aborted
102  * with the busy error. 
103  */
104 EXT int rx_BusyThreshold GLOBALSINIT(-1);       /* default is disabled */
105 EXT int rx_BusyError GLOBALSINIT(-1);
106
107 /* These definitions should be in one place */
108 #ifdef  AFS_SUN5_ENV
109 #define RX_CBUF_TIME    180     /* Check for packet deficit */
110 #define RX_REAP_TIME    90      /* Check for tossable connections every 90 seconds */
111 #else
112 #define RX_CBUF_TIME    120     /* Check for packet deficit */
113 #define RX_REAP_TIME    60      /* Check for tossable connections every 60 seconds */
114 #endif
115
116 #define RX_FAST_ACK_RATE 1      /* as of 3.4, ask for an ack every 
117                                  * other packet. */
118
119 EXT int rx_minWindow GLOBALSINIT(1);
120 EXT int rx_initReceiveWindow GLOBALSINIT(16);   /* how much to accept */
121 EXT int rx_maxReceiveWindow GLOBALSINIT(32);    /* how much to accept */
122 EXT int rx_initSendWindow GLOBALSINIT(8);
123 EXT int rx_maxSendWindow GLOBALSINIT(32);
124 EXT int rx_nackThreshold GLOBALSINIT(3);        /* Number NACKS to trigger congestion recovery */
125 EXT int rx_nDgramThreshold GLOBALSINIT(4);      /* Number of packets before increasing
126                                          * packets per datagram */
127 #define RX_MAX_FRAGS 4
128 EXT int rxi_nSendFrags GLOBALSINIT(RX_MAX_FRAGS);       /* max fragments in a datagram */
129 EXT int rxi_nRecvFrags GLOBALSINIT(RX_MAX_FRAGS);
130 EXT int rxi_OrphanFragSize GLOBALSINIT(512);
131
132 #define RX_MAX_DGRAM_PACKETS 6  /* max packets per jumbogram */
133
134 EXT int rxi_nDgramPackets GLOBALSINIT(RX_MAX_DGRAM_PACKETS);
135 /* allow n packets between soft acks - must be power of 2 -1, else change
136  * macro below */
137 EXT int rxi_SoftAckRate GLOBALSINIT(RX_FAST_ACK_RATE);
138 /* consume n packets before sending hard ack, should be larger than above,
139    but not absolutely necessary.  If it's smaller, than fast receivers will
140    send a soft ack, immediately followed by a hard ack. */
141 EXT int rxi_HardAckRate GLOBALSINIT(RX_FAST_ACK_RATE + 1);
142
143 /* EXT int rx_maxWindow GLOBALSINIT(15);   Temporary HACK:  transmit/receive window */
144
145 /* If window sizes become very variable (in terms of #packets), be
146  * sure that the sender can get back a hard acks without having to wait for
147  * some kind of timer event first (like a keep-alive, for instance).
148  * It might be kind of tricky, so it might be better to shrink the
149  * window size by reducing the packet size below the "natural" MTU. */
150
151 #define ACKHACK(p,r) { if (((p)->header.seq & (rxi_SoftAckRate))==0) (p)->header.flags |= RX_REQUEST_ACK; }
152
153 EXT int rx_nPackets GLOBALSINIT(100);   /* obsolete; use rx_extraPackets now */
154
155 /*
156  * pthreads thread-specific rx info support
157  * the rx_ts_info_t struct is meant to support all kinds of
158  * thread-specific rx data:
159  *
160  *  _FPQ member contains a thread-specific free packet queue
161  */
162 #ifdef AFS_PTHREAD_ENV
163 EXT pthread_key_t rx_ts_info_key;
164 typedef struct rx_ts_info_t {
165     struct {
166         struct rx_queue queue;
167         int len;                /* local queue length */
168         int delta;              /* number of new packets alloc'd locally since last sync w/ global queue */
169         
170         /* FPQ stats */
171         int checkin_ops;
172         int checkin_xfer;
173         int checkout_ops;
174         int checkout_xfer;
175         int gtol_ops;
176         int gtol_xfer;
177         int ltog_ops;
178         int ltog_xfer;
179         int alloc_ops;
180         int alloc_xfer;
181     } _FPQ;
182     struct rx_packet * local_special_packet;
183 } rx_ts_info_t;
184 EXT struct rx_ts_info_t * rx_ts_info_init();   /* init function for thread-specific data struct */
185 #define RX_TS_INFO_GET(ts_info_p) \
186     do { \
187         ts_info_p = (struct rx_ts_info_t*)pthread_getspecific(rx_ts_info_key); \
188         if (ts_info_p == NULL) { \
189             assert((ts_info_p = rx_ts_info_init()) != NULL); \
190         } \
191     } while(0)
192 #endif /* AFS_PTHREAD_ENV */
193
194
195 /* List of free packets */
196 /* in pthreads rx, free packet queue is now a two-tiered queueing system
197  * in which the first tier is thread-specific, and the second tier is
198  * a global free packet queue */
199 EXT struct rx_queue rx_freePacketQueue;
200 #define RX_FPQ_MARK_FREE(p) \
201     do { \
202         if ((p)->flags & RX_PKTFLAG_FREE) \
203             osi_Panic("rx packet already free\n"); \
204         (p)->flags |= RX_PKTFLAG_FREE; \
205     } while(0)
206 #define RX_FPQ_MARK_USED(p) \
207     do { \
208         if (!((p)->flags & RX_PKTFLAG_FREE)) \
209             osi_Panic("rx packet not free\n"); \
210         (p)->flags = 0;         /* clear RX_PKTFLAG_FREE, initialize the rest */ \
211         (p)->header.flags = 0; \
212     } while(0)
213 #define RX_PACKET_IOV_INIT(p) \
214     do { \
215         (p)->wirevec[0].iov_base = (char *)((p)->wirehead); \
216         (p)->wirevec[0].iov_len = RX_HEADER_SIZE; \
217         (p)->wirevec[1].iov_base = (char *)((p)->localdata); \
218         (p)->wirevec[1].iov_len = RX_FIRSTBUFFERSIZE; \
219     } while(0)
220 #define RX_PACKET_IOV_FULLINIT(p) \
221     do { \
222         (p)->wirevec[0].iov_base = (char *)((p)->wirehead); \
223         (p)->wirevec[0].iov_len = RX_HEADER_SIZE; \
224         (p)->wirevec[1].iov_base = (char *)((p)->localdata); \
225         (p)->wirevec[1].iov_len = RX_FIRSTBUFFERSIZE; \
226         (p)->niovecs = 2; \
227         (p)->length = RX_FIRSTBUFFERSIZE; \
228     } while(0)
229
230 #ifdef RX_ENABLE_LOCKS
231 EXT afs_kmutex_t rx_freePktQ_lock;
232 #endif /* RX_ENABLE_LOCKS */
233
234 #if defined(AFS_PTHREAD_ENV)
235 #define RX_ENABLE_TSFPQ
236 EXT int rx_TSFPQGlobSize GLOBALSINIT(3); /* number of packets to transfer between global and local queues in one op */
237 EXT int rx_TSFPQLocalMax GLOBALSINIT(15); /* max number of packets on local FPQ before returning a glob to the global pool */
238 EXT int rx_TSFPQMaxProcs GLOBALSINIT(0); /* max number of threads expected */
239 EXT void rxi_MorePacketsTSFPQ(int apackets, int flush_global, int num_keep_local); /* more flexible packet alloc function */
240 EXT void rxi_AdjustLocalPacketsTSFPQ(int num_keep_local, int allow_overcommit); /* adjust thread-local queue length, for places where we know how many packets we will need a priori */
241 EXT void rxi_FlushLocalPacketsTSFPQ(void); /* flush all thread-local packets to global queue */
242 #define RX_TS_FPQ_FLUSH_GLOBAL 1
243 #define RX_TS_FPQ_PULL_GLOBAL 1
244 #define RX_TS_FPQ_ALLOW_OVERCOMMIT 1
245 /* compute the localmax and globsize values from rx_TSFPQMaxProcs and rx_nPackets.
246    arbitarily set local max so that all threads consume 90% of packets, if all local queues are full.
247    arbitarily set transfer glob size to 20% of max local packet queue length.
248    also set minimum values of 15 and 3. */
249 #define RX_TS_FPQ_COMPUTE_LIMITS \
250     do { \
251         register int newmax, newglob; \
252         newmax = (rx_nPackets * 9) / (10 * rx_TSFPQMaxProcs); \
253         newmax = (newmax >= 15) ? newmax : 15; \
254         newglob = newmax / 5; \
255         newglob = (newglob >= 3) ? newglob : 3; \
256         rx_TSFPQLocalMax = newmax; \
257         rx_TSFPQGlobSize = newglob; \
258     } while(0)
259 /* move packets from local (thread-specific) to global free packet queue.
260    rx_freePktQ_lock must be held. default is to move the difference between the current lenght, and the 
261    allowed max plus one extra glob. */
262 #define RX_TS_FPQ_LTOG(rx_ts_info_p) \
263     do { \
264         register int i; \
265         register struct rx_packet * p; \
266         register int tsize = (rx_ts_info_p)->_FPQ.len - rx_TSFPQLocalMax + rx_TSFPQGlobSize; \
267         for (i=0,p=queue_Last(&((rx_ts_info_p)->_FPQ), rx_packet); \
268              i < tsize; i++,p=queue_Prev(p, rx_packet)); \
269         queue_SplitAfterPrepend(&((rx_ts_info_p)->_FPQ),&rx_freePacketQueue,p); \
270         (rx_ts_info_p)->_FPQ.len -= tsize; \
271         rx_nFreePackets += tsize; \
272         (rx_ts_info_p)->_FPQ.ltog_ops++; \
273         (rx_ts_info_p)->_FPQ.ltog_xfer += tsize; \
274         if ((rx_ts_info_p)->_FPQ.delta) { \
275             (rx_ts_info_p)->_FPQ.alloc_ops++; \
276             (rx_ts_info_p)->_FPQ.alloc_xfer += (rx_ts_info_p)->_FPQ.delta; \
277             MUTEX_ENTER(&rx_stats_mutex); \
278             rx_nPackets += (rx_ts_info_p)->_FPQ.delta; \
279             RX_TS_FPQ_COMPUTE_LIMITS; \
280             MUTEX_EXIT(&rx_stats_mutex); \
281            (rx_ts_info_p)->_FPQ.delta = 0; \
282         } \
283     } while(0)
284 /* same as above, except user has direct control over number to transfer */
285 #define RX_TS_FPQ_LTOG2(rx_ts_info_p,num_transfer) \
286     do { \
287         register int i; \
288         register struct rx_packet * p; \
289         for (i=0,p=queue_Last(&((rx_ts_info_p)->_FPQ), rx_packet); \
290              i < (num_transfer); i++,p=queue_Prev(p, rx_packet)); \
291         queue_SplitAfterPrepend(&((rx_ts_info_p)->_FPQ),&rx_freePacketQueue,p); \
292         (rx_ts_info_p)->_FPQ.len -= (num_transfer); \
293         rx_nFreePackets += (num_transfer); \
294         (rx_ts_info_p)->_FPQ.ltog_ops++; \
295         (rx_ts_info_p)->_FPQ.ltog_xfer += (num_transfer); \
296         if ((rx_ts_info_p)->_FPQ.delta) { \
297             (rx_ts_info_p)->_FPQ.alloc_ops++; \
298             (rx_ts_info_p)->_FPQ.alloc_xfer += (rx_ts_info_p)->_FPQ.delta; \
299             MUTEX_ENTER(&rx_stats_mutex); \
300             rx_nPackets += (rx_ts_info_p)->_FPQ.delta; \
301             RX_TS_FPQ_COMPUTE_LIMITS; \
302             MUTEX_EXIT(&rx_stats_mutex); \
303             (rx_ts_info_p)->_FPQ.delta = 0; \
304         } \
305     } while(0)
306 /* move packets from global to local (thread-specific) free packet queue.
307    rx_freePktQ_lock must be held. */
308 #define RX_TS_FPQ_GTOL(rx_ts_info_p) \
309     do { \
310         register int i, tsize; \
311         register struct rx_packet * p; \
312         tsize = (rx_TSFPQGlobSize <= rx_nFreePackets) ? \
313                  rx_TSFPQGlobSize : rx_nFreePackets; \
314         for (i=0,p=queue_First(&rx_freePacketQueue, rx_packet); \
315              i < tsize; i++,p=queue_Next(p, rx_packet)); \
316         queue_SplitBeforeAppend(&rx_freePacketQueue,&((rx_ts_info_p)->_FPQ),p); \
317         (rx_ts_info_p)->_FPQ.len += i; \
318         rx_nFreePackets -= i; \
319         (rx_ts_info_p)->_FPQ.gtol_ops++; \
320         (rx_ts_info_p)->_FPQ.gtol_xfer += i; \
321     } while(0)
322 /* same as above, except user has direct control over number to transfer */
323 #define RX_TS_FPQ_GTOL2(rx_ts_info_p,num_transfer) \
324     do { \
325         register int i; \
326         register struct rx_packet * p; \
327         for (i=0,p=queue_First(&rx_freePacketQueue, rx_packet); \
328              i < (num_transfer); i++,p=queue_Next(p, rx_packet)); \
329         queue_SplitBeforeAppend(&rx_freePacketQueue,&((rx_ts_info_p)->_FPQ),p); \
330         (rx_ts_info_p)->_FPQ.len += i; \
331         rx_nFreePackets -= i; \
332         (rx_ts_info_p)->_FPQ.gtol_ops++; \
333         (rx_ts_info_p)->_FPQ.gtol_xfer += i; \
334     } while(0)
335 /* checkout a packet from the thread-specific free packet queue */
336 #define RX_TS_FPQ_CHECKOUT(rx_ts_info_p,p) \
337     do { \
338         (p) = queue_First(&((rx_ts_info_p)->_FPQ), rx_packet); \
339         queue_Remove(p); \
340         RX_FPQ_MARK_USED(p); \
341         (rx_ts_info_p)->_FPQ.len--; \
342         (rx_ts_info_p)->_FPQ.checkout_ops++; \
343         (rx_ts_info_p)->_FPQ.checkout_xfer++; \
344     } while(0)
345 /* checkout multiple packets from the thread-specific free packet queue */
346 #define RX_TS_FPQ_CHECKOUT2(rx_ts_info_p,num_transfer,q) \
347     do { \
348         register int i; \
349         register struct rx_packet *p; \
350         for (i=0, p=queue_First(&((rx_ts_info_p)->_FPQ), rx_packet); \
351              i < (num_transfer); \
352              i++, p=queue_Next(p, rx_packet)) { \
353             RX_FPQ_MARK_USED(p); \
354         } \
355         queue_SplitBeforeAppend(&((rx_ts_info_p)->_FPQ),(q),p); \
356         (rx_ts_info_p)->_FPQ.len -= (num_transfer); \
357         (rx_ts_info_p)->_FPQ.checkout_ops++; \
358         (rx_ts_info_p)->_FPQ.checkout_xfer += (num_transfer); \
359     } while(0)
360 /* check a packet into the thread-specific free packet queue */
361 #define RX_TS_FPQ_CHECKIN(rx_ts_info_p,p) \
362     do { \
363         queue_Prepend(&((rx_ts_info_p)->_FPQ), (p)); \
364         RX_FPQ_MARK_FREE(p); \
365         (rx_ts_info_p)->_FPQ.len++; \
366         (rx_ts_info_p)->_FPQ.checkin_ops++; \
367         (rx_ts_info_p)->_FPQ.checkin_xfer++; \
368     } while(0)
369 /* check multiple packets into the thread-specific free packet queue */
370 /* num_transfer must equal length of (q); it is not a means of checking 
371  * in part of (q).  passing num_transfer just saves us instructions 
372  * since caller already knows length of (q) for other reasons */
373 #define RX_TS_FPQ_CHECKIN2(rx_ts_info_p,num_transfer,q) \
374     do { \
375         register struct rx_packet *p, *np; \
376         for (queue_Scan((q), p, np, rx_packet)) { \
377             RX_FPQ_MARK_FREE(p); \
378         } \
379         queue_SplicePrepend(&((rx_ts_info_p)->_FPQ),(q)); \
380         (rx_ts_info_p)->_FPQ.len += (num_transfer); \
381         (rx_ts_info_p)->_FPQ.checkin_ops++; \
382         (rx_ts_info_p)->_FPQ.checkin_xfer += (num_transfer); \
383     } while(0)
384 #endif /* AFS_PTHREAD_ENV */
385
386 /* Number of free packets */
387 EXT int rx_nFreePackets GLOBALSINIT(0);
388 EXT int rxi_NeedMorePackets GLOBALSINIT(0);
389 EXT int rx_nWaiting GLOBALSINIT(0);
390 EXT int rx_nWaited GLOBALSINIT(0);
391 EXT int rx_packetReclaims GLOBALSINIT(0);
392
393 /* largest packet which we can safely receive, initialized to AFS 3.2 value
394  * This is provided for backward compatibility with peers which may be unable
395  * to swallow anything larger. THIS MUST NEVER DECREASE WHILE AN APPLICATION
396  * IS RUNNING! */
397 EXT afs_uint32 rx_maxReceiveSize GLOBALSINIT(OLD_MAX_PACKET_SIZE * RX_MAX_FRAGS +
398                                       UDP_HDR_SIZE * (RX_MAX_FRAGS - 1));
399
400 /* this is the maximum packet size that the user wants us to receive */
401 /* this is set by rxTune if required */
402 EXT afs_uint32 rx_maxReceiveSizeUser GLOBALSINIT(0xffffffff);
403
404 /* rx_MyMaxSendSize is the size of the largest packet we will send,
405  * including the RX header. Just as rx_maxReceiveSize is the
406  * max we will receive, including the rx header.
407  */
408 EXT afs_uint32 rx_MyMaxSendSize GLOBALSINIT(8588);
409
410 /* Maximum size of a jumbo datagram we can receive */
411 EXT afs_uint32 rx_maxJumboRecvSize GLOBALSINIT(RX_MAX_PACKET_SIZE);
412
413 /* need this to permit progs to run on AIX systems */
414 EXT int (*rxi_syscallp) (afs_uint32 a3, afs_uint32 a4, void *a5)GLOBALSINIT(0);
415
416 /* List of free queue entries */
417 EXT struct rx_serverQueueEntry *rx_FreeSQEList GLOBALSINIT(0);
418 #ifdef  RX_ENABLE_LOCKS
419 EXT afs_kmutex_t freeSQEList_lock;
420 #endif
421
422 /* List of free call structures */
423 EXT struct rx_queue rx_freeCallQueue;
424 #ifdef  RX_ENABLE_LOCKS
425 EXT afs_kmutex_t rx_freeCallQueue_lock;
426 #endif
427 EXT afs_int32 rxi_nCalls GLOBALSINIT(0);
428
429 /* 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. */
430 EXT u_short rx_port;
431
432 #if !defined(KERNEL) && !defined(AFS_PTHREAD_ENV)
433 /* 32-bit select Mask for rx_Listener. */
434 EXT fd_set rx_selectMask;
435 EXT osi_socket rx_maxSocketNumber;      /* Maximum socket number in the select mask. */
436 /* Minumum socket number in the select mask. */
437 EXT osi_socket rx_minSocketNumber GLOBALSINIT(0x7fffffff);
438 #endif
439
440 /* This is actually the minimum number of packets that must remain free,
441     overall, immediately after a packet of the requested class has been
442     allocated.  *WARNING* These must be assigned with a great deal of care.
443     In order, these are receive quota, send quota, special quota, receive
444     continuation quota, and send continuation quota. */
445 #define RX_PACKET_QUOTAS {1, 10, 0, 1, 10}
446 /* value large enough to guarantee that no allocation fails due to RX_PACKET_QUOTAS.
447    Make it a little bigger, just for fun */
448 #define RX_MAX_QUOTA    15      /* part of min packet computation */
449 EXT int rx_packetQuota[RX_N_PACKET_CLASSES] GLOBALSINIT(RX_PACKET_QUOTAS);
450 EXT int meltdown_1pkt GLOBALSINIT(1);   /* prefer to schedule single-packet calls */
451 EXT int rxi_doreclaim GLOBALSINIT(1);   /* if discard one packet, discard all */
452 EXT int rxi_md2cnt GLOBALSINIT(0);      /* counter of skipped calls */
453 EXT int rxi_2dchoice GLOBALSINIT(1);    /* keep track of another call to schedule */
454
455 /* quota system: each attached server process must be able to make
456     progress to avoid system deadlock, so we ensure that we can always
457     handle the arrival of the next unacknowledged data packet for an
458     attached call.  rxi_dataQuota gives the max # of packets that must be
459     reserved for active calls for them to be able to make progress, which is
460     essentially enough to queue up a window-full of packets (the first packet
461     may be missing, so these may not get read) + the # of packets the thread
462     may use before reading all of its input (# free must be one more than send
463     packet quota).  Thus, each thread allocates rx_maxReceiveWindow+1 (max
464     queued packets) + an extra for sending data.  The system also reserves
465     RX_MAX_QUOTA (must be more than RX_PACKET_QUOTA[i], which is 10), so that
466     the extra packet can be sent (must be under the system-wide send packet
467     quota to send any packets) */
468 /* # to reserve so that thread with input can still make calls (send packets)
469    without blocking */
470 EXT int rxi_dataQuota GLOBALSINIT(RX_MAX_QUOTA);        /* packets to reserve for active threads */
471
472 EXT afs_int32 rxi_availProcs GLOBALSINIT(0);    /* number of threads in the pool */
473 EXT afs_int32 rxi_totalMin GLOBALSINIT(0);      /* Sum(minProcs) forall services */
474 EXT afs_int32 rxi_minDeficit GLOBALSINIT(0);    /* number of procs needed to handle all minProcs */
475
476 EXT int rx_nextCid;             /* Next connection call id */
477 EXT int rx_epoch;               /* Initialization time of rx */
478 #ifdef  RX_ENABLE_LOCKS
479 EXT afs_kcondvar_t rx_waitingForPackets_cv;
480 #endif
481 EXT char rx_waitingForPackets;  /* Processes set and wait on this variable when waiting for packet buffers */
482
483 EXT struct rx_stats rx_stats;
484
485 EXT struct rx_peer **rx_peerHashTable;
486 EXT struct rx_connection **rx_connHashTable;
487 EXT struct rx_connection *rx_connCleanup_list GLOBALSINIT(0);
488 EXT afs_uint32 rx_hashTableSize GLOBALSINIT(257);       /* Prime number */
489 #ifdef RX_ENABLE_LOCKS
490 EXT afs_kmutex_t rx_peerHashTable_lock;
491 EXT afs_kmutex_t rx_connHashTable_lock;
492 #endif /* RX_ENABLE_LOCKS */
493
494 #define CONN_HASH(host, port, cid, epoch, type) ((((cid)>>RX_CIDSHIFT)%rx_hashTableSize))
495
496 #define PEER_HASH(host, port)  ((host ^ port) % rx_hashTableSize)
497
498 /* Forward definitions of internal procedures */
499 #define rxi_ChallengeOff(conn)  rxevent_Cancel((conn)->challengeEvent, (struct rx_call*)0, 0);
500 #define rxi_KeepAliveOff(call) rxevent_Cancel((call)->keepAliveEvent, call, RX_CALL_REFCOUNT_ALIVE)
501
502 #define rxi_AllocSecurityObject() (struct rx_securityClass *) rxi_Alloc(sizeof(struct rx_securityClass))
503 #define rxi_FreeSecurityObject(obj) rxi_Free(obj, sizeof(struct rx_securityClass))
504 #define rxi_AllocService()      (struct rx_service *) rxi_Alloc(sizeof(struct rx_service))
505 #define rxi_FreeService(obj)    rxi_Free(obj, sizeof(struct rx_service))
506 #define rxi_AllocPeer()         (struct rx_peer *) rxi_Alloc(sizeof(struct rx_peer))
507 #define rxi_FreePeer(peer)      rxi_Free(peer, sizeof(struct rx_peer))
508 #define rxi_AllocConnection()   (struct rx_connection *) rxi_Alloc(sizeof(struct rx_connection))
509 #define rxi_FreeConnection(conn) (rxi_Free(conn, sizeof(struct rx_connection)))
510
511 #ifdef RXDEBUG
512 /* Some debugging stuff */
513 EXT FILE *rx_debugFile;         /* Set by the user to a stdio file for debugging output */
514 EXT FILE *rxevent_debugFile;    /* Set to an stdio descriptor for event logging to that file */
515
516 #define rx_Log rx_debugFile
517 #ifdef AFS_NT40_ENV
518 EXT int rxdebug_active;
519 #if !defined(_WIN64)
520 #define dpf(args) if (rxdebug_active) rxi_DebugPrint args;
521 #else
522 #define dpf(args)
523 #endif
524 #else
525 #ifdef DPF_FSLOG
526 #define dpf(args) FSLog args
527 #else
528 #define dpf(args) if (rx_debugFile) rxi_DebugPrint args; else
529 #endif 
530 #endif
531 #define rx_Log_event rxevent_debugFile
532
533 EXT char *rx_packetTypes[RX_N_PACKET_TYPES] GLOBALSINIT(RX_PACKET_TYPES);       /* Strings defined in rx.h */
534
535 #ifndef KERNEL
536 /*
537  * Counter used to implement connection specific data
538  */
539 EXT int rxi_keyCreate_counter GLOBALSINIT(0);
540 /*
541  * Array of function pointers used to destory connection specific data
542  */
543 EXT rx_destructor_t *rxi_keyCreate_destructor GLOBALSINIT(NULL);
544 #ifdef RX_ENABLE_LOCKS
545 EXT afs_kmutex_t rxi_keyCreate_lock;
546 #endif /* RX_ENABLE_LOCKS */
547 #endif /* !KERNEL */
548
549 #else
550 #define dpf(args)
551 #endif /* RXDEBUG */
552
553 /*
554  * SERVER ONLY: Threshholds used to throttle error replies to looping
555  * clients. When consecutive calls are aborting with the same error, the
556  * server throttles the client by waiting before sending error messages.
557  * Disabled if abort thresholds are zero.
558  */
559 EXT int rxi_connAbortThreshhold GLOBALSINIT(0);
560 EXT int rxi_connAbortDelay GLOBALSINIT(3000);
561 EXT int rxi_callAbortThreshhold GLOBALSINIT(0);
562 EXT int rxi_callAbortDelay GLOBALSINIT(3000);
563
564 /*
565  * Thread specific thread ID used to implement LWP_Index().
566  */
567
568 #if defined(AFS_PTHREAD_ENV)
569 EXT int rxi_fcfs_thread_num GLOBALSINIT(0);
570 EXT pthread_key_t rx_thread_id_key;
571 /* keep track of pthread numbers - protected by rx_stats_mutex, 
572    except in rx_Init() before mutex exists! */
573 EXT int rxi_pthread_hinum GLOBALSINIT(0);
574 #else
575 #define rxi_fcfs_thread_num (0)
576 #endif
577
578 #if defined(RX_ENABLE_LOCKS)
579 EXT afs_kmutex_t rx_stats_mutex;        /* used to activate stats gathering */
580 #endif
581
582 EXT2 int rx_enable_stats GLOBALSINIT(0);
583
584 /*
585  * Set this flag to enable the listener thread to trade places with an idle
586  * worker thread to move the context switch from listener to worker out of
587  * the request path.
588  */
589 EXT int rx_enable_hot_thread GLOBALSINIT(0);
590
591 #endif /* AFS_RX_GLOBALS_H */