Skip to content

Commit 907d1bd

Browse files
Alex Pakhunovkuba-moo
authored andcommitted
tg3: Move the [rt]x_dropped counters to tg3_napi
This change moves [rt]x_dropped counters to tg3_napi so that they can be updated by a single writer, race-free. Signed-off-by: Alex Pakhunov <alexey.pakhunov@spacex.com> Signed-off-by: Vincent Wong <vincent.wong2@spacex.com> Reviewed-by: Michael Chan <michael.chan@broadcom.com> Link: https://lore.kernel.org/r/20231113182350.37472-1-alexey.pakhunov@spacex.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent b6cb454 commit 907d1bd

2 files changed

Lines changed: 35 additions & 7 deletions

File tree

drivers/net/ethernet/broadcom/tg3.c

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6889,7 +6889,7 @@ static int tg3_rx(struct tg3_napi *tnapi, int budget)
68896889
desc_idx, *post_ptr);
68906890
drop_it_no_recycle:
68916891
/* Other statistics kept track of by card. */
6892-
tp->rx_dropped++;
6892+
tnapi->rx_dropped++;
68936893
goto next_pkt;
68946894
}
68956895

@@ -8190,7 +8190,7 @@ static netdev_tx_t __tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
81908190
drop:
81918191
dev_kfree_skb_any(skb);
81928192
drop_nofree:
8193-
tp->tx_dropped++;
8193+
tnapi->tx_dropped++;
81948194
return NETDEV_TX_OK;
81958195
}
81968196

@@ -9405,7 +9405,7 @@ static void __tg3_set_rx_mode(struct net_device *);
94059405
/* tp->lock is held. */
94069406
static int tg3_halt(struct tg3 *tp, int kind, bool silent)
94079407
{
9408-
int err;
9408+
int err, i;
94099409

94109410
tg3_stop_fw(tp);
94119411

@@ -9426,6 +9426,13 @@ static int tg3_halt(struct tg3 *tp, int kind, bool silent)
94269426

94279427
/* And make sure the next sample is new data */
94289428
memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
9429+
9430+
for (i = 0; i < TG3_IRQ_MAX_VECS; ++i) {
9431+
struct tg3_napi *tnapi = &tp->napi[i];
9432+
9433+
tnapi->rx_dropped = 0;
9434+
tnapi->tx_dropped = 0;
9435+
}
94299436
}
94309437

94319438
return err;
@@ -11975,6 +11982,9 @@ static void tg3_get_nstats(struct tg3 *tp, struct rtnl_link_stats64 *stats)
1197511982
{
1197611983
struct rtnl_link_stats64 *old_stats = &tp->net_stats_prev;
1197711984
struct tg3_hw_stats *hw_stats = tp->hw_stats;
11985+
unsigned long rx_dropped;
11986+
unsigned long tx_dropped;
11987+
int i;
1197811988

1197911989
stats->rx_packets = old_stats->rx_packets +
1198011990
get_stat64(&hw_stats->rx_ucast_packets) +
@@ -12021,8 +12031,26 @@ static void tg3_get_nstats(struct tg3 *tp, struct rtnl_link_stats64 *stats)
1202112031
stats->rx_missed_errors = old_stats->rx_missed_errors +
1202212032
get_stat64(&hw_stats->rx_discards);
1202312033

12024-
stats->rx_dropped = tp->rx_dropped;
12025-
stats->tx_dropped = tp->tx_dropped;
12034+
/* Aggregate per-queue counters. The per-queue counters are updated
12035+
* by a single writer, race-free. The result computed by this loop
12036+
* might not be 100% accurate (counters can be updated in the middle of
12037+
* the loop) but the next tg3_get_nstats() will recompute the current
12038+
* value so it is acceptable.
12039+
*
12040+
* Note that these counters wrap around at 4G on 32bit machines.
12041+
*/
12042+
rx_dropped = (unsigned long)(old_stats->rx_dropped);
12043+
tx_dropped = (unsigned long)(old_stats->tx_dropped);
12044+
12045+
for (i = 0; i < tp->irq_cnt; i++) {
12046+
struct tg3_napi *tnapi = &tp->napi[i];
12047+
12048+
rx_dropped += tnapi->rx_dropped;
12049+
tx_dropped += tnapi->tx_dropped;
12050+
}
12051+
12052+
stats->rx_dropped = rx_dropped;
12053+
stats->tx_dropped = tx_dropped;
1202612054
}
1202712055

1202812056
static int tg3_get_regs_len(struct net_device *dev)

drivers/net/ethernet/broadcom/tg3.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3018,6 +3018,7 @@ struct tg3_napi {
30183018
u16 *rx_rcb_prod_idx;
30193019
struct tg3_rx_prodring_set prodring;
30203020
struct tg3_rx_buffer_desc *rx_rcb;
3021+
unsigned long rx_dropped;
30213022

30223023
u32 tx_prod ____cacheline_aligned;
30233024
u32 tx_cons;
@@ -3026,6 +3027,7 @@ struct tg3_napi {
30263027
u32 prodmbox;
30273028
struct tg3_tx_buffer_desc *tx_ring;
30283029
struct tg3_tx_ring_info *tx_buffers;
3030+
unsigned long tx_dropped;
30293031

30303032
dma_addr_t status_mapping;
30313033
dma_addr_t rx_rcb_mapping;
@@ -3220,8 +3222,6 @@ struct tg3 {
32203222

32213223

32223224
/* begin "everything else" cacheline(s) section */
3223-
unsigned long rx_dropped;
3224-
unsigned long tx_dropped;
32253225
struct rtnl_link_stats64 net_stats_prev;
32263226
struct tg3_ethtool_stats estats_prev;
32273227

0 commit comments

Comments
 (0)