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