diff options
author | Hauke Mehrtens <hauke@hauke-m.de> | 2020-11-08 17:15:41 +0100 |
---|---|---|
committer | Hauke Mehrtens <hauke@hauke-m.de> | 2020-12-05 21:24:57 +0100 |
commit | 5023d8e2f8e22bb41c5b8c5c92f9457c47f3bce5 (patch) | |
tree | ebad19a06cf1740d8ccad7fdf7b07a641b535f74 | |
parent | c9b7156421cae96cda5b6a2c4a1dfd57b5db780e (diff) | |
download | backports-5023d8e2f8e22bb41c5b8c5c92f9457c47f3bce5.tar.gz |
backports: Add dev_fetch_sw_netstats()
Add the dev_fetch_sw_netstats which was added in commit 44fa32f008ab
("net: add function dev_fetch_sw_netstats for fetching
pcpu_sw_netstats") in kernel 5.10. This is used by qmi_wwan, usbnet,
qtnfmac and mac80211.
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
-rw-r--r-- | backport/backport-include/linux/netdevice.h | 4 | ||||
-rw-r--r-- | backport/compat/backport-5.10.c | 34 |
2 files changed, 38 insertions, 0 deletions
diff --git a/backport/backport-include/linux/netdevice.h b/backport/backport-include/linux/netdevice.h index 411757d2..ed691961 100644 --- a/backport/backport-include/linux/netdevice.h +++ b/backport/backport-include/linux/netdevice.h @@ -401,6 +401,10 @@ static inline bool netif_is_bridge_port(const struct net_device *dev) #endif #if LINUX_VERSION_IS_LESS(5,10,0) +#define dev_fetch_sw_netstats LINUX_BACKPORT(dev_fetch_sw_netstats) +void dev_fetch_sw_netstats(struct rtnl_link_stats64 *s, + const struct pcpu_sw_netstats __percpu *netstats); + #define netif_rx_any_context LINUX_BACKPORT(netif_rx_any_context) int netif_rx_any_context(struct sk_buff *skb); #endif /* < 5.10 */ diff --git a/backport/compat/backport-5.10.c b/backport/compat/backport-5.10.c index a83907f4..141862da 100644 --- a/backport/compat/backport-5.10.c +++ b/backport/compat/backport-5.10.c @@ -4,6 +4,40 @@ #include <linux/kernel.h> #include <linux/netdevice.h> +/** + * dev_fetch_sw_netstats - get per-cpu network device statistics + * @s: place to store stats + * @netstats: per-cpu network stats to read from + * + * Read per-cpu network statistics and populate the related fields in @s. + */ +void dev_fetch_sw_netstats(struct rtnl_link_stats64 *s, + const struct pcpu_sw_netstats __percpu *netstats) +{ + int cpu; + + for_each_possible_cpu(cpu) { + const struct pcpu_sw_netstats *stats; + struct pcpu_sw_netstats tmp; + unsigned int start; + + stats = per_cpu_ptr(netstats, cpu); + do { + start = u64_stats_fetch_begin_irq(&stats->syncp); + tmp.rx_packets = stats->rx_packets; + tmp.rx_bytes = stats->rx_bytes; + tmp.tx_packets = stats->tx_packets; + tmp.tx_bytes = stats->tx_bytes; + } while (u64_stats_fetch_retry_irq(&stats->syncp, start)); + + s->rx_packets += tmp.rx_packets; + s->rx_bytes += tmp.rx_bytes; + s->tx_packets += tmp.tx_packets; + s->tx_bytes += tmp.tx_bytes; + } +} +EXPORT_SYMBOL_GPL(dev_fetch_sw_netstats); + int netif_rx_any_context(struct sk_buff *skb) { /* |