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