Re: strange ping response times...

From: Luigi Rizzo <rizzo_at_iet.unipi.it>
Date: Thu, 12 Apr 2012 09:54:30 +0200
On Thu, Apr 12, 2012 at 01:18:59PM +1000, Bruce Evans wrote:
> On Wed, 11 Apr 2012, Luigi Rizzo wrote:
> 
> >On Wed, Apr 11, 2012 at 02:16:49PM +0200, Andre Oppermann wrote:
...
> >ping takes a timestamp in userspace before trying to transmit
> >the packet, and then the timestamp for the received packet
> >is recorded in the kernel (in the interrupt or netisr thread
> >i believe -- anyways, not in userspace).
> 
> No, all timestamps recorded used by ping are recorded in userland.

Bruce, look at the code in ping.c -- SO_TIMESTAMP is defined,
so the program does (successfully) a

	setsockopt(s, SOL_SOCKET, SO_TIMESTAMP, &on, sizeof(on));

and then (verified that at runtime the code follows this path)

	struct cmsghdr *cmsg = (struct cmsghdr *)&ctrl;
	msg.msg_controllen = sizeof(ctrl);
	msg.msg_namelen = sizeof(from);
	if ((cc = recvmsg(s, &msg, 0)) < 0) {
		if (errno == EINTR)
			continue;
		warn("recvmsg");
		continue;
	}
	if (cmsg->cmsg_level == SOL_SOCKET &&
	    cmsg->cmsg_type == SCM_TIMESTAMP &&
	    cmsg->cmsg_len == CMSG_LEN(sizeof *tv)) {
		/* Copy to avoid alignment problems: */
		memcpy(&now, CMSG_DATA(cmsg), sizeof(now));
		tv = &now;
	}

...

> My normal ping -fq localhost RTT is 2-3 usec
>     (closer to 3; another bug in this area is that the timestamps only
>     have microseconds resolution so you can't see if 3 is actually
>     more like 2.5.  I was thinking of changing the resolution to
>     nanoseconds 8-10 years ago, before the FreeBSD-5 pessimizations
>     and CPU speeds hitting a wall made this not really necessary),
> but the kernel I'm testing with uses ipfw which bloats the RTT to 8-9

ipfw overhead obviously depends on your firewall configuration,
i have tested without ipfw to remove that noise.

cheers
luigi
Received on Thu Apr 12 2012 - 05:35:17 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:25 UTC