receiving UDP packets - where does the latency come from?
Hi network experts,
I have a microcontroller sending a 500 bytes UDP packet every millisecond to my PC (direct cable connection, no other device or software on the dedicated eth2 interface). With tcpdump I see the packets arriving with latencies (time between two packets) of 1000µs (+/- 11µs) - this is what I want. BUT, my C program sees latencies between 10µs and 3500µs (when executed as a user). When I run it as root with "nice -n -20" the latencies get better - between 10µs and 2000µs, but still not good. Most of the measured latencies are still around 1000µs, but there are packets that arrive with a hefty delay. If that delayed packet is received, my program receives immediately (10µs) the next packet. So, what is the reason for the delay of the packets? I expected it to be the Linux scheduler, but with "nice -n -20" I hoped it would be nicer to me. Any idea how to get rid of the delay? The program uses blocking I/O recvfrom() to receive the UDP packet. The machine is a 2x dual core Opteron running 2.6.34-gentoo-r6-cs x86_64 Cheers, mibo |
I doubt the networking system is designed to send packets 1/ms.
|
An example of how Linux is not a real-time OS. For that matter, neither TCP/IP or ethernet are deterministic. If you need hard real-time, consider an OS that is built for it, such as vxWorks.
--- rod. |
tcpdump uses packet_mmap interface. Try that out with a realtime priority+scheduler config. Also, you should make sure that your system doesn't have the NO_HZ option enabled.
|
Thank you very much for the hints.
Especially thank you orgcandman. packet_mmap seems to be exactly the key word I was looking for. Changing the operating system is no option because there is already running some special real-time stuff on other cpu cores (there are digital control loops with response times well below 10µs - the code is locked to it's own cpu core and "shut down" for the Linux system). I can't do this for the UDP packet receiving code because I want to use sockets and other kernel functionality. All the best, mibo |
The worst latency for the packets went down from 1000µs to 500µs by setting my process to real-time scheduling priority using the code below.
But, I don't understand the PF_PACKET raw packet sending/receiving - that I need for packet_mmap :-( I will open a new thread for this. Thanks for your help, mibo Code:
// set process to highest priority |
All times are GMT -5. The time now is 09:31 AM. |