Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket reading and timestamps

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:

  • It is another syscall (I'm receiving about 24000 messages per second, so each syscall is notifiable)
  • If using this approach, I can only 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".

like image 499
pmf Avatar asked Nov 09 '12 08:11

pmf


People also ask

What is hardware timestamp?

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.

How do I enable hardware timestamp in Linux?

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.

What is Sol_socket Python?

SOL_SOCKET is the socket layer itself. It is used for options that are protocol independent.


1 Answers

Use recvmmsg(2) system call, if available with your kernel, and set SO_TIMESTAMP option.

like image 132
Nikolai Fetissov Avatar answered Sep 17 '22 22:09

Nikolai Fetissov