diff options
author | Eric Dumazet <edumazet@google.com> | 2019-11-08 03:27:15 +0300 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2019-11-08 07:03:08 +0300 |
commit | dd5382a08157756510aa8d7269c662eccde775cb (patch) | |
tree | ab87e4101df24bc5d2bc30b4207cc4ce0a59c1c0 /include | |
parent | de7d5084d82794a8e83afb994fcb07f82da3cd7b (diff) | |
download | linux-dd5382a08157756510aa8d7269c662eccde775cb.tar.xz |
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>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/netdevice.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 75561992c31f..461a36220cf4 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2403,6 +2403,16 @@ struct pcpu_lstats { 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) \ ({ \ typeof(type) __percpu *pcpu_stats = alloc_percpu_gfp(type, gfp);\ |