diff mbox series

[05/47] backports: Add dev_sw_netstats_rx_add() and dev_sw_netstats_tx_add()

Message ID 20211019214320.2035704-6-hauke@hauke-m.de (mailing list archive)
State New, archived
Headers show
Series backports: Update to kernel 5.15-rc6 | expand

Commit Message

Hauke Mehrtens Oct. 19, 2021, 9:42 p.m. UTC
Copy dev_sw_netstats_rx_add() and dev_sw_netstats_tx_add() from the
upstream kernel.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
---
 backport/backport-include/linux/netdevice.h | 28 +++++++++++++++++++++
 1 file changed, 28 insertions(+)
diff mbox series

Patch

diff --git a/backport/backport-include/linux/netdevice.h b/backport/backport-include/linux/netdevice.h
index d854faef..5c30426d 100644
--- a/backport/backport-include/linux/netdevice.h
+++ b/backport/backport-include/linux/netdevice.h
@@ -113,6 +113,34 @@  void dev_fetch_sw_netstats(struct rtnl_link_stats64 *s,
 int netif_rx_any_context(struct sk_buff *skb);
 #endif /* < 5.10 */
 
+#if LINUX_VERSION_IS_LESS(5,10,0)
+#define dev_sw_netstats_rx_add LINUX_BACKPORT(dev_sw_netstats_rx_add)
+static inline void dev_sw_netstats_rx_add(struct net_device *dev, unsigned int len)
+{
+	struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
+
+	u64_stats_update_begin(&tstats->syncp);
+	tstats->rx_bytes += len;
+	tstats->rx_packets++;
+	u64_stats_update_end(&tstats->syncp);
+}
+#endif /* < 5.10 */
+
+#if LINUX_VERSION_IS_LESS(5,11,0)
+#define dev_sw_netstats_tx_add LINUX_BACKPORT(dev_sw_netstats_tx_add)
+static inline void dev_sw_netstats_tx_add(struct net_device *dev,
+					  unsigned int packets,
+					  unsigned int len)
+{
+	struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
+
+	u64_stats_update_begin(&tstats->syncp);
+	tstats->tx_bytes += len;
+	tstats->tx_packets += packets;
+	u64_stats_update_end(&tstats->syncp);
+}
+#endif /* < 5.11 */
+
 #if LINUX_VERSION_IS_LESS(5,11,0)
 #define dev_get_tstats64 LINUX_BACKPORT(dev_get_tstats64)
 void dev_get_tstats64(struct net_device *dev, struct rtnl_link_stats64 *s);