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