diff mbox series

[v4,net-next,1/7] net: mvneta: introduce mvneta_update_stats routine

Message ID e8888c37e1c397801e3aa8485ce4103811f6a655.1571258792.git.lorenzo@kernel.org
State Changes Requested
Delegated to: David Miller
Headers show
Series add XDP support to mvneta driver | expand

Commit Message

Lorenzo Bianconi Oct. 16, 2019, 9:03 p.m. UTC
Introduce mvneta_update_stats routine to collect {rx/tx} statistics
(packets and bytes). This is a preliminary patch to add XDP support to
mvneta driver

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/net/ethernet/marvell/mvneta.c | 41 +++++++++++++--------------
 1 file changed, 20 insertions(+), 21 deletions(-)

Comments

Jakub Kicinski Oct. 17, 2019, 1:01 a.m. UTC | #1
On Wed, 16 Oct 2019 23:03:06 +0200, Lorenzo Bianconi wrote:
> Introduce mvneta_update_stats routine to collect {rx/tx} statistics
> (packets and bytes). This is a preliminary patch to add XDP support to
> mvneta driver
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
>  drivers/net/ethernet/marvell/mvneta.c | 41 +++++++++++++--------------
>  1 file changed, 20 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c
> index e49820675c8c..128b9fded959 100644
> --- a/drivers/net/ethernet/marvell/mvneta.c
> +++ b/drivers/net/ethernet/marvell/mvneta.c
> @@ -1900,6 +1900,23 @@ static void mvneta_rxq_drop_pkts(struct mvneta_port *pp,
>  	}
>  }
>  
> +static void
> +mvneta_update_stats(struct mvneta_port *pp, u32 pkts,
> +		    u32 len, bool tx)
> +{
> +	struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats);
> +
> +	u64_stats_update_begin(&stats->syncp);
> +	if (tx) {
> +		stats->tx_packets += pkts;
> +		stats->tx_bytes += len;
> +	} else {
> +		stats->rx_packets += pkts;
> +		stats->rx_bytes += len;
> +	}
> +	u64_stats_update_end(&stats->syncp);
> +}
> +
>  static inline
>  int mvneta_rx_refill_queue(struct mvneta_port *pp, struct mvneta_rx_queue *rxq)
>  {
> @@ -2075,14 +2092,7 @@ static int mvneta_rx_swbm(struct napi_struct *napi,
>  		rxq->left_size = 0;
>  	}
>  
> -	if (rcvd_pkts) {

nit: you're getting rid of this check in the new helper, perhaps worth
     mentioning in the commit message why its irrelevant

> -		struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats);
> -
> -		u64_stats_update_begin(&stats->syncp);
> -		stats->rx_packets += rcvd_pkts;
> -		stats->rx_bytes   += rcvd_bytes;
> -		u64_stats_update_end(&stats->syncp);
> -	}
> +	mvneta_update_stats(pp, rcvd_pkts, rcvd_bytes, false);
>  
>  	/* return some buffers to hardware queue, one at a time is too slow */
>  	refill = mvneta_rx_refill_queue(pp, rxq);
diff mbox series

Patch

diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c
index e49820675c8c..128b9fded959 100644
--- a/drivers/net/ethernet/marvell/mvneta.c
+++ b/drivers/net/ethernet/marvell/mvneta.c
@@ -1900,6 +1900,23 @@  static void mvneta_rxq_drop_pkts(struct mvneta_port *pp,
 	}
 }
 
+static void
+mvneta_update_stats(struct mvneta_port *pp, u32 pkts,
+		    u32 len, bool tx)
+{
+	struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats);
+
+	u64_stats_update_begin(&stats->syncp);
+	if (tx) {
+		stats->tx_packets += pkts;
+		stats->tx_bytes += len;
+	} else {
+		stats->rx_packets += pkts;
+		stats->rx_bytes += len;
+	}
+	u64_stats_update_end(&stats->syncp);
+}
+
 static inline
 int mvneta_rx_refill_queue(struct mvneta_port *pp, struct mvneta_rx_queue *rxq)
 {
@@ -2075,14 +2092,7 @@  static int mvneta_rx_swbm(struct napi_struct *napi,
 		rxq->left_size = 0;
 	}
 
-	if (rcvd_pkts) {
-		struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats);
-
-		u64_stats_update_begin(&stats->syncp);
-		stats->rx_packets += rcvd_pkts;
-		stats->rx_bytes   += rcvd_bytes;
-		u64_stats_update_end(&stats->syncp);
-	}
+	mvneta_update_stats(pp, rcvd_pkts, rcvd_bytes, false);
 
 	/* return some buffers to hardware queue, one at a time is too slow */
 	refill = mvneta_rx_refill_queue(pp, rxq);
@@ -2206,14 +2216,7 @@  static int mvneta_rx_hwbm(struct napi_struct *napi,
 		napi_gro_receive(napi, skb);
 	}
 
-	if (rcvd_pkts) {
-		struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats);
-
-		u64_stats_update_begin(&stats->syncp);
-		stats->rx_packets += rcvd_pkts;
-		stats->rx_bytes   += rcvd_bytes;
-		u64_stats_update_end(&stats->syncp);
-	}
+	mvneta_update_stats(pp, rcvd_pkts, rcvd_bytes, false);
 
 	/* Update rxq management counters */
 	mvneta_rxq_desc_num_update(pp, rxq, rx_done, rx_done);
@@ -2459,7 +2462,6 @@  static netdev_tx_t mvneta_tx(struct sk_buff *skb, struct net_device *dev)
 
 out:
 	if (frags > 0) {
-		struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats);
 		struct netdev_queue *nq = netdev_get_tx_queue(dev, txq_id);
 
 		netdev_tx_sent_queue(nq, len);
@@ -2474,10 +2476,7 @@  static netdev_tx_t mvneta_tx(struct sk_buff *skb, struct net_device *dev)
 		else
 			txq->pending += frags;
 
-		u64_stats_update_begin(&stats->syncp);
-		stats->tx_packets++;
-		stats->tx_bytes  += len;
-		u64_stats_update_end(&stats->syncp);
+		mvneta_update_stats(pp, 1, len, true);
 	} else {
 		dev->stats.tx_dropped++;
 		dev_kfree_skb_any(skb);