afs: release the packets used by rx on shutdown
[openafs.git] / src / rx / rx_globals.h
index b7cc832..66dff99 100644 (file)
@@ -21,6 +21,7 @@
 
 #ifndef GLOBALSINIT
 #define GLOBALSINIT(x)
+#define POSTAMBLE
 #if defined(AFS_NT40_ENV)
 #define RX_STATS_INTERLOCKED 1
 #if defined(AFS_PTHREAD_ENV)
@@ -43,15 +44,6 @@ EXT struct rx_service *rx_services[RX_MAX_SERVICES + 1];
 EXT afs_kmutex_t rx_serverPool_lock;
 #endif /* RX_ENABLE_LOCKS */
 
-/* Incoming calls wait on this queue when there are no available server processes */
-EXT struct rx_queue rx_incomingCallQueue;
-
-/* Server processes wait on this queue when there are no appropriate calls to process */
-EXT struct rx_queue rx_idleServerQueue;
-
-/* 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. */
-EXT struct clock rx_lastAckDelay;
-
 /* Constant delay time before sending a hard ack if the receiver consumes
  * a packet while no delayed ack event is scheduled. Ensures that the
  * sender is able to advance its window when the receiver consumes a packet
@@ -59,13 +51,8 @@ EXT struct clock rx_lastAckDelay;
  */
 EXT struct clock rx_hardAckDelay;
 
-/* Constant delay time before sending a soft ack when none was requested.
- * This is to make sure we send soft acks before the sender times out,
- * Normally we wait and send a hard ack when the receiver consumes the packet */
-EXT struct clock rx_softAckDelay;
-
-/* Variable to allow introduction of network unreliability */
-#ifdef RXDEBUG
+#if defined(RXDEBUG) || defined(AFS_NT40_ENV)
+/* Variable to allow introduction of network unreliability; exported from libafsrpc */
 EXT int rx_intentionallyDroppedPacketsPer100 GLOBALSINIT(0);   /* Dropped on Send */
 EXT int rx_intentionallyDroppedOnReadPer100  GLOBALSINIT(0);   /* Dropped on Read */
 #endif
@@ -124,13 +111,13 @@ EXT int rx_BusyError GLOBALSINIT(-1);
 #define RX_FAST_ACK_RATE 1     /* as of 3.4, ask for an ack every
                                 * other packet. */
 
-EXT int rx_minPeerTimeout GLOBALSINIT(350); /* in milliseconds */
+EXT int rx_minPeerTimeout GLOBALSINIT(20);      /* in milliseconds */
 EXT int rx_minWindow GLOBALSINIT(1);
-EXT int rx_maxWindow GLOBALSINIT(65535);        /* twind is u_short */
+EXT int rx_maxWindow GLOBALSINIT(RX_MAXACKS);   /* must ack what we receive */
 EXT int rx_initReceiveWindow GLOBALSINIT(16);  /* how much to accept */
-EXT int rx_maxReceiveWindow GLOBALSINIT(128);  /* how much to accept */
+EXT int rx_maxReceiveWindow GLOBALSINIT(32);   /* how much to accept */
 EXT int rx_initSendWindow GLOBALSINIT(16);
-EXT int rx_maxSendWindow GLOBALSINIT(128);
+EXT int rx_maxSendWindow GLOBALSINIT(32);
 EXT int rx_nackThreshold GLOBALSINIT(3);       /* Number NACKS to trigger congestion recovery */
 EXT int rx_nDgramThreshold GLOBALSINIT(4);     /* Number of packets before increasing
                                                  * packets per datagram */
@@ -142,22 +129,13 @@ EXT int rxi_OrphanFragSize GLOBALSINIT(512);
 #define RX_MAX_DGRAM_PACKETS 6 /* max packets per jumbogram */
 
 EXT int rxi_nDgramPackets GLOBALSINIT(RX_MAX_DGRAM_PACKETS);
