From 6a8e622bbec9fd6263d621669208e26f88339391 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Sun, 19 Sep 2010 09:47:37 -0700 Subject: [PATCH] Rx: only compute peer bytes sent and received if rx_stats_active 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 Tested-by: Derrick Brashear (cherry picked from commit 7d16c8b84ac8cc0251231819bfb0eefc2040322a) Reviewed-on: http://gerrit.openafs.org/2807 --- src/rx/rx_packet.c | 66 ++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/src/rx/rx_packet.c b/src/rx/rx_packet.c index 92aef6131..c5ba1621b 100644 --- a/src/rx/rx_packet.c +++ b/src/rx/rx_packet.c @@ -14,7 +14,6 @@ #include #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); + } } -- 2.39.5