When reading from a (non-stream) socket in Linux, I can get the (hardware-generated) timestamp of the last received message via a ioctl(sock, SIOCGSTAMP, &tv)
. However, this poses two problems:
read()
one message at a time, followed by the ioctl()
to get the timestamp. (If I'm reading more than one message in a read()
-call, the following ioctl
only yields the timestamp of the last message.)My question is how to achieve receiving messages and their timestamps in as few syscalls as possible. It would be perfect if there was a syscall with semantics like "read as much messages as are pending and their timestamps".
Hardware timestamping is implemented with hardware TSUs timed by clock signals generated by PHCs. The hardware TSUs are often integrated with PHYs and MACs for proximity to the physical layer. The logical PHC and TSU functions can be implemented in a single silicon device or they can be implemented in separate devices.
You need to explicitly tell the Linux to enable the hardware timestamping feature of your NIC. In order to to that, you need to have a ioctl() call. What you have to do is to call it with SIOCSHWTSTAMP , which is a device request code to indicate which device you want to handle as well as what you want to do.
SOL_SOCKET is the socket layer itself. It is used for options that are protocol independent.
Use recvmmsg(2)
system call, if available with your kernel, and set SO_TIMESTAMP
option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With