Hacker News new | ask | show | jobs
by DenseComet 2056 days ago
A question very marginally related to embedded Linux, but is there any way to do hard real time on Linux? I'm working on an embedded project that requires it, and while its achievable with microcontrollers and embedded Rust, it would just be so much easier if I had an actual OS.
6 comments

The wiki for the PREEMPT_RT patchset has a general HOWTO: https://rt.wiki.kernel.org/index.php/HOWTO:_Build_an_RT-appl...

Generally speaking, your limiting factor wrt. hard RT performance is going to be the underlying hardware, not the OS per se. This of course assumes that you avoid known sources of OS-related latency.

> A question very marginally related to embedded Linux, but is there any way to do hard real time on Linux?

Go look at the Beaglebone Black/Green/Blue/AI.

The microprocessors in those run Linux but have at least two PRUs (programmable real-time unit). Those PRU units are bare-metal, hard real-time but can communicate out to the Linux system which can do the "soft" real time stuff.

A numbers of SoC makers have adapted by adding M4 or M7s as real-time coprocessors to the main application core. There's also the TI Sitara (Beaglebone) with its PRU that can function as a real-time assist.
Yes, there's nothing more challenging about using Linux for hard realtime. You still need to address your IO to ensure realtime constraints but you have the benefit of already constructed realtime ethernet drivers, etc.

It's also common to run your code as init and avoid calling into the kernel.

A more modern treatment is to write whatever and then qualify the system thoroughly, and all things considered this will probably overtake everything else as the main development methodology.

ive not done hard real time for a number of years (usually I have foubd its not needed), but Xenomai would be one option for real hard realtime. The other option is to use the rtlinux patches, however that is not true hard real time, but for most use-cases works ok.
Interesting, thank you! I'll take a look at Xemomai, but it seems like the options are very limited. I'm building a TVC rocket, so hard real time is unfortunately a strict requirement.
I think you can do hard real time inside drivers. The other is some embedded linux capable chips have TPU's, aka Time Processing Units.

For something like a thrust vectoring rocket, I'd stick to a sub processor running an actual RTOS or bare metal code.

Xenomai might be fast enough with some coprocessing added if necessary. It makes your RT threads have essentially "normal" POSIX RT api, but runs them on separate kernel that can respond to things like interrupts much, much faster (including stable timeslicing)
Have you looked into Nuttx?