Skip to contentSkip to conversation

net: netdevice.h: sw_netstats_rx_add helper

PATCH In review Fabian Frederick 2 participants 2 messages Oct 5, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/9 net: netdevice.h: sw_netstats_rx_add helper

some drivers/network protocols update rx bytes/packets under u64_stats_update_begin/end sequence.
Add a specific helper like dev_lstats_add()

---
 include/linux/netdevice.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
include/linux/netdevice.h +11 -0
index 0c79d9e56a5e5..42b18e034adde 100644
@@ -2530,6 +2530,17 @@ struct pcpu_lstats {
 
 void dev_lstats_read(struct net_device *dev, u64 *packets, u64 *bytes);
 
+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);
+
+}
+
 static inline void dev_lstats_add(struct net_device *dev, unsigned int len)
 {
 	struct pcpu_lstats *lstats = this_cpu_ptr(dev->lstats);
Signature · 1 line
2.28.0
maintainer
#1 lore raw

include/linux/netdevice.h struct pcpu_lstats { · line 2541

Quoted 9 lines · On Mon, 5 Oct 2020 22:34:18 +0200 Fabian Frederick wrote:
include/linux/netdevice.h +9 -0
+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);
+

checkpatch points out there is an unnecessary empty line here

Quoted 1 line

+}