All of lore.kernel.org
 help / color / mirror / Atom feed
* CLOCK_MONOTONIC datagram timestamps by the kernel
@ 2007-02-25 21:29 John
  2007-02-26 10:26 ` John
  0 siblings, 1 reply; 22+ messages in thread
From: John @ 2007-02-25 21:29 UTC (permalink / raw)
  To: linux-kernel; +Cc: johnstul, mingo, zippel, tglx, linux.kernel, akpm

Hello,

It is possible to ask Linux to timestamp incoming datagrams when they
are received, then to retrieve this timestamp with an ioctl command or
a recvmsg call (which would save one round trip to kernel space).

SIOCGSTAMP
     Return a struct timeval with the receive timestamp of the last
packet passed to the user. This is useful for accurate round trip time
measurements. See setitimer(2) for a description of struct timeval.

As far as I understand, this timestamp is given by the CLOCK_REALTIME
clock. I would like to get the timestamp given by a different clock: the
CLOCK_MONOTONIC clock.

In other words, I would like the kernel to do the equivalent of

   struct timespec spec;
   clock_gettime(CLOCK_MONOTONIC, &spec)

for each datagram the system receives, as soon as it is received.

Is there a way to achieve that?

Is there a different ioctl perhaps? (I don't think so.)

Regards.

^ permalink raw reply	[flat|nested] 22+ messages in thread
* CLOCK_MONOTONIC datagram timestamps by the kernel
@ 2007-02-28 10:18 John
  2007-02-28 13:37 ` John
  0 siblings, 1 reply; 22+ messages in thread
From: John @ 2007-02-28 10:18 UTC (permalink / raw)
  To: linux-net; +Cc: netdev, linux.kernel

Hello,

I know it's possible to have Linux timestamp incoming datagrams as soon 
as they are received, then for one to retrieve this timestamp later with 
an ioctl command or a recvmsg call.

As far as I understand, one can either do

   const int on = 1;
   setsockopt(sock, SOL_SOCKET, SO_TIMESTAMP, &on, sizeof on);

then use recvmsg()

or not set the SO_TIMESTAMP socket option and just call

   ioctl(sock, SIOCGSTAMP, &tv);

after each datagram has been received.

SIOCGSTAMP
     Return a struct timeval with the receive timestamp of the last
packet passed to the user. This is useful for accurate round trip time
measurements. See setitimer(2) for a description of struct timeval.


As far as I understand, this timestamp is given by the CLOCK_REALTIME 
clock. However, I would like to obtain a timestamp given by the 
CLOCK_MONOTONIC clock.

Relevant parts of the code (I think):

net/core/dev.c

void net_enable_timestamp(void)
{
   atomic_inc(&netstamp_needed);
}

void __net_timestamp(struct sk_buff *skb)
{
   struct timeval tv;

   do_gettimeofday(&tv);
   skb_set_timestamp(skb, &tv);
}

static inline void net_timestamp(struct sk_buff *skb)
{
   if (atomic_read(&netstamp_needed))
     __net_timestamp(skb);
   else {
     skb->tstamp.off_sec = 0;
     skb->tstamp.off_usec = 0;
   }
}

do_gettimeofday() just calls __get_realtime_clock_ts()

Would it be possible to replace do_gettimeofday() by ktime_get_ts() with 
the appropriate division by 1000 to convert the struct timespec back 
into a struct timeval?

void __net_timestamp(struct sk_buff *skb)
{
   struct timespec now;
   struct timeval tv;

   ktime_get_ts(&ts);
   tv.tv_sec = now.tv_sec;
   tv->tv_usec = now.tv_nsec/1000;
   skb_set_timestamp(skb, &tv);
}

How many apps / drivers would this break?

Is there perhaps a different way to achieve this?

Regards.


^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2007-03-02 10:11 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-25 21:29 CLOCK_MONOTONIC datagram timestamps by the kernel John
2007-02-26 10:26 ` John
2007-02-26 12:20   ` Andi Kleen
2007-02-26 14:17     ` John
2007-02-28 11:23       ` John
2007-02-28 10:18 John
2007-02-28 13:37 ` John
2007-02-28 13:55   ` Eric Dumazet
2007-02-28 14:23     ` John
2007-02-28 14:55       ` Eric Dumazet
2007-02-28 16:07         ` John
2007-03-01 10:03           ` Evgeniy Polyakov
2007-03-01 11:30           ` Eric Dumazet
2007-03-01 15:54             ` Stephen Hemminger
2007-03-01 16:13               ` Eric Dumazet
2007-03-01 18:53             ` Stephen Hemminger
2007-03-01 23:14               ` Eric Dumazet
2007-03-01 23:34                 ` Stephen Hemminger
2007-03-02  0:56                   ` Eric Dumazet
2007-03-02  9:26             ` John
2007-03-02 10:11               ` Eric Dumazet
2007-02-28 18:22   ` Stephen Hemminger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.