From: Junchang Wang <junchangwang@gmail.com>
To: davem@davemloft.net, eric.dumazet@gmail.com,
greearb@candelatech.com, adobriyan@gmail.com,
jasowang@redhat.com, joe@perches.com
Cc: netdev@vger.kernel.org
Subject: [PATCH net-next] 8139too: Add 64bit statistics
Date: Mon, 5 Mar 2012 19:33:55 +0800 [thread overview]
Message-ID: <20120305113353.GA12969@Spy32> (raw)
Switch to use ndo_get_stats64 to get 64bit statistics.
Two sync entries are used (one for Rx and one for Tx).
Signed-off-by: Junchang Wang <junchangwang@gmail.com>
---
drivers/net/ethernet/realtek/8139too.c | 61 +++++++++++++++++++++++++++----
1 files changed, 53 insertions(+), 8 deletions(-)
diff --git a/drivers/net/ethernet/realtek/8139too.c b/drivers/net/ethernet/realtek/8139too.c
index abd6aca..a00d76b 100644
--- a/drivers/net/ethernet/realtek/8139too.c
+++ b/drivers/net/ethernet/realtek/8139too.c
@@ -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 featur
static 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
next reply other threads:[~2012-03-05 11:32 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-05 11:33 Junchang Wang [this message]
2012-03-05 13:32 ` [PATCH net-next] 8139too: Add 64bit statistics Eric Dumazet
2012-03-05 13:58 ` [PATCH net-next] net: export netdev_stats_to_stats64 Eric Dumazet
2012-03-05 14:20 ` Eric Dumazet
2012-03-05 14:50 ` [PATCH net-next v2] " Eric Dumazet
2012-03-05 20:40 ` David Miller
2012-03-06 4:38 ` [PATCH net-next] " Junchang Wang
2012-03-06 4:43 ` Eric Dumazet
2012-03-06 4:44 ` Eric Dumazet
2012-03-06 5:00 ` Junchang Wang
2012-03-05 14:07 ` [PATCH net-next] 8139too: Add 64bit statistics Junchang Wang
2012-03-06 3:13 ` [PATCH net-next V2] " Junchang Wang
2012-03-06 5:05 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120305113353.GA12969@Spy32 \
--to=junchangwang@gmail.com \
--cc=adobriyan@gmail.com \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=greearb@candelatech.com \
--cc=jasowang@redhat.com \
--cc=joe@perches.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.