提交 dd5382a0 编写于 作者: E Eric Dumazet 提交者: David S. Miller

net: provide dev_lstats_add() helper

Many network drivers need it and hand-coded the same function.

In order to ease u64_stats_t adoption, it is time to factorize.
Signed-off-by: NEric Dumazet <edumazet@google.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 de7d5084
...@@ -68,7 +68,6 @@ EXPORT_SYMBOL(blackhole_netdev); ...@@ -68,7 +68,6 @@ EXPORT_SYMBOL(blackhole_netdev);
static netdev_tx_t loopback_xmit(struct sk_buff *skb, static netdev_tx_t loopback_xmit(struct sk_buff *skb,
struct net_device *dev) struct net_device *dev)
{ {
struct pcpu_lstats *lb_stats;
int len; int len;
skb_tx_timestamp(skb); skb_tx_timestamp(skb);
...@@ -85,16 +84,9 @@ static netdev_tx_t loopback_xmit(struct sk_buff *skb, ...@@ -85,16 +84,9 @@ static netdev_tx_t loopback_xmit(struct sk_buff *skb,
skb->protocol = eth_type_trans(skb, dev); skb->protocol = eth_type_trans(skb, dev);
/* it's OK to use per_cpu_ptr() because BHs are off */
lb_stats = this_cpu_ptr(dev->lstats);
len = skb->len; len = skb->len;
if (likely(netif_rx(skb) == NET_RX_SUCCESS)) { if (likely(netif_rx(skb) == NET_RX_SUCCESS))
u64_stats_update_begin(&lb_stats->syncp); dev_lstats_add(dev, len);
lb_stats->bytes += len;
lb_stats->packets++;
u64_stats_update_end(&lb_stats->syncp);
}
return NETDEV_TX_OK; return NETDEV_TX_OK;
} }
......
...@@ -2403,6 +2403,16 @@ struct pcpu_lstats { ...@@ -2403,6 +2403,16 @@ struct pcpu_lstats {
void dev_lstats_read(struct net_device *dev, u64 *packets, u64 *bytes); void dev_lstats_read(struct net_device *dev, u64 *packets, u64 *bytes);
static inline void dev_lstats_add(struct net_device *dev, unsigned int len)
{
struct pcpu_lstats *lstats = this_cpu_ptr(dev->lstats);
u64_stats_update_begin(&lstats->syncp);
lstats->bytes += len;
lstats->packets++;
u64_stats_update_end(&lstats->syncp);
}
#define __netdev_alloc_pcpu_stats(type, gfp) \ #define __netdev_alloc_pcpu_stats(type, gfp) \
({ \ ({ \
typeof(type) __percpu *pcpu_stats = alloc_percpu_gfp(type, gfp);\ typeof(type) __percpu *pcpu_stats = alloc_percpu_gfp(type, gfp);\
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册