rx-fpq-optimize-20050425
[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 checkout_ops;
166         int gtol_ops;
167         int gtol_xfer;
168         int ltog_ops;
169         int ltog_xfer;
170         int alloc_ops;
171         int alloc_xfer;
172     } _FPQ;
173 } rx_ts_info_t;
174 EXT struct rx_ts_info_t * rx_ts_info_init();   /* init function for thread-specific data struct */
175 #define RX_TS_INFO_GET(ts_info_p) \
176     do { \
177         ts_info_p = (struct rx_ts_info_t*)pthread_getspecific(rx_ts_info_key); \
178         if (ts_info_p == NULL) { \
179             assert((ts_info_p = rx_ts_info_init()) != NULL); \
180         } \
181     } while(0)
182 #endif /* AFS_PTHREAD_ENV */
183
184
185 /* List of free packets */
186 /* in pthreads rx, free packet queue is now a two-tiered queueing system
187  * in which the first tier is thread-specific, and the second tier is
188  * a global free packet queue */
189 EXT struct rx_queue rx_freePacketQueue;
190 #define RX_FPQ_MARK_FREE(p) \
191     do { \
192         if ((p)->flags & RX_PKTFLAG_FREE) \
193             osi_Panic("rx packet already free\n"); \
194         (p)->flags |= RX_PKTFLAG_FREE; \
195     } while(0)
196 #define RX_FPQ_MARK_USED(p) \
197     do { \
198         if (!((p)->flags & RX_PKTFLAG_FREE)) \
199             osi_Panic("rx packet not free\n"); \
200         (p)->flags = 0;         /* clear RX_PKTFLAG_FREE, initialize the rest */ \
201         (p)->header.flags = 0; \
202     } while(0)
203 #define RX_PACKET_IOV_INIT(p) \
204     do { \
205         (p)->wirevec[0].iov_base = (char *)((p)->wirehead); \
206         (p)->wirevec[0].iov_len = RX_HEADER_SIZE; \
207         (p)->wirevec[1].iov_base = (char *)((p)->localdata); \
208         (p)->wirevec[1].iov_len = RX_FIRSTBUFFERSIZE; \
209     } while(0)
210 #define RX_PACKET_IOV_FULLINIT(p) \
211     do { \
212         (p)->wirevec[0].iov_base = (char *)((p)->wirehead); \
213         (p)->wirevec[0].iov_len = RX_HEADER_SIZE; \
214         (p)->wirevec[1].iov_base = (char *)((p)->localdata); \
215         (p)->wirevec[1].iov_len = RX_FIRSTBUFFERSIZE; \
216         (p)->niovecs = 2; \
217         (p)->length = RX_FIRSTBUFFERSIZE; \
218     } while(0)
219 #ifdef RX_ENABLE_LOCKS
220 EXT afs_kmutex_t rx_freePktQ_lock;
221 #endif /* RX_ENABLE_LOCKS */
222
223 #if defined(AFS_PTHREAD_ENV)
224 #define RX_ENABLE_TSFPQ
225 EXT int rx_TSFPQGlobSize INIT(3); /* number of packets to transfer between global and local queues in one op */
226 EXT int rx_TSFPQLocalMax INIT(15); /* max number of packets on local FPQ before returning a glob to the global pool */
227 EXT int rx_TSFPQMaxProcs INIT(0); /* max number of threads expected */
228 EXT void rxi_MorePacketsTSFPQ(int apackets, int flush_global, int num_keep_local); /* more flexible packet alloc function */
229 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 */
230 EXT void rxi_FlushLocalPacketsTSFPQ(void); /* flush all thread-local packets to global queue */
231 #define RX_TS_FPQ_FLUSH_GLOBAL 1
232 #define RX_TS_FPQ_PULL_GLOBAL 1
233 #define RX_TS_FPQ_ALLOW_OVERCOMMIT 1
234 /* compute the localmax and globsize values from rx_TSFPQMaxProcs and rx_nPackets.
235    arbitarily set local max so that all threads consume 90% of packets, if all local queues are full.
236    arbitarily set transfer glob size to 20% of max local packet queue length.
237    also set minimum values of 15 and 3. */
238 #define RX_TS_FPQ_COMPUTE_LIMITS \
239     do { \
240         register int newmax, newglob; \
241         newmax = (rx_nPackets * 9) / (10 * rx_TSFPQMaxProcs); \
242         newmax = (newmax >= 15) ? newmax : 15; \
243         newglob = newmax / 5; \
244         newglob = (newglob >= 3) ? newglob : 3; \
245         rx_TSFPQLocalMax = newmax; \
246         rx_TSFPQGlobSize = newglob; \
247     } while(0)
248 /* move packets from local (thread-specific) to global free packet queue.
249    rx_freePktQ_lock must be held. default is to move the difference between the current lenght, and the 
250    allowed max plus one extra glob. */
251 #define RX_TS_FPQ_LTOG(rx_ts_info_p) \
252     do { \
253         register int i; \
254         register struct rx_packet * p; \
255         register int tsize = (rx_ts_info_p)->_FPQ.len - rx_TSFPQLocalMax + rx_TSFPQGlobSize; \
256         for (i=0,p=queue_Last(&((rx_ts_info_p)->_FPQ), rx_packet); \
257              i < tsize; i++,p=queue_Prev(p, rx_packet)); \
258         queue_SplitAfterPrepend(&((rx_ts_info_p)->_FPQ),&rx_freePacketQueue,p); \
259         (rx_ts_info_p)->_FPQ.len -= tsize; \
260         rx_nFreePackets += tsize; \
261         (rx_ts_info_p)->_FPQ.ltog_ops++; \
262         (rx_ts_info_p)->_FPQ.ltog_xfer += tsize; \
263         if ((rx_ts_info_p)->_FPQ.delta) { \
264             (rx_ts_info_p)->_FPQ.alloc_ops++; \
265             (rx_ts_info_p)->_FPQ.alloc_xfer += (rx_ts_info_p)->_FPQ.delta; \
266             MUTEX_ENTER(&rx_stats_mutex); \
267             rx_nPackets += (rx_ts_info_p)->_FPQ.delta; \
268             RX_TS_FPQ_COMPUTE_LIMITS; \
269             MUTEX_EXIT(&rx_stats_mutex); \
270            (rx_ts_info_p)->_FPQ.delta = 0; \
271         } \
272     } while(0)
273 /* same as above, except user has direct control over number to transfer */
274 #define RX_TS_FPQ_LTOG2(rx_ts_info_p,num_transfer) \
275     do { \
276         register int i; \
277         register struct rx_packet * p; \
278         for (i=0,p=queue_Last(&((rx_ts_info_p)->_FPQ), rx_packet); \
279              i < (num_transfer); i++,p=queue_Prev(p, rx_packet)); \
280         queue_SplitAfterPrepend(&((rx_ts_info_p)->_FPQ),&rx_freePacketQueue,p); \
281         (rx_ts_info_p)->_FPQ.len -= (num_transfer); \
282         rx_nFreePackets += (num_transfer); \
283         (rx_ts_info_p)->_FPQ.ltog_ops++; \
284         (rx_ts_info_p)->_FPQ.ltog_xfer += (num_transfer); \
285         if ((rx_ts_info_p)->_FPQ.delta) { \
286             (rx_ts_info_p)->_FPQ.alloc_ops++; \
287             (rx_ts_info_p)->_FPQ.alloc_xfer += (rx_ts_info_p)->_FPQ.delta; \
288             MUTEX_ENTER(&rx_stats_mutex); \
289             rx_nPackets += (rx_ts_info_p)->_FPQ.delta; \
290             RX_TS_FPQ_COMPUTE_LIMITS; \
291             MUTEX_EXIT(&rx_stats_mutex); \
292             (rx_ts_info_p)->_FPQ.delta = 0; \
293         } \
294     } while(0)
295 /* move packets from global to local (thread-specific) free packet queue.
296    rx_freePktQ_lock must be held. */
297 #define RX_TS_FPQ_GTOL(rx_ts_info_p) \
298     do { \
299         register int i, tsize; \
300         register struct rx_packet * p; \
301         tsize = (rx_TSFPQGlobSize <= rx_nFreePackets) ? \
302                  rx_TSFPQGlobSize : rx_nFreePackets; \
303         for (i=0,p=queue_First(&rx_freePacketQueue, rx_packet); \
304              i < tsize; i++,p=queue_Next(p, rx_packet)); \
305         queue_SplitBeforeAppend(&rx_freePacketQueue,&((rx_ts_info_p)->_FPQ),p); \
306         (rx_ts_info_p)->_FPQ.len += i; \
307         rx_nFreePackets -= i; \
308         (rx_ts_info_p)->_FPQ.gtol_ops++; \
309         (rx_ts_info_p)->_FPQ.gtol_xfer += i; \
310     } while(0)
311 /* same as above, except user has direct control over number to transfer */
312 #define RX_TS_FPQ_GTOL2(rx_ts_info_p,num_transfer) \
313     do { \
314         register int i; \
315         register struct rx_packet * p; \
316         for (i=0,p=queue_First(&rx_freePacketQueue, rx_packet); \
317              i < (num_transfer); i++,p=queue_Next(p, rx_packet)); \
318         queue_SplitBeforeAppend(&rx_freePacketQueue,&((rx_ts_info_p)->_FPQ),p); \
319         (rx_ts_info_p)->_FPQ.len += i; \
320         rx_nFreePackets -= i; \
321         (rx_ts_info_p)->_FPQ.gtol_ops++; \
322         (rx_ts_info_p)->_FPQ.gtol_xfer += i; \
323     } while(0)
324 /* checkout a packet from the thread-specific free packet queue */
325 #define RX_TS_FPQ_CHECKOUT(rx_ts_info_p,p) \
326     do { \
327         (p) = queue_First(&((rx_ts_info_p)->_FPQ), rx_packet); \
328         queue_Remove(p); \
329         RX_FPQ_MARK_USED(p); \
330         (rx_ts_info_p)->_FPQ.len--; \
331         (rx_ts_info_p)->_FPQ.checkout_ops++; \
332     } while(0)
333 /* check a packet into the thread-specific free packet queue */
334 #define RX_TS_FPQ_CHECKIN(rx_ts_info_p,p) \
335     do { \
336         queue_Prepend(&((rx_ts_info_p)->_FPQ), (p)); \
337         RX_FPQ_MARK_FREE(p); \
338         (rx_ts_info_p)->_FPQ.len++; \
339         (rx_ts_info_p)->_FPQ.checkin_ops++; \
340     } while(0)
341 #endif /* AFS_PTHREAD_ENV */
342
343 /* Number of free packets */
344 EXT int rx_nFreePackets INIT(0);
345 EXT int rxi_NeedMorePackets INIT(0);
346 EXT int rx_nWaiting INIT(0);
347 EXT int rx_nWaited INIT(0);
348 EXT int rx_packetReclaims INIT(0);
349
350 /* largest packet which we can safely receive, initialized to AFS 3.2 value
351  * This is provided for backward compatibility with peers which may be unable
352  * to swallow anything larger. THIS MUST NEVER DECREASE WHILE AN APPLICATION
353  * IS RUNNING! */
354 EXT afs_uint32 rx_maxReceiveSize INIT(OLD_MAX_PACKET_SIZE * RX_MAX_FRAGS +
355                                       UDP_HDR_SIZE * (RX_MAX_FRAGS - 1));
356
357 /* this is the maximum packet size that the user wants us to receive */
358 /* this is set by rxTune if required */
359 EXT afs_uint32 rx_maxReceiveSizeUser INIT(0xffffffff);
360
361 /* rx_MyMaxSendSize is the size of the largest packet we will send,
362  * including the RX header. Just as rx_maxReceiveSize is the
363  * max we will receive, including the rx header.
364  */
365 EXT afs_uint32 rx_MyMaxSendSize INIT(8588);
366
367 /* Maximum size of a jumbo datagram we can receive */
368 EXT afs_uint32 rx_maxJumboRecvSize INIT(RX_MAX_PACKET_SIZE);
369
370 /* need this to permit progs to run on AIX systems */
371 EXT int (*rxi_syscallp) (afs_uint32 a3, afs_uint32 a4, void *a5)INIT(0);
372
373 /* List of free queue entries */
374 EXT struct rx_serverQueueEntry *rx_FreeSQEList INIT(0);
375 #ifdef  RX_ENABLE_LOCKS
376 EXT afs_kmutex_t freeSQEList_lock;
377 #endif
378
379 /* List of free call structures */
380 EXT struct rx_queue rx_freeCallQueue;
381 #ifdef  RX_ENABLE_LOCKS
382 EXT afs_kmutex_t rx_freeCallQueue_lock;
383 #endif
384 EXT afs_int32 rxi_nCalls INIT(0);
385
386 /* 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. */
387 EXT u_short rx_port;
388
389 #if !defined(KERNEL) && !defined(AFS_PTHREAD_ENV)
390 /* 32-bit select Mask for rx_Listener. */
391 EXT fd_set rx_selectMask;
392 EXT int rx_maxSocketNumber;     /* Maximum socket number in the select mask. */
393 /* Minumum socket number in the select mask. */
394 EXT int rx_minSocketNumber INIT(0x7fffffff);
395 #endif
396
397 /* This is actually the minimum number of packets that must remain free,
398     overall, immediately after a packet of the requested class has been
399     allocated.  *WARNING* These must be assigned with a great deal of care.
400     In order, these are receive quota, send quota, special quota, receive
401     continuation quota, and send continuation quota. */
402 #define RX_PACKET_QUOTAS {1, 10, 0, 1, 10}
403 /* value large enough to guarantee that no allocation fails due to RX_PACKET_QUOTAS.
404    Make it a little bigger, just for fun */
405 #define RX_MAX_QUOTA    15      /* part of min packet computation */
406 EXT int rx_packetQuota[RX_N_PACKET_CLASSES] INIT(RX_PACKET_QUOTAS);
407 EXT int meltdown_1pkt INIT(1);  /* prefer to schedule single-packet calls */
408 EXT int rxi_doreclaim INIT(1);  /* if discard one packet, discard all */
409 EXT int rxi_md2cnt INIT(0);     /* counter of skipped calls */
410 EXT int rxi_2dchoice INIT(1);   /* keep track of another call to schedule */
411
412 /* quota system: each attached server process must be able to make
413     progress to avoid system deadlock, so we ensure that we can always
414     handle the arrival of the next unacknowledged data packet for an
415     attached call.  rxi_dataQuota gives the max # of packets that must be
416     reserved for active calls for them to be able to make progress, which is
417     essentially enough to queue up a window-full of packets (the first packet
418     may be missing, so these may not get read) + the # of packets the thread
419     may use before reading all of its input (# free must be one more than send
420     packet quota).  Thus, each thread allocates rx_maxReceiveWindow+1 (max
421     queued packets) + an extra for sending data.  The system also reserves
422     RX_MAX_QUOTA (must be more than RX_PACKET_QUOTA[i], which is 10), so that
423     the extra packet can be sent (must be under the system-wide send packet
424     quota to send any packets) */
425 /* # to reserve so that thread with input can still make calls (send packets)
426    without blocking */
427 EXT int rxi_dataQuota INIT(RX_MAX_QUOTA);       /* packets to reserve for active threads */
428
429 EXT afs_int32 rxi_availProcs INIT(0);   /* number of threads in the pool */
430 EXT afs_int32 rxi_totalMin INIT(0);     /* Sum(minProcs) forall services */
431 EXT afs_int32 rxi_minDeficit INIT(0);   /* number of procs needed to handle all minProcs */
432
433 EXT int rx_nextCid;             /* Next connection call id */
434 EXT int rx_epoch;               /* Initialization time of rx */
435 #ifdef  RX_ENABLE_LOCKS
436 EXT afs_kcondvar_t rx_waitingForPackets_cv;
437 #endif
438 EXT char rx_waitingForPackets;  /* Processes set and wait on this variable when waiting for packet buffers */
439
440 EXT struct rx_stats rx_stats;
441
442 EXT struct rx_peer **rx_peerHashTable;
443 EXT struct rx_connection **rx_connHashTable;
444 EXT struct rx_connection *rx_connCleanup_list INIT(0);
445 EXT afs_uint32 rx_hashTableSize INIT(257);      /* Prime number */
446 #ifdef RX_ENABLE_LOCKS
447 EXT afs_kmutex_t rx_peerHashTable_lock;
448 EXT afs_kmutex_t rx_connHashTable_lock;
449 #endif /* RX_ENABLE_LOCKS */
450
451 #define CONN_HASH(host, port, cid, epoch, type) ((((cid)>>RX_CIDSHIFT)%rx_hashTableSize))
452
453 #define PEER_HASH(host, port)  ((host ^ port) % rx_hashTableSize)
454
455 /* Forward definitions of internal procedures */
456 #define rxi_ChallengeOff(conn)  rxevent_Cancel((conn)->challengeEvent, (struct rx_call*)0, 0);
457 #define rxi_KeepAliveOff(call) rxevent_Cancel((call)->keepAliveEvent, call, RX_CALL_REFCOUNT_ALIVE)
458
459 #define rxi_AllocSecurityObject() (struct rx_securityClass *) rxi_Alloc(sizeof(struct rx_securityClass))
460 #define rxi_FreeSecurityObject(obj) rxi_Free(obj, sizeof(struct rx_securityClass))
461 #define rxi_AllocService()      (struct rx_service *) rxi_Alloc(sizeof(struct rx_service))
462 #define rxi_FreeService(obj)    rxi_Free(obj, sizeof(struct rx_service))
463 #define rxi_AllocPeer()         (struct rx_peer *) rxi_Alloc(sizeof(struct rx_peer))
464 #define rxi_FreePeer(peer)      rxi_Free(peer, sizeof(struct rx_peer))
465 #define rxi_AllocConnection()   (struct rx_connection *) rxi_Alloc(sizeof(struct rx_connection))
466 #define rxi_FreeConnection(conn) (rxi_Free(conn, sizeof(struct rx_connection)))
467
468 #ifdef RXDEBUG
469 /* Some debugging stuff */
470 EXT FILE *rx_debugFile;         /* Set by the user to a stdio file for debugging output */
471 EXT FILE *rxevent_debugFile;    /* Set to an stdio descriptor for event logging to that file */
472
473 #define rx_Log rx_debugFile
474 #define dpf(args) if (rx_debugFile) rxi_DebugPrint args; else
475 #define rx_Log_event rxevent_debugFile
476
477 EXT char *rx_packetTypes[RX_N_PACKET_TYPES] INIT(RX_PACKET_TYPES);      /* Strings defined in rx.h */
478
479 #ifndef KERNEL
480 /*
481  * Counter used to implement connection specific data
482  */
483 EXT int rxi_keyCreate_counter INIT(0);
484 /*
485  * Array of function pointers used to destory connection specific data
486  */
487 EXT rx_destructor_t *rxi_keyCreate_destructor INIT(NULL);
488 #ifdef RX_ENABLE_LOCKS
489 EXT afs_kmutex_t rxi_keyCreate_lock;
490 #endif /* RX_ENABLE_LOCKS */
491 #endif /* !KERNEL */
492
493 #else
494 #define dpf(args)
495 #endif /* RXDEBUG */
496
497 /*
498  * SERVER ONLY: Threshholds used to throttle error replies to looping
499  * clients. When consecutive calls are aborting with the same error, the
500  * server throttles the client by waiting before sending error messages.
501  * Disabled if abort thresholds are zero.
502  */
503 EXT int rxi_connAbortThreshhold INIT(0);
504 EXT int rxi_connAbortDelay INIT(3000);
505 EXT int rxi_callAbortThreshhold INIT(0);
506 EXT int rxi_callAbortDelay INIT(3000);
507
508 /*
509  * Thread specific thread ID used to implement LWP_Index().
510  */
511
512 #if defined(AFS_PTHREAD_ENV)
513 EXT int rxi_fcfs_thread_num INIT(0);
514 EXT pthread_key_t rx_thread_id_key;
515 /* keep track of pthread numbers - protected by rx_stats_mutex, 
516    except in rx_Init() before mutex exists! */
517 EXT int rxi_pthread_hinum INIT(0);
518 #else
519 #define rxi_fcfs_thread_num (0)
520 #endif
521
522 #if defined(RX_ENABLE_LOCKS)
523 EXT afs_kmutex_t rx_stats_mutex;        /* used to activate stats gathering */
524 #endif
525
526 EXT int rx_enable_stats INIT(0);
527
528 /*
529  * Set this flag to enable the listener thread to trade places with an idle
530  * worker thread to move the context switch from listener to worker out of
531  * the request path.
532  */
533 EXT int rx_enable_hot_thread INIT(0);
534
535 #endif /* AFS_RX_GLOBALS_H */