Netdev List
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Sathya Perla <sathya.perla@emulex.com>,
	David Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Subject: [PATCH] be2net: fix netdev_stats_update()
Date: Mon, 13 Jun 2011 08:49:08 +0200	[thread overview]
Message-ID: <1307947748.2872.182.camel@edumazet-laptop> (raw)
In-Reply-To: <f67e2aac-b763-404d-8e45-5c5f52c56d18@exht1.ad.emulex.com>

Le lundi 13 juin 2011 à 11:31 +0530, Sathya Perla a écrit :
> This patch provides support for multiple TX queues.
> 
> Signed-off-by: Sathya Perla <sathya.perla@emulex.com>
> ---
>  drivers/net/benet/be.h         |   13 ++-
>  drivers/net/benet/be_ethtool.c |   50 +++++++---
>  drivers/net/benet/be_main.c    |  227 ++++++++++++++++++++++------------------
>  3 files changed, 171 insertions(+), 119 deletions(-)
> 

>  static void
> diff --git a/drivers/net/benet/be_main.c b/drivers/net/benet/be_main.c
> index 9ba197b..af6647a 100644
> --- a/drivers/net/benet/be_main.c
> +++ b/drivers/net/benet/be_main.c
> @@ -427,6 +427,7 @@ void netdev_stats_update(struct be_adapter *adapter)
>  	struct be_drv_stats *drvs = &adapter->drv_stats;
>  	struct net_device_stats *dev_stats = &adapter->netdev->stats;
>  	struct be_rx_obj *rxo;
> +	struct be_tx_obj *txo;
>  	int i;
>  
>  	memset(dev_stats, 0, sizeof(*dev_stats));
> @@ -450,8 +451,10 @@ void netdev_stats_update(struct be_adapter *adapter)
>  		}
>  	}
>  
> -	dev_stats->tx_packets = tx_stats(adapter)->be_tx_pkts;
> -	dev_stats->tx_bytes = tx_stats(adapter)->be_tx_bytes;
> +	for_all_tx_queues(adapter, txo, i) {
> +		dev_stats->tx_packets += tx_stats(txo)->be_tx_pkts;
> +		dev_stats->tx_bytes += tx_stats(txo)->be_tx_bytes;
> +	}
>  
>  	/* bad pkts received */
>  	dev_stats->rx_errors = drvs->rx_crc_errors +
> @@ -554,9 +557,9 @@ static u32 be_calc_rate(u64 bytes, unsigned long ticks)
>  	return rate;
>  }
>  

Hi Sathya

Browsing into this patch made me realize be2net netdev_stats_update() is
wrong.

It should not reset even temporarly netdev->stats.

You should have something like the following I cooked for linux-2.6, so
that you get the idea. Please respin your patch after applying following
fix.

[PATCH] be2net: fix netdev_stats_update()

Since this driver uses the default dev_get_stats() [ as it doesnt
provide ndo_get_stats() nor ndo_get_stats64() method ], resetting
netdev->stats can lead some SNMP readers catching intermediate values,
breaking the rule that counters only can increase in time.

We instead should use temporary accumulators and only set netdev->stats
values with final results.

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
 drivers/net/benet/be_main.c |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/drivers/net/benet/be_main.c b/drivers/net/benet/be_main.c
index a485f7f..962509d 100644
--- a/drivers/net/benet/be_main.c
+++ b/drivers/net/benet/be_main.c
@@ -427,28 +427,33 @@ void netdev_stats_update(struct be_adapter *adapter)
 	struct be_drv_stats *drvs = &adapter->drv_stats;
 	struct net_device_stats *dev_stats = &adapter->netdev->stats;
 	struct be_rx_obj *rxo;
+	unsigned long rx_packets = 0, rx_bytes = 0, multicast = 0;
+	unsigned long rx_dropped = 0;
 	int i;
 
-	memset(dev_stats, 0, sizeof(*dev_stats));
 	for_all_rx_queues(adapter, rxo, i) {
-		dev_stats->rx_packets += rx_stats(rxo)->rx_pkts;
-		dev_stats->rx_bytes += rx_stats(rxo)->rx_bytes;
-		dev_stats->multicast += rx_stats(rxo)->rx_mcast_pkts;
+		rx_packets += rx_stats(rxo)->rx_pkts;
+		rx_bytes += rx_stats(rxo)->rx_bytes;
+		multicast += rx_stats(rxo)->rx_mcast_pkts;
 		/*  no space in linux buffers: best possible approximation */
 		if (adapter->generation == BE_GEN3) {
 			if (!(lancer_chip(adapter))) {
 				struct be_erx_stats_v1 *erx_stats =
 					be_erx_stats_from_cmd(adapter);
-				dev_stats->rx_dropped +=
+				rx_dropped +=
 				erx_stats->rx_drops_no_fragments[rxo->q.id];
 			}
 		} else {
 			struct be_erx_stats_v0 *erx_stats =
 					be_erx_stats_from_cmd(adapter);
-			dev_stats->rx_dropped +=
+			rx_dropped +=
 				erx_stats->rx_drops_no_fragments[rxo->q.id];
 		}
 	}
+	dev_stats->rx_packets = rx_packets;
+	dev_stats->rx_bytes = rx_bytes;
+	dev_stats->multicast = multicast;
+	dev_stats->rx_dropped = rx_dropped;
 
 	dev_stats->tx_packets = tx_stats(adapter)->be_tx_pkts;
 	dev_stats->tx_bytes = tx_stats(adapter)->be_tx_bytes;



  reply	other threads:[~2011-06-13  6:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-13  6:01 [PATCH net-next-2.6] be2net: support multiple TX queues Sathya Perla
2011-06-13  6:49 ` Eric Dumazet [this message]
2011-06-13  7:09   ` [PATCH] be2net: fix netdev_stats_update() Sathya.Perla
2011-06-17  3:06     ` David Miller
2011-06-17  3:02 ` [PATCH net-next-2.6] be2net: support multiple TX queues David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1307947748.2872.182.camel@edumazet-laptop \
    --to=eric.dumazet@gmail.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=sathya.perla@emulex.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox