New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
udp: Add support for SO_TIMESTAMP #11210
Conversation
/* Store reception timestamp if enabled and not provided by hardware. */ | ||
|
||
#if defined(CONFIG_NET_TIMESTAMP) && !defined(CONFIG_ARCH_HAVE_NETDEV_TIMESTAMP) | ||
clock_gettime(CLOCK_REALTIME, &dev->d_rxtime); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's create a new patch to update socketcan to allow the net can driver return timestamp too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SocketCAN does something similar here but I'm unfamiliar with CAN and have no way to test it, so I cannot help in updating it.
*/ | ||
|
||
offset = (dev->d_appdata - iob->io_data) - iob->io_offset; | ||
|
||
#ifdef CONFIG_NET_TIMESTAMP | ||
/* Store timestamp while packet is being queued. | ||
* This is done unconditionally to avoid race condition when SO_TIMESTAMP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we make the similar change to can socket?
Adds support for timestamping received UDP packets, either in hardware or in kernel. Builds on the existing support of SO_TIMESTAMP for SocketCAN. Implementation uses CLOCK_REALTIME for timestamping to match the behavior of Linux. This could be made configurable in future if needed.
f2af9cf
to
9fad832
Compare
Summary
Adds support for timestamping received UDP packets, either in hardware or in kernel. Builds on the existing support of
SO_TIMESTAMP
for SocketCAN.Implementation uses
CLOCK_REALTIME
for timestamping to match the behavior of Linux. This could be made configurable in future if needed.Impact
When
CONFIG_NET_TIMESTAMP
is enabled,setsockopt(..., SO_TIMESTAMP)
can be used to enable timestamping.Software timestamping is supported on all platforms. This already removes any queuing latency, but threads with higher priority than network processing can delay timestamping.
Platforms where hardware support exists can define
ARCH_HAVE_NETDEV_TIMESTAMP
and store the timestamp tod_rxtime
before callingipv4_input
/ipv6_input
.Testing
Tested on custom STM32F4 board with a ptpd version that has SO_TIMESTAMP support. I'll submit a pull request of that to nuttx-apps once I have cleaned it up.