-/* allow n packets between soft acks - must be power of 2 -1, else change
- * macro below */
+/* allow n packets between soft acks */
 EXT int rxi_SoftAckRate GLOBALSINIT(RX_FAST_ACK_RATE);
 /* consume n packets before sending hard ack, should be larger than above,
    but not absolutely necessary.  If it's smaller, than fast receivers will
    send a soft ack, immediately followed by a hard ack. */
 EXT int rxi_HardAckRate GLOBALSINIT(RX_FAST_ACK_RATE + 1);
 
-/* If window sizes become very variable (in terms of #packets), be
- * sure that the sender can get back a hard acks without having to wait for
- * some kind of timer event first (like a keep-alive, for instance).
- * It might be kind of tricky, so it might be better to shrink the
- * window size by reducing the packet size below the "natural" MTU. */
-
-#define        ACKHACK(p,r) { if (((p)->header.seq & (rxi_SoftAckRate))==0) (p)->header.flags |= RX_REQUEST_ACK; }
-
 EXT int rx_nPackets GLOBALSINIT(0);    /* preallocate packets with rx_extraPackets */
 
 /*
@@ -171,7 +149,7 @@ EXT int rx_nPackets GLOBALSINIT(0); /* preallocate packets with rx_extraPackets
 EXT pthread_key_t rx_ts_info_key;
 typedef struct rx_ts_info_t {
     struct {
-        struct rx_queue queue;
+        struct opr_queue queue;
         int len;                /* local queue length */
         int delta;              /* number of new packets alloc'd locally since last sync w/ global queue */
 
@@ -196,7 +174,7 @@ EXT struct rx_ts_info_t * rx_ts_info_init(void);   /* init function for thread-s
     do { \
         ts_info_p = (struct rx_ts_info_t*)pthread_getspecific(rx_ts_info_key); \
         if (ts_info_p == NULL) { \
-            assert((ts_info_p = rx_ts_info_init()) != NULL); \
+            opr_Verify((ts_info_p = rx_ts_info_init()) != NULL); \
         } \
     } while(0)
 #endif /* AFS_PTHREAD_ENV */
@@ -206,7 +184,7 @@ EXT struct rx_ts_info_t * rx_ts_info_init(void);   /* init function for thread-s
 /* in pthreads rx, free packet queue is now a two-tiered queueing system
  * in which the first tier is thread-specific, and the second tier is
  * a global free packet queue */
