diff mbox

[3/9] veth: convert to 64 bit statistics

Message ID 20110609005417.449670103@vyatta.com
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

stephen hemminger June 9, 2011, 12:53 a.m. UTC
Not much change, device was already keeping per cpu statistics.
Use recent 64 statistics interface.

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>



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

Ben Hutchings June 9, 2011, 2 a.m. UTC | #1
On Wed, 2011-06-08 at 17:53 -0700, Stephen Hemminger wrote:
> Not much change, device was already keeping per cpu statistics.
> Use recent 64 statistics interface.
[...]

It's also going to need to use u64_stats_sync functions.

Ben.
stephen hemminger June 9, 2011, 3:22 a.m. UTC | #2
On Thu, 09 Jun 2011 03:00:41 +0100
Ben Hutchings <bhutchings@solarflare.com> wrote:

> On Wed, 2011-06-08 at 17:53 -0700, Stephen Hemminger wrote:
> > Not much change, device was already keeping per cpu statistics.
> > Use recent 64 statistics interface.
> [...]
> 
> It's also going to need to use u64_stats_sync functions.
> 
> Ben.
> 

No veth is doing per-cpu update therefore the new code has the same guarantee
as the old code.
--
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
David Miller June 9, 2011, 6:26 a.m. UTC | #3
From: Stephen Hemminger <shemminger@vyatta.com>
Date: Wed, 08 Jun 2011 17:53:59 -0700

> Not much change, device was already keeping per cpu statistics.
> Use recent 64 statistics interface.
> 
> Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>

Applied.
--
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
Ben Hutchings June 10, 2011, 4:34 p.m. UTC | #4
On Wed, 2011-06-08 at 20:22 -0700, Stephen Hemminger wrote:
> On Thu, 09 Jun 2011 03:00:41 +0100
> Ben Hutchings <bhutchings@solarflare.com> wrote:
> 
> > On Wed, 2011-06-08 at 17:53 -0700, Stephen Hemminger wrote:
> > > Not much change, device was already keeping per cpu statistics.
> > > Use recent 64 statistics interface.
> > [...]
> > 
> > It's also going to need to use u64_stats_sync functions.
> > 
> > Ben.
> > 
> 
> No veth is doing per-cpu update therefore the new code has the same guarantee
> as the old code.

Per-cpu statistics avoid the problem of races between writers without
using expensive atomic operations.  They don't solve the problem of
races between writer and reader (on 32-bit systems).

For example, if veth_get_stats() races with a receive or transmit that
increments a value from 0x00000001ffffffff to 0x0000000200000000, it may
see the value as 0x00000002ffffffff.

Ben.
diff mbox

Patch

--- a/drivers/net/veth.c	2011-06-07 20:04:42.221679879 +0900
+++ b/drivers/net/veth.c	2011-06-07 20:10:04.259276778 +0900
@@ -24,12 +24,12 @@ 
 #define MAX_MTU 65535		/* Max L3 MTU (arbitrary) */
 
 struct veth_net_stats {
-	unsigned long	rx_packets;
-	unsigned long	tx_packets;
-	unsigned long	rx_bytes;
-	unsigned long	tx_bytes;
-	unsigned long	tx_dropped;
-	unsigned long	rx_dropped;
+	u64	rx_packets;
+	u64	tx_packets;
+	u64	rx_bytes;
+	u64	tx_bytes;
+	u64	tx_dropped;
+	u64	rx_dropped;
 };
 
 struct veth_priv {
@@ -159,32 +159,27 @@  rx_drop:
  * general routines
  */
 
-static struct net_device_stats *veth_get_stats(struct net_device *dev)
+static struct rtnl_link_stats64 *veth_get_stats64(struct net_device *dev,
+						  struct rtnl_link_stats64 *tot)
 {
 	struct veth_priv *priv;
 	int cpu;
-	struct veth_net_stats *stats, total = {0};
+	struct veth_net_stats *stats;
 
 	priv = netdev_priv(dev);
 
 	for_each_possible_cpu(cpu) {
 		stats = per_cpu_ptr(priv->stats, cpu);
 
-		total.rx_packets += stats->rx_packets;
-		total.tx_packets += stats->tx_packets;
-		total.rx_bytes   += stats->rx_bytes;
-		total.tx_bytes   += stats->tx_bytes;
-		total.tx_dropped += stats->tx_dropped;
-		total.rx_dropped += stats->rx_dropped;
+		tot->rx_packets += stats->rx_packets;
+		tot->tx_packets += stats->tx_packets;
+		tot->rx_bytes   += stats->rx_bytes;
+		tot->tx_bytes   += stats->tx_bytes;
+		tot->tx_dropped += stats->tx_dropped;
+		tot->rx_dropped += stats->rx_dropped;
 	}
-	dev->stats.rx_packets = total.rx_packets;
-	dev->stats.tx_packets = total.tx_packets;
-	dev->stats.rx_bytes   = total.rx_bytes;
-	dev->stats.tx_bytes   = total.tx_bytes;
-	dev->stats.tx_dropped = total.tx_dropped;
-	dev->stats.rx_dropped = total.rx_dropped;
 
-	return &dev->stats;
+	return tot;
 }
 
 static int veth_open(struct net_device *dev)
@@ -254,7 +249,7 @@  static const struct net_device_ops veth_
 	.ndo_stop            = veth_close,
 	.ndo_start_xmit      = veth_xmit,
 	.ndo_change_mtu      = veth_change_mtu,
-	.ndo_get_stats       = veth_get_stats,
+	.ndo_get_stats64     = veth_get_stats64,
 	.ndo_set_mac_address = eth_mac_addr,
 };