Java – Is it possible to detect the time difference between the moment the kernel generates an epoll and the moment the Sun JVM reads it?

Is it possible to detect the time difference between the moment the kernel generates an epoll and the moment the Sun JVM reads it?… here is a solution to the problem.

Is it possible to detect the time difference between the moment the kernel generates an epoll and the moment the Sun JVM reads it?

i.e. time A = voltage hits the NIC; Time B = The selector from the Java NIO package is able to select the socket channel for I/O.

Solution

Use SO_TIMESTAMP and find one that actually supports timestamping and one that supports timestamps with a resolution better than milliseconds. Then you should have a chance, if you can get Java to read incoming cmsg auxiliary data.

Without good hardware support, packets will be marked by the kernel as a low-resolution unstable timer.

(Edit #1) C sample code I think 2.6.30 or newer kernel is needed:

http://www.mjmwired.net/kernel/Documentation/networking/timestamping/timestamping.c

(Edit #2) Sample code for determining kernel-to-user space latency in C:

http://vilimpoc.org/research/ku-latency/

(Edit #3) I recommend following the J-OWAMP project, which relies on high-resolution timers and packet delay testing. The OWAMP team has been plugging in Linux kernels for better SO_TIMESTAMP support.

http://www.av.it.pt/jowamp/

Related Problems and Solutions