diff mbox

be2net: fix netdev_stats_update()

Message ID 1307947748.2872.182.camel@edumazet-laptop
State Awaiting Upstream, archived
Delegated to: David Miller
Headers show

Commit Message

Eric Dumazet June 13, 2011, 6:49 a.m. UTC
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(-)


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Sathya Perla June 13, 2011, 7:09 a.m. UTC | #1
Thanks Eric. Will do.

Dave, I would prefer to send a separate patch fixing the netdev stats issue after you apply this multiple TXQ patch. Are you OK with that?

> -----Original Message-----

> From: Eric Dumazet [mailto:eric.dumazet@gmail.com]

> Sent: Monday, June 13, 2011 12:19 PM

> To: Perla, Sathya; David Miller

> Cc: netdev@vger.kernel.org

> Subject: [PATCH] be2net: fix netdev_stats_update()

> 

> 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(-)

> >

<snip>
> >  	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;

>
David Miller June 17, 2011, 3:06 a.m. UTC | #2
From: <Sathya.Perla@Emulex.Com>
Date: Mon, 13 Jun 2011 00:09:38 -0700

> Dave, I would prefer to send a separate patch fixing the netdev
> stats issue after you apply this multiple TXQ patch. Are you OK with
> that?

Sure.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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;