Commit 4a43b1f9 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

net: dummy: use standard dev_lstats_add() and dev_lstats_read()

This driver can simply use the common infrastructure instead
of duplicating it.

This cleanup will ease u64_stats_t adoption in a single location.
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4f77eb09
...@@ -51,41 +51,15 @@ static void set_multicast_list(struct net_device *dev) ...@@ -51,41 +51,15 @@ static void set_multicast_list(struct net_device *dev)
{ {
} }
struct pcpu_dstats {
u64 tx_packets;
u64 tx_bytes;
struct u64_stats_sync syncp;
};
static void dummy_get_stats64(struct net_device *dev, static void dummy_get_stats64(struct net_device *dev,
struct rtnl_link_stats64 *stats) struct rtnl_link_stats64 *stats)
{ {
int i; dev_lstats_read(dev, &stats->tx_packets, &stats->tx_bytes);
for_each_possible_cpu(i) {
const struct pcpu_dstats *dstats;
u64 tbytes, tpackets;
unsigned int start;
dstats = per_cpu_ptr(dev->dstats, i);
do {
start = u64_stats_fetch_begin_irq(&dstats->syncp);
tbytes = dstats->tx_bytes;
tpackets = dstats->tx_packets;
} while (u64_stats_fetch_retry_irq(&dstats->syncp, start));
stats->tx_bytes += tbytes;
stats->tx_packets += tpackets;
}
} }
static netdev_tx_t dummy_xmit(struct sk_buff *skb, struct net_device *dev) static netdev_tx_t dummy_xmit(struct sk_buff *skb, struct net_device *dev)
{ {
struct pcpu_dstats *dstats = this_cpu_ptr(dev->dstats); dev_lstats_add(dev, skb->len);
u64_stats_update_begin(&dstats->syncp);
dstats->tx_packets++;
dstats->tx_bytes += skb->len;
u64_stats_update_end(&dstats->syncp);
skb_tx_timestamp(skb); skb_tx_timestamp(skb);
dev_kfree_skb(skb); dev_kfree_skb(skb);
...@@ -94,8 +68,8 @@ static netdev_tx_t dummy_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -94,8 +68,8 @@ static netdev_tx_t dummy_xmit(struct sk_buff *skb, struct net_device *dev)
static int dummy_dev_init(struct net_device *dev) static int dummy_dev_init(struct net_device *dev)
{ {
dev->dstats = netdev_alloc_pcpu_stats(struct pcpu_dstats); dev->lstats = netdev_alloc_pcpu_stats(struct pcpu_lstats);
if (!dev->dstats) if (!dev->lstats)
return -ENOMEM; return -ENOMEM;
return 0; return 0;
...@@ -103,7 +77,7 @@ static int dummy_dev_init(struct net_device *dev) ...@@ -103,7 +77,7 @@ static int dummy_dev_init(struct net_device *dev)
static void dummy_dev_uninit(struct net_device *dev) static void dummy_dev_uninit(struct net_device *dev)
{ {
free_percpu(dev->dstats); free_percpu(dev->lstats);
} }
static int dummy_change_carrier(struct net_device *dev, bool new_carrier) static int dummy_change_carrier(struct net_device *dev, bool new_carrier)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment