Commit 6b10de38 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

loopback: Implement 64bit stats on 32bit arches

Uses a seqcount_t to synchronize stat producer and consumer, for packets
and bytes counter, now u64 types.

(dropped counter being rarely used, stay a native "unsigned long" type)

No noticeable performance impact on x86, as it only adds two increments
per frame. It might be more expensive on arches where smp_wmb() is not
free.
Signed-off-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c68f24cc
...@@ -60,11 +60,51 @@ ...@@ -60,11 +60,51 @@
#include <net/net_namespace.h> #include <net/net_namespace.h>
struct pcpu_lstats { struct pcpu_lstats {
unsigned long packets; u64 packets;
unsigned long bytes; u64 bytes;
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
seqcount_t seq;
#endif
unsigned long drops; unsigned long drops;
}; };
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
static void inline lstats_update_begin(struct pcpu_lstats *lstats)
{
write_seqcount_begin(&lstats->seq);
}
static void inline lstats_update_end(struct pcpu_lstats *lstats)
{
write_seqcount_end(&lstats->seq);
}
static void inline lstats_fetch_and_add(u64 *packets, u64 *bytes, const struct pcpu_lstats *lstats)
{
u64 tpackets, tbytes;
unsigned int seq;
do {
seq = read_seqcount_begin(&lstats->seq);
tpackets = lstats->packets;
tbytes = lstats->bytes;
} while (read_seqcount_retry(&lstats->seq, seq));
*packets += tpackets;
*bytes += tbytes;
}
#else
static void inline lstats_update_begin(struct pcpu_lstats *lstats)
{
}
static void inline lstats_update_end(struct pcpu_lstats *lstats)
{
}
static void inline lstats_fetch_and_add(u64 *packets, u64 *bytes, const struct pcpu_lstats *lstats)
{
*packets += lstats->packets;
*bytes += lstats->bytes;
}
#endif
/* /*
* The higher levels take care of making this non-reentrant (it's * The higher levels take care of making this non-reentrant (it's
* called with bh's disabled). * called with bh's disabled).
...@@ -86,21 +126,23 @@ static netdev_tx_t loopback_xmit(struct sk_buff *skb, ...@@ -86,21 +126,23 @@ static netdev_tx_t loopback_xmit(struct sk_buff *skb,
len = skb->len; len = skb->len;
if (likely(netif_rx(skb) == NET_RX_SUCCESS)) { if (likely(netif_rx(skb) == NET_RX_SUCCESS)) {
lstats_update_begin(lb_stats);
lb_stats->bytes += len; lb_stats->bytes += len;
lb_stats->packets++; lb_stats->packets++;
lstats_update_end(lb_stats);
} else } else
lb_stats->drops++; lb_stats->drops++;
return NETDEV_TX_OK; return NETDEV_TX_OK;
} }
static struct net_device_stats *loopback_get_stats(struct net_device *dev) static struct rtnl_link_stats64 *loopback_get_stats64(struct net_device *dev)
{ {
const struct pcpu_lstats __percpu *pcpu_lstats; const struct pcpu_lstats __percpu *pcpu_lstats;
struct net_device_stats *stats = &dev->stats; struct rtnl_link_stats64 *stats = &dev->stats64;
unsigned long bytes = 0; u64 bytes = 0;
unsigned long packets = 0; u64 packets = 0;
unsigned long drops = 0; u64 drops = 0;
int i; int i;
pcpu_lstats = (void __percpu __force *)dev->ml_priv; pcpu_lstats = (void __percpu __force *)dev->ml_priv;
...@@ -108,8 +150,7 @@ static struct net_device_stats *loopback_get_stats(struct net_device *dev) ...@@ -108,8 +150,7 @@ static struct net_device_stats *loopback_get_stats(struct net_device *dev)
const struct pcpu_lstats *lb_stats; const struct pcpu_lstats *lb_stats;
lb_stats = per_cpu_ptr(pcpu_lstats, i); lb_stats = per_cpu_ptr(pcpu_lstats, i);
bytes += lb_stats->bytes; lstats_fetch_and_add(&packets, &bytes, lb_stats);
packets += lb_stats->packets;
drops += lb_stats->drops; drops += lb_stats->drops;
} }
stats->rx_packets = packets; stats->rx_packets = packets;
...@@ -158,7 +199,7 @@ static void loopback_dev_free(struct net_device *dev) ...@@ -158,7 +199,7 @@ static void loopback_dev_free(struct net_device *dev)
static const struct net_device_ops loopback_ops = { static const struct net_device_ops loopback_ops = {
.ndo_init = loopback_dev_init, .ndo_init = loopback_dev_init,
.ndo_start_xmit= loopback_xmit, .ndo_start_xmit= loopback_xmit,
.ndo_get_stats = loopback_get_stats, .ndo_get_stats64 = loopback_get_stats64,
}; };
/* /*
......
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