more statistics updates
Subsystems (3)
cover more statistics updates
Fix drivers that are using 64 bit statistics with unsafe access on 32 bit. These are compile tested only, because the hardware to test it is not easily available.
PATCH 1/5 vxge: fix 64 bit access on 32 bit platforms
Need to add stat_sync wrapper around 64 bit statistic values. Fix wraparound bug in lockup detector where it is unsafely comparing 64 bit value that is not atomic. Since only care about detecting activity just looking at current low order bits will work.
Remove unused entries in old vxge_sw_stats structure.
Change the error counters to unsigned long since they won't grow so large as to have to be 64 bits.
drivers/net/vxge/vxge-main.c +41 -10
@@ -296,11 +296,13 @@ vxge_rx_complete(struct vxge_ring *ring,skb_record_rx_queue (skb, ring->driver_id); skb->protocol =eth_type_trans (skb, ring->ndev); +u64_stats_update_begin (&ring->stats.syncp); ring->stats.rx_frms++; ring->stats.rx_bytes += pkt_length;if (skb->pkt_type ==PACKET_MULTICAST ) ring->stats.rx_mcast++; +u64_stats_update_end (&ring->stats.syncp); vxge_debug_rx(VXGE_TRACE, "%s: %s:%d skb protocol = %d",
@@ -592,8 +594,10 @@ vxge_xmit_compl(struct __vxge_hw_fifo *fvxge_hw_fifo_txdl_free (fifo_hw, dtr);/* Updating the statistics block */ +u64_stats_update_begin (&fifo->stats.syncp); fifo->stats.tx_frms++; fifo->stats.tx_bytes += skb->len; +u64_stats_update_end (&fifo->stats.syncp); *done_skb++ = skb;
@@ -2630,11 +2634,16 @@ static void vxge_poll_vp_lockup(unsignedstruct vxge_vpath *vpath;struct vxge_ring *ring;int i; +unsigned long rx_frms;for (i =0 ; i < vdev->no_of_vpath; i++) { ring = &vdev->vpaths[i].ring; + +/* Truncated to machine word size number of frames */ + rx_frms =ACCESS_ONCE (ring->stats.rx_frms); +/* Did this vpath received any packets */ -if (ring->stats.prev_rx_frms == ring->stats.rx_frms) { +if (ring->stats.prev_rx_frms == rx_frms) { status =vxge_hw_vpath_check_leak (ring->handle);/* Did it received any packets last time */
@@ -2654,7 +2663,7 @@ static void vxge_poll_vp_lockup(unsigned } } } - ring->stats.prev_rx_frms = ring->stats.rx_frms; + ring->stats.prev_rx_frms = rx_frms; ring->last_status = status; }
@@ -3125,14 +3134,36 @@ vxge_get_stats64(struct net_device *dev,/* net_stats already zeroed by caller */ for (k =0 ; k < vdev->no_of_vpath; k++) { - net_stats->rx_packets += vdev->vpaths[k].ring.stats.rx_frms; - net_stats->rx_bytes += vdev->vpaths[k].ring.stats.rx_bytes; - net_stats->rx_errors += vdev->vpaths[k].ring.stats.rx_errors; - net_stats->multicast += vdev->vpaths[k].ring.stats.rx_mcast; - net_stats->rx_dropped += vdev->vpaths[k].ring.stats.rx_dropped; - net_stats->tx_packets += vdev->vpaths[k].fifo.stats.tx_frms; - net_stats->tx_bytes += vdev->vpaths[k].fifo.stats.tx_bytes; - net_stats->tx_errors += vdev->vpaths[k].fifo.stats.tx_errors; +struct vxge_ring_stats *rxstats = &vdev->vpaths[k].ring.stats; +struct vxge_fifo_stats *txstats = &vdev->vpaths[k].fifo.stats; +unsigned int start; +u64 packets, bytes, multicast; + +do { + start =u64_stats_fetch_begin (&rxstats->syncp); + + packets = rxstats->rx_frms; + multicast = rxstats->rx_mcast; + bytes = rxstats->rx_bytes; + }while (u64_stats_fetch_retry (&rxstats->syncp, start)); + + net_stats->rx_packets += packets; + net_stats->rx_bytes += bytes; + net_stats->multicast += multicast; + + net_stats->rx_errors += rxstats->rx_errors; + net_stats->rx_dropped += rxstats->rx_dropped; + +do { + start =u64_stats_fetch_begin (&txstats->syncp); + + packets = txstats->tx_frms; + bytes = txstats->tx_bytes; + }while (u64_stats_fetch_retry (&txstats->syncp, start)); + + net_stats->tx_packets += packets; + net_stats->tx_bytes += bytes; + net_stats->tx_errors += txstats->tx_errors; }return net_stats;
drivers/net/vxge/vxge-main.h +18 -30
74 lines not on this page · raw message
Re: [PATCH net-next 1/5] vxge: fix 64 bit access on 32 bit platforms
From: Stephen Hemminger <[email protected]>
Date: Mon, 20 Jun 2011 13:35:07 -0700
Quoted 10 lines
Need to add
stat_syncwrapper around 64 bit statistic values. Fix wraparound bug in lockup detector where it is unsafely comparing 64 bit value that is not atomic. Since only care about detecting activity just looking at current low order bits will work.Remove unused entries in old
vxge_sw_statsstructure.
Change the error counters to unsigned long since they won't grow so large as to have to be 64 bits.Signed-off-by Stephen Hemminger <[email protected]>
Applied.
PATCH 2/5 niu: fix 64 bit statistics on 32 bit platform
In reply to Stephen HemmingerThis resolves issues with NIU driver statistics wrapping on 32 bit SMP. Use stats_sync wrapper for bytes and packets, and change error counters to natural word size (unsigned long).
drivers/net/niu.c +41 -30
@@ -3512,8 +3512,10 @@ static int niu_process_rx_pkt(struct nap (u32)rh->hashval1_2 << 0);skb_pull (skb,sizeof (*rh)); +u64_stats_update_begin (&rp->syncp); rp->rx_packets++; rp->rx_bytes += skb->len; +u64_stats_update_end (&rp->syncp); skb->protocol =eth_type_trans (skb, np->dev);skb_record_rx_queue (skb, rp->rx_channel);
@@ -6252,59 +6254,59 @@ static void niu_sync_mac_stats(struct nistatic void niu_get_rx_stats (struct niu *np,struct rtnl_link_stats64 *stats) { -u64 pkts, dropped, errors, bytes;struct rx_ring_info *rx_rings;int i; - pkts = dropped = errors = bytes =0 ; - rx_rings =ACCESS_ONCE (np->rx_rings);if (!rx_rings) - goto no_rings; +return ;for (i =0 ; i < np->num_rx_rings; i++) {struct rx_ring_info *rp = &rx_rings[i]; +unsigned int start; +u64 pkts, bytes;niu_sync_rx_discard_stats (np, rp,0 ); - pkts += rp->rx_packets; - bytes += rp->rx_bytes; - dropped += rp->rx_dropped; - errors += rp->rx_errors; - } +do { + start =u64_stats_fetch_begin (&rp->syncp); -no_rings: - stats->rx_packets = pkts; - stats->rx_bytes = bytes; - stats->rx_dropped = dropped; - stats->rx_errors = errors; + pkts = rp->rx_packets; + bytes = rp->rx_bytes; + }while (u64_stats_fetch_retry (&rp->syncp, start)); + + stats->rx_packets += pkts; + stats->rx_bytes += bytes; + stats->rx_dropped += rp->rx_dropped; + stats->rx_errors += rp->rx_errors; + } }static void niu_get_tx_stats (struct niu *np,struct rtnl_link_stats64 *stats) { -u64 pkts, errors, bytes;struct tx_ring_info *tx_rings;int i; - pkts = errors = bytes =0 ; - tx_rings =ACCESS_ONCE (np->tx_rings);if (!tx_rings) - goto no_rings; +return ;for (i =0 ; i < np->num_tx_rings; i++) {struct tx_ring_info *rp = &tx_rings[i]; +unsigned int start; +u64 pkts, bytes; - pkts += rp->tx_packets; - bytes += rp->tx_bytes; - errors += rp->tx_errors; +do { + start =u64_stats_fetch_begin (&rp->syncp); + pkts = rp->tx_packets; + bytes = rp->tx_bytes; + }while (u64_stats_fetch_retry (&rp->syncp, start)); + + stats->tx_packets += pkts; + stats->tx_bytes += bytes; + stats->tx_errors += rp->tx_errors; } - -no_rings: - stats->tx_packets = pkts; - stats->tx_bytes = bytes; - stats->tx_errors = errors; } static struct rtnl_link_stats64 *niu_get_stats(struct net_device *dev,
@@ -7818,6 +7820,7 @@ static void niu_get_ethtool_stats(struct struct ethtool_stats *stats, u64 *data) { struct niu *np = netdev_priv(dev); +unsigned int start;int i;niu_sync_mac_stats (np);
@@ -7836,8 +7839,13 @@ static void niu_get_ethtool_stats(structniu_sync_rx_discard_stats (np, rp,0 ); data[0 ] = rp->rx_channel; - data[1 ] = rp->rx_packets; - data[2 ] = rp->rx_bytes; +do { + start =u64_stats_fetch_begin (&rp->syncp); + + data[1 ] = rp->rx_packets; + data[2 ] = rp->rx_bytes; + }while (u64_stats_fetch_retry (&rp->syncp, start)); + data[3 ] = rp->rx_dropped; data[4 ] = rp->rx_errors; data +=5 ;
@@ -7846,8 +7854,11 @@ static void niu_get_ethtool_stats(structstruct tx_ring_info *rp = &np->tx_rings[i]; data[0 ] = rp->tx_channel; - data[1 ] = rp->tx_packets; - data[2 ] = rp->tx_bytes; +do { + start =u64_stats_fetch_begin (&rp->syncp); + data[1 ] = rp->tx_packets; + data[2 ] = rp->tx_bytes; + }while (u64_stats_fetch_retry (&rp->syncp, start)); data[3 ] = rp->tx_errors; data +=4 ; }
drivers/net/niu.h +5 -3
@@ -2866,9 +2866,10 @@ struct tx_ring_info {struct txdma_mailbox *mbox;__le64 *descr; +struct u64_stats_sync syncp;u64 tx_packets;u64 tx_bytes; -u64 tx_errors; +unsigned long tx_errors;u64 mbox_dma;u64 descr_dma;
@@ -2922,10 +2923,11 @@ struct rx_ring_info {__le32 *rbr;#define RBR_DESCR_ADDR_SHIFT 12 +struct u64_stats_sync syncp;u64 rx_packets;u64 rx_bytes; -u64 rx_dropped; -u64 rx_errors; +unsigned long rx_dropped; +unsigned long rx_errors;u64 mbox_dma;u64 rcr_dma;
Re: [PATCH net-next 2/5] niu: fix 64 bit statistics on 32 bit platform
Quoted 3 lines · Stephen Hemminger
This resolves issues with NIU driver statistics wrapping on 32 bit SMP. Use
stats_syncwrapper for bytes and packets, and change error counters to natural word size (unsigned long).
[...]
Quoted 22 lines
static void niu_get_tx_stats(struct niu *np,
drivers/net/niu.c +3
-7struct rtnl_link_stats64 *stats) { -u64 pkts, errors, bytes;struct tx_ring_info *tx_rings;int i; - pkts = errors = bytes =0 ; - tx_rings =ACCESS_ONCE (np->tx_rings);if (!tx_rings) - goto no_rings; +return ;for (i =0 ; i < np->num_tx_rings; i++) {struct tx_ring_info *rp = &tx_rings[i]; +unsigned int start; +u64 pkts, bytes; - pkts += rp->tx_packets; - bytes += rp->tx_bytes; - errors += rp->tx_errors;
drivers/net/niu.c static void niu_sync_mac_stats(struct ni · line 6309
Quoted 10 lines
drivers/net/niu.c +9
-0+do { + start =u64_stats_fetch_begin (&rp->syncp); + pkts = rp->tx_packets; + bytes = rp->tx_bytes; + }while (u64_stats_fetch_retry (&rp->syncp, start)); + + stats->tx_packets += pkts; + stats->tx_bytes += bytes; + stats->tx_errors += rp->tx_errors; }
[...]
It looks like you also need to update release_tx_packet() where these stats are written.
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.
Re: [PATCH net-next 2/5] niu: fix 64 bit statistics on 32 bit platform
Quoted 3 lines
It looks like you also need to update
release_tx_packet()where these stats are written.
Probably need to split tx/rx update as well.
Re: [PATCH net-next 2/5] niu: fix 64 bit statistics on 32 bit platform
Quoted 4 lines · Stephen Hemminger
Quoted 2 lines
It looks like you also need to update
release_tx_packet()where these stats are written.Probably need to split tx/rx update as well.
Its already done in your patch ;)
PATCH 3/5 netxen: make 64 bit stats safe on 32 bit platform
In reply to Stephen HemmingerUse stats_update wrapper to avoid problems where 64 bit statistic update is not atomic on 32 bit platform.
--- drivers/net/netxen/netxen_nic.h | 1 + drivers/net/netxen/netxen_nic_init.c | 2 ++ drivers/net/netxen/netxen_nic_main.c | 16 ++++++++++++---- 3 files changed, 15 insertions(+), 4 deletions(-)
drivers/net/netxen/netxen_nic.h +1 -0
@@ -607,6 +607,7 @@ struct netxen_hardware_context {#define ETHERNET_FCS_SIZE 4struct netxen_adapter_stats { +struct u64_stats_sync syncp;u64 xmitcalled;u64 xmitfinished;u64 rxdropped;
drivers/net/netxen/netxen_nic_init.c +2 -0
@@ -1616,8 +1616,10 @@ netxen_process_lro(struct netxen_adapternetif_receive_skb (skb); +u64_stats_update_begin (&adapter->stats.syncp); adapter->stats.lro_pkts++; adapter->stats.rxbytes += length; +u64_stats_update_end (&adapter->stats.syncp);return buffer; }
drivers/net/netxen/netxen_nic_main.c +12 -4
@@ -1968,8 +1968,10 @@ netxen_nic_xmit_frame(struct sk_buff *sknetxen_nic_update_cmd_producer (adapter, tx_ring); +u64_stats_update_begin (&adapter->stats.syncp); adapter->stats.txbytes += skb->len; adapter->stats.xmitcalled++; +u64_stats_update_end (&adapter->stats.syncp);return NETDEV_TX_OK ;
@@ -2115,11 +2117,17 @@ static struct rtnl_link_stats64 *netxen_ struct rtnl_link_stats64 *stats) {struct netxen_adapter *adapter =netdev_priv (netdev); +unsigned int start; + +do { + start =u64_stats_fetch_begin (&adapter->stats.syncp); + + stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts; + stats->tx_packets = adapter->stats.xmitfinished; + stats->rx_bytes = adapter->stats.rxbytes; + stats->tx_bytes = adapter->stats.txbytes; + }while (u64_stats_fetch_retry (&adapter->stats.syncp, start)); - stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts; - stats->tx_packets = adapter->stats.xmitfinished; - stats->rx_bytes = adapter->stats.rxbytes; - stats->tx_bytes = adapter->stats.txbytes; stats->rx_dropped = adapter->stats.rxdropped; stats->tx_dropped = adapter->stats.txdropped;
Re: [PATCH net-next 3/5] netxen: make 64 bit stats safe on 32 bit platform
Quoted 6 lines · Stephen Hemminger
pièce jointe document texte brut (netxen-stats-sync.patch) Use
stats_updatewrapper to avoid problems where 64 bit statistic update is not atomic on 32 bit platform.Signed-off-by Stephen Hemminger <[email protected]>
Same remark than ifb : You need to be careful not having two different cpus doing an u64_stats_update_begin(one_syncp);
(Separate rx & tx)
Re: [PATCH net-next 3/5] netxen: make 64 bit stats safe on 32 bit platform
In reply to Stephen HemmingerQuoted 2 lines · Stephen Hemminger
Use
stats_updatewrapper to avoid problems where 64 bit statistic update is not atomic on 32 bit platform.
[...]
Quoted 11 lines
drivers/net/netxen/netxen_nic_main.c +7
-0@@ -2115,11 +2117,17 @@ static struct rtnl_link_stats64 *netxen_ struct rtnl_link_stats64 *stats) {struct netxen_adapter *adapter =netdev_priv (netdev); +unsigned int start; + + do { + start = u64_stats_fetch_begin(&adapter->stats.syncp); + + stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts; + stats->tx_packets = adapter->stats.xmitfinished;
drivers/net/netxen/netxen_nic_main.c static struct rtnl_link_stats64 *netxen_ · line 2132
Quoted 10 lines
drivers/net/netxen/netxen_nic_main.c +3
-4+ stats->rx_bytes = adapter->stats.rxbytes; + stats->tx_bytes = adapter->stats.txbytes; + }while (u64_stats_fetch_retry (&adapter->stats.syncp, start)); - stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts; - stats->tx_packets = adapter->stats.xmitfinished; - stats->rx_bytes = adapter->stats.rxbytes; - stats->tx_bytes = adapter->stats.txbytes; stats->rx_dropped = adapter->stats.rxdropped; stats->tx_dropped = adapter->stats.txdropped;
netxen_nic_get_ethtool_stats() should also be fixed.
The 'txdropped' and 'csummed' stats are also 64-bit and updated on the data path. ('rxdropped' isn't updated at all, AFAICS.)
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.
Re: [PATCH net-next 3/5] netxen: make 64 bit stats safe on 32 bit platform
Quoted 28 lines · Stephen Hemminger
Quoted 3 lines
Use
stats_updatewrapper to avoid problems where 64 bit statistic update is not atomic on 32 bit platform.[...]
Quoted 17 lines
drivers/net/netxen/netxen_nic_main.c +4
-0@@ -2115,11 +2117,17 @@ static struct rtnl_link_stats64 *netxen_ struct rtnl_link_stats64 *stats) {struct netxen_adapter *adapter =netdev_priv (netdev); +unsigned int start; + + do { + start =u64_stats_fetch_begin (&adapter->stats.syncp); + + stats->rx_packets = adapter->stats.rx_pkts +
adapter->stats.lro_pkts; +stats->tx_packets=adapter->stats.xmitfinished; +stats->rx_bytes=adapter->stats.rxbytes; +stats->tx_bytes=adapter->stats.txbytes;
+ } while (u64_stats_fetch_retry(&adapter->stats.syncp, start));-
stats->rx_packets=adapter->stats.rx_pkts+adapter->stats.lro_pkts; -stats->tx_packets=adapter->stats.xmitfinished; -stats->rx_bytes=adapter->stats.rxbytes; -stats->tx_bytes=adapter->stats.txbytes;drivers/net/netxen/netxen_nic_main.c static struct rtnl_link_stats64 *netxen_ · line 2132
Quoted 2 lines
drivers/net/netxen/netxen_nic_main.c +0
-0stats->rx_dropped = adapter->stats.rxdropped; stats->tx_dropped = adapter->stats.txdropped;
netxen_nic_get_ethtool_stats()should also be fixed.
Quoted 2 lines
The 'txdropped' and 'csummed' stats are also 64-bit and updated on the data path. ('rxdropped' isn't updated at all, AFAICS.)
Since they are error counters, just changing them to unsigned long is easier.
Re: [PATCH net-next 3/5] netxen: make 64 bit stats safe on 32 bit platform
Quoted 27 lines · Stephen Hemminger
Quoted 27 lines · Stephen Hemminger
Quoted 3 lines
Use
stats_updatewrapper to avoid problems where 64 bit statistic update is not atomic on 32 bit platform.[...]
Quoted 17 lines
drivers/net/netxen/netxen_nic_main.c +4
-0@@ -2115,11 +2117,17 @@ static struct rtnl_link_stats64 *netxen_ struct rtnl_link_stats64 *stats) {struct netxen_adapter *adapter =netdev_priv (netdev); +unsigned int start; + + do { + start =u64_stats_fetch_begin (&adapter->stats.syncp); + + stats->rx_packets = adapter->stats.rx_pkts +
adapter->stats.lro_pkts; +stats->tx_packets=adapter->stats.xmitfinished; +stats->rx_bytes=adapter->stats.rxbytes; +stats->tx_bytes=adapter->stats.txbytes;
+ } while (u64_stats_fetch_retry(&adapter->stats.syncp, start));-
stats->rx_packets=adapter->stats.rx_pkts+adapter->stats.lro_pkts; -stats->tx_packets=adapter->stats.xmitfinished; -stats->rx_bytes=adapter->stats.rxbytes; -stats->tx_bytes=adapter->stats.txbytes;drivers/net/netxen/netxen_nic_main.c static struct rtnl_link_stats64 *netxen_ · line 2132
Quoted 2 lines
drivers/net/netxen/netxen_nic_main.c +0
-0stats->rx_dropped = adapter->stats.rxdropped; stats->tx_dropped = adapter->stats.txdropped;
netxen_nic_get_ethtool_stats()should also be fixed.
Quoted 5 lines
Quoted 2 lines
The 'txdropped' and 'csummed' stats are also 64-bit and updated on the data path. ('rxdropped' isn't updated at all, AFAICS.)
Since they are error counters, just changing them to unsigned long is easier.
'csummed' is not.
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.
PATCH 4/5 xen: convert to 64 bit stats interface
In reply to Stephen HemmingerConvert xen driver to 64 bit statistics interface. Use stats_sync to ensure that 64 bit update is read atomically on 32 bit platform. Put hot statistics into per-cpu table.
---
v2 - add stats_sync and per-cpu
drivers/net/xen-netfront.c +64 -6
@@ -70,6 +70,14 @@ struct netfront_cb {#define NET_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE)#define TX_MAX_TARGET min_t(int, NET_RX_RING_SIZE, 256) +struct netfront_stats { +u64 rx_packets; +u64 tx_packets; +u64 rx_bytes; +u64 tx_bytes; +struct u64_stats_sync syncp; +}; +struct netfront_info {struct list_head list;struct net_device *netdev;
@@ -122,6 +130,8 @@ struct netfront_info {struct mmu_update rx_mmu[NET_RX_RING_SIZE ];/* Statistics */ +struct netfront_stats __percpu *stats; +unsigned long rx_gso_checksum_fixup; };
@@ -468,6 +478,7 @@ static int xennet_start_xmit(struct sk_b {unsigned short id;struct netfront_info *np =netdev_priv (dev); +struct netfront_stats *stats =this_cpu_ptr (np->stats);struct xen_netif_tx_request *tx;struct xen_netif_extra_info *extra;char *data = skb->data;
@@ -552,8 +563,10 @@ static int xennet_start_xmit(struct sk_bif (notify)notify_remote_via_irq (np->netdev->irq); - dev->stats.tx_bytes += skb->len; - dev->stats.tx_packets++; +u64_stats_update_begin (&stats->syncp); + stats->tx_bytes += skb->len; + stats->tx_packets++; +u64_stats_update_end (&stats->syncp);/* Note: It is not safe to access skb after xennet_tx_buf_gc()! */ xennet_tx_buf_gc (dev);
@@ -847,6 +860,8 @@ out:static int handle_incoming_queue (struct net_device *dev,struct sk_buff_head *rxq) { +struct netfront_info *np =netdev_priv (dev); +struct netfront_stats *stats =this_cpu_ptr (np->stats);int packets_dropped =0 ;struct sk_buff *skb;
@@ -867,12 +882,13 @@ static int handle_incoming_queue(structif (checksum_setup (dev, skb)) {kfree_skb (skb); packets_dropped++; - dev->stats.rx_errors++;continue ; } - dev->stats.rx_packets++; - dev->stats.rx_bytes += skb->len; +u64_stats_update_begin (&stats->syncp); + stats->rx_packets++; + stats->rx_bytes += skb->len; +u64_stats_update_end (&stats->syncp);/* Pass it up. */ netif_receive_skb (skb);
@@ -1034,6 +1050,38 @@ 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 *tot) +{ +struct netfront_info *np =netdev_priv (dev); +int cpu; + +for_each_possible_cpu (cpu) { +struct netfront_stats *stats =per_cpu_ptr (np->stats, cpu); +u64 rx_packets, rx_bytes, tx_packets, tx_bytes; +unsigned int start; + +do { + start =u64_stats_fetch_begin_bh (&stats->syncp); + + rx_packets = stats->rx_packets; + tx_packets = stats->tx_packets; + rx_bytes = stats->rx_bytes; + tx_bytes = stats->tx_bytes; + }while (u64_stats_fetch_retry_bh (&stats->syncp, start)); + + tot->rx_packets += rx_packets; + tot->tx_packets += tx_packets; + tot->rx_bytes += rx_bytes; + tot->tx_bytes += tx_bytes; + } + + tot->rx_errors = dev->stats.rx_errors; + tot->tx_dropped = dev->stats.tx_dropped; + +return tot; +} +static void xennet_release_tx_bufs (struct netfront_info *np) {struct sk_buff *skb;
@@ -1182,6 +1230,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,
@@ -1216,6 +1265,11 @@ static struct net_device * __devinit xen np->rx_refill_timer.data = (unsigned long )netdev; np->rx_refill_timer.function = rx_refill_timeout; + err = -ENOMEM ; + np->stats = alloc_percpu(struct netfront_stats); +if (np->stats ==NULL ) + goto exit; +/* Initialise tx_skbs as a free chain containing every entry. */ np->tx_skb_freelist =0 ;for (i =0 ; i <NET_TX_RING_SIZE ; i++) {
@@ -1234,7 +1288,7 @@ static struct net_device * __devinit xen &np->gref_tx_head) < 0) {printk (KERN_ALERT "#### netfront can't alloc tx grant refs\n" ); err = -ENOMEM ; - goto exit; + goto exit_free_stats; }/* A grant for every rx ring slot */ if (gnttab_alloc_grant_references(RX_MAX_TARGET,
@@ -1270,6 +1324,8 @@ static struct net_device * __devinit xen exit_free_tx:gnttab_free_grant_references (np->gref_tx_head); + exit_free_stats: +free_percpu (np->stats); exit:free_netdev (netdev);return ERR_PTR (err);
@@ -1869,6 +1925,8 @@ static int __devexit xennet_remove(strucxennet_sysfs_delif (info->netdev); +free_percpu (info->stats); +free_netdev (info->netdev);return 0 ;
Quoted 1 line
From [email protected] Mon Jun 20 13:36:03 2011
Message-Id: <[email protected]>
User-Agent: quilt/0.48-1
Date: Mon, 20 Jun 2011 13:35:11 -0700
From: Stephen Hemminger <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: [PATCH net-next 5/5] ifb: convert to 64 bit stats
References: <[email protected]>
Content-Disposition: inline; filename=ifb-stats64.patch
Convert input functional block device to use 64 bit stats.
---
v2 - add stats_sync
drivers/net/ifb.c +45 -8
98 lines not on this page · raw message
Re: [Xen-devel] [PATCH net-next 4/5] xen: convert to 64 bit stats interface
Quoted 5 lines · Stephen Hemminger
Convert xen driver to 64 bit statistics interface. Use
stats_syncto ensure that 64 bit update is read atomically on 32 bit platform. Put hot statistics into per-cpu table.Signed-off-by Stephen Hemminger <[email protected]>
Thanks Stephen.
drivers/net/xen-netfront.c static int handle_incoming_queue(struct · line 870
Quoted 5 lines
drivers/net/xen-netfront.c +0
-1@@ -867,12 +882,13 @@ static int handle_incoming_queue(structif (checksum_setup (dev, skb)) {kfree_skb (skb); packets_dropped++; - dev->stats.rx_errors++;
Why is this dropped? We should be counting these somehow, I think.
[...]
drivers/net/ifb.c
Quoted 21 lines
Quoted 1 line
From [email protected] Mon Jun 20 13:36:03 2011
Message-Id: <[email protected]>
User-Agent: quilt/0.48-1
Date: Mon, 20 Jun 2011 13:35:11 -0700
From: Stephen Hemminger <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: [PATCH net-next 5/5] ifb: convert to 64 bit stats
References: <[email protected]>
Content-Disposition: inline; filename=ifb-stats64.patchConvert input functional block device to use 64 bit stats.
Signed-off-by Stephen Hemminger <[email protected]>---
v2 - addstats_syncdrivers/net/ifb.c +0
-0
This entire patch was appended in the mail I got -- something up with your scripting?
Ian.
Re: [Xen-devel] [PATCH net-next 4/5] xen: convert to 64 bit stats interface
Quoted 38 lines · On Tue, 21 Jun 2011 15:05:54 +0100 Ian Campbell <[email protected]> wrote:
Quoted 5 lines · Stephen Hemminger
Convert xen driver to 64 bit statistics interface. Use
stats_syncto ensure that 64 bit update is read atomically on 32 bit platform. Put hot statistics into per-cpu table.Signed-off-by Stephen Hemminger <[email protected]>Thanks Stephen.
drivers/net/xen-netfront.c static int handle_incoming_queue(struct · line 870
Quoted 5 lines
drivers/net/xen-netfront.c +0
-1@@ -867,12 +882,13 @@ static int handle_incoming_queue(structif (checksum_setup (dev, skb)) {kfree_skb (skb); packets_dropped++; - dev->stats.rx_errors++;Why is this dropped? We should be counting these somehow, I think.
[...]
Quoted 19 lines
Quoted 1 line
From [email protected] Mon Jun 20 13:36:03 2011
Message-Id: <[email protected]>
User-Agent: quilt/0.48-1
Date: Mon, 20 Jun 2011 13:35:11 -0700
From: Stephen Hemminger <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: [PATCH net-next 5/5] ifb: convert to 64 bit stats
References: <[email protected]>
Content-Disposition: inline; filename=ifb-stats64.patchConvert input functional block device to use 64 bit stats.
Signed-off-by Stephen Hemminger <[email protected]>---
v2 - addstats_sync
Quoted 5 lines
drivers/net/ifb.c
Quoted 2 lines
drivers/net/ifb.c +0
-0This entire patch was appended in the mail I got -- something up with your scripting?
Bad mbox file to quilt, merged two patches
Re: [Xen-devel] [PATCH net-next 4/5] xen: convert to 64 bit stats interface
In reply to Ian CampbellConvert xen driver to 64 bit statistics interface.
Use stats_sync to ensure that 64 bit update is read atomically on 32 bit platform. Put hot statistics into per-cpu table.
---
v2 - add stats_sync and per-cpu
v2.1 - keep rx_errors on checksum error
drivers/net/xen-netfront.c +64 -5
@@ -70,6 +70,14 @@ struct netfront_cb {#define NET_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE)#define TX_MAX_TARGET min_t(int, NET_RX_RING_SIZE, 256) +struct netfront_stats { +u64 rx_packets; +u64 tx_packets; +u64 rx_bytes; +u64 tx_bytes; +struct u64_stats_sync syncp; +}; +struct netfront_info {struct list_head list;struct net_device *netdev;
@@ -122,6 +130,8 @@ struct netfront_info {struct mmu_update rx_mmu[NET_RX_RING_SIZE ];/* Statistics */ +struct netfront_stats __percpu *stats; +unsigned long rx_gso_checksum_fixup; };
@@ -468,6 +478,7 @@ static int xennet_start_xmit(struct sk_b {unsigned short id;struct netfront_info *np =netdev_priv (dev); +struct netfront_stats *stats =this_cpu_ptr (np->stats);struct xen_netif_tx_request *tx;struct xen_netif_extra_info *extra;char *data = skb->data;
@@ -552,8 +563,10 @@ static int xennet_start_xmit(struct sk_bif (notify)notify_remote_via_irq (np->netdev->irq); - dev->stats.tx_bytes += skb->len; - dev->stats.tx_packets++; +u64_stats_update_begin (&stats->syncp); + stats->tx_bytes += skb->len; + stats->tx_packets++; +u64_stats_update_end (&stats->syncp);/* Note: It is not safe to access skb after xennet_tx_buf_gc()! */ xennet_tx_buf_gc (dev);
@@ -847,6 +860,8 @@ out:static int handle_incoming_queue (struct net_device *dev,struct sk_buff_head *rxq) { +struct netfront_info *np =netdev_priv (dev); +struct netfront_stats *stats =this_cpu_ptr (np->stats);int packets_dropped =0 ;struct sk_buff *skb;
@@ -871,8 +886,10 @@ static int handle_incoming_queue(structcontinue ; } - dev->stats.rx_packets++; - dev->stats.rx_bytes += skb->len; +u64_stats_update_begin (&stats->syncp); + stats->rx_packets++; + stats->rx_bytes += skb->len; +u64_stats_update_end (&stats->syncp);/* Pass it up. */ netif_receive_skb (skb);
@@ -1034,6 +1051,38 @@ 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 *tot) +{ +struct netfront_info *np =netdev_priv (dev); +int cpu; + +for_each_possible_cpu (cpu) { +struct netfront_stats *stats =per_cpu_ptr (np->stats, cpu); +u64 rx_packets, rx_bytes, tx_packets, tx_bytes; +unsigned int start; + +do { + start =u64_stats_fetch_begin_bh (&stats->syncp); + + rx_packets = stats->rx_packets; + tx_packets = stats->tx_packets; + rx_bytes = stats->rx_bytes; + tx_bytes = stats->tx_bytes; + }while (u64_stats_fetch_retry_bh (&stats->syncp, start)); + + tot->rx_packets += rx_packets; + tot->tx_packets += tx_packets; + tot->rx_bytes += rx_bytes; + tot->tx_bytes += tx_bytes; + } + + tot->rx_errors = dev->stats.rx_errors; + tot->tx_dropped = dev->stats.tx_dropped; + +return tot; +} +static void xennet_release_tx_bufs (struct netfront_info *np) {struct sk_buff *skb;
@@ -1182,6 +1231,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,
@@ -1216,6 +1266,11 @@ static struct net_device * __devinit xen np->rx_refill_timer.data = (unsigned long )netdev; np->rx_refill_timer.function = rx_refill_timeout; + err = -ENOMEM ; + np->stats = alloc_percpu(struct netfront_stats); +if (np->stats ==NULL ) + goto exit; +/* Initialise tx_skbs as a free chain containing every entry. */ np->tx_skb_freelist =0 ;for (i =0 ; i <NET_TX_RING_SIZE ; i++) {
@@ -1234,7 +1289,7 @@ static struct net_device * __devinit xen &np->gref_tx_head) < 0) {printk (KERN_ALERT "#### netfront can't alloc tx grant refs\n" ); err = -ENOMEM ; - goto exit; + goto exit_free_stats; }/* A grant for every rx ring slot */ if (gnttab_alloc_grant_references(RX_MAX_TARGET,
@@ -1270,6 +1325,8 @@ static struct net_device * __devinit xen exit_free_tx:gnttab_free_grant_references (np->gref_tx_head); + exit_free_stats: +free_percpu (np->stats); exit:free_netdev (netdev);return ERR_PTR (err);
@@ -1869,6 +1926,8 @@ static int __devexit xennet_remove(strucxennet_sysfs_delif (info->netdev); +free_percpu (info->stats); +free_netdev (info->netdev);return 0 ;
Ian Campbell
Acked-byRe: [Xen-devel] [PATCH net-next 4/5] xen: convert to 64 bit stats interface
Quoted 9 lines · Stephen Hemminger
Convert xen driver to 64 bit statistics interface.
Usestats_syncto ensure that 64 bit update is read atomically on 32 bit platform. Put hot statistics into per-cpu table.Signed-off-by Stephen Hemminger <[email protected]>---
v2 - addstats_syncand per-cpu
v2.1 - keeprx_errorson checksum error
Thanks. Looks good to me from the Xen side.
Quoted 157 lines
drivers/net/xen-netfront.c +64
-5@@ -70,6 +70,14 @@ struct netfront_cb {#define NET_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE)#define TX_MAX_TARGET min_t(int, NET_RX_RING_SIZE, 256) +struct netfront_stats { +u64 rx_packets; +u64 tx_packets; +u64 rx_bytes; +u64 tx_bytes; +struct u64_stats_sync syncp; +}; +struct netfront_info {struct list_head list;struct net_device *netdev;@@ -122,6 +130,8 @@ struct netfront_info {struct mmu_update rx_mmu[NET_RX_RING_SIZE ];/* Statistics */ +struct netfront_stats __percpu *stats; +unsigned long rx_gso_checksum_fixup; };@@ -468,6 +478,7 @@ static int xennet_start_xmit(struct sk_b {unsigned short id;struct netfront_info *np =netdev_priv (dev); +struct netfront_stats *stats =this_cpu_ptr (np->stats);struct xen_netif_tx_request *tx;struct xen_netif_extra_info *extra;char *data = skb->data;@@ -552,8 +563,10 @@ static int xennet_start_xmit(struct sk_bif (notify)notify_remote_via_irq (np->netdev->irq); - dev->stats.tx_bytes += skb->len; - dev->stats.tx_packets++; +u64_stats_update_begin (&stats->syncp); + stats->tx_bytes += skb->len; + stats->tx_packets++; +u64_stats_update_end (&stats->syncp);/* Note: It is not safe to access skb after xennet_tx_buf_gc()! */ xennet_tx_buf_gc (dev);@@ -847,6 +860,8 @@ out:static int handle_incoming_queue (struct net_device *dev,struct sk_buff_head *rxq) { +struct netfront_info *np =netdev_priv (dev); +struct netfront_stats *stats =this_cpu_ptr (np->stats);int packets_dropped =0 ;struct sk_buff *skb;@@ -871,8 +886,10 @@ static int handle_incoming_queue(structcontinue ; } - dev->stats.rx_packets++; - dev->stats.rx_bytes += skb->len; +u64_stats_update_begin (&stats->syncp); + stats->rx_packets++; + stats->rx_bytes += skb->len; +u64_stats_update_end (&stats->syncp);/* Pass it up. */ netif_receive_skb (skb);@@ -1034,6 +1051,38 @@ 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 *tot) +{ +struct netfront_info *np =netdev_priv (dev); +int cpu; + +for_each_possible_cpu (cpu) { +struct netfront_stats *stats =per_cpu_ptr (np->stats, cpu); +u64 rx_packets, rx_bytes, tx_packets, tx_bytes; +unsigned int start; + +do { + start =u64_stats_fetch_begin_bh (&stats->syncp); + + rx_packets = stats->rx_packets; + tx_packets = stats->tx_packets; + rx_bytes = stats->rx_bytes; + tx_bytes = stats->tx_bytes; + }while (u64_stats_fetch_retry_bh (&stats->syncp, start)); + + tot->rx_packets += rx_packets; + tot->tx_packets += tx_packets; + tot->rx_bytes += rx_bytes; + tot->tx_bytes += tx_bytes; + } + + tot->rx_errors = dev->stats.rx_errors; + tot->tx_dropped = dev->stats.tx_dropped; + +return tot; +} +static void xennet_release_tx_bufs (struct netfront_info *np) {struct sk_buff *skb;@@ -1182,6 +1231,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,@@ -1216,6 +1266,11 @@ static struct net_device * __devinit xen np->rx_refill_timer.data = (unsigned long )netdev; np->rx_refill_timer.function = rx_refill_timeout; + err = -ENOMEM ; + np->stats = alloc_percpu(struct netfront_stats); +if (np->stats ==NULL ) + goto exit; +/* Initialise tx_skbs as a free chain containing every entry. */ np->tx_skb_freelist =0 ;for (i =0 ; i <NET_TX_RING_SIZE ; i++) {@@ -1234,7 +1289,7 @@ static struct net_device * __devinit xen &np->gref_tx_head) < 0) {printk (KERN_ALERT "#### netfront can't alloc tx grant refs\n" ); err = -ENOMEM ; - goto exit; + goto exit_free_stats; }/* A grant for every rx ring slot */ if (gnttab_alloc_grant_references(RX_MAX_TARGET,@@ -1270,6 +1325,8 @@ static struct net_device * __devinit xen exit_free_tx:gnttab_free_grant_references (np->gref_tx_head); + exit_free_stats: +free_percpu (np->stats); exit:free_netdev (netdev);return ERR_PTR (err);@@ -1869,6 +1926,8 @@ static int __devexit xennet_remove(strucxennet_sysfs_delif (info->netdev); +free_percpu (info->stats); +free_netdev (info->netdev);return 0 ;
Re: [Xen-devel] [PATCH net-next 4/5] xen: convert to 64 bit stats interface
From: Ian Campbell <[email protected]>
Date: Tue, 21 Jun 2011 16:38:48 +0100
Quoted 7 lines · Stephen Hemminger
Quoted 6 lines
Convert xen driver to 64 bit statistics interface.
Usestats_syncto ensure that 64 bit update is read atomically on 32 bit platform. Put hot statistics into per-cpu table.Signed-off-by Stephen Hemminger <[email protected]>
Quoted 7 lines
Quoted 3 lines
---
v2 - addstats_syncand per-cpu
v2.1 - keeprx_errorson checksum errorThanks. Looks good to me from the Xen side.
Acked-by Ian Campbell <[email protected]>
Applied.
David Miller
maintainerFrom: Stephen Hemminger <[email protected]>
Date: Mon, 20 Jun 2011 13:35:06 -0700
Quoted 3 lines
Fix drivers that are using 64 bit statistics with unsafe access on 32 bit. These are compile tested only, because the hardware to test it is not easily available.
Where is patch #5?
PATCH 5/5 ifb: convert to 64 bit stats
Convert input functional block device to use 64 bit stats.
---
v2 - add stats_sync
drivers/net/ifb.c +43 -9
@@ -41,8 +41,16 @@struct ifb_private {struct tasklet_struct ifb_tasklet;int tasklet_pending; + +struct u64_stats_sync stats_sync; +struct sk_buff_head rq; +u64 rx_packets; +u64 rx_bytes; +struct sk_buff_head tq; +u64 tx_packets; +u64 tx_bytes; };static int numifbs =2 ;
@@ -54,10 +62,8 @@ static int ifb_close(struct net_device *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,18 @@ 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; + +u64_stats_update_begin (&dp->stats_sync); + dp->tx_packets++; + dp->tx_bytes += skb->len; +u64_stats_update_end (&dp->stats_sync);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++; + _dev->stats.tx_dropped++;if (skb_queue_len (&dp->tq) !=0 ) goto resched;break ;
@@ -120,9 +129,33 @@ resched: } +static struct rtnl_link_stats64 *ifb_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats) +{ +struct ifb_private *dp =netdev_priv (dev); +unsigned int start; + +do { + start =u64_stats_fetch_begin_bh (&dp->stats_sync); + + stats->rx_packets = dp->rx_packets; + stats->rx_bytes = dp->rx_bytes; + stats->tx_packets = dp->tx_packets; + stats->tx_bytes = dp->tx_bytes; + + }while (u64_stats_fetch_retry_bh (&dp->stats_sync, start)); + + stats->rx_dropped = dev->stats.rx_dropped; + stats->tx_dropped = dev->stats.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 +186,16 @@ static void ifb_setup(struct net_devicestatic 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; +u64_stats_update_begin (&dp->stats_sync); + dp->rx_packets++; + dp->rx_bytes += skb->len; +u64_stats_update_end (&dp->stats_sync);if (!(from & (AT_INGRESS |AT_EGRESS )) || !skb->skb_iif) {dev_kfree_skb (skb); - stats->rx_dropped++; + dev->stats.rx_dropped++;return NETDEV_TX_OK ; }
Re: [PATCH net-next 5/5] ifb: convert to 64 bit stats
Quoted 7 lines · Stephen Hemminger
Convert input functional block device to use 64 bit stats.
Signed-off-by Stephen Hemminger <[email protected]>---
v2 - addstats_sync
Re: [PATCH net-next 5/5] ifb: convert to 64 bit stats
Quoted 11 lines · Eric Dumazet
Quoted 7 lines · Stephen Hemminger
Convert input functional block device to use 64 bit stats.
Signed-off-by Stephen Hemminger <[email protected]>---
v2 - addstats_syncAcked-by Eric Dumazet <[email protected]>
Ah well, I am wondering if ri_tasklet() & ifb_xmit() could run concurrently
If so, we need two separate syncp, one for each function.
Re: [PATCH net-next 5/5] ifb: convert to 64 bit stats
Quoted 10 lines · On Mon, 20 Jun 2011 23:27:01 +0200 Eric Dumazet <[email protected]> wrote:
Quoted 9 lines · Eric Dumazet
Quoted 7 lines · Stephen Hemminger
Convert input functional block device to use 64 bit stats.
Signed-off-by Stephen Hemminger <[email protected]>---
v2 - addstats_sync
Quoted 7 lines
Quoted 2 lines
Acked-by Eric Dumazet <[email protected]>Ah well, I am wondering if
ri_tasklet()&ifb_xmit()could run concurrentlyIf so, we need two separate syncp, one for each function.
For the normal case that isn't possible but
someone could be perverse and put an address on the ifb device and try and use like loopback?
Re: [PATCH net-next 5/5] ifb: convert to 64 bit stats
From: Stephen Hemminger <[email protected]>
Quoted 16 lines · Stephen Hemminger
Quoted 13 lines · On Mon, 20 Jun 2011 23:27:01 +0200 Eric Dumazet <[email protected]> wrote:
Quoted 11 lines · Eric Dumazet
Quoted 7 lines · Stephen Hemminger
Convert input functional block device to use 64 bit stats.
Signed-off-by Stephen Hemminger <[email protected]>---
v2 - addstats_syncAcked-by Eric Dumazet <[email protected]>
Quoted 8 lines
Quoted 4 lines
Ah well, I am wondering if
ri_tasklet()&ifb_xmit()could run concurrentlyIf so, we need two separate syncp, one for each function.
For the normal case that isn't possible but
someone could be perverse and put an address on the ifb device and try and use like loopback?
Hmm, this can occur on normal case I think, on SMP.
Here is an updated patch
[PATCH net-next v3] ifb: convert to 64 bit stats
Convert input functional block device to use 64 bit stats.
[Eric Dumazet]: Use two different synchronization points for rx and tx.
---
v2 - add stats_sync
v3 - must use two different sync
drivers/net/ifb.c | 58 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 9 deletions(-)
drivers/net/ifb.c +49 -9
@@ -41,8 +41,16 @@struct ifb_private {struct tasklet_struct ifb_tasklet;int tasklet_pending; +struct sk_buff_head rq; +u64 rx_packets; +u64 rx_bytes; +struct u64_stats_sync stats_rx_sync; +struct sk_buff_head tq; +u64 tx_packets; +u64 tx_bytes; +struct u64_stats_sync stats_tx_sync; };static int numifbs =2 ;
@@ -54,10 +62,8 @@ static int ifb_close(struct net_device *dev);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,18 @@ 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; + +u64_stats_update_begin (&dp->stats_tx_sync); + dp->tx_packets++; + dp->tx_bytes += skb->len; +u64_stats_update_end (&dp->stats_tx_sync);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++; + _dev->stats.tx_dropped++;if (skb_queue_len (&dp->tq) !=0 ) goto resched;break ;
@@ -120,9 +129,39 @@ resched: } +static struct rtnl_link_stats64 *ifb_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats) +{ +const struct ifb_private *dp =netdev_priv (dev); +unsigned int start; + +do { + start =u64_stats_fetch_begin_bh (&dp->stats_rx_sync); + + stats->rx_packets = dp->rx_packets; + stats->rx_bytes = dp->rx_bytes; + + }while (u64_stats_fetch_retry_bh (&dp->stats_rx_sync, start)); + +do { + start =u64_stats_fetch_begin_bh (&dp->stats_tx_sync); + + stats->tx_packets = dp->tx_packets; + stats->tx_bytes = dp->tx_bytes; + + }while (u64_stats_fetch_retry_bh (&dp->stats_tx_sync, start)); + + stats->rx_dropped = dev->stats.rx_dropped; + stats->tx_dropped = dev->stats.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 +192,16 @@ static void ifb_setup(struct net_device *dev)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; +u64_stats_update_begin (&dp->stats_rx_sync); + dp->rx_packets++; + dp->rx_bytes += skb->len; +u64_stats_update_end (&dp->stats_rx_sync);if (!(from & (AT_INGRESS |AT_EGRESS )) || !skb->skb_iif) {dev_kfree_skb (skb); - stats->rx_dropped++; + dev->stats.rx_dropped++;return NETDEV_TX_OK ; }
PATCH 5/5 ifb: convert to 64 bit stats (v3)
In reply to Eric DumazetSubject: ifb: convert to 64 bit stats
Convert input functional block device to use 64 bit stats.
---
v3 - split tx/rsync
drivers/net/ifb.c +47 -9
@@ -41,8 +41,16 @@struct ifb_private {struct tasklet_struct ifb_tasklet;int tasklet_pending; + +struct u64_stats_sync rsync;struct sk_buff_head rq; +u64 rx_packets; +u64 rx_bytes; + +struct u64_stats_sync tsync;struct sk_buff_head tq; +u64 tx_packets; +u64 tx_bytes; };static int numifbs =2 ;
@@ -54,10 +62,8 @@ static int ifb_close(struct net_device *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,18 @@ 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; + +u64_stats_update_begin (&dp->tsync); + dp->tx_packets++; + dp->tx_bytes += skb->len; +u64_stats_update_end (&dp->tsync);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++; + _dev->stats.tx_dropped++;if (skb_queue_len (&dp->tq) !=0 ) goto resched;break ;
@@ -120,9 +129,37 @@ resched: } +static struct rtnl_link_stats64 *ifb_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats) +{ +struct ifb_private *dp =netdev_priv (dev); +unsigned int start; + +do { + start =u64_stats_fetch_begin_bh (&dp->rsync); + stats->rx_packets = dp->rx_packets; + stats->rx_bytes = dp->rx_bytes; + }while (u64_stats_fetch_retry_bh (&dp->rsync, start)); + +do { + start =u64_stats_fetch_begin_bh (&dp->tsync); + + stats->tx_packets = dp->tx_packets; + stats->tx_bytes = dp->tx_bytes; + + }while (u64_stats_fetch_retry_bh (&dp->tsync, start)); + + stats->rx_dropped = dev->stats.rx_dropped; + stats->tx_dropped = dev->stats.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 +190,16 @@ static void ifb_setup(struct net_devicestatic 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; +u64_stats_update_begin (&dp->rsync); + dp->rx_packets++; + dp->rx_bytes += skb->len; +u64_stats_update_end (&dp->rsync);if (!(from & (AT_INGRESS |AT_EGRESS )) || !skb->skb_iif) {dev_kfree_skb (skb); - stats->rx_dropped++; + dev->stats.rx_dropped++;return NETDEV_TX_OK ; }
Re: [PATCH net-next 5/5] ifb: convert to 64 bit stats (v3)
Quoted 8 lines · Stephen Hemminger
Subject: ifb: convert to 64 bit stats
Convert input functional block device to use 64 bit stats.
Signed-off-by Stephen Hemminger <[email protected]>---
v3 - split tx/rsync
Seems good :)
jamal
Acked-byRe: [PATCH net-next 5/5] ifb: convert to 64 bit stats (v3)
Quoted 1 line · Eric Dumazet
Signed-off-by Eric Dumazet <[email protected]>
cheers,
jamal
Re: [PATCH net-next 5/5] ifb: convert to 64 bit stats (v3)
From: jamal <[email protected]>
Date: Mon, 20 Jun 2011 20:04:41 -0400
Quoted 5 lines · Eric Dumazet
Quoted 2 lines
Signed-off-by Eric Dumazet <[email protected]>Acked-by Jamal Hadi Salim <[email protected]>
Applied.