Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Linux - Kernel This forum is for all discussion relating to the Linux kernel.


  Search this Thread
Old 06-14-2018, 07:56 AM   #1
Poison Nuke
Registered: Aug 2012
Location: Germany
Posts: 40

Rep: Reputation: Disabled
how to measure kernel to udp time?


I have integrated a simple udp sender into a touch-driver, to receive every touch-event on another computer inside a Unity application. With nothing else to render at 600fps I have a end to end latency of 80-100 milliseconds (counted frames between visible touchdown and reaction on screen).

I want to narrow down the source of this extrem high latency. So first step is the time between touchdown - kernel-module - udp stack and finally the electrical signal on the LAN.

Any suggestions, how to measure any part of this?
Old 06-14-2018, 05:52 PM   #2
Senior Member
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 & 7
Posts: 3,046

Rep: Reputation: 813Reputation: 813Reputation: 813Reputation: 813Reputation: 813Reputation: 813Reputation: 813
You can measure the network stack <-> wire <-> network stack with ping. For two computers going through a single router I get a small number:

PING ( 56(84) bytes of data.
64 bytes from icmp_seq=1 ttl=63 time=0.178 ms
64 bytes from icmp_seq=2 ttl=63 time=0.300 ms
64 bytes from icmp_seq=3 ttl=63 time=0.331 ms
64 bytes from icmp_seq=4 ttl=63 time=0.293 ms
Maybe the sending end is buffering the input to reduce the number of packets going over the wire. Call fflush to make sure that the write buffer is emptied and passed to UDP.
Old 06-15-2018, 09:38 AM   #3
Poison Nuke
Registered: Aug 2012
Location: Germany
Posts: 40

Original Poster
Rep: Reputation: Disabled
both computers are wired directly, so microsecond delay between the PHYs. I have now written a small Python script, which sends UDP packets to my application and I create an UDP answer inside the app and measure the time with Python. That way around I was able to measure the latency of both network stacks up to layer 7. Interestingly, the measured times, with 2000 sent packets, look like that:
Average receive: 0.00431398940086
95 percentile: 0.00771732330322
min: 0.00134086608887 max: 0.0193440914154
which is a 10 to 20-fold difference to the camera based measurement.

Im trying to implement a UDP server into the kernel-module, to see if there is a difference (I hope the timestamps of dmesg are precise enough, otherwise I would need to implement a multi-thread timing). But I have some issues with that and will create a new thread with some code-related problems.

I was looking for fflush, but looks like it is not meant for something like that? There is no stream open at all. Im using raw kernel-sockets. And looking into wireshark, all packets have constant time-gap.
Old 06-25-2018, 04:42 PM   #4
Registered: Apr 2016
Posts: 382

Rep: Reputation: Disabled
yes. i would say your first step is not hacking the kernel. don't even bother looking in /sys or /proc

assume the kernel IS NOT LATENT. then assume you do not have a graphical topological tool showing your TCP/IP stack and hw to application delivery mechanisms (which layered protocol ipv6 can breach but ipv4 cannot), and that local delivery is also not the latency issue. (the stack goes from hardware buffer all the way to card, but these days might have a usb pass-through or feature detour like bridge)

traceroute(1) was the "nice cisco router IPV4" old tool for doing this. there are replacements for it renamed, which depend on your 'nix - and there may be a few choices to choose from. routers like hanging up on traceroute(1) these days without answering. ipv6 tools may give you route-route-router timings.

of course: UDP may not flow like TCP (udp is a different flow and time purpose as you know), and i doubt there is a tool for udp specifically.

Last edited by X-LFS-2010; 06-25-2018 at 04:46 PM.
Old 06-25-2018, 05:28 PM   #5
Poison Nuke
Registered: Aug 2012
Location: Germany
Posts: 40

Original Poster
Rep: Reputation: Disabled
I doubt too, that there is anything with kernel or some sort of write-buffer. But still, 80-100ms latency from touching the surface of the touchpad to the output of the screen are really long.

I do know, that the monitor has a total input lag of 12 to 20 ms. Togehter with total processing and network time this results in something around 25ms.

Two parts of the route are unkown:
- cpu to gpu to monitor time (I doubt that this will be more than a few microseconds)
- touchpad to kernel time (dont know how to measure this, tried a comparison against latency of ps/2 keyboard to local screen, but resulted only in less than 10ms difference (I have only 30fps camera in the moment, so measurement of latency is only possible down to 7-10ms depending on shutter-speed, but is enough for my case).


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to measure kernel space time and user space time in linux bhas.bhaskar Linux - Newbie 1 11-28-2010 12:01 PM
How to Measure Time to execute a function in Kernel space barunparichha Linux - Software 4 01-07-2008 12:48 PM
how to measure execution time in kernel space? didio Linux - Kernel 1 10-08-2007 11:01 PM
LXer: Measure Time in Linux with Time Base LXer Syndicated Linux News 0 04-11-2007 07:46 AM
RFC 868 udp 37 time-udp gpl SUSE / openSUSE 2 03-31-2005 11:07 AM > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 08:27 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration