diff --git a/gtests/net/packetdrill/packet_socket_linux.c b/gtests/net/packetdrill/packet_socket_linux.c index 95e852bdf23158cf0bf8a74fdb3cced05e735f72..8abf10666bc4422ab32e4c63cbb5489dcc5a249b 100644 --- a/gtests/net/packetdrill/packet_socket_linux.c +++ b/gtests/net/packetdrill/packet_socket_linux.c @@ -80,6 +80,8 @@ static void bind_to_interface(int fd, int interface_index) */ static void packet_socket_setup(struct packet_socket *psock) { + struct timeval tv; + psock->packet_fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); if (psock->packet_fd < 0) die_perror("socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))"); @@ -92,6 +94,12 @@ static void packet_socket_setup(struct packet_socket *psock) bind_to_interface(psock->packet_fd, psock->index); set_receive_buffer_size(psock->packet_fd, PACKET_SOCKET_RCVBUF_BYTES); + + + /* Pay the non-trivial latency cost to enable timestamps now, before + * the test starts, to avoid significant delays in the middle of tests. + */ + ioctl(psock->packet_fd, SIOCGSTAMP, &tv); } /* Add a filter so we only sniff packets we want. */