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