-EXT struct rx_queue rx_freePacketQueue;
+EXT struct opr_queue rx_freePacketQueue;
 #ifdef RX_TRACK_PACKETS
 #define RX_FPQ_MARK_FREE(p) \
     do { \
@@ -257,7 +235,19 @@ EXT struct rx_queue rx_freePacketQueue;
 EXT afs_kmutex_t rx_freePktQ_lock;
 #endif /* RX_ENABLE_LOCKS */
 
-#if defined(AFS_PTHREAD_ENV)
+/*!
+ * \brief Queue of allocated packets.
+ *
+ * This queue is used to keep track of the blocks of allocated packets.
+ * This information is used when afs is being unmounted and the memory
+ * used by those packets needs to be released.
+ */
+EXT struct opr_queue rx_mallocedPacketQueue;
+#ifdef RX_ENABLE_LOCKS
+EXT afs_kmutex_t rx_mallocedPktQ_lock;
+#endif /* RX_ENABLE_LOCKS */
+
+#if defined(AFS_PTHREAD_ENV) && !defined(KERNEL)
 #define RX_ENABLE_TSFPQ
 EXT int rx_TSFPQGlobSize GLOBALSINIT(3); /* number of packets to transfer between global and local queues in one op */
 EXT int rx_TSFPQLocalMax GLOBALSINIT(15); /* max number of packets on local FPQ before returning a glob to the global pool */
@@ -307,9 +297,12 @@ EXT int rx_TSFPQMaxProcs GLOBALSINIT(0); /* max number of threads expected */
         struct rx_packet * p; \
         int tsize = MIN((rx_ts_info_p)->_FPQ.len, (rx_ts_info_p)->_FPQ.len - rx_TSFPQLocalMax + 3 *  rx_TSFPQGlobSize); \
        if (tsize <= 0) break; \
-        for (i=0,p=queue_Last(&((rx_ts_info_p)->_FPQ), rx_packet); \
-             i < tsize; i++,p=queue_Prev(p, rx_packet)); \
-        queue_SplitAfterPrepend(&((rx_ts_info_p)->_FPQ),&rx_freePacketQueue,p); \
+        for (i=0,p=opr_queue_Last(&((rx_ts_info_p)->_FPQ.queue), \
+                                struct rx_packet, entry); \
+             i < tsize; i++,p=opr_queue_Prev(&p->entry, \
+                                           struct rx_packet, entry )); \
+        opr_queue_SplitAfterPrepend(&((rx_ts_info_p)->_FPQ.queue), \
+                                  &rx_freePacketQueue, &p->entry); \
         (rx_ts_info_p)->_FPQ.len -= tsize; \
         rx_nFreePackets += tsize; \
         (rx_ts_info_p)->_FPQ.ltog_ops++; \
@@ -327,9 +320,12 @@ EXT int rx_TSFPQMaxProcs GLOBALSINIT(0); /* max number of threads expected */
         int i; \
         struct rx_packet * p; \
         if (num_transfer <= 0) break; \
-        for (i=0,p=queue_Last(&((rx_ts_info_p)->_FPQ), rx_packet); \
-            i < (num_transfer); i++,p=queue_Prev(p, rx_packet)); \
-        queue_SplitAfterPrepend(&((rx_ts_info_p)->_FPQ),&rx_freePacketQueue,p); \
+        for (i=0,p=opr_queue_Last(&((rx_ts_info_p)->_FPQ.queue), \
+                                struct rx_packet, entry ); \
+            i < (num_transfer); \
+            i++,p=opr_queue_Prev(&p->entry, struct rx_packet, entry )); \
+        opr_queue_SplitAfterPrepend(&((rx_ts_info_p)->_FPQ.queue), \
+                                  &rx_freePacketQueue, &p->entry); \
         (rx_ts_info_p)->_FPQ.len -= (num_transfer); \
         rx_nFreePackets += (num_transfer); \
         (rx_ts_info_p)->_FPQ.ltog_ops++; \
@@ -349,9 +345,12 @@ EXT int rx_TSFPQMaxProcs GLOBALSINIT(0); /* max number of threads expected */
         struct rx_packet * p; \
         tsize = (rx_TSFPQGlobSize <= rx_nFreePackets) ? \
                  rx_TSFPQGlobSize : rx_nFreePackets; \
-        for (i=0,p=queue_First(&rx_freePacketQueue, rx_packet); \
-             i < tsize; i++,p=queue_Next(p, rx_packet)); \
-        queue_SplitBeforeAppend(&rx_freePacketQueue,&((rx_ts_info_p)->_FPQ),p); \
+        for (i=0, \
+              p=opr_queue_First(&rx_freePacketQueue, struct rx_packet, entry); \
+             i < tsize; \
+            i++,p=opr_queue_Next(&p->entry, struct rx_packet, entry)); \
+        opr_queue_SplitBeforeAppend(&rx_freePacketQueue, \
+                                  &((rx_ts_info_p)->_FPQ.queue), &p->entry); \
         (rx_ts_info_p)->_FPQ.len += i; \
         rx_nFreePackets -= i; \
         (rx_ts_info_p)->_FPQ.gtol_ops++; \
@@ -364,9 +363,12 @@ EXT int rx_TSFPQMaxProcs GLOBALSINIT(0); /* max number of threads expected */
         struct rx_packet * p; \
         tsize = (num_transfer); \
         if (tsize > rx_nFreePackets) tsize = rx_nFreePackets; \
-        for (i=0,p=queue_First(&rx_freePacketQueue, rx_packet); \
-             i < tsize; i++,p=queue_Next(p, rx_packet)); \
-        queue_SplitBeforeAppend(&rx_freePacketQueue,&((rx_ts_info_p)->_FPQ),p); \
+        for (i=0, \
+              p=opr_queue_First(&rx_freePacketQueue, struct rx_packet, entry); \
+             i < tsize; \
+            i++, p=opr_queue_Next(&p->entry, struct rx_packet, entry)); \
+        opr_queue_SplitBeforeAppend(&rx_freePacketQueue, \
+                                  &((rx_ts_info_p)->_FPQ.queue), &p->entry); \
         (rx_ts_info_p)->_FPQ.len += i; \
         rx_nFreePackets -= i; \
         (rx_ts_info_p)->_FPQ.gtol_ops++; \
@@ -375,8 +377,9 @@ EXT int rx_TSFPQMaxProcs GLOBALSINIT(0); /* max number of threads expected */
 /* checkout a packet from the thread-specific free packet queue */
 #define RX_TS_FPQ_CHECKOUT(rx_ts_info_p,p) \
     do { \
-        (p) = queue_First(&((rx_ts_info_p)->_FPQ), rx_packet); \
-        queue_Remove(p); \
+        (p) = opr_queue_First(&((rx_ts_info_p)->_FPQ.queue), \
+                            struct rx_packet, entry); \
+        opr_queue_Remove(&p->entry); \
         RX_FPQ_MARK_USED(p); \
         (rx_ts_info_p)->_FPQ.len--; \
         (rx_ts_info_p)->_FPQ.checkout_ops++; \
@@ -390,12 +393,14 @@ EXT int rx_TSFPQMaxProcs GLOBALSINIT(0); /* max number of threads expected */
         int i; \
         struct rx_packet *p; \
         if (num_transfer > (rx_ts_info_p)->_FPQ.len) num_transfer = (rx_ts_info_p)->_FPQ.len; \
-        for (i=0, p=queue_First(&((rx_ts_info_p)->_FPQ), rx_packet); \
+        for (i=0, p=opr_queue_First(&((rx_ts_info_p)->_FPQ.queue), \
+                                  struct rx_packet, entry); \
              i < num_transfer; \
-             i++, p=queue_Next(p, rx_packet)) { \
+             i++, p=opr_queue_Next(&p->entry, struct rx_packet, entry)) { \
             RX_FPQ_MARK_USED(p); \
         } \
-        queue_SplitBeforeAppend(&((rx_ts_info_p)->_FPQ),(q),p); \
+        opr_queue_SplitBeforeAppend(&((rx_ts_info_p)->_FPQ.queue),(q), \
+                                  &((p)->entry)); \
         (rx_ts_info_p)->_FPQ.len -= num_transfer; \
         (rx_ts_info_p)->_FPQ.checkout_ops++; \
         (rx_ts_info_p)->_FPQ.checkout_xfer += num_transfer; \
@@ -403,7 +408,7 @@ EXT int rx_TSFPQMaxProcs GLOBALSINIT(0); /* max number of threads expected */
 /* check a packet into the thread-specific free packet queue */
 #define RX_TS_FPQ_CHECKIN(rx_ts_info_p,p) \
     do { \
-        queue_Prepend(&((rx_ts_info_p)->_FPQ), (p)); \
+        opr_queue_Prepend(&((rx_ts_info_p)->_FPQ.queue), &((p)->entry)); \
         RX_FPQ_MARK_FREE(p); \
         (rx_ts_info_p)->_FPQ.len++; \
         (rx_ts_info_p)->_FPQ.checkin_ops++; \
@@ -415,22 +420,20 @@ EXT int rx_TSFPQMaxProcs GLOBALSINIT(0); /* max number of threads expected */
  * since caller already knows length of (q) for other reasons */
 #define RX_TS_FPQ_QCHECKIN(rx_ts_info_p,num_transfer,q) \
     do { \
-        struct rx_packet *p, *np; \
-        for (queue_Scan((q), p, np, rx_packet)) { \
-            RX_FPQ_MARK_FREE(p); \
+       struct opr_queue *cur; \
+        for (opr_queue_Scan((q), cur)) { \
+            RX_FPQ_MARK_FREE(opr_queue_Entry(cur, struct rx_packet, entry)); \
         } \
-        queue_SplicePrepend(&((rx_ts_info_p)->_FPQ),(q)); \
+        opr_queue_SplicePrepend(&((rx_ts_info_p)->_FPQ.queue),(q)); \
         (rx_ts_info_p)->_FPQ.len += (num_transfer); \
         (rx_ts_info_p)->_FPQ.checkin_ops++; \
         (rx_ts_info_p)->_FPQ.checkin_xfer += (num_transfer); \
     } while(0)
-#endif /* AFS_PTHREAD_ENV */
+#endif /* AFS_PTHREAD_ENV && !KERNEL */
 
 /* Number of free packets */
 EXT int rx_nFreePackets GLOBALSINIT(0);
 EXT int rxi_NeedMorePackets GLOBALSINIT(0);
-EXT int rx_nWaiting GLOBALSINIT(0);
-EXT int rx_nWaited GLOBALSINIT(0);
 EXT int rx_packetReclaims GLOBALSINIT(0);
 
 /* largest packet which we can safely receive, initialized to AFS 3.2 value
@@ -463,7 +466,7 @@ EXT afs_kmutex_t freeSQEList_lock;
 #endif
 
 /* List of free call structures */
-EXT struct rx_queue rx_freeCallQueue;
+EXT struct opr_queue rx_freeCallQueue;
 #ifdef RX_ENABLE_LOCKS
 EXT afs_kmutex_t rx_freeCallQueue_lock;
 #endif
@@ -491,7 +494,6 @@ EXT osi_socket rx_minSocketNumber GLOBALSINIT(0x7fffffff);
 #define        RX_MAX_QUOTA    15      /* part of min packet computation */
 EXT int rx_packetQuota[RX_N_PACKET_CLASSES] GLOBALSINIT(RX_PACKET_QUOTAS);
 EXT int meltdown_1pkt GLOBALSINIT(1);  /* prefer to schedule single-packet calls */
-EXT int rxi_doreclaim GLOBALSINIT(1);  /* if discard one packet, discard all */
 EXT int rxi_md2cnt GLOBALSINIT(0);     /* counter of skipped calls */
 EXT int rxi_2dchoice GLOBALSINIT(1);   /* keep track of another call to schedule */
 
@@ -516,15 +518,13 @@ EXT afs_int32 rxi_availProcs GLOBALSINIT(0);      /* number of threads in the pool */
 EXT afs_int32 rxi_totalMin GLOBALSINIT(0);     /* Sum(minProcs) forall services */
 EXT afs_int32 rxi_minDeficit GLOBALSINIT(0);   /* number of procs needed to handle all minProcs */
 
-EXT int rx_nextCid;            /* Next connection call id */
-EXT int rx_epoch;              /* Initialization time of rx */
+EXT afs_uint32 rx_nextCid;             /* Next connection call id */
+EXT afs_uint32 rx_epoch;               /* Initialization time of rx */
 #ifdef RX_ENABLE_LOCKS
 EXT afs_kcondvar_t rx_waitingForPackets_cv;
 #endif
 EXT char rx_waitingForPackets; /* Processes set and wait on this variable when waiting for packet buffers */
 
-EXT struct rx_statistics rx_stats;
-
 EXT struct rx_peer **rx_peerHashTable;
 EXT struct rx_connection **rx_connHashTable;
 EXT struct rx_connection *rx_connCleanup_list GLOBALSINIT(0);
@@ -539,9 +539,10 @@ EXT afs_kmutex_t rx_connHashTable_lock;
 #define PEER_HASH(host, port)  ((host ^ port) % rx_hashTableSize)
 
 /* Forward definitions of internal procedures */
-#define        rxi_ChallengeOff(conn)  rxevent_Cancel((conn)->challengeEvent, (struct rx_call*)0, 0);
-#define rxi_KeepAliveOff(call) rxevent_Cancel((call)->keepAliveEvent, call, RX_CALL_REFCOUNT_ALIVE)
-#define rxi_NatKeepAliveOff(conn) rxevent_Cancel((conn)->natKeepAliveEvent, (struct rx_call*)0, 0)
+#define        rxi_ChallengeOff(conn)  \
+       rxevent_Cancel(&(conn)->challengeEvent)
+#define rxi_NatKeepAliveOff(conn) \
+       rxevent_Cancel(&(conn)->natKeepAliveEvent)
 
 #define rxi_AllocSecurityObject() rxi_Alloc(sizeof(struct rx_securityClass))
 #define        rxi_FreeSecurityObject(obj) rxi_Free(obj, sizeof(struct rx_securityClass))
@@ -565,24 +566,24 @@ EXT FILE *rxevent_debugFile;      /* Set to an stdio descriptor for event logging to
 #endif
 
 #ifdef RXDEBUG
-#define rx_Log rx_debugFile
-#ifdef AFS_NT40_ENV
+# define rx_Log rx_debugFile
+# ifdef AFS_NT40_ENV
 EXT int rxdebug_active;
-#define dpf(args) do { if (rxdebug_active) rxi_DebugPrint args; } while (0)
-#else
-#ifdef DPF_FSLOG
-#include <afs/afsutil.h>
-#define dpf(args) FSLog args
+#  define dpf(args) do { if (rxdebug_active) rxi_DebugPrint args; } while (0)
+# else
+#  ifdef DPF_FSLOG
+#   include <afs/afsutil.h>
+#   define dpf(args) FSLog args
+#  else
+#   define dpf(args) do { if (rx_debugFile) rxi_DebugPrint args; } while (0)
+#  endif
+# endif
+# define rx_Log_event rxevent_debugFile
 #else
-#define dpf(args) do { if (rx_debugFile) rxi_DebugPrint args; } while (0)
-#endif
-#endif
-#define rx_Log_event rxevent_debugFile
+# define dpf(args)
+#endif /* RXDEBUG */
 
 EXT char *rx_packetTypes[RX_N_PACKET_TYPES] GLOBALSINIT(RX_PACKET_TYPES);      /* Strings defined in rx.h */
-#else
-#define dpf(args)
-#endif /* RXDEBUG */
 
 #ifndef KERNEL
 /*
@@ -616,19 +617,16 @@ EXT int rxi_callAbortDelay GLOBALSINIT(3000);
 #if defined(AFS_PTHREAD_ENV)
 EXT int rxi_fcfs_thread_num GLOBALSINIT(0);
 EXT pthread_key_t rx_thread_id_key;
-/* keep track of pthread numbers - protected by rx_stats_mutex,
- * except in rx_Init() before mutex exists! */
-EXT int rxi_pthread_hinum GLOBALSINIT(0);
 #else
 #define rxi_fcfs_thread_num (0)
 #endif
 
 #if defined(RX_ENABLE_LOCKS)
-EXT afs_kmutex_t rx_stats_mutex;       /* used to protect stats gathering */
-EXT afs_kmutex_t rx_waiting_mutex;     /* used to protect waiting counters */
-EXT afs_kmutex_t rx_quota_mutex;       /* used to protect quota counters */
-EXT afs_kmutex_t rx_pthread_mutex;     /* used to protect pthread counters */
-EXT afs_kmutex_t rx_packets_mutex;     /* used to protect packet counters */
+EXT afs_kmutex_t rx_waiting_mutex POSTAMBLE;   /* used to protect waiting counters */
+EXT afs_kmutex_t rx_quota_mutex POSTAMBLE;     /* used to protect quota counters */
+EXT afs_kmutex_t rx_pthread_mutex POSTAMBLE;   /* used to protect pthread counters */
+EXT afs_kmutex_t rx_packets_mutex POSTAMBLE;   /* used to protect packet counters */
+EXT afs_kmutex_t rx_refcnt_mutex POSTAMBLE;       /* used to protect conn/call ref counts */
 #endif
 
 EXT int rx_enable_stats GLOBALSINIT(0);