Skip to content

ice: properly use u64_stats API for all ring stats

Jacob Keller intel-wired-lan netdev 4 versions – In review

Get series with b4
b4 am [email protected] change-id 20251016-jk-refactor-queue-stats-9e721b34ce01

Versions newest first

  1. v4 Latest6 patches 18 repliesIn review
  2. v39 patches 2 repliesSuperseded
  3. v29 patches 7 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v19 patches11 repliesSuperseded

Changes in v4 from the cover letter

- Drop the cacheline_group changes. Olek and I plan to work on a full
solution in a separate series.
- Drop moving prev_pkt out of the stats. This might still be a good idea,
but it should wait for the cacheline group changes.
- Link to v3: https://patch.msgid.link/[email protected]

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6ice: initialize ring_stats->syncpdrivers/net/ethernet/intel/ice/ice_lib.c+5 -04 replies
2/6ice: pass pointer to ice_fetch_u64_stats_per_ringdrivers/net/ethernet/intel/ice/ice.h drivers/net/ethernet/intel/ice/ice_main.c+9 -183 replies
3/6ice: remove ice_q_stats struct and use struct_groupdrivers/net/ethernet/intel/ice/ice_base.c drivers/net/ethernet/intel/ice/ice_ethtool.c drivers/net/ethernet/intel/ice/ice_lib.c +1 more+16 -173 replies
4/6ice: use u64_stats API to access pkts/bytes in dim sampledrivers/net/ethernet/intel/ice/ice_ethtool.c drivers/net/ethernet/intel/ice/ice_lib.c drivers/net/ethernet/intel/ice/ice_lib.h +1 more+75 -222 replies
5/6ice: shorten ring stat names and add accessorsdrivers/net/ethernet/intel/ice/ice_main.c drivers/net/ethernet/intel/ice/ice_txrx.c drivers/net/ethernet/intel/ice/ice_txrx.h +3 more+60 -353 replies
6/6ice: convert all ring stats to u64_stats_tdrivers/net/ethernet/intel/ice/ice_lib.c drivers/net/ethernet/intel/ice/ice_main.c drivers/net/ethernet/intel/ice/ice_txrx.h+147 -903 replies

Reviews trailers per patch

All 6 patches have a Reviewed-by or Acked-by.

PatchAleksandr LoktionovSimon HormanRinitha S
1/6R-b R-b T-b
2/6R-b R-b T-b
3/6R-b R-b T-b
4/6R-b R-b T-b
5/6R-b R-b T-b
6/6R-b R-b T-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v4 thread

Cover letter [PATCH iwl-next v4 0/6] ice: properly use u64_stats API for all ring stats

The ice driver has multiple u64 values stored in the ring structures for each queue used for statistics. These are accumulated in ice_update_vsi_stats(). The packet and byte values are read using the u64_stats API from <linux/u64_stats_sync.h>.

Several non-standard counters are also accumulated in the same function, but do not use the u64_stats API. This could result in load/store tears on 32-bit architectures. Further, since commit 316580b69d0a ("u64_stats:
provide u64_stats_t type"), the u64 stats API has had u64_stats_t and access functions which convert to local64_t on 64-bit architectures.

The ice driver doesn't use u64_stats_t and these access functions. Thus even on 64-bit architectures it could read inconsistent values. This series refactors the ice driver to use the updated API. Along the way I noticed several other issues and inconsistencies which I have cleaned up, summarized below.

*) The driver never called u64_stats_init, leaving the syncp improperly
initialized. Since the field is part of a kzalloc block, this only impacts 32-bit systems with CONFIG_LOCKDEP enabled.

*) A few locations accessed the packets and byte counts directly without
using the u64 stats API.

*) The ice_fetch_u64_stats_per_ring() function took the ice_q_stats by
value, defeating the point of using the u64_stats API entirely.

To keep the stats increments short, I introduced ice_stats_inc, as otherwise each stat increment has to be quite verbose. Similarly a few places read only one stat, so I added ice_stats_read for those.

This version uses struct ice_vsi_(tx|rx)_stats structures defined in ice_main.c for the accumulator. I haven't come up with a better solution that allows accumulating nicely without this structure. Its a bit frustrating as it copies the entries in the ring stats structures but with u64 instead of u64_stats_t.

I am also still not entirely certain how the ice_update_vsi_ring_stats() function is synchronized in the ice driver. It is called from multiple places without an obvious synchronization mechanism. It is ultimately called from the service task and from ethtool, and I think it may also be called from one of the netdev stats callbacks.

I'm open to suggestions on ways to improve this, as I think the result still has some ugly logic and a fair amount of near duplicate code.

---
Changes in v4:
- Drop the cacheline_group changes. Olek and I plan to work on a full
solution in a separate series.
- Drop moving prev_pkt out of the stats. This might still be a good idea,
but it should wait for the cacheline group changes.
- Link to v3: https://patch.msgid.link/[email protected]

Changes in v3:
- Use SMP_CACHE_BYTES in assertions to avoid issues on ARM v7 with 128-byte
cache (due to xdp_rxq_info changing size)
- Only check the tx_lock cache group size for non-debug kernels, rather
than keeping logic to check its size when DEBUG_LOCK_ALLOC is enabled.
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Fix minor typos.
- Link to v1: https://patch.msgid.link/[email protected]

---
Jacob Keller (6):
ice: initialize ring_stats->syncp
ice: pass pointer to ice_fetch_u64_stats_per_ring
ice: remove ice_q_stats struct and use struct_group
ice: use u64_stats API to access pkts/bytes in dim sample
ice: shorten ring stat names and add accessors
ice: convert all ring stats to u64_stats_t

 drivers/net/ethernet/intel/ice/ice.h          |   3 -
 drivers/net/ethernet/intel/ice/ice_lib.h      |   6 +
 drivers/net/ethernet/intel/ice/ice_txrx.h     |  77 +++++++---
 drivers/net/ethernet/intel/ice/ice_txrx_lib.h |   2 +-
 drivers/net/ethernet/intel/ice/ice_base.c     |   4 +-
 drivers/net/ethernet/intel/ice/ice_ethtool.c  |  30 ++--
 drivers/net/ethernet/intel/ice/ice_lib.c      |  61 +++++---
 drivers/net/ethernet/intel/ice/ice_main.c     | 196 +++++++++++++++++---------
 drivers/net/ethernet/intel/ice/ice_txrx.c     |  45 +++---
 drivers/net/ethernet/intel/ice/ice_txrx_lib.c |   2 +-
 drivers/net/ethernet/intel/ice/ice_xsk.c      |   4 +-
 11 files changed, 280 insertions(+), 150 deletions(-)

---
base-commit: 2fcc88754f4c49e3d9aef226fdfaa1634aa24c66
change-id: 20251016-jk-refactor-queue-stats-9e721b34ce01

Best regards,

Signature · 1 line
Jacob Keller <[email protected]>