Skip to content

Commit dd5382a

Browse files
edumazetdavem330
authored andcommitted
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: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent de7d508 commit dd5382a

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

‎drivers/net/loopback.c‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ EXPORT_SYMBOL(blackhole_netdev);
6868
static netdev_tx_t loopback_xmit(struct sk_buff *skb,
6969
struct net_device *dev)
7070
{
71-
struct pcpu_lstats *lb_stats;
7271
int len;
7372

7473
skb_tx_timestamp(skb);
@@ -85,16 +84,9 @@ static netdev_tx_t loopback_xmit(struct sk_buff *skb,
8584

8685
skb->protocol = eth_type_trans(skb, dev);
8786

88-
/* it's OK to use per_cpu_ptr() because BHs are off */
89-
lb_stats = this_cpu_ptr(dev->lstats);
90-
9187
len = skb->len;
92-
if (likely(netif_rx(skb) == NET_RX_SUCCESS)) {
93-
u64_stats_update_begin(&lb_stats->syncp);
94-
lb_stats->bytes += len;
95-
lb_stats->packets++;
96-
u64_stats_update_end(&lb_stats->syncp);
97-
}
88+
if (likely(netif_rx(skb) == NET_RX_SUCCESS))
89+
dev_lstats_add(dev, len);
9890

9991
return NETDEV_TX_OK;
10092
}

‎include/linux/netdevice.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,6 +2403,16 @@ struct pcpu_lstats {
24032403

24042404
void dev_lstats_read(struct net_device *dev, u64 *packets, u64 *bytes);
24052405

2406+
static inline void dev_lstats_add(struct net_device *dev, unsigned int len)
2407+
{
2408+
struct pcpu_lstats *lstats = this_cpu_ptr(dev->lstats);
2409+
2410+
u64_stats_update_begin(&lstats->syncp);
2411+
lstats->bytes += len;
2412+
lstats->packets++;
2413+
u64_stats_update_end(&lstats->syncp);
2414+
}
2415+
24062416
#define __netdev_alloc_pcpu_stats(type, gfp) \
24072417
({ \
24082418
typeof(type) __percpu *pcpu_stats = alloc_percpu_gfp(type, gfp);\

0 commit comments

Comments
 (0)