Skip to content

Commit c35947b

Browse files
LorenzoBianconidavem330
authored andcommitted
net: mvneta: move rx_dropped and rx_errors in per-cpu stats
Move rx_dropped and rx_errors counters in mvneta_pcpu_stats in order to avoid possible races updating statistics Fixes: 562e2f4 ("net: mvneta: Improve the buffer allocation method for SWBM") Fixes: dc35a10 ("net: mvneta: bm: add support for hardware buffer management") Fixes: c5aff18 ("net: mvneta: driver for Marvell Armada 370/XP network unit") Signed-off-by: Lorenzo Bianconi <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 45a8317 commit c35947b

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

drivers/net/ethernet/marvell/mvneta.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ struct mvneta_pcpu_stats {
401401
struct u64_stats_sync syncp;
402402
u64 rx_packets;
403403
u64 rx_bytes;
404+
u64 rx_dropped;
405+
u64 rx_errors;
404406
u64 tx_packets;
405407
u64 tx_bytes;
406408
};
@@ -738,6 +740,8 @@ mvneta_get_stats64(struct net_device *dev,
738740
struct mvneta_pcpu_stats *cpu_stats;
739741
u64 rx_packets;
740742
u64 rx_bytes;
743+
u64 rx_dropped;
744+
u64 rx_errors;
741745
u64 tx_packets;
742746
u64 tx_bytes;
743747

@@ -746,19 +750,20 @@ mvneta_get_stats64(struct net_device *dev,
746750
start = u64_stats_fetch_begin_irq(&cpu_stats->syncp);
747751
rx_packets = cpu_stats->rx_packets;
748752
rx_bytes = cpu_stats->rx_bytes;
753+
rx_dropped = cpu_stats->rx_dropped;
754+
rx_errors = cpu_stats->rx_errors;
749755
tx_packets = cpu_stats->tx_packets;
750756
tx_bytes = cpu_stats->tx_bytes;
751757
} while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start));
752758

753759
stats->rx_packets += rx_packets;
754760
stats->rx_bytes += rx_bytes;
761+
stats->rx_dropped += rx_dropped;
762+
stats->rx_errors += rx_errors;
755763
stats->tx_packets += tx_packets;
756764
stats->tx_bytes += tx_bytes;
757765
}
758766

759-
stats->rx_errors = dev->stats.rx_errors;
760-
stats->rx_dropped = dev->stats.rx_dropped;
761-
762767
stats->tx_dropped = dev->stats.tx_dropped;
763768
}
764769

@@ -1736,8 +1741,14 @@ static u32 mvneta_txq_desc_csum(int l3_offs, int l3_proto,
17361741
static void mvneta_rx_error(struct mvneta_port *pp,
17371742
struct mvneta_rx_desc *rx_desc)
17381743
{
1744+
struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats);
17391745
u32 status = rx_desc->status;
17401746

1747+
/* update per-cpu counter */
1748+
u64_stats_update_begin(&stats->syncp);
1749+
stats->rx_errors++;
1750+
u64_stats_update_end(&stats->syncp);
1751+
17411752
switch (status & MVNETA_RXD_ERR_CODE_MASK) {
17421753
case MVNETA_RXD_ERR_CRC:
17431754
netdev_err(pp->dev, "bad rx status %08x (crc error), size=%d\n",
@@ -2179,11 +2190,15 @@ mvneta_swbm_rx_frame(struct mvneta_port *pp,
21792190

21802191
rxq->skb = build_skb(xdp->data_hard_start, PAGE_SIZE);
21812192
if (unlikely(!rxq->skb)) {
2182-
netdev_err(dev,
2183-
"Can't allocate skb on queue %d\n",
2184-
rxq->id);
2185-
dev->stats.rx_dropped++;
2193+
struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats);
2194+
2195+
netdev_err(dev, "Can't allocate skb on queue %d\n", rxq->id);
21862196
rxq->skb_alloc_err++;
2197+
2198+
u64_stats_update_begin(&stats->syncp);
2199+
stats->rx_dropped++;
2200+
u64_stats_update_end(&stats->syncp);
2201+
21872202
return -ENOMEM;
21882203
}
21892204
page_pool_release_page(rxq->page_pool, page);
@@ -2270,7 +2285,6 @@ static int mvneta_rx_swbm(struct napi_struct *napi,
22702285
/* Check errors only for FIRST descriptor */
22712286
if (rx_status & MVNETA_RXD_ERR_SUMMARY) {
22722287
mvneta_rx_error(pp, rx_desc);
2273-
dev->stats.rx_errors++;
22742288
/* leave the descriptor untouched */
22752289
continue;
22762290
}
@@ -2372,7 +2386,6 @@ static int mvneta_rx_hwbm(struct napi_struct *napi,
23722386
mvneta_bm_pool_put_bp(pp->bm_priv, bm_pool,
23732387
rx_desc->buf_phys_addr);
23742388
err_drop_frame:
2375-
dev->stats.rx_errors++;
23762389
mvneta_rx_error(pp, rx_desc);
23772390
/* leave the descriptor untouched */
23782391
continue;

0 commit comments

Comments
 (0)