Skip to content

Feature/hw timestamp -- userspace/dpdk/ena: add HW RX timestamp support #372

Open
RichardLeeY wants to merge 3 commits into
amzn:masterfrom
RichardLeeY:feature/hw-timestamp
Open

Feature/hw timestamp -- userspace/dpdk/ena: add HW RX timestamp support #372
RichardLeeY wants to merge 3 commits into
amzn:masterfrom
RichardLeeY:feature/hw-timestamp

Conversation

@RichardLeeY
Copy link
Copy Markdown

Summary

Port hardware RX timestamp support from the kernel ENA driver to the DPDK PMD. The ENA NIC writes per-packet nanosecond timestamps into extended completion descriptors, but the DPDK PMD previously ignored these fields (labeled reserved_w6/reserved_w7).

This PR wires the feature through the ena_com HAL and the DPDK ethdev layer so applications can opt in via RTE_ETH_RX_OFFLOAD_TIMESTAMP and read the HW timestamp from the standard mbuf dynfield.

Changes

ena_com HAL

  • ena_admin_defs.h: add ENA_ADMIN_HW_TIMESTAMP feature ID 31 with version/TX/RX enums and feature descriptor struct.
  • ena_eth_io_defs.h: rename reserved_w6/w7 to timestamp_low/high in RX extended cdesc; add TX extended cdesc struct.
  • ena_com.[ch]: add use_extended_tx_cdesc/use_extended_rx_cdesc flags and use_extended_cdesc in create_io_ctx; allocate extended cdescs conditionally in init_io_cq; implement hw_timestamping_supported/get/set helpers.
  • ena_eth_com.[ch]: extract timestamp from the extended RX cdesc into a new timestamp + has_timestamp pair on ena_com_rx_ctx.

DPDK PMD (ethdev layer)

  • Query HW timestamp support at init and advertise RTE_ETH_RX_OFFLOAD_TIMESTAMP capability.
  • Enable the feature via admin command in dev_configure and populate the mbuf dynfield + dynflag from the cdesc timestamp in the RX path.
  • Reject RTE_ETH_TX_OFFLOAD_TIMESTAMP explicitly (TX HW timestamping is not implemented).
  • Rollback path in dev_configure: if dynfield/dynflag registration fails after the feature was enabled on the device, disable it so cdesc sizes stay consistent with the driver.
  • Disable the feature on reconfigure-without-offload and in ena_close so state stays consistent across reset cycles.
  • Cache hw_ts_enabled, dynfield offset and dynflag bit in struct ena_ring so the RX fast path avoids an adapter pointer-chase per packet.

Correctness notes

  • has_timestamp is an explicit flag so a legitimate timestamp value of 0 is not dropped.
  • has_timestamp/timestamp are zero-initialized in the per-packet RX loop to avoid stale stack data.
  • The extended-cdesc branch in ena_com_rx_pkt() is no longer marked unlikely() — when the feature is enabled this is the common path.

Test plan

  • meson/ninja build against DPDK 25.03: 0 errors, 0 warnings.
  • Runtime verification on ENA-capable instance with an application consuming RTE_MBUF_DYNFIELD_TIMESTAMP_NAME.
  • Verify TX offload rejection path returns -ENOTSUP cleanly.
  • Verify dev_configuredev_configure without the offload correctly disables the feature on-device.

RichardLeeY and others added 3 commits April 20, 2026 16:32
Port hardware timestamp support from the kernel ENA driver to the DPDK
PMD. The ENA NIC writes per-packet nanosecond timestamps into extended
completion descriptors, but the DPDK PMD previously ignored these fields
(labeled reserved_w6/reserved_w7).

Changes across the ena_com HAL layer:
- ena_admin_defs.h: add ENA_ADMIN_HW_TIMESTAMP feature ID 31, enums
  for version/tx/rx support, and feature descriptor struct
- ena_eth_io_defs.h: rename reserved_w6/w7 to timestamp_low/high in
  rx cdesc_ext, add tx cdesc_ext struct
- ena_com.h: add use_extended_tx/rx_cdesc flags, use_extended_cdesc
  in create_io_ctx, declare hw timestamping functions
- ena_com.c: conditional extended cdesc allocation in init_io_cq,
  implement hw_timestamping_supported/get/set functions
- ena_eth_com.h: add timestamp field to rx_ctx, add cdesc helpers
- ena_eth_com.c: extract timestamp from extended rx cdesc

Changes in the PMD ethdev layer:
- ena_ethdev.h: add hw_ts state fields to adapter struct
- ena_ethdev.c: query HW timestamp support at init, advertise
  RTE_ETH_RX_OFFLOAD_TIMESTAMP capability, enable via admin command
  in dev_configure, allocate extended cdescs for RX queues, populate
  mbuf dynfield with HW timestamp, disable on close

Tested: builds cleanly against DPDK 25.03 (meson, 0 errors).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fixes from security/performance/robustness review of the HW RX
timestamp feature:

- Add explicit has_timestamp flag in ena_com_rx_ctx so a legitimate
  timestamp value of 0 is no longer dropped as "no timestamp".
- Zero-init has_timestamp and timestamp in the per-packet RX loop to
  avoid stale stack data being written to the mbuf dynfield.
- Remove the wrong unlikely() hint from the extended-cdesc branch in
  ena_com_rx_pkt(); when the feature is enabled this is the common
  path and the hint caused consistent mispredicts.
- Cache hw_ts_enabled, dynfield offset and dynflag bit in struct
  ena_ring so the RX fast path avoids an adapter pointer-chase and
  cold-cacheline load per packet.
- Check rx_ring->hw_ts_enabled first in ena_rx_mbuf_prepare so the
  feature-off path short-circuits before touching has_timestamp.
- Add rollback in ena_dev_configure: if dynfield/dynflag registration
  fails after HW timestamping was enabled on the device, disable it
  again and reset driver state so the device and driver no longer
  disagree on cdesc size.
- Disable HW timestamping on the device when the user reconfigures
  without the offload, to keep cdesc sizes consistent across
  dev_configure cycles.
- Reject RTE_ETH_TX_OFFLOAD_TIMESTAMP in dev_configure instead of
  silently ignoring it; TX HW timestamping is not implemented.
- Hoist the dynfield/dynflag descriptor statics out of function
  scope for readability.
- Clear per-ring hw_ts_enabled and adapter dynfield state in
  ena_close to keep state consistent across reset cycles.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@akiyano akiyano requested a review from shaibran May 5, 2026 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant