neturils/ptpd: various improvements - #3789
Merged
Merged
Conversation
Author
|
@xiaoxiang781216 @daniel-p-carvalho please review this pr |
xiaoxiang781216
approved these changes
Sep 17, 2026
Contributor
|
Hi @wenquan2015, thanks for tagging! The changes look great — moving the IGMP join after Just a heads up regarding PR #3782: it adds P2P delay support, which introduces the P2P multicast join ( Whichever PR is merged first, the rebase will be trivial to align both (placing the P2P join in your new post- LGTM! |
added 2 commits
September 18, 2026 10:19
The IGMP multicast join (ipmsfilter) was previously called before the interface address (interface_addr) was populated via SIOCGIFADDR. This meant the IGMP join had to locate the network device without a valid local address, which could fail or join on the wrong interface. Move the multicast group subscription to after the interface address is queried, and guard it with an AF_INET check since IGMP only applies to IPv4. This ensures the IGMP join can always locate the correct network device. Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
Replace the sigqueue + shared-memory IPC mechanism in ptpd_status()
with a file-based approach:
- Daemon side: on SIGUSR1, write a binary ptpd_status_s struct to
a temp file and atomically rename it to the status path.
- Client side: send kill(SIGUSR1), poll for the file to appear,
then read the struct back.
This removes the CONFIG_BUILD_FLAT restriction (the old code returned
-ENOTSUP for Protected and Kernel builds) and avoids passing pointers
across address spaces via sigqueue. The status file path is
configurable via NETUTILS_PTPD_STATUSFILE (default /tmp/ptpd.status).
The atomic temp + rename pattern ensures readers never see a partial
write.
Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
wenquan2015
force-pushed
the
ptpd-improvements
branch
from
September 18, 2026 02:19
71d83fd to
0dd9ae9
Compare
jerpelea
approved these changes
Sep 18, 2026
daniel-p-carvalho
added a commit
to daniel-p-carvalho/nuttx-apps
that referenced
this pull request
Sep 18, 2026
…tus() PR apache#3789 replaced the in-memory sigqueue + shared memory IPC in ptpd_status() with file-based IPC to support Protected and Kernel modes across address spaces. However, on microcontrollers running CONFIG_BUILD_FLAT, a filesystem or /tmp (TMPFS) is rarely mounted or available, causing ptpd_status() to fail with -ETIMEDOUT (errno 110) because the status file cannot be created. Retain the file-based IPC for !CONFIG_BUILD_FLAT (Protected and Kernel modes) while restoring the zero-overhead in-memory sigqueue + semaphore IPC for CONFIG_BUILD_FLAT. Both modes share the status serialization logic via ptp_populate_status() and support all fields including P2P. Assisted-by: Gemini:gemini-3.8-flash-medium Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
daniel-p-carvalho
added a commit
to daniel-p-carvalho/nuttx-apps
that referenced
this pull request
Sep 20, 2026
…tus() PR apache#3789 replaced the in-memory sigqueue + shared memory IPC in ptpd_status() with file-based IPC to support Protected and Kernel modes across address spaces. However, on microcontrollers running CONFIG_BUILD_FLAT, a filesystem or /tmp (TMPFS) is rarely mounted or available, causing ptpd_status() to fail with -ETIMEDOUT (errno 110) because the status file cannot be created. Retain the file-based IPC for !CONFIG_BUILD_FLAT (Protected and Kernel modes) while restoring the zero-overhead in-memory sigqueue + semaphore IPC for CONFIG_BUILD_FLAT. Both modes share the status serialization logic via ptp_populate_status() and support all fields including P2P. Assisted-by: Gemini:gemini-3.8-flash-medium Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
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
Replace the
sigqueue+ shared-memory IPC mechanism inptpd_status()with a file-based approach that works across allNuttX build modes (Flat, Protected, Kernel).
The old implementation passed a pointer to caller-owned memory via
sigqueue(SIGUSR1, sival_ptr), which only works inCONFIG_BUILD_FLATand returned
-ENOTSUPfor Protected/Kernel builds. The new approach:SIGUSR1, writes theptpd_status_sstruct toa temp file and atomically renames it to the status path. The
dumpflag is a simpleboolchecked in the main loop.ptpd_status()): deletes any stale status file,sends
kill(pid, SIGUSR1), polls for the file to appear (up to 3s),reads the struct back.
The atomic temp + rename pattern ensures readers never see a partial
write. The status file path is configurable via a new Kconfig option
NETUTILS_PTPD_STATUSFILE(default/tmp/ptpd.status).ptpd_status()— remove#ifdef CONFIG_BUILD_FLATguardNETUTILS_PTPD_STATUSFILEstring config to Kconfig#include <sys/stat.h>forO_CREATmode bitsImpact
ptpd_status()now works in Protected and Kernel builds (previouslyreturned
-ENOTSUP)./tmp/ptpd.status) is created on demand whenSIGUSR1is received; it does not exist unless status is queried.ptpd_status(int pid, struct ptpd_status_s *)are unaffected.NETUTILS_PTPD_STATUSFILE(string, default/tmp/ptpd.status).Testing
Build:
sim:tcpblasterwithCONFIG_NET_IGMP=y,CONFIG_NETUTILS_PTPD=y,CONFIG_PTP_CLOCK=y,CONFIG_CLOCK_ADJTIME=yadded.Host: Linux x86_64, GCC.
Runtime verification on NuttX sim — status query via file IPC:
nsh> ifup eth0
ifup eth0...OK
nsh> ptpd -S -i eth0 &
ptpd [10:100]
nsh> ptpd -t 10
PTPD (PID 10) status:
nsh> ptpd -d 10
Stopped ptpd
ptpd -t 10successfully retrieves daemon status through the newSIGUSR1 → status-file → read-back path. The daemon writes
/tmp/ptpd.statusatomically; the client detects it within one pollcycle (~100ms).