PTPd Service Enhancement: Supports Ethernet Synchronization / Logic Optimization / Alignment with Linux PTPv4 Options
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:
-
Core Infrastructure (dc94b2418a, 32ef6dc612):
- Added CMake build system support for ptpd
- Fixed structure byte alignment for cross-core communication compatibility
-
Debug and Logging (5aecb30da3):
- Migrated from custom NETUTILS_PTPD_DEBUG to standard DEBUG_PTP_* macros
- Integrated with NuttX PTP clock device debug framework
-
Task Management Redesign (e2737dd6f1, 09420b3f46):
- Replaced separate task creation with main task execution model
- Unified command interface:
ptpd -i eth0 &for start,ptpd -d pidfor stop - Introduced struct ptpd_config_s for dynamic configuration
- Enables background execution with proper lifecycle management
-
Hardware Timestamping Support (0985006e26, d5713d2494):
- Runtime-configurable hardware timestamp via hardware_ts flag
- Replaced CONFIG_NET_TIMESTAMP with dynamic configuration
- Enhanced precision using SO_TIMESTAMPNS for nanosecond timestamps
-
PTP Clock Device Integration (71598b6f5d, 10b7258a14, 757744add4):
- 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
-
BMCA and Clock Selection (3b20797945, 3cab597f01):
- Fixed missing comparisons in is_better_clock() for BMCA compliance
- Added semaphore cleanup in ptpd_status() to prevent resource leaks
-
Transport Layer (ebd885e1dd, 8f8bc63769):
- Implemented PTP Ethernet transport (Layer 2) via raw socket support
- Added -B option to control BMCA (Best Master Clock Algorithm) messages
-
Configuration Flexibility (32b4ef4dc5):
- 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
-
gPTP Switch Support (f61389ed64):
- 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.