8139too: Add 64bit statistics
Subsystems (2)
PATCH 1/1 8139too: Add 64bit statistics
Switch to use ndo_get_stats64 to get 64bit statistics. Two sync entries are used (one for Rx and one for Tx).
--- drivers/net/ethernet/realtek/8139too.c | 61 +++++++++++++++++++++++++++---- 1 files changed, 53 insertions(+), 8 deletions(-)
drivers/net/ethernet/realtek/8139too.c +53 -8
@@ -565,6 +565,12 @@ struct rtl_extra_stats {unsigned long rx_lost_in_ring; }; +struct rtl8139_stats { +u64 packets; +u64 bytes; +struct u64_stats_sync syncp; +}; +struct rtl8139_private {void __iomem *mmio_addr;int drv_flags;
@@ -575,11 +581,13 @@ struct rtl8139_private {unsigned char *rx_ring;unsigned int cur_rx;/* RX buf index of next pkt */ +struct rtl8139_stats rx_stats;dma_addr_t rx_ring_dma;unsigned int tx_flag;unsigned long cur_tx;unsigned long dirty_tx; +struct rtl8139_stats tx_stats;unsigned char *tx_buf[NUM_TX_DESC ];/* Tx bounce buffers */ unsigned char *tx_bufs;/* Tx bounce buffer region. */ dma_addr_t tx_bufs_dma;
@@ -641,7 +649,9 @@ static int rtl8139_poll(struct napi_struct *napi, int budget);static irqreturn_t rtl8139_interrupt (int irq,void *dev_instance);static int rtl8139_close (struct net_device *dev);static int netdev_ioctl (struct net_device *dev,struct ifreq *rq,int cmd); -static struct net_device_stats *rtl8139_get_stats (struct net_device *dev); +static struct rtnl_link_stats64 *rtl8139_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 + *stats);static void rtl8139_set_rx_mode (struct net_device *dev);static void __set_rx_mode (struct net_device *dev);static void rtl8139_hw_start (struct net_device *dev);
@@ -937,7 +947,7 @@ static int rtl8139_set_features(struct net_device *dev, netdev_features_t featurstatic const struct net_device_ops rtl8139_netdev_ops = { .ndo_open = rtl8139_open, .ndo_stop = rtl8139_close, - .ndo_get_stats = rtl8139_get_stats, + .ndo_get_stats64 = rtl8139_get_stats64, .ndo_change_mtu = eth_change_mtu, .ndo_validate_addr = eth_validate_addr, .ndo_set_mac_address = rtl8139_set_mac_address,
@@ -1807,8 +1817,10 @@ static void rtl8139_tx_interrupt (struct net_device *dev, dev->stats.tx_fifo_errors++; } dev->stats.collisions += (txstatus >>24 ) &15 ; - dev->stats.tx_bytes += txstatus &0x7ff ; - dev->stats.tx_packets++; +u64_stats_update_begin (&tp->tx_stats.syncp); + tp->tx_stats.packets++; + tp->tx_stats.bytes += txstatus &0x7ff ; +u64_stats_update_end (&tp->tx_stats.syncp); } dirty_tx++;
@@ -2050,8 +2062,10 @@ keep_pkt: skb->protocol =eth_type_trans (skb, dev); - dev->stats.rx_bytes += pkt_size; - dev->stats.rx_packets++; +u64_stats_update_begin (&tp->rx_stats.syncp); + tp->rx_stats.packets++; + tp->rx_stats.bytes += pkt_size; +u64_stats_update_end (&tp->rx_stats.syncp);netif_receive_skb (skb); }else {
@@ -2515,11 +2529,13 @@ static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) } -static struct net_device_stats *rtl8139_get_stats (struct net_device *dev) +static struct rtnl_link_stats64 * +rtl8139_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats) {struct rtl8139_private *tp =netdev_priv (dev);void __iomem *ioaddr = tp->mmio_addr;unsigned long flags; +unsigned int start;if (netif_running (dev)) {spin_lock_irqsave (&tp->lock, flags);
@@ -2528,7 +2544,36 @@ static struct net_device_stats *rtl8139_get_stats (struct net_device *dev)spin_unlock_irqrestore (&tp->lock, flags); } -return &dev->stats; +do { + start =u64_stats_fetch_begin_bh (&tp->rx_stats.syncp); + stats->rx_packets = tp->rx_stats.packets; + stats->rx_bytes = tp->rx_stats.bytes; + }while (u64_stats_fetch_retry_bh (&tp->rx_stats.syncp, start)); + +do { + start =u64_stats_fetch_begin_bh (&tp->tx_stats.syncp); + stats->tx_packets = tp->tx_stats.packets; + stats->tx_bytes = tp->tx_stats.bytes; + }while (u64_stats_fetch_retry_bh (&tp->tx_stats.syncp, start)); + + stats->rx_errors = dev->stats.rx_errors; + stats->tx_errors = dev->stats.tx_errors; + stats->rx_dropped = dev->stats.rx_dropped; + stats->tx_dropped = dev->stats.tx_dropped; + stats->collisions = dev->stats.collisions; + + stats->rx_length_errors = dev->stats.rx_length_errors; + stats->rx_crc_errors = dev->stats.rx_crc_errors; + stats->rx_frame_errors = dev->stats.rx_frame_errors; + stats->rx_fifo_errors = dev->stats.rx_fifo_errors; + stats->rx_missed_errors = dev->stats.rx_missed_errors; + + stats->tx_aborted_errors = dev->stats.tx_aborted_errors; + stats->tx_carrier_errors = dev->stats.tx_carrier_errors; + stats->tx_fifo_errors = dev->stats.tx_fifo_errors; + stats->tx_window_errors = dev->stats.tx_window_errors; + +return stats; }/* Set or clear the multicast filter for this adaptor.
--
--Junchang
Quoted 5 lines · Junchang Wang
Switch to use
ndo_get_stats64to get 64bit statistics. Two sync entries are used (one for Rx and one for Tx).Signed-off-by Junchang Wang <[email protected]>---
...
Quoted 10 lines
drivers/net/ethernet/realtek/8139too.c +9
-0+ stats->rx_errors = dev->stats.rx_errors; + stats->tx_errors = dev->stats.tx_errors; + stats->rx_dropped = dev->stats.rx_dropped; + stats->tx_dropped = dev->stats.tx_dropped; + stats->collisions = dev->stats.collisions; + + stats->rx_length_errors = dev->stats.rx_length_errors; + stats->rx_crc_errors = dev->stats.rx_crc_errors; + stats->rx_frame_errors = dev->stats.rx_frame_errors;
drivers/net/ethernet/realtek/8139too.c static struct net_device_stats *rtl8139_get_stats (struct net_device *dev) · line 2577
Quoted 10 lines
drivers/net/ethernet/realtek/8139too.c +9
-0+ stats->rx_fifo_errors = dev->stats.rx_fifo_errors; + stats->rx_missed_errors = dev->stats.rx_missed_errors; + + stats->tx_aborted_errors = dev->stats.tx_aborted_errors; + stats->tx_carrier_errors = dev->stats.tx_carrier_errors; + stats->tx_fifo_errors = dev->stats.tx_fifo_errors; + stats->tx_window_errors = dev->stats.tx_window_errors; + +return stats; }
Maybe its time to export netdev_stats_to_stats64() after all, to avoid all this duplicate code.
I'll submit a patch.
Could you repost this after netdev_stats_to_stats64() being available to drivers ?
Thanks
PATCH 1/1 net: export netdev_stats_to_stats64
Some drivers use internal netdev stats member to store part of their stats, yet advertize ndo_get_stats64() to implement some 64bit fields.
Allow them to use netdev_stats_to_stats64() helper to make the copy of netdev stats before they compute their 64bit counters.
---
Also changed some incorrect spaces to tabs.
net/core/dev.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
net/core/dev.c +5 -4
@@ -5834,12 +5834,12 @@ void netdev_run_todo(void)/* Convert net_device_stats to rtnl_link_stats64. They have the same * fields in the same order, with only the type differing. */ -static void netdev_stats_to_stats64 (struct rtnl_link_stats64 *stats64, -const struct net_device_stats *netdev_stats) +void netdev_stats_to_stats64 (struct rtnl_link_stats64 *stats64, +const struct net_device_stats *netdev_stats) {#if BITS_PER_LONG ==64 -BUILD_BUG_ON (sizeof (*stats64) !=sizeof (*netdev_stats)); -memcpy (stats64, netdev_stats,sizeof (*stats64)); +BUILD_BUG_ON (sizeof (*stats64) !=sizeof (*netdev_stats)); +memcpy (stats64, netdev_stats,sizeof (*stats64));#else size_t i, n =sizeof (*stats64) /sizeof (u64);const unsigned long *src = (const unsigned long *)netdev_stats;
@@ -5851,6 +5851,7 @@ static void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64, dst[i] = src[i];#endif } +EXPORT_SYMBOL (netdev_stats_to_stats64);/** * dev_get_stats - get network device statistics
Re: [PATCH net-next] net: export netdev_stats_to_stats64
Quoted 5 lines · Eric Dumazet
Some drivers use internal netdev stats member to store part of their stats, yet advertize
ndo_get_stats64()to implement some 64bit fields.Allow them to use
netdev_stats_to_stats64()helper to make the copy of netdev stats before they compute their 64bit counters.
Oh well, I forgot the include file in the commit, I'll send a v2
PATCH v2 1/1 net: export netdev_stats_to_stats64
In reply to Eric DumazetSome drivers use internal netdev stats member to store part of their stats, yet advertize ndo_get_stats64() to implement some 64bit fields.
Allow them to use netdev_stats_to_stats64() helper to make the copy of netdev stats before they compute their 64bit counters.
---
V2: added the include bit as well, sorry guys.
include/linux/netdevice.h | 2 ++ net/core/dev.c | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-)
include/linux/netdevice.h +2 -0
@@ -2557,6 +2557,8 @@ extern void dev_load(struct net *net, const char *name);extern void dev_mcast_init (void );extern struct rtnl_link_stats64 *dev_get_stats (struct net_device *dev,struct rtnl_link_stats64 *storage); +extern void netdev_stats_to_stats64 (struct rtnl_link_stats64 *stats64, +const struct net_device_stats *netdev_stats);extern int netdev_max_backlog;extern int netdev_tstamp_prequeue;
net/core/dev.c +5 -4
@@ -5834,12 +5834,12 @@ void netdev_run_todo(void)/* Convert net_device_stats to rtnl_link_stats64. They have the same * fields in the same order, with only the type differing. */ -static void netdev_stats_to_stats64 (struct rtnl_link_stats64 *stats64, -const struct net_device_stats *netdev_stats) +void netdev_stats_to_stats64 (struct rtnl_link_stats64 *stats64, +const struct net_device_stats *netdev_stats) {#if BITS_PER_LONG ==64 -BUILD_BUG_ON (sizeof (*stats64) !=sizeof (*netdev_stats)); -memcpy (stats64, netdev_stats,sizeof (*stats64)); +BUILD_BUG_ON (sizeof (*stats64) !=sizeof (*netdev_stats)); +memcpy (stats64, netdev_stats,sizeof (*stats64));#else size_t i, n =sizeof (*stats64) /sizeof (u64);const unsigned long *src = (const unsigned long *)netdev_stats;
@@ -5851,6 +5851,7 @@ static void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64, dst[i] = src[i];#endif } +EXPORT_SYMBOL (netdev_stats_to_stats64);/** * dev_get_stats - get network device statistics
Re: [PATCH net-next v2] net: export netdev_stats_to_stats64
From: Eric Dumazet <[email protected]>
Date: Mon, 05 Mar 2012 06:50:09 -0800
Quoted 7 lines
Some drivers use internal netdev stats member to store part of their stats, yet advertize
ndo_get_stats64()to implement some 64bit fields.Allow them to use
netdev_stats_to_stats64()helper to make the copy of netdev stats before they compute their 64bit counters.Signed-off-by Eric Dumazet <[email protected]>
Applied, thanks Eric.
Re: [PATCH net-next] net: export netdev_stats_to_stats64
In reply to Eric DumazetQuoted 7 lines
Some drivers use internal netdev stats member to store part of their stats, yet advertize
ndo_get_stats64()to implement some 64bit fields.Allow them to use
netdev_stats_to_stats64()helper to make the copy of netdev stats before they compute their 64bit counters.Signed-off-by Eric Dumazet <[email protected]>
Hi Eric,
And I think we can add a netdev_stats_add_to_stats64() helper to avoid following duplicate code. Is that acceptable? Thanks.
drivers/net/bonding/bond_main.c
stats->rx_packets += sstats->rx_packets;
stats->rx_bytes += sstats->rx_bytes;
stats->rx_errors += sstats->rx_errors;
stats->rx_dropped += sstats->rx_dropped;
stats->tx_packets += sstats->tx_packets;
stats->tx_bytes += sstats->tx_bytes;
stats->tx_errors += sstats->tx_errors;
stats->tx_dropped += sstats->tx_dropped;
stats->multicast += sstats->multicast;
stats->collisions += sstats->collisions;
stats->rx_length_errors += sstats->rx_length_errors;
stats->rx_over_errors += sstats->rx_over_errors;
stats->rx_crc_errors += sstats->rx_crc_errors;
stats->rx_frame_errors += sstats->rx_frame_errors;
stats->rx_fifo_errors += sstats->rx_fifo_errors;
stats->rx_missed_errors += sstats->rx_missed_errors;
stats->tx_aborted_errors += sstats->tx_aborted_errors;
stats->tx_carrier_errors += sstats->tx_carrier_errors;
stats->tx_fifo_errors += sstats->tx_fifo_errors;
stats->tx_heartbeat_errors += sstats->tx_heartbeat_errors;
stats->tx_window_errors += sstats->tx_window_errors;Signature · 1 line
--Junchang
Re: [PATCH net-next] net: export netdev_stats_to_stats64
Quoted 30 lines · Junchang Wang
Quoted 7 lines
Some drivers use internal netdev stats member to store part of their stats, yet advertize
ndo_get_stats64()to implement some 64bit fields.Allow them to use
netdev_stats_to_stats64()helper to make the copy of netdev stats before they compute their 64bit counters.Signed-off-by Eric Dumazet <[email protected]>Hi Eric,
And I think we can add anetdev_stats_add_to_stats64()helper to avoid following duplicate code. Is that acceptable? Thanks.
drivers/net/bonding/bond_main.cstats->rx_packets += sstats->rx_packets; stats->rx_bytes += sstats->rx_bytes; stats->rx_errors += sstats->rx_errors; stats->rx_dropped += sstats->rx_dropped; stats->tx_packets += sstats->tx_packets; stats->tx_bytes += sstats->tx_bytes; stats->tx_errors += sstats->tx_errors; stats->tx_dropped += sstats->tx_dropped; stats->multicast += sstats->multicast; stats->collisions += sstats->collisions; stats->rx_length_errors += sstats->rx_length_errors; stats->rx_over_errors += sstats->rx_over_errors; stats->rx_crc_errors += sstats->rx_crc_errors; stats->rx_frame_errors += sstats->rx_frame_errors;
Quoted 9 lines
stats->rx_fifo_errors += sstats->rx_fifo_errors;
stats->rx_missed_errors += sstats->rx_missed_errors;
stats->tx_aborted_errors += sstats->tx_aborted_errors;
stats->tx_carrier_errors += sstats->tx_carrier_errors;
stats->tx_fifo_errors += sstats->tx_fifo_errors;
stats->tx_heartbeat_errors += sstats->tx_heartbeat_errors;
stats->tx_window_errors += sstats->tx_window_errors;Yep, I was currently preparing these patches :)
Re: [PATCH net-next] net: export netdev_stats_to_stats64
In reply to Junchang WangQuoted 6 lines · Junchang Wang
Quoted 6 lines
Some drivers use internal netdev stats member to store part of their stats, yet advertize
ndo_get_stats64()to implement some 64bit fields.Allow them to use
netdev_stats_to_stats64()helper to make the copy of netdev stats before they compute their 64bit counters.
Quoted 8 lines
Quoted 1 line
Signed-off-by Eric Dumazet <[email protected]>Hi Eric,
And I think we can add anetdev_stats_add_to_stats64()helper to avoid following duplicate code. Is that acceptable? Thanks.
drivers/net/bonding/bond_main.cstats->rx_packets += sstats->rx_packets;
Oops, I misread your mail, I was preparing other stuff, not an add() helper. I dont think it would be that usefull (only bond AFAIK)
Re: [PATCH net-next] net: export netdev_stats_to_stats64
Quoted 4 lines
Oops, I misread your mail, I was preparing other stuff, not an
add()helper. I dont think it would be that usefull (only bond AFAIK)
Oh. Yes, it seems only bond benefits from this helper. I won't submit it.
Thanks.
--Junchang
Quoted 3 lines
Maybe its time to export
netdev_stats_to_stats64()after all, to avoid all this duplicate code.
Yes, I noticed this duplicate code in both 8139too.c and r8169.c, and netdev_stats_to_stats64 was not exported.
Quoted 6 lines
I'll submit a patch.
Could you repost this after
netdev_stats_to_stats64()being available to drivers ?
Sure, I'll resubmit it based on your patch. Thanks.
--Junchang
Switch to use ndo_get_stats64 to get 64bit statistics. Two sync entries are used (one for Rx and one for Tx).
---
V2: based on Eric's patch "net: export netdev_stats_to_stats64"
drivers/net/ethernet/realtek/8139too.c | 46 ++++++++++++++++++++++++++----- 1 files changed, 38 insertions(+), 8 deletions(-)
drivers/net/ethernet/realtek/8139too.c +38 -8
@@ -565,6 +565,12 @@ struct rtl_extra_stats {unsigned long rx_lost_in_ring; }; +struct rtl8139_stats { +u64 packets; +u64 bytes; +struct u64_stats_sync syncp; +}; +struct rtl8139_private {void __iomem *mmio_addr;int drv_flags;
@@ -575,11 +581,13 @@ struct rtl8139_private {unsigned char *rx_ring;unsigned int cur_rx;/* RX buf index of next pkt */ +struct rtl8139_stats rx_stats;dma_addr_t rx_ring_dma;unsigned int tx_flag;unsigned long cur_tx;unsigned long dirty_tx; +struct rtl8139_stats tx_stats;unsigned char *tx_buf[NUM_TX_DESC ];/* Tx bounce buffers */ unsigned char *tx_bufs;/* Tx bounce buffer region. */ dma_addr_t tx_bufs_dma;
@@ -641,7 +649,9 @@ static int rtl8139_poll(struct napi_struct *napi, int budget);static irqreturn_t rtl8139_interrupt (int irq,void *dev_instance);static int rtl8139_close (struct net_device *dev);static int netdev_ioctl (struct net_device *dev,struct ifreq *rq,int cmd); -static struct net_device_stats *rtl8139_get_stats (struct net_device *dev); +static struct rtnl_link_stats64 *rtl8139_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 + *stats);static void rtl8139_set_rx_mode (struct net_device *dev);static void __set_rx_mode (struct net_device *dev);static void rtl8139_hw_start (struct net_device *dev);
@@ -937,7 +947,7 @@ static int rtl8139_set_features(struct net_device *dev, netdev_features_t featurstatic const struct net_device_ops rtl8139_netdev_ops = { .ndo_open = rtl8139_open, .ndo_stop = rtl8139_close, - .ndo_get_stats = rtl8139_get_stats, + .ndo_get_stats64 = rtl8139_get_stats64, .ndo_change_mtu = eth_change_mtu, .ndo_validate_addr = eth_validate_addr, .ndo_set_mac_address = rtl8139_set_mac_address,
@@ -1807,8 +1817,10 @@ static void rtl8139_tx_interrupt (struct net_device *dev, dev->stats.tx_fifo_errors++; } dev->stats.collisions += (txstatus >>24 ) &15 ; - dev->stats.tx_bytes += txstatus &0x7ff ; - dev->stats.tx_packets++; +u64_stats_update_begin (&tp->tx_stats.syncp); + tp->tx_stats.packets++; + tp->tx_stats.bytes += txstatus &0x7ff ; +u64_stats_update_end (&tp->tx_stats.syncp); } dirty_tx++;
@@ -2050,8 +2062,10 @@ keep_pkt: skb->protocol =eth_type_trans (skb, dev); - dev->stats.rx_bytes += pkt_size; - dev->stats.rx_packets++; +u64_stats_update_begin (&tp->rx_stats.syncp); + tp->rx_stats.packets++; + tp->rx_stats.bytes += pkt_size; +u64_stats_update_end (&tp->rx_stats.syncp);netif_receive_skb (skb); }else {
@@ -2515,11 +2529,13 @@ static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) } -static struct net_device_stats *rtl8139_get_stats (struct net_device *dev) +static struct rtnl_link_stats64 * +rtl8139_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats) {struct rtl8139_private *tp =netdev_priv (dev);void __iomem *ioaddr = tp->mmio_addr;unsigned long flags; +unsigned int start;if (netif_running (dev)) {spin_lock_irqsave (&tp->lock, flags);
@@ -2528,7 +2544,21 @@ static struct net_device_stats *rtl8139_get_stats (struct net_device *dev)spin_unlock_irqrestore (&tp->lock, flags); } -return &dev->stats; +netdev_stats_to_stats64 (stats, &dev->stats); + +do { + start =u64_stats_fetch_begin_bh (&tp->rx_stats.syncp); + stats->rx_packets = tp->rx_stats.packets; + stats->rx_bytes = tp->rx_stats.bytes; + }while (u64_stats_fetch_retry_bh (&tp->rx_stats.syncp, start)); + +do { + start =u64_stats_fetch_begin_bh (&tp->tx_stats.syncp); + stats->tx_packets = tp->tx_stats.packets; + stats->tx_bytes = tp->tx_stats.bytes; + }while (u64_stats_fetch_retry_bh (&tp->tx_stats.syncp, start)); + +return stats; }/* Set or clear the multicast filter for this adaptor.
--
From: Junchang Wang <[email protected]>
Date: Tue, 6 Mar 2012 11:13:05 +0800
Quoted 5 lines
Switch to use
ndo_get_stats64to get 64bit statistics. Two sync entries are used (one for Rx and one for Tx).Signed-off-by Junchang Wang <[email protected]>
Applied, thanks.