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