Retain the per-ring packet, byte and error counters when queue vectors are freed, so that the legacy statistics keep their history across an ethtool -L, a reset or a resume. Fold the retained values into the aggregates through the qstats_base_* accumulators and protect the ring-to-base handoff with hw_stats_lock. The accumulators are read under that same lock, which wx_free_q_vector() holds while it folds a ring and clears its pointer, so a reader cannot mix a ring with its retained value. Clear the queue counts only after every ring has been folded, so that a reader which pairs the counts with the base values cannot skip a ring that is still waiting to be folded; that keeps base plus live rings invariant at every instant. The per-queue counters reported by ethtool -S keep describing the live queues only, so after a reconfiguration they no longer add up to the aggregates. Initialize each ring's u64_stats_sync instances and serialize the per-ring counter updates and reads. Name them after the writer they protect: napi_syncp for the counters updated from NAPI, xmit_syncp for the ones updated from the xmit path, so that a new writer goes under the matching lock by name and the two producers never hold the same seqcount odd at the same time. The xmit-side lock is only taken when the transmit queue is stopped and when a full ring defers a packet, not on the normal transmit path, so the 32-bit preemption and seqcount cost is paid at queue-stop boundaries rather than per packet. Rename rx_stats.csum_good_cnt and its accumulator to use csum_unnecessary_cnt; the local snapshot uses the same wording. The counter reflects the packets that wx_rx_checksum() hands to the stack with CHECKSUM_UNNECESSARY. Count the transmit queue stops in the ring, next to restart_queue, and report both as retained stop and wake counters. A stop is counted when wx_maybe_stop_tx() leaves the queue stopped; the reprieve path only adds a wake. The snapshot type is named after what it holds, wx_tx_retained_stats, and its wake member already includes the NAPI wake-ups, so a consumer cannot lose them by adding up only one of the two producers. Refresh software aggregates while the device is down or resetting, while skipping hardware register reads. This keeps retained values visible through ethtool -S after queue teardown. Use shared ring snapshots in the aggregation, teardown, stats64 and ethtool readers. Clearing the ring pointers stays under the lock as well, but the teardown itself does not stop the device: every caller has already disabled NAPI and the TX queues, and vectors from a partially failed allocation were never enabled, so no writer races the fold. Signed-off-by: Mengyuan Lou --- .../net/ethernet/wangxun/libwx/wx_ethtool.c | 19 +-- drivers/net/ethernet/wangxun/libwx/wx_hw.c | 74 ++++---- drivers/net/ethernet/wangxun/libwx/wx_lib.c | 158 ++++++++++++------ drivers/net/ethernet/wangxun/libwx/wx_type.h | 82 ++++++++- 4 files changed, 238 insertions(+), 95 deletions(-) diff --git a/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c b/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c index 05f915e778645..8f0bbdbb4cf23 100644 --- a/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c +++ b/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c @@ -127,8 +127,9 @@ void wx_get_ethtool_stats(struct net_device *netdev, struct ethtool_stats *stats, u64 *data) { struct wx *wx = netdev_priv(netdev); + struct wx_tx_ring_stats tx_stats; + struct wx_rx_ring_stats rx_stats; struct wx_ring *ring; - unsigned int start; int i, j, k; char *p; @@ -163,11 +164,9 @@ void wx_get_ethtool_stats(struct net_device *netdev, continue; } - do { - start = u64_stats_fetch_begin(&ring->syncp); - data[i] = ring->stats.packets; - data[i + 1] = ring->stats.bytes; - } while (u64_stats_fetch_retry(&ring->syncp, start)); + wx_ring_get_tx_stats(ring, &tx_stats); + data[i] = tx_stats.queue.packets; + data[i + 1] = tx_stats.queue.bytes; i += 2; } for (j = 0; j < WX_NUM_RX_QUEUES; j++) { @@ -178,11 +177,9 @@ void wx_get_ethtool_stats(struct net_device *netdev, continue; } - do { - start = u64_stats_fetch_begin(&ring->syncp); - data[i] = ring->stats.packets; - data[i + 1] = ring->stats.bytes; - } while (u64_stats_fetch_retry(&ring->syncp, start)); + wx_ring_get_rx_stats(ring, &rx_stats); + data[i] = rx_stats.queue.packets; + data[i + 1] = rx_stats.queue.bytes; i += 2; } rcu_read_unlock(); diff --git a/drivers/net/ethernet/wangxun/libwx/wx_hw.c b/drivers/net/ethernet/wangxun/libwx/wx_hw.c index c285c1de24ba9..a367ed45fc127 100644 --- a/drivers/net/ethernet/wangxun/libwx/wx_hw.c +++ b/drivers/net/ethernet/wangxun/libwx/wx_hw.c @@ -2920,13 +2920,13 @@ void wx_update_stats(struct wx *wx) u64 hw_csum_rx_good = 0, hw_csum_rx_error = 0; u64 restart_queue = 0, tx_busy = 0; int num_rx_queues, num_tx_queues; + u64 rsc_count = 0, rsc_flush = 0; + bool update_hw_stats; u32 i; - if (test_bit(WX_STATE_DOWN, wx->state) || - test_bit(WX_STATE_RESETTING, wx->state)) - return; - spin_lock(&wx->hw_stats_lock); + update_hw_stats = !test_bit(WX_STATE_DOWN, wx->state) && + !test_bit(WX_STATE_RESETTING, wx->state); num_rx_queues = READ_ONCE(wx->num_rx_queues); num_tx_queues = READ_ONCE(wx->num_tx_queues); @@ -2934,48 +2934,55 @@ void wx_update_stats(struct wx *wx) /* gather some stats to the wx struct that are per queue */ for (i = 0; i < num_rx_queues; i++) { struct wx_ring *rx_ring = rcu_dereference(wx->rx_ring[i]); + struct wx_rx_ring_stats ring_stats; if (!rx_ring) continue; - non_eop_descs += rx_ring->rx_stats.non_eop_descs; - alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed; - hw_csum_rx_good += rx_ring->rx_stats.csum_good_cnt; - hw_csum_rx_error += rx_ring->rx_stats.csum_err; - } - wx->non_eop_descs = non_eop_descs; - wx->alloc_rx_buff_failed = alloc_rx_buff_failed; - wx->hw_csum_rx_error = hw_csum_rx_error; - wx->hw_csum_rx_good = hw_csum_rx_good; - - if (test_bit(WX_FLAG_RSC_ENABLED, wx->flags)) { - u64 rsc_count = 0; - u64 rsc_flush = 0; - for (i = 0; i < num_rx_queues; i++) { - struct wx_ring *rx_ring = rcu_dereference(wx->rx_ring[i]); - - if (!rx_ring) - continue; - - rsc_count += rx_ring->rx_stats.rsc_count; - rsc_flush += rx_ring->rx_stats.rsc_flush; - } - wx->rsc_count = rsc_count; - wx->rsc_flush = rsc_flush; - } + wx_ring_get_rx_stats(rx_ring, &ring_stats); + + non_eop_descs += ring_stats.rx.non_eop_descs; + alloc_rx_buff_failed += ring_stats.rx.alloc_rx_buff_failed; + hw_csum_rx_good += ring_stats.rx.csum_unnecessary_cnt; + hw_csum_rx_error += ring_stats.rx.csum_err; + rsc_count += ring_stats.rx.rsc_count; + rsc_flush += ring_stats.rx.rsc_flush; + } + wx->non_eop_descs = + wx->qstats_base_rx_stats.non_eop_descs + non_eop_descs; + wx->alloc_rx_buff_failed = + wx->qstats_base_rx_stats.alloc_rx_buff_failed + + alloc_rx_buff_failed; + wx->hw_csum_rx_error = + wx->qstats_base_rx_stats.csum_err + hw_csum_rx_error; + wx->hw_csum_rx_good = + wx->qstats_base_rx_stats.csum_unnecessary_cnt + hw_csum_rx_good; + + /* The ring counters are folded into this value when they are freed, + * so keep it current even while RSC is turned off and no ring can + * add to it. + */ + wx->rsc_count = wx->qstats_base_rx_stats.rsc_count + rsc_count; + wx->rsc_flush = wx->qstats_base_rx_stats.rsc_flush + rsc_flush; for (i = 0; i < num_tx_queues; i++) { struct wx_ring *tx_ring = rcu_dereference(wx->tx_ring[i]); + struct wx_tx_ring_stats ring_stats; if (!tx_ring) continue; - restart_queue += tx_ring->tx_stats.restart_queue; - tx_busy += tx_ring->tx_stats.tx_busy; + wx_ring_get_tx_stats(tx_ring, &ring_stats); + + restart_queue += ring_stats.tx.wake; + tx_busy += ring_stats.tx.tx_busy; } rcu_read_unlock(); - wx->restart_queue = restart_queue; - wx->tx_busy = tx_busy; + wx->restart_queue = wx->qstats_base_tx_stats.wake + restart_queue; + wx->tx_busy = wx->qstats_base_tx_stats.tx_busy + tx_busy; + + if (!update_hw_stats) + goto skip_hw_stats; wx_update_xoff_rx_lfc(wx); @@ -3016,6 +3023,7 @@ void wx_update_stats(struct wx *wx) hwstats->qmprc += rd32_wrap(wx, WX_PX_MPRC(i), &wx->last_stats.qmprc[i]); +skip_hw_stats: spin_unlock(&wx->hw_stats_lock); } EXPORT_SYMBOL(wx_update_stats); diff --git a/drivers/net/ethernet/wangxun/libwx/wx_lib.c b/drivers/net/ethernet/wangxun/libwx/wx_lib.c index 10f095fb7085c..2868232792588 100644 --- a/drivers/net/ethernet/wangxun/libwx/wx_lib.c +++ b/drivers/net/ethernet/wangxun/libwx/wx_lib.c @@ -387,6 +387,7 @@ u16 wx_desc_unused(struct wx_ring *ring) * @rx_ring: Rx ring being processed * @rx_desc: Rx descriptor for current buffer * @skb: Current socket buffer containing buffer in progress + * @stats: RX counters accumulated for this NAPI poll * * This function updates next to clean. If the buffer is an EOP buffer * this function exits returning false, otherwise it will place the @@ -395,7 +396,8 @@ u16 wx_desc_unused(struct wx_ring *ring) **/ static bool wx_is_non_eop(struct wx_ring *rx_ring, union wx_rx_desc *rx_desc, - struct sk_buff *skb) + struct sk_buff *skb, + struct wx_rx_queue_stats *stats) { struct wx *wx = rx_ring->q_vector->wx; u32 ntc = rx_ring->next_to_clean + 1; @@ -429,7 +431,7 @@ static bool wx_is_non_eop(struct wx_ring *rx_ring, return false; rx_ring->rx_buffer_info[ntc].skb = skb; - rx_ring->rx_stats.non_eop_descs++; + stats->non_eop_descs++; return true; } @@ -529,10 +531,12 @@ static void wx_rx_hash(struct wx_ring *ring, * @ring: structure containing ring specific data * @rx_desc: current Rx descriptor being processed * @skb: skb currently being received and modified + * @stats: RX counters accumulated for this NAPI poll **/ static void wx_rx_checksum(struct wx_ring *ring, union wx_rx_desc *rx_desc, - struct sk_buff *skb) + struct sk_buff *skb, + struct wx_rx_queue_stats *stats) { struct wx_dec_ptype dptype = wx_decode_ptype(WX_RXD_PKTTYPE(rx_desc)); @@ -546,7 +550,7 @@ static void wx_rx_checksum(struct wx_ring *ring, wx_test_staterr(rx_desc, WX_RXD_ERR_IPE)) || (wx_test_staterr(rx_desc, WX_RXD_STAT_OUTERIPCS) && wx_test_staterr(rx_desc, WX_RXD_ERR_OUTERIPER))) { - ring->rx_stats.csum_err++; + stats->csum_err++; return; } @@ -561,7 +565,7 @@ static void wx_rx_checksum(struct wx_ring *ring, /* if L4 checksum error */ if (wx_test_staterr(rx_desc, WX_RXD_ERR_TCPE)) { - ring->rx_stats.csum_err++; + stats->csum_err++; return; } @@ -574,7 +578,7 @@ static void wx_rx_checksum(struct wx_ring *ring, */ if (dptype.etype >= WX_DEC_PTYPE_ETYPE_IG) __skb_incr_checksum_unnecessary(skb); - ring->rx_stats.csum_good_cnt++; + stats->csum_unnecessary_cnt++; } static void wx_rx_vlan(struct wx_ring *ring, union wx_rx_desc *rx_desc, @@ -606,14 +610,15 @@ static void wx_set_rsc_gso_size(struct wx_ring *ring, } static void wx_update_rsc_stats(struct wx_ring *rx_ring, - struct sk_buff *skb) + struct sk_buff *skb, + struct wx_rx_queue_stats *stats) { /* if append_cnt is 0 then frame is not RSC */ if (!WX_CB(skb)->append_cnt) return; - rx_ring->rx_stats.rsc_count += WX_CB(skb)->append_cnt; - rx_ring->rx_stats.rsc_flush++; + stats->rsc_count += WX_CB(skb)->append_cnt; + stats->rsc_flush++; wx_set_rsc_gso_size(rx_ring, skb); @@ -626,6 +631,7 @@ static void wx_update_rsc_stats(struct wx_ring *rx_ring, * @rx_ring: rx descriptor ring packet is being transacted on * @rx_desc: pointer to the EOP Rx descriptor * @skb: pointer to current skb being populated + * @stats: RX counters accumulated for this NAPI poll * * This function checks the ring, descriptor, and packet information in * order to populate the hash, checksum, protocol, and @@ -633,15 +639,16 @@ static void wx_update_rsc_stats(struct wx_ring *rx_ring, **/ static void wx_process_skb_fields(struct wx_ring *rx_ring, union wx_rx_desc *rx_desc, - struct sk_buff *skb) + struct sk_buff *skb, + struct wx_rx_queue_stats *stats) { struct wx *wx = netdev_priv(rx_ring->netdev); if (test_bit(WX_FLAG_RSC_CAPABLE, wx->flags)) - wx_update_rsc_stats(rx_ring, skb); + wx_update_rsc_stats(rx_ring, skb, stats); wx_rx_hash(rx_ring, rx_desc, skb); - wx_rx_checksum(rx_ring, rx_desc, skb); + wx_rx_checksum(rx_ring, rx_desc, skb, stats); if (unlikely(test_bit(WX_FLAG_RX_HWTSTAMP_ENABLED, wx->flags)) && unlikely(wx_test_staterr(rx_desc, WX_RXD_STAT_TS))) { @@ -673,6 +680,7 @@ static int wx_clean_rx_irq(struct wx_q_vector *q_vector, { unsigned int total_rx_bytes = 0, total_rx_packets = 0; u16 cleaned_count = wx_desc_unused(rx_ring); + struct wx_rx_queue_stats rx_stats = {}; do { struct wx_rx_buffer *rx_buffer; @@ -702,7 +710,7 @@ static int wx_clean_rx_irq(struct wx_q_vector *q_vector, /* exit if we failed to retrieve a buffer */ if (!skb) { - rx_ring->rx_stats.alloc_rx_buff_failed++; + rx_stats.alloc_rx_buff_failed++; break; } @@ -710,7 +718,7 @@ static int wx_clean_rx_irq(struct wx_q_vector *q_vector, cleaned_count++; /* place incomplete frames back on ring for completion */ - if (wx_is_non_eop(rx_ring, rx_desc, skb)) + if (wx_is_non_eop(rx_ring, rx_desc, skb, &rx_stats)) continue; /* verify the packet layout is correct */ @@ -721,17 +729,25 @@ static int wx_clean_rx_irq(struct wx_q_vector *q_vector, total_rx_bytes += skb->len; /* populate checksum, timestamp, VLAN, and protocol */ - wx_process_skb_fields(rx_ring, rx_desc, skb); + wx_process_skb_fields(rx_ring, rx_desc, skb, &rx_stats); napi_gro_receive(&q_vector->napi, skb); /* update budget accounting */ total_rx_packets++; } while (likely(total_rx_packets < budget)); - u64_stats_update_begin(&rx_ring->syncp); + u64_stats_update_begin(&rx_ring->napi_syncp); rx_ring->stats.packets += total_rx_packets; rx_ring->stats.bytes += total_rx_bytes; - u64_stats_update_end(&rx_ring->syncp); + rx_ring->rx_stats.non_eop_descs += rx_stats.non_eop_descs; + rx_ring->rx_stats.csum_unnecessary_cnt += + rx_stats.csum_unnecessary_cnt; + rx_ring->rx_stats.csum_err += rx_stats.csum_err; + rx_ring->rx_stats.alloc_rx_buff_failed += + rx_stats.alloc_rx_buff_failed; + rx_ring->rx_stats.rsc_count += rx_stats.rsc_count; + rx_ring->rx_stats.rsc_flush += rx_stats.rsc_flush; + u64_stats_update_end(&rx_ring->napi_syncp); q_vector->rx.total_packets += total_rx_packets; q_vector->rx.total_bytes += total_rx_bytes; @@ -888,10 +904,10 @@ static bool wx_clean_tx_irq(struct wx_q_vector *q_vector, i += tx_ring->count; tx_ring->next_to_clean = i; - u64_stats_update_begin(&tx_ring->syncp); + u64_stats_update_begin(&tx_ring->napi_syncp); tx_ring->stats.bytes += total_bytes; tx_ring->stats.packets += total_packets; - u64_stats_update_end(&tx_ring->syncp); + u64_stats_update_end(&tx_ring->napi_syncp); q_vector->tx.total_bytes += total_bytes; q_vector->tx.total_packets += total_packets; @@ -916,7 +932,9 @@ static bool wx_clean_tx_irq(struct wx_q_vector *q_vector, !test_bit(WX_STATE_DOWN, wx->state)) { netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index); - ++tx_ring->tx_stats.restart_queue; + u64_stats_update_begin(&tx_ring->napi_syncp); + ++tx_ring->tx_stats.restart_queue_napi; + u64_stats_update_end(&tx_ring->napi_syncp); } } @@ -1021,12 +1039,18 @@ static int wx_maybe_stop_tx(struct wx_ring *tx_ring, u16 size) /* We need to check again in a case another CPU has just * made room available. */ - if (likely(wx_desc_unused(tx_ring) < size)) + if (likely(wx_desc_unused(tx_ring) < size)) { + u64_stats_update_begin(&tx_ring->xmit_syncp); + ++tx_ring->tx_stats.stop_queue; + u64_stats_update_end(&tx_ring->xmit_syncp); return -EBUSY; + } /* A reprieve! - use start_queue because it doesn't call schedule */ netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); + u64_stats_update_begin(&tx_ring->xmit_syncp); ++tx_ring->tx_stats.restart_queue; + u64_stats_update_end(&tx_ring->xmit_syncp); return 0; } @@ -1631,7 +1655,9 @@ static netdev_tx_t wx_xmit_frame_ring(struct sk_buff *skb, frags[f])); if (wx_maybe_stop_tx(tx_ring, count + 3)) { + u64_stats_update_begin(&tx_ring->xmit_syncp); tx_ring->tx_stats.tx_busy++; + u64_stats_update_end(&tx_ring->xmit_syncp); return NETDEV_TX_BUSY; } @@ -2182,6 +2208,8 @@ static int wx_alloc_q_vector(struct wx *wx, /* apply Tx specific ring traits */ ring->count = wx->tx_ring_count; + u64_stats_init(&ring->napi_syncp); + u64_stats_init(&ring->xmit_syncp); ring->queue_index = txr_idx; ring->reg_idx = wx_get_reg_idx(wx, txr_idx, false); @@ -2210,6 +2238,7 @@ static int wx_alloc_q_vector(struct wx *wx, /* apply Rx specific ring traits */ ring->count = wx->rx_ring_count; + u64_stats_init(&ring->napi_syncp); ring->queue_index = rxr_idx; ring->reg_idx = wx_get_reg_idx(wx, rxr_idx, true); @@ -2241,11 +2270,37 @@ static void wx_free_q_vector(struct wx *wx, int v_idx) struct wx_q_vector *q_vector = wx->q_vector[v_idx]; struct wx_ring *ring; - wx_for_each_ring(ring, q_vector->tx) + spin_lock(&wx->hw_stats_lock); + wx_for_each_ring(ring, q_vector->tx) { + struct wx_tx_ring_stats ring_stats; + + wx_ring_get_tx_stats(ring, &ring_stats); + wx->qstats_base_tx.packets += ring_stats.queue.packets; + wx->qstats_base_tx.bytes += ring_stats.queue.bytes; + wx->qstats_base_tx_stats.stop += ring_stats.tx.stop; + wx->qstats_base_tx_stats.wake += ring_stats.tx.wake; + wx->qstats_base_tx_stats.tx_busy += ring_stats.tx.tx_busy; rcu_assign_pointer(wx->tx_ring[ring->queue_index], NULL); + } - wx_for_each_ring(ring, q_vector->rx) + wx_for_each_ring(ring, q_vector->rx) { + struct wx_rx_ring_stats ring_stats; + + wx_ring_get_rx_stats(ring, &ring_stats); + wx->qstats_base_rx.packets += ring_stats.queue.packets; + wx->qstats_base_rx.bytes += ring_stats.queue.bytes; + wx->qstats_base_rx_stats.non_eop_descs += + ring_stats.rx.non_eop_descs; + wx->qstats_base_rx_stats.alloc_rx_buff_failed += + ring_stats.rx.alloc_rx_buff_failed; + wx->qstats_base_rx_stats.csum_unnecessary_cnt += + ring_stats.rx.csum_unnecessary_cnt; + wx->qstats_base_rx_stats.csum_err += ring_stats.rx.csum_err; + wx->qstats_base_rx_stats.rsc_count += ring_stats.rx.rsc_count; + wx->qstats_base_rx_stats.rsc_flush += ring_stats.rx.rsc_flush; rcu_assign_pointer(wx->rx_ring[ring->queue_index], NULL); + } + spin_unlock(&wx->hw_stats_lock); wx->q_vector[v_idx] = NULL; netif_napi_del(&q_vector->napi); @@ -2288,13 +2343,13 @@ static int wx_alloc_q_vectors(struct wx *wx) return 0; err_out: + while (v_idx--) + wx_free_q_vector(wx, v_idx); + WRITE_ONCE(wx->num_tx_queues, 0); WRITE_ONCE(wx->num_rx_queues, 0); wx->num_q_vectors = 0; - while (v_idx--) - wx_free_q_vector(wx, v_idx); - return -ENOMEM; } @@ -2310,12 +2365,16 @@ static void wx_free_q_vectors(struct wx *wx) { int v_idx = wx->num_q_vectors; + while (v_idx--) + wx_free_q_vector(wx, v_idx); + + /* Publish the zeroed counts only once every ring has been folded into + * the base values, so a reader that pairs the counts with the base + * cannot miss a ring that is still waiting to be folded. + */ WRITE_ONCE(wx->num_tx_queues, 0); WRITE_ONCE(wx->num_rx_queues, 0); wx->num_q_vectors = 0; - - while (v_idx--) - wx_free_q_vector(wx, v_idx); } void wx_reset_interrupt_capability(struct wx *wx) @@ -3087,39 +3146,42 @@ void wx_get_stats64(struct net_device *netdev, num_rx_queues = READ_ONCE(wx->num_rx_queues); num_tx_queues = READ_ONCE(wx->num_tx_queues); + /* Pair with kfree_rcu() in wx_free_q_vector(). */ rcu_read_lock(); + /* wx_free_q_vector() folds a ring into the base values under the same + * lock, so the snapshot cannot mix a ring with its retained value. + * The lock has to span the ring walk: the base values are read after + * it, and a ring folded in between would be counted twice. + */ + spin_lock(&wx->hw_stats_lock); for (i = 0; i < num_rx_queues; i++) { struct wx_ring *ring = rcu_dereference(wx->rx_ring[i]); - u64 bytes, packets; - unsigned int start; if (ring) { - do { - start = u64_stats_fetch_begin(&ring->syncp); - packets = ring->stats.packets; - bytes = ring->stats.bytes; - } while (u64_stats_fetch_retry(&ring->syncp, start)); - stats->rx_packets += packets; - stats->rx_bytes += bytes; + struct wx_rx_ring_stats ring_stats; + + wx_ring_get_rx_stats(ring, &ring_stats); + stats->rx_packets += ring_stats.queue.packets; + stats->rx_bytes += ring_stats.queue.bytes; } } for (i = 0; i < num_tx_queues; i++) { struct wx_ring *ring = rcu_dereference(wx->tx_ring[i]); - u64 bytes, packets; - unsigned int start; if (ring) { - do { - start = u64_stats_fetch_begin(&ring->syncp); - packets = ring->stats.packets; - bytes = ring->stats.bytes; - } while (u64_stats_fetch_retry(&ring->syncp, - start)); - stats->tx_packets += packets; - stats->tx_bytes += bytes; + struct wx_tx_ring_stats ring_stats; + + wx_ring_get_tx_stats(ring, &ring_stats); + stats->tx_packets += ring_stats.queue.packets; + stats->tx_bytes += ring_stats.queue.bytes; } } + stats->rx_packets += wx->qstats_base_rx.packets; + stats->rx_bytes += wx->qstats_base_rx.bytes; + stats->tx_packets += wx->qstats_base_tx.packets; + stats->tx_bytes += wx->qstats_base_tx.bytes; + spin_unlock(&wx->hw_stats_lock); rcu_read_unlock(); diff --git a/drivers/net/ethernet/wangxun/libwx/wx_type.h b/drivers/net/ethernet/wangxun/libwx/wx_type.h index f376c0b22da52..c343831c1dd0a 100644 --- a/drivers/net/ethernet/wangxun/libwx/wx_type.h +++ b/drivers/net/ethernet/wangxun/libwx/wx_type.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -1044,13 +1045,26 @@ struct wx_queue_stats { struct wx_tx_queue_stats { u64 restart_queue; + u64 restart_queue_napi; + u64 stop_queue; u64 tx_busy; u32 tx_done_old; }; +/* TX counters that survive a queue teardown, named after what netdev-genl + * reports: stop counts the times the queue was stopped because it was + * full, wake counts every restart, both from the xmit reprieve path and + * from NAPI. + */ +struct wx_tx_retained_stats { + u64 stop; + u64 wake; + u64 tx_busy; +}; + struct wx_rx_queue_stats { u64 non_eop_descs; - u64 csum_good_cnt; + u64 csum_unnecessary_cnt; u64 csum_err; u64 alloc_rx_buff_failed; u64 rsc_count; @@ -1114,13 +1128,65 @@ struct wx_ring { }; struct wx_queue_stats stats; - struct u64_stats_sync syncp; + /* Guards the counters updated from NAPI: stats and rx_stats on an RX + * ring, stats and tx_stats.restart_queue_napi on a TX ring. + */ + struct u64_stats_sync napi_syncp; + /* Guards the counters updated from the xmit path on a TX ring: + * tx_stats.restart_queue, tx_stats.stop_queue and tx_stats.tx_busy. + * Keep it separate from napi_syncp so that the two producers never + * hold the same seqcount odd at the same time. + */ + struct u64_stats_sync xmit_syncp; union { struct wx_tx_queue_stats tx_stats; struct wx_rx_queue_stats rx_stats; }; } ____cacheline_internodealigned_in_smp; +struct wx_rx_ring_stats { + struct wx_queue_stats queue; + struct wx_rx_queue_stats rx; +}; + +struct wx_tx_ring_stats { + struct wx_queue_stats queue; + struct wx_tx_retained_stats tx; +}; + +static inline void wx_ring_get_rx_stats(struct wx_ring *ring, + struct wx_rx_ring_stats *stats) +{ + unsigned int start; + + do { + start = u64_stats_fetch_begin(&ring->napi_syncp); + stats->queue = ring->stats; + stats->rx = ring->rx_stats; + } while (u64_stats_fetch_retry(&ring->napi_syncp, start)); +} + +static inline void wx_ring_get_tx_stats(struct wx_ring *ring, + struct wx_tx_ring_stats *stats) +{ + u64 restart_queue_napi; + unsigned int start; + + do { + start = u64_stats_fetch_begin(&ring->napi_syncp); + stats->queue = ring->stats; + restart_queue_napi = ring->tx_stats.restart_queue_napi; + } while (u64_stats_fetch_retry(&ring->napi_syncp, start)); + + do { + start = u64_stats_fetch_begin(&ring->xmit_syncp); + stats->tx.stop = ring->tx_stats.stop_queue; + stats->tx.wake = ring->tx_stats.restart_queue + + restart_queue_napi; + stats->tx.tx_busy = ring->tx_stats.tx_busy; + } while (u64_stats_fetch_retry(&ring->xmit_syncp, start)); +} + struct wx_q_vector { struct wx *wx; int cpu; /* CPU for DCA */ @@ -1371,6 +1437,10 @@ struct wx { struct wx_ring __rcu *tx_ring[64] ____cacheline_aligned_in_smp; struct wx_ring __rcu *rx_ring[64]; struct wx_q_vector *q_vector[64]; + struct wx_queue_stats qstats_base_rx; + struct wx_queue_stats qstats_base_tx; + struct wx_rx_queue_stats qstats_base_rx_stats; + struct wx_tx_retained_stats qstats_base_tx_stats; int num_rx_pools; int num_rx_queues_per_pool; @@ -1401,7 +1471,13 @@ struct wx { struct wx_hw_stats stats; struct wx_last_stats last_stats; - spinlock_t hw_stats_lock; /* spinlock for accessing to hw stats */ + /* Protects the read-modify-write updates of wx->stats, including the + * hardware counters sampled in wx_update_stats(), the qstats_base_* + * accumulators and the hand-off of a ring into them when a queue + * vector is freed. Readers hold it while they pair the live rings + * with the retained values. + */ + spinlock_t hw_stats_lock; u64 tx_busy; u64 non_eop_descs; u64 restart_queue; -- 2.30.1