Skip to content
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

Merged
merged 1 commit into from Nov 18, 2023

Conversation

PetteriAimonen
Copy link
Contributor

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 to d_rxtime before calling ipv4_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.

net/udp/udp_recvfrom.c Outdated Show resolved Hide resolved
/* 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);
Copy link
Contributor

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

Copy link
Contributor Author

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.

net/udp/udp.h Outdated Show resolved Hide resolved
net/udp/udp_callback.c Outdated Show resolved Hide resolved
*/

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
Copy link
Contributor

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.
@xiaoxiang781216 xiaoxiang781216 merged commit cb16194 into apache:master Nov 18, 2023
26 checks passed
@jerpelea jerpelea added this to To-Add in Release Notes - 12.4.0 Dec 27, 2023
@jerpelea jerpelea moved this from To-Add to Net in Release Notes - 12.4.0 Jan 8, 2024
@jerpelea jerpelea moved this from Net to processed in Release Notes - 12.4.0 Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants