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