rx-warning-cleanup-and-afsconfig-20010605
[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 #ifdef  KERNEL
13 #include "../rx/rx.h"
14 #else /* KERNEL */
15 # include "rx.h"
16 #endif /* KERNEL */
17
18 #ifndef INIT
19 #define INIT(x)
20 #if defined(AFS_NT40_ENV) && defined(AFS_PTHREAD_ENV)
21 #define EXT __declspec(dllimport) extern
22 #else
23 #define EXT extern
24 #endif
25 #endif
26
27 /* Basic socket for client requests; other sockets (for receiving server requests) are in the service structures */
28 EXT osi_socket rx_socket;
29
30 /* The array of installed services.  Null terminated. */
31 EXT struct rx_service *rx_services[RX_MAX_SERVICES+1];
32 #ifdef RX_ENABLE_LOCKS
33 /* Protects nRequestsRunning as well as pool allocation variables. */
34 EXT afs_kmutex_t rx_serverPool_lock;
35 EXT afs_kcondvar_t rx_serverPool_cv;
36 #endif /* RX_ENABLE_LOCKS */
37
38 /* Incoming calls wait on this queue when there are no available server processes */
39 EXT struct rx_queue rx_incomingCallQueue;
40
41 /* Server processes wait on this queue when there are no appropriate calls to process */
42 EXT struct rx_queue rx_idleServerQueue;
43
44 /* 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. */
45 EXT struct clock rx_lastAckDelay;
46
47 /* Constant delay time before sending a hard ack if the receiver consumes
48  * a packet while no delayed ack event is scheduled. Ensures that the
49  * sender is able to advance its window when the receiver consumes a packet
50  * after the sender has exhausted its transmit window.
51  */
52 EXT struct clock rx_hardAckDelay;
53
54 /* Constant delay time before sending a soft ack when none was requested.
55  * This is to make sure we send soft acks before the sender times out,
56  * Normally we wait and send a hard ack when the receiver consumes the packet */
57 EXT struct clock rx_softAckDelay;
58
59 /* Variable to allow introduction of network unreliability */
60 #ifdef RXDEBUG
61 EXT int rx_intentionallyDroppedPacketsPer100 INIT(0);   /* Dropped on Send */
62 #endif
63
64 /* extra packets to add to the quota */
65 EXT int rx_extraQuota INIT(0);
66 /* extra packets to alloc (2 windows by deflt) */
67 EXT int rx_extraPackets INIT(32);
68
69 EXT int rx_stackSize INIT(RX_DEFAULT_STACK_SIZE);
70
71 /* Time until an unresponsive connection is declared dead */
72 EXT int rx_connDeadTime INIT(12);
73 /* Set rx default connection dead time; set on both services and connections at creation time */
74 #define rx_SetRxDeadTime(seconds)   (rx_connDeadTime = (seconds))
75
76 /* Time until we toss an idle connection */
77 EXT int rx_idleConnectionTime INIT(700);
78 /* Time until we toss a peer structure, after all connections using are gone */
79 EXT int rx_idlePeerTime INIT(60);
80
81 /* The file server is temporarily salvaging */
82 EXT int rx_tranquil     INIT(0);
83
84 /* UDP rcv buffer size */
85 EXT int rx_UdpBufSize   INIT(64*1024);
86 #define rx_GetMinUdpBufSize()   (64*1024)
87 #define rx_SetUdpBufSize(x)     (((x)>rx_GetMinUdpBufSize()) ? (rx_UdpBufSize = (x)):0)
88
89 /*
90  * Variables to control RX overload management. When the number of calls
91  * waiting for a thread exceed the threshold, new calls are aborted
92  * with the busy error. 
93  */
94 EXT int rx_BusyThreshold INIT(-1);      /* default is disabled */
95 EXT int rx_BusyError INIT(-1);
96
97 /* These definitions should be in one place */
98 #ifdef  AFS_SUN5_ENV
99 #define RX_CBUF_TIME    180     /* Check for packet deficit */
100 #define RX_REAP_TIME    90          /* Check for tossable connections every 90 seconds */
101 #else
102 #define RX_CBUF_TIME    120     /* Check for packet deficit */
103 #define RX_REAP_TIME    60          /* Check for tossable connections every 60 seconds */
104 #endif
105
106 #define RX_FAST_ACK_RATE 1      /* as of 3.4, ask for an ack every 
107                                    other packet. */
108
109 EXT int rx_minWindow INIT(1); 
110 EXT int rx_initReceiveWindow INIT(16); /* how much to accept */
111 EXT int rx_maxReceiveWindow INIT(32);  /* how much to accept */
112 EXT int rx_initSendWindow INIT(8); 
113 EXT int rx_maxSendWindow INIT(32); 
114 EXT int rx_nackThreshold INIT(3);      /* Number NACKS to trigger congestion recovery */
115 EXT int rx_nDgramThreshold INIT(4);    /* Number of packets before increasing
116                                           packets per datagram */
117 #define RX_MAX_FRAGS 4
118 EXT int rxi_nSendFrags INIT(RX_MAX_FRAGS);  /* max fragments in a datagram */
119 EXT int rxi_nRecvFrags INIT(RX_MAX_FRAGS);
120 EXT int rxi_OrphanFragSize INIT(512);
121
122 #define RX_MAX_DGRAM_PACKETS 6 /* max packets per jumbogram */
123
124 EXT int rxi_nDgramPackets INIT(RX_MAX_DGRAM_PACKETS);
125 /* allow n packets between soft acks - must be power of 2 -1, else change
126  * macro below */
127 EXT int rxi_SoftAckRate INIT(RX_FAST_ACK_RATE);  
128 /* consume n packets before sending hard ack, should be larger than above,
129    but not absolutely necessary.  If it's smaller, than fast receivers will
130    send a soft ack, immediately followed by a hard ack. */
131 EXT int rxi_HardAckRate INIT(RX_FAST_ACK_RATE+1);
132
133 /* EXT int rx_maxWindow INIT(15);   Temporary HACK:  transmit/receive window */
134
135 /* If window sizes become very variable (in terms of #packets), be
136  * sure that the sender can get back a hard acks without having to wait for
137  * some kind of timer event first (like a keep-alive, for instance).
138  * It might be kind of tricky, so it might be better to shrink the
139  * window size by reducing the packet size below the "natural" MTU. */
140
141 #define ACKHACK(p,r) { if (((p)->header.seq & (rxi_SoftAckRate))==0) (p)->header.flags |= RX_REQUEST_ACK; } 
142
143 EXT int rx_nPackets INIT(100);  /* obsolete; use rx_extraPackets now */
144
145 /* List of free packets */
146 EXT struct rx_queue rx_freePacketQueue;
147 #ifdef RX_ENABLE_LOCKS
148 EXT afs_kmutex_t rx_freePktQ_lock;
149 #endif
150
151 /* Number of free packets */
152 EXT int rx_nFreePackets INIT(0);
153 EXT int rxi_NeedMorePackets INIT(0);
154 EXT int rx_nWaiting INIT(0);
155 EXT int rx_packetReclaims INIT(0);
156
157 /* largest packet which we can safely receive, initialized to AFS 3.2 value
158  * This is provided for backward compatibility with peers which may be unable
159  * to swallow anything larger. THIS MUST NEVER DECREASE WHILE AN APPLICATION
160  * IS RUNNING! */
161 EXT afs_uint32 rx_maxReceiveSize INIT(OLD_MAX_PACKET_SIZE*RX_MAX_FRAGS + UDP_HDR_SIZE*(RX_MAX_FRAGS-1));
162
163 /* this is the maximum packet size that the user wants us to receive */
164 /* this is set by rxTune if required */
165 EXT afs_uint32 rx_maxReceiveSizeUser INIT(0xffffffff);
166
167 /* rx_MyMaxSendSize is the size of the largest packet we will send,
168  * including the RX header. Just as rx_maxReceiveSize is the
169  * max we will receive, including the rx header.
170  */
171 EXT afs_uint32 rx_MyMaxSendSize INIT(8588);
172
173 /* Maximum size of a jumbo datagram we can receive */
174 EXT afs_uint32 rx_maxJumboRecvSize INIT(RX_MAX_PACKET_SIZE);
175
176 /* need this to permit progs to run on AIX systems */
177 EXT int (*rxi_syscallp) () INIT(0); 
178
179 /* List of free queue entries */
180 EXT struct rx_serverQueueEntry *rx_FreeSQEList INIT(0);
181 #ifdef  RX_ENABLE_LOCKS
182 EXT afs_kmutex_t freeSQEList_lock;
183 #endif
184
185 /* List of free call structures */
186 EXT struct rx_queue rx_freeCallQueue;
187 #ifdef  RX_ENABLE_LOCKS
188 EXT afs_kmutex_t rx_freeCallQueue_lock;
189 #endif
190 EXT afs_int32 rxi_nCalls INIT(0);
191
192 /* 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. */
193 EXT u_short rx_port;
194
195 #if !defined(KERNEL) && !defined(AFS_PTHREAD_ENV)
196 /* 32-bit select Mask for rx_Listener. */
197 EXT fd_set rx_selectMask;
198 EXT int rx_maxSocketNumber; /* Maximum socket number in the select mask. */
199 /* Minumum socket number in the select mask. */
200 EXT int rx_minSocketNumber INIT(0x7fffffff);
201 #endif
202
203 /* This is actually the minimum number of packets that must remain free,
204     overall, immediately after a packet of the requested class has been
205     allocated.  *WARNING* These must be assigned with a great deal of care.
206     In order, these are receive quota, send quota, special quota, receive
207     continuation quota, and send continuation quota. */
208 #define RX_PACKET_QUOTAS {1, 10, 0, 1, 10}
209 /* value large enough to guarantee that no allocation fails due to RX_PACKET_QUOTAS.
210    Make it a little bigger, just for fun */
211 #define RX_MAX_QUOTA    15      /* part of min packet computation */
212 EXT int rx_packetQuota[RX_N_PACKET_CLASSES] INIT(RX_PACKET_QUOTAS);
213 EXT int meltdown_1pkt INIT(1); /* prefer to schedule single-packet calls */
214 EXT int rxi_doreclaim INIT(1);    /* if discard one packet, discard all */
215 EXT int rxi_md2cnt INIT(0);    /* counter of skipped calls */
216 EXT int rxi_2dchoice INIT(1);    /* keep track of another call to schedule */
217
218 /* quota system: each attached server process must be able to make
219     progress to avoid system deadlock, so we ensure that we can always
220     handle the arrival of the next unacknowledged data packet for an
221     attached call.  rxi_dataQuota gives the max # of packets that must be
222     reserved for active calls for them to be able to make progress, which is
223     essentially enough to queue up a window-full of packets (the first packet
224     may be missing, so these may not get read) + the # of packets the thread
225     may use before reading all of its input (# free must be one more than send
226     packet quota).  Thus, each thread allocates rx_maxReceiveWindow+1 (max
227     queued packets) + an extra for sending data.  The system also reserves
228     RX_MAX_QUOTA (must be more than RX_PACKET_QUOTA[i], which is 10), so that
229     the extra packet can be sent (must be under the system-wide send packet
230     quota to send any packets) */
231 /* # to reserve so that thread with input can still make calls (send packets)
232    without blocking */
233 EXT int rxi_dataQuota INIT(RX_MAX_QUOTA); /* packets to reserve for active threads */
234
235 EXT afs_int32 rxi_availProcs INIT(0);   /* number of threads in the pool */
236 EXT afs_int32 rxi_totalMin INIT(0);             /* Sum(minProcs) forall services */
237 EXT afs_int32 rxi_minDeficit INIT(0);   /* number of procs needed to handle all minProcs */
238
239 EXT int rx_nextCid;         /* Next connection call id */
240 EXT int rx_epoch;           /* Initialization time of rx */
241 #ifdef  RX_ENABLE_LOCKS
242 EXT afs_kcondvar_t rx_waitingForPackets_cv;
243 #endif
244 EXT char rx_waitingForPackets; /* Processes set and wait on this variable when waiting for packet buffers */
245
246 EXT struct rx_stats rx_stats;
247
248 EXT struct rx_peer **rx_peerHashTable;
249 EXT struct rx_connection **rx_connHashTable;
250 EXT struct rx_connection *rx_connCleanup_list INIT(0);
251 EXT afs_uint32 rx_hashTableSize INIT(256);      /* Power of 2 */
252 EXT afs_uint32 rx_hashTableMask INIT(255);      /* One less than rx_hashTableSize */
253 #ifdef RX_ENABLE_LOCKS
254 EXT afs_kmutex_t rx_peerHashTable_lock;
255 EXT afs_kmutex_t rx_connHashTable_lock;
256 #endif /* RX_ENABLE_LOCKS */
257
258 #define CONN_HASH(host, port, cid, epoch, type) ((((cid)>>RX_CIDSHIFT)&rx_hashTableMask))
259
260 #define PEER_HASH(host, port)  ((host ^ port) & rx_hashTableMask)
261
262
263 #ifdef  notdef /* Use a func for now to measure allocated structs */
264 #define rxi_Free(addr, size)    osi_Free(addr, size)
265 #endif /* notdef */
266
267 void rxi_Free();
268
269 /* Forward definitions of internal procedures */
270 struct rx_packet *rxi_AllocPacket();
271 struct rx_packet *rxi_AllocSendPacket();
272 char *rxi_Alloc();
273 struct rx_peer *rxi_FindPeer();
274 struct rx_call *rxi_NewCall();
275 void rxi_FreeCall();
276 struct rx_call *rxi_FindCall();
277 int rxi_ReadPacket();
278 struct rx_packet *rxi_ReceivePacket();
279 struct rx_packet *rxi_ReceiveDataPacket();
280 struct rx_packet *rxi_ReceiveAckPacket();
281 struct rx_packet *rxi_ReceiveResponsePacket();
282 struct rx_packet *rxi_ReceiveChallengePacket();
283 void rx_ServerProc();
284 void rxi_ServerProc();
285 void rxi_AttachServerProc();
286 void rxi_ChallengeOn();
287 #define rxi_ChallengeOff(conn)  rxevent_Cancel((conn)->challengeEvent, (struct rx_call*)0, 0);
288 void rxi_ChallengeEvent();
289 void rxi_SendDelayedConnAbort();
290 void rxi_SendDelayedCallAbort();
291 struct rx_packet *rxi_SendAck();
292 void rxi_ClearTransmitQueue();
293 void rxi_ClearReceiveQueue();
294 void rxi_InitCall();
295 void rxi_ResetCall();
296 void rxi_CallError();
297 void rxi_ConnectionError();
298 void rxi_QueuePackets();
299 void rxi_Start();
300 void rxi_CallIsIdle();
301 void rxi_CallTimedOut();
302 void rxi_ComputeRoundTripTime();
303 void rxi_ScheduleKeepAliveEvent();
304 void rxi_KeepAliveEvent();
305 void rxi_KeepAliveOn();
306 #define rxi_KeepAliveOff(call) rxevent_Cancel((call)->keepAliveEvent, call, RX_CALL_REFCOUNT_ALIVE)
307 void rxi_AckAll();
308 void rxi_SendDelayedAck();
309 struct rx_packet *rxi_SendSpecial();
310 struct rx_packet *rxi_SendCallAbort();
311 struct rx_packet *rxi_SendConnectionAbort();
312 void rxi_ScheduleDecongestionEvent();
313 void rxi_CongestionWait();
314 void rxi_ReapConnections();
315 void rxi_EncodePacketHeader();
316 void rxi_DecodePacketHeader();
317 void rxi_DebugPrint();
318 void rxi_SendDelayedAck();
319 void rxi_PrepareSendPacket();
320 void rxi_Send();
321
322
323 #define rxi_AllocSecurityObject() (struct rx_securityClass *) rxi_Alloc(sizeof(struct rx_securityClass))
324 #define rxi_FreeSecurityObject(obj) rxi_Free(obj, sizeof(struct rx_securityClass))
325 #define rxi_AllocService()      (struct rx_service *) rxi_Alloc(sizeof(struct rx_service))
326 #define rxi_FreeService(obj)    rxi_Free(obj, sizeof(struct rx_service))
327 #define rxi_AllocPeer()         (struct rx_peer *) rxi_Alloc(sizeof(struct rx_peer))
328 #define rxi_FreePeer(peer)      rxi_Free(peer, sizeof(struct rx_peer))
329 #define rxi_AllocConnection()   (struct rx_connection *) rxi_Alloc(sizeof(struct rx_connection))
330 #define rxi_FreeConnection(conn) (rxi_Free(conn, sizeof(struct rx_connection)))
331
332 #ifdef RXDEBUG
333 /* Some debugging stuff */
334 EXT FILE *rx_debugFile; /* Set by the user to a stdio file for debugging output */
335 EXT FILE *rxevent_debugFile;    /* Set to an stdio descriptor for event logging to that file */
336
337 #define rx_Log rx_debugFile
338 #define dpf(args) if (rx_debugFile) rxi_DebugPrint args; else
339 #define rx_Log_event rxevent_debugFile
340
341 EXT char *rx_packetTypes[RX_N_PACKET_TYPES] INIT(RX_PACKET_TYPES); /* Strings defined in rx.h */
342
343 #ifndef KERNEL
344 /*
345  * Counter used to implement connection specific data
346  */
347 EXT int rxi_keyCreate_counter INIT(0);
348 /*
349  * Array of function pointers used to destory connection specific data
350  */
351 EXT rx_destructor_t *rxi_keyCreate_destructor INIT(NULL);
352 #ifdef RX_ENABLE_LOCKS
353 EXT afs_kmutex_t rxi_keyCreate_lock;
354 #endif /* RX_ENABLE_LOCKS */
355 #endif /* !KERNEL */
356
357 #else
358 #define dpf(args) 
359 #endif /* RXDEBUG */
360
361 /*
362  * SERVER ONLY: Threshholds used to throttle error replies to looping
363  * clients. When consecutive calls are aborting with the same error, the
364  * server throttles the client by waiting before sending error messages.
365  * Disabled if abort thresholds are zero.
366  */
367 EXT int rxi_connAbortThreshhold INIT(0);
368 EXT int rxi_connAbortDelay INIT(3000);
369 EXT int rxi_callAbortThreshhold INIT(0);
370 EXT int rxi_callAbortDelay INIT(3000);
371
372 /*
373  * Thread specific thread ID used to implement LWP_Index().
374  */
375
376 #if defined(AFS_PTHREAD_ENV)
377 EXT pthread_key_t rx_thread_id_key;
378 #endif
379
380 #if defined(RX_ENABLE_LOCKS)
381 EXT afs_kmutex_t rx_stats_mutex; /* used to activate stats gathering */
382 #endif
383
384 EXT int rx_enable_stats INIT(0);
385
386 /*
387  * Set this flag to enable the listener thread to trade places with an idle
388  * worker thread to move the context switch from listener to worker out of
389  * the request path.
390  */
391 EXT int rx_enable_hot_thread INIT(0);