[PATCH net-next v3 3/4] net: add dev_dstats_rx_dropped_add() helper

Breno Leitao posted 4 patches 3 months, 3 weeks ago
There is a newer version of this series
[PATCH net-next v3 3/4] net: add dev_dstats_rx_dropped_add() helper
Posted by Breno Leitao 3 months, 3 weeks ago
Introduce the dev_dstats_rx_dropped_add() helper to allow incrementing
the rx_drops per-CPU statistic by an arbitrary value, rather than just
one. This is useful for drivers or code paths that need to account for
multiple dropped packets at once, such as when dropping entire queues.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 include/linux/netdevice.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 9cbc4e54b7e4a..03c26bb0fbbef 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -3016,6 +3016,16 @@ static inline void dev_dstats_rx_dropped(struct net_device *dev)
 	u64_stats_update_end(&dstats->syncp);
 }
 
+static inline void dev_dstats_rx_dropped_add(struct net_device *dev,
+					     unsigned int packets)
+{
+	struct pcpu_dstats *dstats = this_cpu_ptr(dev->dstats);
+
+	u64_stats_update_begin(&dstats->syncp);
+	u64_stats_add(&dstats->rx_drops, packets);
+	u64_stats_update_end(&dstats->syncp);
+}
+
 static inline void dev_dstats_tx_add(struct net_device *dev,
 				     unsigned int len)
 {

-- 
2.47.1
Re: [PATCH net-next v3 3/4] net: add dev_dstats_rx_dropped_add() helper
Posted by Joe Damato 3 months, 3 weeks ago
On Tue, Jun 17, 2025 at 01:18:59AM -0700, Breno Leitao wrote:
> Introduce the dev_dstats_rx_dropped_add() helper to allow incrementing
> the rx_drops per-CPU statistic by an arbitrary value, rather than just
> one. This is useful for drivers or code paths that need to account for
> multiple dropped packets at once, such as when dropping entire queues.
> 
> Signed-off-by: Breno Leitao <leitao@debian.org>
> ---
>  include/linux/netdevice.h | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>

Reviewed-by: Joe Damato <joe@dama.to>