Skip to content

Conversation

@Donny9
Copy link
Contributor

@Donny9 Donny9 commented Dec 15, 2025

Summary

This patch series brings comprehensive PTP (Precision Time Protocol) daemon
support to NuttX, implementing a complete IEEE 1588 PTPv2 stack with the
following key enhancements:

  1. Core Infrastructure (dc94b24, 32ef6dc):

    • Added CMake build system support for ptpd
    • Fixed structure byte alignment for cross-core communication compatibility
  2. Debug and Logging (5aecb30):

    • Migrated from custom NETUTILS_PTPD_DEBUG to standard DEBUG_PTP_* macros
    • Integrated with NuttX PTP clock device debug framework
  3. Task Management Redesign (e2737dd, 09420b3):

    • Replaced separate task creation with main task execution model
    • Unified command interface: ptpd -i eth0 & for start, ptpd -d pid for stop
    • Introduced struct ptpd_config_s for dynamic configuration
    • Enables background execution with proper lifecycle management
  4. Hardware Timestamping Support (0985006, d5713d2):

    • Runtime-configurable hardware timestamp via hardware_ts flag
    • Replaced CONFIG_NET_TIMESTAMP with dynamic configuration
    • Enhanced precision using SO_TIMESTAMPNS for nanosecond timestamps
  5. PTP Clock Device Integration (71598b6, 10b7258, 757744a):

    • Added NET_PKT dependency for PTP clock device support
    • Implemented clock_adjtime() support for PTP hardware clocks via CLOCKFD
    • Added CONFIG_NETUTILS_PTPD_ADJTIME_THRESHOLD_NS for accelerated adjustment
    • Optimized time adjustment convergence speed
  6. BMCA and Clock Selection (3b20797, 3cab597):

    • Fixed missing comparisons in is_better_clock() for BMCA compliance
    • Added semaphore cleanup in ptpd_status() to prevent resource leaks
  7. Transport Layer (ebd885e, 8f8bc63):

    • Implemented PTP Ethernet transport (Layer 2) via raw socket support
    • Added -B option to control BMCA (Best Master Clock Algorithm) messages
  8. Configuration Flexibility (32b4ef4):

    • Dynamic runtime configuration for client-only and delay-e2e modes
    • Removed compile-time Kconfig restrictions (PTPD_CLIENT/PTPD_SERVER)
    • Fixed compilation warnings when enabling subset configurations
  9. gPTP Switch Support (f61389e):

    • Added path delay correction field support for gPTP-aware switches
    • Enables accurate time synchronization in switched network topologies

The series transforms ptpd from a basic proof-of-concept into a production-ready
PTP daemon with hardware timestamp support, flexible transport options, and full
integration with NuttX PTP clock framework.

Impact

Users:

  • New command-line interface requires updating ptpd invocation scripts
  • Old: ptpd start eth0 &, New: ptpd -i eth0 &
  • Background execution now mandatory using '&' operator
  • Client-only and delay mode now configured at runtime, not compile-time

Build System:

  • CMake support added alongside Make build system
  • New Kconfig dependencies: requires NET_PKT when using PTP clock devices
  • Removed several Kconfig options in favor of runtime configuration

Hardware Requirements:

  • Hardware timestamping now supported but optional (fallback to software)
  • PTP clock device (/dev/ptp*) integration requires CONFIG_PTP_CLOCK
  • Network drivers should implement SO_TIMESTAMPNS for best accuracy

Configuration:

  • CONFIG_NETUTILS_PTPD_ADJTIME_THRESHOLD_NS controls adjustment speed
  • BMCA behavior controlled via -B command-line option
  • Transport type (UDP/Ethernet) selected automatically based on capabilities

Compatibility:

  • Breaking: Command-line interface changed
  • Breaking: Some Kconfig options removed
  • Forward: Maintains IEEE 1588-2008 PTPv2 protocol compatibility
  • Enhanced: Better interoperability with gPTP switches

