Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: mvneta: introduce mvneta_update_stats routine

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>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Lorenzo Bianconi and committed by
David S. Miller
ff519e2a 13faf771

+22 -21
+22 -21
drivers/net/ethernet/marvell/mvneta.c
··· 1900 1900 } 1901 1901 } 1902 1902 1903 + static void 1904 + mvneta_update_stats(struct mvneta_port *pp, u32 pkts, 1905 + u32 len, bool tx) 1906 + { 1907 + struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats); 1908 + 1909 + u64_stats_update_begin(&stats->syncp); 1910 + if (tx) { 1911 + stats->tx_packets += pkts; 1912 + stats->tx_bytes += len; 1913 + } else { 1914 + stats->rx_packets += pkts; 1915 + stats->rx_bytes += len; 1916 + } 1917 + u64_stats_update_end(&stats->syncp); 1918 + } 1919 + 1903 1920 static inline 1904 1921 int mvneta_rx_refill_queue(struct mvneta_port *pp, struct mvneta_rx_queue *rxq) 1905 1922 { ··· 2092 2075 rxq->left_size = 0; 2093 2076 } 2094 2077 2095 - if (rcvd_pkts) { 2096 - struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats); 2097 - 2098 - u64_stats_update_begin(&stats->syncp); 2099 - stats->rx_packets += rcvd_pkts; 2100 - stats->rx_bytes += rcvd_bytes; 2101 - u64_stats_update_end(&stats->syncp); 2102 - } 2078 + if (rcvd_pkts) 2079 + mvneta_update_stats(pp, rcvd_pkts, rcvd_bytes, false); 2103 2080 2104 2081 /* return some buffers to hardware queue, one at a time is too slow */ 2105 2082 refill = mvneta_rx_refill_queue(pp, rxq); ··· 2217 2206 napi_gro_receive(napi, skb); 2218 2207 } 2219 2208 2220 - if (rcvd_pkts) { 2221 - struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats); 2222 - 2223 - u64_stats_update_begin(&stats->syncp); 2224 - stats->rx_packets += rcvd_pkts; 2225 - stats->rx_bytes += rcvd_bytes; 2226 - u64_stats_update_end(&stats->syncp); 2227 - } 2209 + if (rcvd_pkts) 2210 + mvneta_update_stats(pp, rcvd_pkts, rcvd_bytes, false); 2228 2211 2229 2212 /* Update rxq management counters */ 2230 2213 mvneta_rxq_desc_num_update(pp, rxq, rx_done, rx_done); ··· 2464 2459 2465 2460 out: 2466 2461 if (frags > 0) { 2467 - struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats); 2468 2462 struct netdev_queue *nq = netdev_get_tx_queue(dev, txq_id); 2469 2463 2470 2464 netdev_tx_sent_queue(nq, len); ··· 2478 2474 else 2479 2475 txq->pending += frags; 2480 2476 2481 - u64_stats_update_begin(&stats->syncp); 2482 - stats->tx_packets++; 2483 - stats->tx_bytes += len; 2484 - u64_stats_update_end(&stats->syncp); 2477 + mvneta_update_stats(pp, 1, len, true); 2485 2478 } else { 2486 2479 dev->stats.tx_dropped++; 2487 2480 dev_kfree_skb_any(skb);