Skip to contentSkip to conversation

64 bit statistics for VM and 10G drivers

PATCH Applied Stephen Hemminger 9 participants 28 messages Jun 9, 2011 – Jun 15, 2011

Subsystems (4)
lore
Share & tools
lore
#3 lore raw

PATCH 2/9 xen: convert to 64 bit stats interface

In reply to Stephen Hemminger

Convert xen driver to 64 bit statistics interface.
This driver was already counting packet per queue in a 64 bit value so not a huge change.

drivers/net/xen-netfront.c +32 -8
@@ -122,7 +122,14 @@ struct netfront_info {
 	struct mmu_update rx_mmu[NET_RX_RING_SIZE];
 
 	/* Statistics */
-	unsigned long rx_gso_checksum_fixup;
+	u64 rx_packets;
+	u64 rx_bytes;
+	u64 rx_errors;
+	u64 rx_gso_checksum_fixup;
+
+	u64 tx_packets;
+	u64 tx_bytes;
+	u64 tx_dropped;
 };
 
 struct netfront_rx_info {
@@ -552,8 +559,8 @@ static int xennet_start_xmit(struct sk_b
 	if (notify)
 		notify_remote_via_irq(np->netdev->irq);
 
-	dev->stats.tx_bytes += skb->len;
-	dev->stats.tx_packets++;
+	np->tx_bytes += skb->len;
+	np->tx_packets++;
 
 	/* Note: It is not safe to access skb after xennet_tx_buf_gc()! */
 	xennet_tx_buf_gc(dev);
@@ -566,7 +573,7 @@ static int xennet_start_xmit(struct sk_b
 	return NETDEV_TX_OK;
 
  drop:
-	dev->stats.tx_dropped++;
+	np->tx_dropped++;
 	dev_kfree_skb(skb);
 	return NETDEV_TX_OK;
 }
@@ -847,6 +854,7 @@ out:
 static int handle_incoming_queue(struct net_device *dev,
 				 struct sk_buff_head *rxq)
 {
+	struct netfront_info *np = netdev_priv(dev);
 	int packets_dropped = 0;
 	struct sk_buff *skb;
 
@@ -867,12 +875,11 @@ static int handle_incoming_queue(struct
 		if (checksum_setup(dev, skb)) {
 			kfree_skb(skb);
 			packets_dropped++;
-			dev->stats.rx_errors++;
 			continue;
 		}
 
-		dev->stats.rx_packets++;
-		dev->stats.rx_bytes += skb->len;
+		np->rx_packets++;
+		np->rx_bytes += skb->len;
 
 		/* Pass it up. */
 		netif_receive_skb(skb);
@@ -919,7 +926,7 @@ static int xennet_poll(struct napi_struc
 err:
 			while ((skb = __skb_dequeue(&tmpq)))
 				__skb_queue_tail(&errq, skb);
-			dev->stats.rx_errors++;
+			np->rx_errors++;
 			i = np->rx.rsp_cons;
 			continue;
 		}
@@ -1034,6 +1041,22 @@ static int xennet_change_mtu(struct net_
 	return 0;
 }
 
+static struct rtnl_link_stats64 *xennet_get_stats64(struct net_device *dev,
+						    struct rtnl_link_stats64 *stats)
+{
+	struct netfront_info *np = netdev_priv(dev);
+
+	stats->rx_packets = np->rx_packets;
+	stats->rx_bytes   = np->rx_bytes;
+	stats->rx_errors  = np->rx_errors;
+
+	stats->tx_packets = np->tx_packets;
+	stats->tx_bytes   = np->tx_bytes;
+	stats->tx_bytes   = np->tx_dropped;
+
+	return stats;
+}
+
 static void xennet_release_tx_bufs(struct netfront_info *np)
 {
 	struct sk_buff *skb;
@@ -1182,6 +1205,7 @@ static const struct net_device_ops xenne
 	.ndo_stop            = xennet_close,
 	.ndo_start_xmit      = xennet_start_xmit,
 	.ndo_change_mtu	     = xennet_change_mtu,
+	.ndo_get_stats64     = xennet_get_stats64,
 	.ndo_set_mac_address = eth_mac_addr,
 	.ndo_validate_addr   = eth_validate_addr,
 	.ndo_fix_features    = xennet_fix_features,
#0 lore raw

cover 64 bit statistics for VM and 10G drivers

All 10G and virtual devices should be using the 64 bit statistics interface because counters can wrap to fast. The standard monitoring program net-snmp polls devices every 3 seconds (too fast), but even that can wrap too fast to be detected.

Net-snmp needs to be updated to use netlink and handle 64 bit values. It is still using /proc

#24 lore raw

PATCH 8/9 niu: support 64 bit stats interface

drivers/net/niu.c +20 -16
@@ -6249,9 +6249,10 @@ static void niu_sync_mac_stats(struct ni
 		niu_sync_bmac_stats(np);
 }
 
-static void niu_get_rx_stats(struct niu *np)
+static void niu_get_rx_stats(struct niu *np,
+			     struct rtnl_link_stats64 *stats)
 {
-	unsigned long pkts, dropped, errors, bytes;
+	u64 pkts, dropped, errors, bytes;
 	struct rx_ring_info *rx_rings;
 	int i;
 
@@ -6273,15 +6274,16 @@ static void niu_get_rx_stats(struct niu
 	}
 
 no_rings:
-	np->dev->stats.rx_packets = pkts;
-	np->dev->stats.rx_bytes = bytes;
-	np->dev->stats.rx_dropped = dropped;
-	np->dev->stats.rx_errors = errors;
+	stats->rx_packets = pkts;
+	stats->rx_bytes = bytes;
+	stats->rx_dropped = dropped;
+	stats->rx_errors = errors;
 }
 
-static void niu_get_tx_stats(struct niu *np)
+static void niu_get_tx_stats(struct niu *np,
+			     struct rtnl_link_stats64 *stats)
 {
-	unsigned long pkts, errors, bytes;
+	u64 pkts, errors, bytes;
 	struct tx_ring_info *tx_rings;
 	int i;
 
@@ -6300,20 +6302,22 @@ static void niu_get_tx_stats(struct niu
 	}
 
 no_rings:
-	np->dev->stats.tx_packets = pkts;
-	np->dev->stats.tx_bytes = bytes;
-	np->dev->stats.tx_errors = errors;
+	stats->tx_packets = pkts;
+	stats->tx_bytes = bytes;
+	stats->tx_errors = errors;
 }
 
-static struct net_device_stats *niu_get_stats(struct net_device *dev)
+static struct rtnl_link_stats64 *niu_get_stats(struct net_device *dev,
+					       struct rtnl_link_stats64 *stats)
 {
 	struct niu *np = netdev_priv(dev);
 
 	if (netif_running(dev)) {
-		niu_get_rx_stats(np);
-		niu_get_tx_stats(np);
+		niu_get_rx_stats(np, stats);
+		niu_get_tx_stats(np, stats);
 	}
-	return &dev->stats;
+
+	return stats;
 }
 
 static void niu_load_hash_xmac(struct niu *np, u16 *hash)
@@ -9711,7 +9715,7 @@ static const struct net_device_ops niu_n
 	.ndo_open		= niu_open,
 	.ndo_stop		= niu_close,
 	.ndo_start_xmit		= niu_start_xmit,
-	.ndo_get_stats		= niu_get_stats,
+	.ndo_get_stats64	= niu_get_stats,
 	.ndo_set_multicast_list	= niu_set_rx_mode,
 	.ndo_validate_addr	= eth_validate_addr,
 	.ndo_set_mac_address	= niu_set_mac_addr,
#7 lore raw

PATCH 3/9 veth: convert to 64 bit statistics

In reply to Stephen Hemminger

Not much change, device was already keeping per cpu statistics. Use recent 64 statistics interface.

drivers/net/veth.c +17 -22
@@ -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,
 };
 
#12 lore raw

PATCH 4/9 ifb: convert to 64 bit stats

In reply to Stephen Hemminger

Convert input functional block device to use 64 bit stats.

drivers/net/ifb.c +31 -8
@@ -42,7 +42,14 @@ struct ifb_private {
 	struct tasklet_struct   ifb_tasklet;
 	int     tasklet_pending;
 	struct sk_buff_head     rq;
+	u64 rx_packets;
+	u64 rx_bytes;
+	u64 rx_dropped;
+
 	struct sk_buff_head     tq;
+	u64 tx_packets;
+	u64 tx_bytes;
+	u64 tx_dropped;
 };
 
 static int numifbs = 2;
@@ -57,7 +64,6 @@ static void ri_tasklet(unsigned long dev
 
 	struct net_device *_dev = (struct net_device *)dev;
 	struct ifb_private *dp = netdev_priv(_dev);
-	struct net_device_stats *stats = &_dev->stats;
 	struct netdev_queue *txq;
 	struct sk_buff *skb;
 
@@ -77,15 +83,16 @@ static void ri_tasklet(unsigned long dev
 
 		skb->tc_verd = 0;
 		skb->tc_verd = SET_TC_NCLS(skb->tc_verd);
-		stats->tx_packets++;
-		stats->tx_bytes +=skb->len;
+
+		dp->tx_packets++;
+		dp->tx_bytes +=skb->len;
 
 		rcu_read_lock();
 		skb->dev = dev_get_by_index_rcu(&init_net, skb->skb_iif);
 		if (!skb->dev) {
 			rcu_read_unlock();
 			dev_kfree_skb(skb);
-			stats->tx_dropped++;
+			dp->tx_dropped++;
 			if (skb_queue_len(&dp->tq) != 0)
 				goto resched;
 			break;
@@ -120,9 +127,26 @@ resched:
 
 }
 
+static struct rtnl_link_stats64 *ifb_stats64(struct net_device *dev,
+					     struct rtnl_link_stats64 *stats)
+{
+	struct ifb_private *dp = netdev_priv(dev);
+
+	stats->rx_packets = dp->rx_packets;
+	stats->rx_bytes = dp->rx_bytes;
+	stats->rx_dropped = dp->rx_dropped;
+	stats->tx_packets = dp->tx_packets;
+	stats->tx_bytes = dp->tx_bytes;
+	stats->tx_dropped = dp->tx_dropped;
+
+	return stats;
+}
+
+
 static const struct net_device_ops ifb_netdev_ops = {
 	.ndo_open	= ifb_open,
 	.ndo_stop	= ifb_close,
+	.ndo_get_stats64 = ifb_stats64,
 	.ndo_start_xmit	= ifb_xmit,
 	.ndo_validate_addr = eth_validate_addr,
 };
@@ -153,15 +177,14 @@ static void ifb_setup(struct net_device
 static netdev_tx_t ifb_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct ifb_private *dp = netdev_priv(dev);
-	struct net_device_stats *stats = &dev->stats;
 	u32 from = G_TC_FROM(skb->tc_verd);
 
-	stats->rx_packets++;
-	stats->rx_bytes+=skb->len;
+	dp->rx_packets++;
+	dp->rx_bytes+=skb->len;
 
 	if (!(from & (AT_INGRESS|AT_EGRESS)) || !skb->skb_iif) {
 		dev_kfree_skb(skb);
-		stats->rx_dropped++;
+		dp->rx_dropped++;
 		return NETDEV_TX_OK;
 	}
 
#16 lore raw

PATCH 5/9 netxen: convert to 64 bit statistics

In reply to Stephen Hemminger

Change to 64 bit statistics interface, driver was already maintaining 64 bit value.

drivers/net/netxen/netxen_nic_main.c +5 -4
@@ -92,7 +92,8 @@ static irqreturn_t netxen_msi_intr(int i
 static irqreturn_t netxen_msix_intr(int irq, void *data);
 
 static void netxen_config_indev_addr(struct net_device *dev, unsigned long);
-static struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev);
+static struct rtnl_link_stats64 *netxen_nic_get_stats(struct net_device *dev,
+						      struct rtnl_link_stats64 *stats);
 static int netxen_nic_set_mac(struct net_device *netdev, void *p);
 
 /*  PCI Device ID Table  */
@@ -520,7 +521,7 @@ static const struct net_device_ops netxe
 	.ndo_open	   = netxen_nic_open,
 	.ndo_stop	   = netxen_nic_close,
 	.ndo_start_xmit    = netxen_nic_xmit_frame,
-	.ndo_get_stats	   = netxen_nic_get_stats,
+	.ndo_get_stats64   = netxen_nic_get_stats,
 	.ndo_validate_addr = eth_validate_addr,
 	.ndo_set_multicast_list = netxen_set_multicast_list,
 	.ndo_set_mac_address    = netxen_nic_set_mac,
@@ -2110,10 +2111,10 @@ request_reset:
 	clear_bit(__NX_RESETTING, &adapter->state);
 }
 
-static struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
+static struct rtnl_link_stats64 *netxen_nic_get_stats(struct net_device *netdev,
+						      struct rtnl_link_stats64 *stats)
 {
 	struct netxen_adapter *adapter = netdev_priv(netdev);
-	struct net_device_stats *stats = &netdev->stats;
 
 	stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
 	stats->tx_packets = adapter->stats.xmitfinished;
#26 lore raw

PATCH 9/9 s2io: implement 64 bit stats

In reply to Stephen Hemminger

Convert s2io driver to 64 bit statistics interface. This driver keeps it private set of counters so change those to the 64 bit netlink type.

drivers/net/s2io.c +6 -16
@@ -4897,7 +4897,8 @@ static void s2io_updt_stats(struct s2io_
  *  Return value:
  *  pointer to the updated net_device_stats structure.
  */
-static struct net_device_stats *s2io_get_stats(struct net_device *dev)
+static struct rtnl_link_stats64 *s2io_get_stats(struct net_device *dev,
+						struct rtnl_link_stats64 *net_stats)
 {
 	struct s2io_nic *sp = netdev_priv(dev);
 	struct mac_info *mac_control = &sp->mac_control;
@@ -4916,40 +4917,32 @@ static struct net_device_stats *s2io_get
 	 */
 	delta = ((u64) le32_to_cpu(stats->rmac_vld_frms_oflow) << 32 |
 		le32_to_cpu(stats->rmac_vld_frms)) - sp->stats.rx_packets;
-	sp->stats.rx_packets += delta;
-	dev->stats.rx_packets += delta;
+	sp->stats.tx_packets += delta;
 
 	delta = ((u64) le32_to_cpu(stats->tmac_frms_oflow) << 32 |
 		le32_to_cpu(stats->tmac_frms)) - sp->stats.tx_packets;
 	sp->stats.tx_packets += delta;
-	dev->stats.tx_packets += delta;
 
 	delta = ((u64) le32_to_cpu(stats->rmac_data_octets_oflow) << 32 |
 		le32_to_cpu(stats->rmac_data_octets)) - sp->stats.rx_bytes;
 	sp->stats.rx_bytes += delta;
-	dev->stats.rx_bytes += delta;
 
 	delta = ((u64) le32_to_cpu(stats->tmac_data_octets_oflow) << 32 |
 		le32_to_cpu(stats->tmac_data_octets)) - sp->stats.tx_bytes;
 	sp->stats.tx_bytes += delta;
-	dev->stats.tx_bytes += delta;
 
 	delta = le64_to_cpu(stats->rmac_drop_frms) - sp->stats.rx_errors;
 	sp->stats.rx_errors += delta;
-	dev->stats.rx_errors += delta;
 
 	delta = ((u64) le32_to_cpu(stats->tmac_any_err_frms_oflow) << 32 |
 		le32_to_cpu(stats->tmac_any_err_frms)) - sp->stats.tx_errors;
 	sp->stats.tx_errors += delta;
-	dev->stats.tx_errors += delta;
 
 	delta = le64_to_cpu(stats->rmac_drop_frms) - sp->stats.rx_dropped;
 	sp->stats.rx_dropped += delta;
-	dev->stats.rx_dropped += delta;
 
 	delta = le64_to_cpu(stats->tmac_drop_frms) - sp->stats.tx_dropped;
 	sp->stats.tx_dropped += delta;
-	dev->stats.tx_dropped += delta;
 
 	/* The adapter MAC interprets pause frames as multicast packets, but
 	 * does not pass them up.  This erroneously increases the multicast
@@ -4961,19 +4954,16 @@ static struct net_device_stats *s2io_get
 	delta -= le64_to_cpu(stats->rmac_pause_ctrl_frms);
 	delta -= sp->stats.multicast;
 	sp->stats.multicast += delta;
-	dev->stats.multicast += delta;
 
 	delta = ((u64) le32_to_cpu(stats->rmac_usized_frms_oflow) << 32 |
 		le32_to_cpu(stats->rmac_usized_frms)) +
 		le64_to_cpu(stats->rmac_long_frms) - sp->stats.rx_length_errors;
 	sp->stats.rx_length_errors += delta;
-	dev->stats.rx_length_errors += delta;
 
 	delta = le64_to_cpu(stats->rmac_fcs_err_frms) - sp->stats.rx_crc_errors;
 	sp->stats.rx_crc_errors += delta;
-	dev->stats.rx_crc_errors += delta;
 
-	return &dev->stats;
+	return &sp->stats;
 }
 
 /**
@@ -7447,7 +7437,7 @@ static int rx_osm_handler(struct ring_in
 		if (err_mask != 0x5) {
 			DBG_PRINT(ERR_DBG, "%s: Rx error Value: 0x%x\n",
 				  dev->name, err_mask);
-			dev->stats.rx_crc_errors++;
+			sp->stats.rx_crc_errors++;
 			swstats->mem_freed
 				+= skb->truesize;
 			dev_kfree_skb(skb);
@@ -7731,7 +7721,7 @@ static int rts_ds_steer(struct s2io_nic
 static const struct net_device_ops s2io_netdev_ops = {
 	.ndo_open	        = s2io_open,
 	.ndo_stop	        = s2io_close,
-	.ndo_get_stats	        = s2io_get_stats,
+	.ndo_get_stats64        = s2io_get_stats,
 	.ndo_start_xmit    	= s2io_xmit,
 	.ndo_validate_addr	= eth_validate_addr,
 	.ndo_set_multicast_list = s2io_set_multicast,
drivers/net/s2io.h +1 -1
@@ -871,7 +871,7 @@ struct s2io_nic {
 
 	struct mac_addr def_mac_addr[256];
 
-	struct net_device_stats stats;
+	struct rtnl_link_stats64 stats;
 	int high_dma_flag;
 	int device_enabled_once;
 
#22 lore raw

PATCH 7/9 myricom: update to 64 bit stats

In reply to Stephen Hemminger

Driver was already keeping 64 bit counters, just not using the new interface.

Ps: IMHO drivers should not be duplicating network device stats into ethtool stats. It is useless duplication.

drivers/net/myri10ge/myri10ge.c +8 -6
@@ -377,7 +377,8 @@ static inline void put_be32(__be32 val,
 	__raw_writel((__force __u32) val, (__force void __iomem *)p);
 }
 
-static struct net_device_stats *myri10ge_get_stats(struct net_device *dev);
+static struct rtnl_link_stats64 *myri10ge_get_stats(struct net_device *dev,
+						    struct rtnl_link_stats64 *stats);
 
 static void set_fw_name(struct myri10ge_priv *mgp, char *name, bool allocated)
 {
@@ -1831,13 +1832,14 @@ myri10ge_get_ethtool_stats(struct net_de
 {
 	struct myri10ge_priv *mgp = netdev_priv(netdev);
 	struct myri10ge_slice_state *ss;
+	struct rtnl_link_stats64 link_stats;
 	int slice;
 	int i;
 
 	/* force stats update */
-	(void)myri10ge_get_stats(netdev);
+	(void)myri10ge_get_stats(netdev, &link_stats);
 	for (i = 0; i < MYRI10GE_NET_STATS_LEN; i++)
-		data[i] = ((unsigned long *)&netdev->stats)[i];
+		data[i] = ((u64 *)&link_stats)[i];
 
 	data[i++] = (unsigned int)mgp->tx_boundary;
 	data[i++] = (unsigned int)mgp->wc_enabled;
@@ -2976,11 +2978,11 @@ drop:
 	return NETDEV_TX_OK;
 }
 
-static struct net_device_stats *myri10ge_get_stats(struct net_device *dev)
+static struct rtnl_link_stats64 *myri10ge_get_stats(struct net_device *dev,
+						    struct rtnl_link_stats64 *stats)
 {
 	struct myri10ge_priv *mgp = netdev_priv(dev);
 	struct myri10ge_slice_netstats *slice_stats;
-	struct net_device_stats *stats = &dev->stats;
 	int i;
 
 	spin_lock(&mgp->stats_lock);
@@ -3790,7 +3792,7 @@ static const struct net_device_ops myri1
 	.ndo_open		= myri10ge_open,
 	.ndo_stop		= myri10ge_close,
 	.ndo_start_xmit		= myri10ge_xmit,
-	.ndo_get_stats		= myri10ge_get_stats,
+	.ndo_get_stats64	= myri10ge_get_stats,
 	.ndo_validate_addr	= eth_validate_addr,
 	.ndo_change_mtu		= myri10ge_change_mtu,
 	.ndo_fix_features	= myri10ge_fix_features,
#1 lore raw

PATCH 1/9 vmxnet3: convert to 64 bit stats interface

In reply to Stephen Hemminger

Convert vmxnet3 driver to 64 bit statistics interface.
This driver was already counting packet per queue in a 64 bit value so not a huge change. Eliminate unused old net_device_stats structure.

drivers/net/vmxnet3/vmxnet3_drv.c +1 -1
@@ -2864,7 +2864,7 @@ vmxnet3_probe_device(struct pci_dev *pde
 		.ndo_set_mac_address = vmxnet3_set_mac_addr,
 		.ndo_change_mtu = vmxnet3_change_mtu,
 		.ndo_set_features = vmxnet3_set_features,
-		.ndo_get_stats = vmxnet3_get_stats,
+		.ndo_get_stats64 = vmxnet3_get_stats64,
 		.ndo_tx_timeout = vmxnet3_tx_timeout,
 		.ndo_set_multicast_list = vmxnet3_set_mc,
 		.ndo_vlan_rx_register = vmxnet3_vlan_rx_register,
drivers/net/vmxnet3/vmxnet3_ethtool.c +24 -24

75 lines not on this page · raw message

drivers/net/vmxnet3/vmxnet3_int.h +3 -2
@@ -323,7 +323,6 @@ struct vmxnet3_adapter {
 	struct Vmxnet3_TxQueueDesc	*tqd_start;     /* all tx queue desc */
 	struct Vmxnet3_RxQueueDesc	*rqd_start;	/* all rx queue desc */
 	struct net_device		*netdev;
-	struct net_device_stats		net_stats;
 	struct pci_dev			*pdev;
 
 	u8			__iomem *hw_addr0; /* for BAR 0 */
@@ -407,7 +406,9 @@ vmxnet3_create_queues(struct vmxnet3_ada
 		      u32 tx_ring_size, u32 rx_ring_size, u32 rx_ring2_size);
 
 extern void vmxnet3_set_ethtool_ops(struct net_device *netdev);
-extern struct net_device_stats *vmxnet3_get_stats(struct net_device *netdev);
+
+extern struct rtnl_link_stats64 *
+vmxnet3_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats);
 
 extern char vmxnet3_driver_name[];
 #endif
#19 lore raw

PATCH 6/9 enic: update to support 64 bit stats

In reply to Stephen Hemminger

The device driver already uses 64 bit statistics, it just doesn't use the 64 bit interface.

drivers/net/enic/enic_main.c +4 -4
@@ -801,10 +801,10 @@ static netdev_tx_t enic_hard_start_xmit(
 }
 
 /* dev_base_lock rwlock held, nominally process context */
-static struct net_device_stats *enic_get_stats(struct net_device *netdev)
+static struct rtnl_link_stats64 *enic_get_stats(struct net_device *netdev,
+						struct rtnl_link_stats64 *net_stats)
 {
 	struct enic *enic = netdev_priv(netdev);
-	struct net_device_stats *net_stats = &netdev->stats;
 	struct vnic_stats *stats;
 
 	enic_dev_stats_dump(enic, &stats);
@@ -2117,7 +2117,7 @@ static const struct net_device_ops enic_
 	.ndo_open		= enic_open,
 	.ndo_stop		= enic_stop,
 	.ndo_start_xmit		= enic_hard_start_xmit,
-	.ndo_get_stats		= enic_get_stats,
+	.ndo_get_stats64	= enic_get_stats,
 	.ndo_validate_addr	= eth_validate_addr,
 	.ndo_set_rx_mode	= enic_set_rx_mode,
 	.ndo_set_multicast_list	= enic_set_rx_mode,
@@ -2139,7 +2139,7 @@ static const struct net_device_ops enic_
 	.ndo_open		= enic_open,
 	.ndo_stop		= enic_stop,
 	.ndo_start_xmit		= enic_hard_start_xmit,
-	.ndo_get_stats		= enic_get_stats,
+	.ndo_get_stats64	= enic_get_stats,
 	.ndo_validate_addr	= eth_validate_addr,
 	.ndo_set_mac_address	= enic_set_mac_address,
 	.ndo_set_rx_mode	= enic_set_rx_mode,
#27 lore raw

Re: [PATCH 9/9] s2io: implement 64 bit stats

In reply to Stephen Hemminger
Quoted 21 lines · Stephen Hemminger

plain text document attachment (s2io-stats.patch) Convert s2io driver to 64 bit statistics interface. This driver keeps it private set of counters so change those to the 64 bit netlink type.

drivers/net/s2io.c +2 -1
@@ -4897,7 +4897,8 @@ static void s2io_updt_stats(struct s2io_
  *  Return value:
  *  pointer to the updated net_device_stats structure.
  */
-static struct net_device_stats *s2io_get_stats(struct net_device *dev)
+static struct rtnl_link_stats64 *s2io_get_stats(struct net_device *dev,
+						struct rtnl_link_stats64 *net_stats)
 {
 	struct s2io_nic *sp = netdev_priv(dev);
 	struct mac_info *mac_control = &sp->mac_control;

drivers/net/s2io.c static struct net_device_stats *s2io_get · line 4920

Quoted 6 lines
drivers/net/s2io.c +1 -2
@@ -4916,40 +4917,32 @@ static struct net_device_stats *s2io_get
 	 */
 	delta = ((u64) le32_to_cpu(stats->rmac_vld_frms_oflow) << 32 |
 		le32_to_cpu(stats->rmac_vld_frms)) - sp->stats.rx_packets;
-	sp->stats.rx_packets += delta;
-	dev->stats.rx_packets += delta;
+	sp->stats.tx_packets += delta;

This is now adding to tx_packets, not rx_packets.

drivers/net/s2io.c static struct net_device_stats *s2io_get · line 4930

Quoted 9 lines
drivers/net/s2io.c +0 -2
 	delta = ((u64) le32_to_cpu(stats->tmac_frms_oflow) << 32 |
 		le32_to_cpu(stats->tmac_frms)) - sp->stats.tx_packets;
 	sp->stats.tx_packets += delta;
-	dev->stats.tx_packets += delta;
 
 	delta = ((u64) le32_to_cpu(stats->rmac_data_octets_oflow) << 32 |
 		le32_to_cpu(stats->rmac_data_octets)) - sp->stats.rx_bytes;
 	sp->stats.rx_bytes += delta;
-	dev->stats.rx_bytes += delta;

[...]

It seems to me that the delta calculations and sp->stats are no longer necessary. These can be just:

	net_stats->rx_packets = ((u64) le32_to_cpu(stats->rmac_vld_frms_oflow) << 32 |
				 le32_to_cpu(stats->rmac_vld_frms));
 	net_stats->tx_packets = ((u64) le32_to_cpu(stats->tmac_frms_oflow) << 32 |
				 le32_to_cpu(stats->tmac_frms));
	net_stats->rx_bytes = ((u64) le32_to_cpu(stats->rmac_data_octets_oflow) << 32 |
		 	       le32_to_cpu(stats->rmac_data_octets));
	...

[...]

drivers/net/s2io.c static int rx_osm_handler(struct ring_in · line 7440

Quoted 6 lines
drivers/net/s2io.c +1 -1
@@ -7447,7 +7437,7 @@ static int rx_osm_handler(struct ring_in
 		if (err_mask != 0x5) {
 			DBG_PRINT(ERR_DBG, "%s: Rx error Value: 0x%x\n",
 				  dev->name, err_mask);
-			dev->stats.rx_crc_errors++;
+			sp->stats.rx_crc_errors++;

[...]

This won't be atomic on 32-bit systems. If this isn't double-counting CRC errors (I suspect it is) then there needs to be a separate unsigned long counter that's folded in by s2io_get_stats().

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#4 lore raw

Re: [PATCH 2/9] xen: convert to 64 bit stats interface

In reply to Stephen Hemminger
Quoted 3 lines · Stephen Hemminger

Convert xen driver to 64 bit statistics interface.
This driver was already counting packet per queue in a 64 bit value so not a huge change.

[...]

I think this driver will need to use u64_stats_sync.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#8 lore raw

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

In reply to Stephen Hemminger
Quoted 2 lines · Stephen Hemminger

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.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#9 lore raw

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

Quoted 9 lines · On Thu, 09 Jun 2011 03:00:41 +0100 Ben Hutchings <[email protected]>…
Quoted 2 lines · Stephen Hemminger

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.

#13 lore raw

Re: [PATCH 4/9] ifb: convert to 64 bit stats

In reply to Stephen Hemminger
Quoted 12 lines · Stephen Hemminger

pièce jointe document texte brut (ifb-stats64.patch) Convert input functional block device to use 64 bit stats.

drivers/net/ifb.c +0 -0
@@ -42,7 +42,14 @@ struct ifb_private {
 	struct tasklet_struct   ifb_tasklet;
 	int     tasklet_pending;
 	struct sk_buff_head     rq;

drivers/net/ifb.c struct ifb_private { · line 54

Quoted 10 lines
drivers/net/ifb.c +7 -0
+	u64 rx_packets;
+	u64 rx_bytes;
+	u64 rx_dropped;
+
 	struct sk_buff_head     tq;
+	u64 tx_packets;
+	u64 tx_bytes;
+	u64 tx_dropped;
 };
 

Hi Stephen

This needs special synchronization on 32bit arches, as Ben pointed out for other drivers.

#14 lore raw

Re: [PATCH 4/9] ifb: convert to 64 bit stats

Quoted 26 lines · On Thu, 09 Jun 2011 05:29:06 +0200 Eric Dumazet <[email protected]> wrote:
Quoted 12 lines · Stephen Hemminger

pièce jointe document texte brut (ifb-stats64.patch) Convert input functional block device to use 64 bit stats.

drivers/net/ifb.c +0 -0
@@ -42,7 +42,14 @@ struct ifb_private {
 	struct tasklet_struct   ifb_tasklet;
 	int     tasklet_pending;
 	struct sk_buff_head     rq;

drivers/net/ifb.c struct ifb_private { · line 54

Quoted 10 lines
drivers/net/ifb.c +7 -0
+	u64 rx_packets;
+	u64 rx_bytes;
+	u64 rx_dropped;
+
 	struct sk_buff_head     tq;
+	u64 tx_packets;
+	u64 tx_bytes;
+	u64 tx_dropped;
 };
 

Hi Stephen

Quoted 2 lines

This needs special synchronization on 32bit arches, as Ben pointed out for other drivers.

IFB is running in single thread context. Therefore just locking would be enough

#15 lore raw

Re: [PATCH 4/9] ifb: convert to 64 bit stats

Quoted 2 lines · Stephen Hemminger

IFB is running in single thread context. Therefore just locking would be enough

Yep, that is provided by include/linux/u64_stats_sync.h for free.

As a bonus, no locking on 64bit arches and a clean interface.

#21 lore raw

Re: [PATCH 6/9] enic: update to support 64 bit stats

In reply to Stephen Hemminger
Quoted 31 lines · Stephen Hemminger

The device driver already uses 64 bit statistics, it just doesn't use the 64 bit interface.

drivers/net/enic/enic_main.c 2011-06-07 17:29:09.670195233 -0700 renamed from drivers/net/enic/enic_main.c 2011-06-07 16:58:31.317079332 -0700 +3 -3
@@ -801,10 +801,10 @@ static netdev_tx_t enic_hard_start_xmit(
 }
 
 /* dev_base_lock rwlock held, nominally process context */
-static struct net_device_stats *enic_get_stats(struct net_device *netdev)
+static struct rtnl_link_stats64 *enic_get_stats(struct net_device *netdev,
+      struct rtnl_link_stats64 *net_stats)
 {
 struct enic *enic = netdev_priv(netdev);
- struct net_device_stats *net_stats = &netdev->stats;
 struct vnic_stats *stats;
 
 enic_dev_stats_dump(enic, &stats);
@@ -2117,7 +2117,7 @@ static const struct net_device_ops enic_
 .ndo_open  = enic_open,
 .ndo_stop  = enic_stop,
 .ndo_start_xmit  = enic_hard_start_xmit,
- .ndo_get_stats  = enic_get_stats,
+ .ndo_get_stats64 = enic_get_stats,
 .ndo_validate_addr = eth_validate_addr,
 .ndo_set_rx_mode = enic_set_rx_mode,
 .ndo_set_multicast_list = enic_set_rx_mode,

drivers/net/enic/enic_main.c 2011-06-07 17:29:09.670195233 -0700 static const struct net_device_ops enic_ · line 2145

Quoted 8 lines
drivers/net/enic/enic_main.c 2011-06-07 17:29:09.670195233 -0700 renamed from drivers/net/enic/enic_main.c 2011-06-07 16:58:31.317079332 -0700 +1 -1
@@ -2139,7 +2139,7 @@ static const struct net_device_ops enic_
 .ndo_open  = enic_open,
 .ndo_stop  = enic_stop,
 .ndo_start_xmit  = enic_hard_start_xmit,
- .ndo_get_stats  = enic_get_stats,
+ .ndo_get_stats64 = enic_get_stats,
 .ndo_validate_addr = eth_validate_addr,
 .ndo_set_mac_address = enic_set_mac_address,
 .ndo_set_rx_mode = enic_set_rx_mode,

ACK..
Thanks Stephen.

#10 lore raw

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

In reply to Stephen Hemminger
Quoted 8 lines · Stephen Hemminger
Quoted 5 lines · On Thu, 09 Jun 2011 03:00:41 +0100 Ben Hutchings <[email protected]>…
Quoted 2 lines · Stephen Hemminger

Not much change, device was already keeping per cpu statistics. Use recent 64 statistics interface.

[...]

Quoted 7 lines
Quoted 4 lines

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.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#5 lore raw

Re: Re: [PATCH 2/9] xen: convert to 64 bit stats interface

In reply to Ben Hutchings
Quoted 7 lines · Ben Hutchings
Quoted 3 lines · Stephen Hemminger

Convert xen driver to 64 bit statistics interface.
This driver was already counting packet per queue in a 64 bit value so not a huge change.

[...]

I think this driver will need to use u64_stats_sync.

Ian?

#6 lore raw

Re: [Xen-devel] Re: [PATCH 2/9] xen: convert to 64 bit stats interface

Quoted 10 lines · Konrad Rzeszutek Wilk
Quoted 7 lines · Ben Hutchings
Quoted 3 lines · Stephen Hemminger

Convert xen driver to 64 bit statistics interface.
This driver was already counting packet per queue in a 64 bit value so not a huge change.

[...]

I think this driver will need to use u64_stats_sync.

Ian?

I'll defer to Ben on this, but the case for needing u64_stats_sync for 64 bit values seems reasonable to me.

Ian.