netutils/ptpd: query timestamping capabilities via SIOCGIFTSCAPS - #3800
Open
daniel-p-carvalho wants to merge 2 commits into
Open
daniel-p-carvalho wants to merge 2 commits into
daniel-p-carvalho wants to merge 2 commits into
Conversation
cederom
requested changes
Sep 24, 2026
cederom
left a comment
Contributor
There was a problem hiding this comment.
Thank you @daniel-p-carvalho, please:
- Follow the PR requirements and template (summary, impact, testing), see https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md.
- Please provide (extract) from build and runtime logs that prove build and runtime solution is working as expected. Overall description (aka "test plan") is not enough as it does not prove anything.
5 tasks
daniel-p-carvalho
force-pushed
the
feat/ptpd-txtstamp-caps
branch
from
September 24, 2026 14:42
815212a to
ebf2986
Compare
Contributor
Author
|
Updated the PR description to follow the template (Summary/Impact/Testing/Self-Check) with real build and runtime log excerpts from two boards tested against a physical PTP Grandmaster, per your request. Thanks for the pointer to the template. |
daniel-p-carvalho
marked this pull request as draft
September 24, 2026 16:23
daniel-p-carvalho
force-pushed
the
feat/ptpd-txtstamp-caps
branch
from
September 24, 2026 16:34
ba4d8d2 to
a857f7d
Compare
Query interface hardware timestamping capabilities using SIOCGIFTSCAPS during initialization instead of detecting support through runtime trial and error. Remove the consecutive failure counter (hwts_tx_failures, PTP_HWTS_TX_MAX_FAILURES, hwts_tx_disabled). When hardware TX timestamping is supported and requested, report genuine runtime timeouts as errors (ptperr) instead of silently downgrading to software timestamping. Invalidate clock_source_valid in ptpd status while a hardware TX timestamp failure persists. Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com> Assisted-by: Gemini:gemini-3.8-pro
daniel-p-carvalho
force-pushed
the
feat/ptpd-txtstamp-caps
branch
from
September 24, 2026 17:43
a857f7d to
e70f19d
Compare
daniel-p-carvalho
marked this pull request as ready for review
September 24, 2026 21:29
daniel-p-carvalho
force-pushed
the
feat/ptpd-txtstamp-caps
branch
from
September 24, 2026 21:34
e70f19d to
34afe7e
Compare
…ort. When ptpd runs over IEEE 802.3 (-2) with hardware timestamping and SIOCGIFTSCAPS reports the interface does not provide hardware RX and TX timestamps, or the ioctl itself fails, refuse to start instead of logging a warning and running in software - the same way linuxptp/ptp4l refuses to start when hardware timestamping is configured but not reported as supported by ethtool, rather than silently degrading. The error message names the missing capability and points to -S, and the usage text documents the requirement. Hardware RX timestamps are required as well: without them the receive timestamps come from the system clock while the transmit ones come from the MAC, and the two cannot be combined into a meaningful delay. The check is limited to the 802.3 transport, the only one on which ptpd retrieves hardware TX timestamps. -H is the default with CONFIG_NET_TIMESTAMP, so applying it to the UDP transports would make a plain "ptpd" refuse to start on any interface whose driver does not declare NETDEV_TX_STAMP, although it never needs that capability. Assisted-by: Claude:claude-sonnet-5 Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
daniel-p-carvalho
force-pushed
the
feat/ptpd-txtstamp-caps
branch
from
September 25, 2026 01:18
34afe7e to
f9e3447
Compare
cederom
approved these changes
Sep 25, 2026
cederom
requested review from
acassis,
linguini1,
michallenc,
simbit18 and
xiaoxiang781216
September 25, 2026 09:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ptpdcurrently detects hardware TX timestamp support by trial and error (three consecutive failures, then a silent, permanent switch to software timestamps). This PR switches it to querying the driver's capabilities once at startup instead, and makes a genuine runtime failure visible instead of turning it into a silent, permanent mode switch. The startup check followslinuxptp/ptp4l, which refuses to start when hardware timestamping is requested but not reported by the driver viaethtool. Runtime handling is deliberately lighter thanptp4l(which takes the port toFAULTYon a TX timestamp timeout): see below.ptp_initialize_state()queries the newSIOCGIFTSCAPSioctl (net: add NETDEV_TX_STAMP capability flag and SIOCGIFTSCAPS query ioctl nuttx#20346) once for the configured interface. If-His requested on the IEEE 802.3 transport (-2) and the driver does not report bothNETDEV_RX_STAMPandNETDEV_TX_STAMP(or the ioctl itself fails),ptpdnow refuses to start. The error message names the missing capability and points to-S, e.g.Interface eth0 does not support hardware TX timestamping, use -S for software timestamps.ptp4l, which checks bothSOF_TIMESTAMPING_RX_HARDWAREandSOF_TIMESTAMPING_TX_HARDWARE.ptpdretrieves hardware TX timestamps.-His the default withCONFIG_NET_TIMESTAMP, so applying it to the UDP transports would make a plainptpdrefuse to start on interfaces that never need the capability.hwts_tx_failures,PTP_HWTS_TX_MAX_FAILURESandhwts_tx_disabled. Hardware TX timestamp use (state->hwts_tx) is now a fixed capability read once, not a runtime state machine.ptp_get_tx_timestamp()timeout on an interface that already reported the capability (a failure at runtime, after startup succeeded) still falls back to the software timestamp for that single message, but it is no longer silent or permanent: it is logged withptperr(wasptpwarn) and setsstate->hwts_tx_failed, which is reported through the existingclock_source_validfield ofstruct ptpd_status_suntil the next hardware TX timestamp succeeds. This reuses the daemon's existing health indicator instead of adding a purpose-built one, and hardware timestamping is retried on every message rather than being disabled.-Husage text now documents that, with-2, it requires hardware RX and TX timestamp support from the interface.Impact
ptpd -2 -Hdecides between hardware and software timestamping (capability query instead of runtime detection), and how a hardware TX timestamp failure is reported.ptpd -2 -Hon an interface whose driver does not declare bothNETDEV_RX_STAMPandNETDEV_TX_STAMPnow exits immediately with an error message instead of running silently in software timestamp mode after a few failed attempts. UDP transports (-4/-6, the default) and-Sare unaffected.ptpdis a userspace daemon; the driver-side capability declaration is in the companion net: add NETDEV_TX_STAMP capability flag and SIOCGIFTSCAPS query ioctl nuttx#20346 PR.-Husage text insystem/ptpdnow states the capability requirement with-2.ptpd -2 -Hmust enable both hardware RX and TX timestamping in their Ethernet driver (e.g.CONFIG_STM32_ETH_TIMESTAMP_RX=yandCONFIG_STM32_ETH_TIMESTAMP_TX=y).Testing
I confirm that changes are verified on local setup and works as intended:
sim).simtarget for the refusal-path check below.CONFIG_STM32_ETH_TIMESTAMP_RX=y,CONFIG_STM32_ETH_TIMESTAMP_TX=y), companion driver change in net: add NETDEV_TX_STAMP capability flag and SIOCGIFTSCAPS query ioctl nuttx#20346.CONFIG_STM32_ETH_TIMESTAMP_RX=y,CONFIG_STM32_ETH_TIMESTAMP_TX=y), companion driver change in net: add NETDEV_TX_STAMP capability flag and SIOCGIFTSCAPS query ioctl nuttx#20346.Build log (STM32H7 board, after change):
Runtime log,
ptpd -s -2 -H -B -P -i eth0 -p /dev/ptp0started on the STM32H7 board with the current revision of this PR (bothNETDEV_RX_STAMPandNETDEV_TX_STAMPreported), status query (ptpd -t <pid>) taken 130 s after start - the daemon started without the refusal error andclock_source_validis1(it would drop to0on a hardware TX timestamp failure):Runtime log, STM32F1/F3/F4 board (
dmesgexcerpt, taken on the previous revision of this PR that only checked TX), full PTP P2P exchange, hardware TX timestamp used throughout, no fallback):Refusal path,
ptpd -2 -H -i eth0on an interface that does not declare the capabilities (simtarget, host build,eth0is the sim's virtual network device, which does not implementNETDEV_RX_STAMP/NETDEV_TX_STAMP;CONFIG_DEBUG_PTP_ERROR=y):Same refusal on the STM32H7 board built without
CONFIG_STM32_ETH_TIMESTAMP_TXand without PTP debug output (ptperrcompiled out),ptpdstill exits:10-minute soak against the Grandmaster (STM32H7 board): 0 ping failures over 19 samples at 30s intervals,
clock_source_validstayed1throughout,path_delay_nsstable between 9381-9395 ns.PR verification Self-Check