0

I am wokring on a project which requires the process to send a TCP/IP data frame via NIC periodically with high time auccuracy --> 1ms cycle time, with a tolerance of 50us(actually, the lower, the better). The application runs on a Linux machine (Ubuntu 20.04 is the distribution we now use). The programming language of our application is C++. So how could I develop an application with such feature?

Some concerning quesiton I can think of right now:

  1. Should I choose a Real-time system? If so, what system would a good choice considering all factors, like cost, stablitity and community activity.

  2. Should I choose some specific hardware to ensure the time accuracy? If so, how should I choose a proper machine. (I am not a hardware engineer, so I do expect adivices on hardware, thanks)

  3. What features of Linux/C++ can I take advantage of to develop such an application? Any relevent/similar projects to recommend?

Linfeng Mu
  • 171
  • 1
  • 11
  • You might want to read about [Real Time Linux](https://wiki.linuxfoundation.org/realtime/start) , as there is no way of stopping standard Linux (or MS-Windows) switching away from your app to run something else for a short while. – Richard Critten Aug 20 '22 at 08:13
  • A $4 Raspberry Pi Pico microcontroller would be better for that. – Mark Setchell Aug 20 '22 at 09:52
  • Use UDP where each send = 1 packet. TCP can batch, delay, resend, etc. – stark Aug 20 '22 at 10:38
  • 1
    A lower end FPGA SoC can be a good choice if you need a very low jitter. You can instantiate a DMA-only Ethernet MAC that will not use interrupts, and you can implement a userspace driver for it to avoid ever going into kernel (i.e., avoid context switches). Zynq or Cyclone V are reasonable choices here. Make sure your process is running on an isolated CPU with NOHZ_FULL. – SK-logic Aug 25 '22 at 15:38
  • @SK-logic. Thanks for the advice. Could recommend recommend some related books/tutorials/blogs? I don't much much about those hardwares. And also, for a real-time OS, which would be good choice? Is a Ubuntu+PREEMT_RT sufficient to run such a process? – Linfeng Mu Aug 29 '22 at 03:08
  • @LinfengMu for this approach you can even use vanilla linux kernel - since your real time process is not interacting with the OS in any way. PREEMPT_RT may still be useful to get a more predictable I/O on the non-realtime processes, to ensure they won't clog the system too much to interfere with the real-time processes. – SK-logic Sep 01 '22 at 13:41
  • @SK-logic, my process still needs to interact with Linux kernel since it needs to send TCP pakcage via net card, do some computation, and maintain an internal clock to synchronize with external devices. – Linfeng Mu Sep 02 '22 at 00:24
  • @LinfengMu then, depending on your budget, you can either use a network card with a fully user-space driver and TCP stack (see Solarflare, they're very popular in high-frequency trading for this reason), or you can use an FPGA SoC with a soft ethernet MAC on an FPGA fabric (and a similar user-space driver). – SK-logic Sep 02 '22 at 21:02
  • @SK-logic I don't think the network card is the main obstacle to implement my application, for my data is not much. The main difficulty to me now is that I can't find a good way to send my data frames precisely at pre-defined timepoint. What suggestions do you have on that? Thanks. – Linfeng Mu Sep 03 '22 at 07:35
  • @LinfengMu this is exactly why you need a network device with a 100% user-space driver - because otherwise Linux won't guarantee you any stable timing in sending the packets. Linux scheduling (context switching between your process and the kernel) and I/O interrupts both will introduce a very significant jitter, which won't exist with the real-time networking devices such as those I listed above. This is exactly why they're used in hard real-time applications like HFT and robotics - not for bandwidth, but for stable predictable timing. – SK-logic Sep 03 '22 at 09:32
  • P.S., something like ZynqUS+ can be quite within budget, there are relatively cheap SBCs based on Zynq with Ethernet PHYs available. See Xilinx Kria modules and their carrier boards for example. Even ZedBoard should be ok too (not sure if Ethernet PHY is connected to PS or PL there, but either way it's possible to get real-time behaviour) – SK-logic Sep 03 '22 at 09:37

0 Answers0