Documentation:

  • New command syntax requires documentation updates
  • PTP clock device integration needs cross-reference to driver docs

Security:

  • Raw socket support (Ethernet transport) requires appropriate permissions
  • No authentication mechanisms added (per IEEE 1588 standard)

Testing

ptp sync base on tricore tc4 platform:
Initial synchronization error: ±50 μs, converging to ±2.5 μs within 3 seconds.

image

Donny9 and others added 16 commits December 15, 2025 15:44
support cmake build

Signed-off-by: dongjiuzhu1 <[email protected]>
pass structure between remote and local core

Signed-off-by: dongjiuzhu1 <[email protected]>
…_DEBUG

using new ptp clock device debug function

Signed-off-by: dongjiuzhu1 <[email protected]>
new starting command:
ptpd start interface &

we should run it in background ways

Signed-off-by: dongjiuzhu1 <[email protected]>
…ting ptpd

origin command change to new command:
ptpd start interface & -> ptpd -i eth0 &
ptpd stop pid          -> ptpd -d pid
ptpd status pid        -> ptpd -t status

Signed-off-by: dongjiuzhu1 <[email protected]>
runtime to config the ways of timestamp

Signed-off-by: dongjiuzhu1 <[email protected]>
…ecision

using nanoseconds as timestamp

Signed-off-by: dongjiuzhu1 <[email protected]>
fix minor issue

Signed-off-by: Xiang Xiao <[email protected]>
Signed-off-by: dongjiuzhu1 <[email protected]>
…aye2e

fix compile warning when only enable PTPD_CLIENT or PTPD_SERVER

ptpd.c:493:38: error: 'CONFIG_NETUTILS_PTPD_PRIORITY1' undeclared (first
use in this function); did you mean 'CONFIG_NETUTILS_PTPD_CLIENT'?

ptpd.c:494:39: error: 'CONFIG_NETUTILS_PTPD_CLASS' undeclared (first use
in this function); did you mean 'CONFIG_NETUTILS_PTPD_CLIENT'?

ptpd.c:495:39: error: 'CONFIG_NETUTILS_PTPD_ACCURACY' undeclared (first
use in this function); did you mean 'CONFIG_NETUTILS_PTPD_DEBUG'?
ptpd.c:498:38: error: 'CONFIG_NETUTILS_PTPD_PRIORITY2' undeclared (first
use in this function); did you mean 'CONFIG_NETUTILS_PTPD_CLIENT'?

ptpd.c:502:36: error: 'CONFIG_NETUTILS_PTPD_CLOCKSOURCE' undeclared
(first use in this function); did you mean
'CONFIG_NETUTILS_PTPD_STACKSIZE'?

Signed-off-by: dongjiuzhu1 <[email protected]>
support ptp clock deivce to adjust time

Signed-off-by: dongjiuzhu1 <[email protected]>
…djustment

optimize the speed of adjustment

Signed-off-by: dongjiuzhu1 <[email protected]>
support ptp clock device

Signed-off-by: dongjiuzhu1 <[email protected]>
support ptp by rawsocket

Signed-off-by: dongjiuzhu1 <[email protected]>
new option -B to BMCA message

Signed-off-by: dongjiuzhu1 <[email protected]>
The current gPTP stack does not support path delay correction of the Switch.
The path delay correction field in the Head is added.

Signed-off-by: dongjiuzhu1 <[email protected]>
@simbit18
Copy link
Contributor

@Donny9 Can you please provide simple update to documentation too ?

https://nuttx.apache.org/docs/latest/applications/system/ptpd/index.html

@acassis
Copy link
Contributor

acassis commented Dec 15, 2025

@Donny9 beside the PTP documentation I think it should be nice to have a documenation about the ptpd with the details you included here, including this graphics to show the time to syncronize

Copy link
Contributor

@cederom cederom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Donny9 very nice update and very nice PR description! CI caught some things to update :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants