]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Rx: only compute peer bytes sent and received if rx_stats_active
authorJeffrey Altman <jaltman@your-file-system.com>
Sun, 19 Sep 2010 16:47:37 +0000 (09:47 -0700)
committerDerrick Brashear <shadow@dementia.org>
Mon, 27 Sep 2010 15:29:39 +0000 (08:29 -0700)
Computing the bytes sent and received is an expensive operation.
If rx statistics collection has been disabled we should not collect
the peer data.  The most expensive operation is the rx_FindPeer()
call that is performed during rxi_ReadPacket().  rxi_ReadPacket()
is processed by the rx listener thread which must be as fast as
possible.

Change-Id: I5403c88aa85f9049fe50a9c1f3dbaad7d8b802bd
Reviewed-on: http://gerrit.openafs.org/2782
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>
(cherry picked from commit 7d16c8b84ac8cc0251231819bfb0eefc2040322a)
Reviewed-on: http://gerrit.openafs.org/2807

src/rx/rx_packet.c

index 92aef613132aacad2550fe7653513d427e89870f..c5ba1621bf436bb52695fc62657968e51ad5449a 100644 (file)
@@ -14,7 +14,6 @@
 #include <afs/param.h>
 #endif
 
-
 #ifdef KERNEL
 #if defined(UKERNEL)
 #include "afs/sysincludes.h"
@@ -1505,30 +1504,31 @@ rxi_ReadPacket(osi_socket socket, struct rx_packet *p, afs_uint32 * host,
        *host = from.sin_addr.s_addr;
        *port = from.sin_port;
        if (p->header.type > 0 && p->header.type < RX_N_PACKET_TYPES) {
-           struct rx_peer *peer;
-            if (rx_stats_active)
+            if (rx_stats_active) {
+                struct rx_peer *peer;
                 rx_MutexIncrement(rx_stats.packetsRead[p->header.type - 1], rx_stats_mutex);
-           /*
-            * Try to look up this peer structure.  If it doesn't exist,
-            * don't create a new one -
-            * we don't keep count of the bytes sent/received if a peer
-            * structure doesn't already exist.
-            *
-            * The peer/connection cleanup code assumes that there is 1 peer
-            * per connection.  If we actually created a peer structure here
-            * and this packet was an rxdebug packet, the peer structure would
-            * never be cleaned up.
-            */
-           peer = rxi_FindPeer(*host, *port, 0, 0);
-           /* Since this may not be associated with a connection,
-            * it may have no refCount, meaning we could race with
-            * ReapConnections
-            */
-           if (peer && (peer->refCount > 0)) {
-               MUTEX_ENTER(&peer->peer_lock);
-               hadd32(peer->bytesReceived, p->length);
-               MUTEX_EXIT(&peer->peer_lock);
-           }
+                /*
+                 * Try to look up this peer structure.  If it doesn't exist,
+                 * don't create a new one -
+                 * we don't keep count of the bytes sent/received if a peer
+                 * structure doesn't already exist.
+                 *
+                 * The peer/connection cleanup code assumes that there is 1 peer
+                 * per connection.  If we actually created a peer structure here
+                 * and this packet was an rxdebug packet, the peer structure would
+                 * never be cleaned up.
+                 */
+                peer = rxi_FindPeer(*host, *port, 0, 0);
+                /* Since this may not be associated with a connection,
+                 * it may have no refCount, meaning we could race with
+                 * ReapConnections
+                 */
+                if (peer && (peer->refCount > 0)) {
+                    MUTEX_ENTER(&peer->peer_lock);
+                    hadd32(peer->bytesReceived, p->length);
+                    MUTEX_EXIT(&peer->peer_lock);
+                }
+            }
        }
 
 #ifdef RX_TRIMDATABUFS
@@ -2336,11 +2336,12 @@ rxi_SendPacket(struct rx_call *call, struct rx_connection *conn,
           ntohs(peer->port), p->header.serial, p->header.epoch, p->header.cid, p->header.callNumber,
           p->header.seq, p->header.flags, p, p->retryTime.sec, p->retryTime.usec / 1000, p->length));
 #endif
-    if (rx_stats_active)
+    if (rx_stats_active) {
         rx_MutexIncrement(rx_stats.packetsSent[p->header.type - 1], rx_stats_mutex);
-    MUTEX_ENTER(&peer->peer_lock);
-    hadd32(peer->bytesSent, p->length);
-    MUTEX_EXIT(&peer->peer_lock);
+        MUTEX_ENTER(&peer->peer_lock);
+        hadd32(peer->bytesSent, p->length);
+        MUTEX_EXIT(&peer->peer_lock);
+    }
 }
 
 /* Send a list of packets to appropriate destination for the specified
@@ -2541,11 +2542,12 @@ rxi_SendPacketList(struct rx_call *call, struct rx_connection *conn,
           p->header.seq, p->header.flags, p, p->retryTime.sec, p->retryTime.usec / 1000, p->length));
 
 #endif
-    if (rx_stats_active)
+    if (rx_stats_active) {
         rx_MutexIncrement(rx_stats.packetsSent[p->header.type - 1], rx_stats_mutex);
-    MUTEX_ENTER(&peer->peer_lock);
-    hadd32(peer->bytesSent, p->length);
-    MUTEX_EXIT(&peer->peer_lock);
+        MUTEX_ENTER(&peer->peer_lock);
+        hadd32(peer->bytesSent, p->length);
+        MUTEX_EXIT(&peer->peer_lock);
+    }
 }