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