The series is mostly complete, except one to two posts on more advanced topics like validation and lockless programming.
[0] https://www.google.com/search?q=hard-realtime+soft-realtime
> A hard-real time system is a system in which a failure to meet even a single deadline may lead to complete or appalling system failure. A soft real-time system is a system in which one or more failures to meet the deadline are not considered complete system failure, but that performance is considered to be degraded.
Technically not relevant but I know that a lot of early handhelds that repurposed RTOS for GUI felt slow, jumpy and unresponsive, perhaps because everything was polled? In that sense RTOS can be slow.
In the context I'm working with (1000Hz hard real-time), the software has to be "performant" (running algorithms like collision detection) in a deterministic manner as each loop iterate has less than 800us of time. When developing such a system, the developer needs to accurately know the performance characteristic of the software ahead of time.
In another system, fast might mean 5ms, which is unacceptably slow in the context above.
- hardware (embedded hardware, brushless motors, propellers, batteries, radio, etc.)
- guidance (sensor fusion algorithms, kalman filtering, etc.)
- navigation (GPS/GNSS, magnetometers, barometers, accelerometers, gyroscopes, etc.)
- control (PWM control, PIDs, feed forward loops, etc.)
Is there a good training ground, like a simulation, for playing around with this stuff?
1) Real-Time Embedded Systems: Design Principles and Engineering Practices by Xiaocong Fan. - Good text book.
2) Introduction to Embedded Systems: Using Microcontrollers and the MSP430 by Manuel Jiminez et.al. - Very good book teaching you bare-metal MCU programming.
3) Hands-On RTOS with Microcontrollers: Building real-time embedded systems using FreeRTOS, STM32 MCUs, and SEGGER debug tools by Brian Amos - Great book showing the use of all tools/ecosystem needed for RTOS programming.
4) POSIX.4 Programmers Guide: Programming for the Real World by Bill Gallmeister. - The classic indispensable work on "real-time programming" for Unix-like systems.
At the practical level, I would suggest the Redhat Realtime linux tuning guide. It covers practical ways to identify and remove latency and jitter from your system.
My experience with the RH realtime kernel is 120 hz is usable. 60 hz can be very good. Of course, YMMV....
Another very good book i forgot to mention is:
5) Real-Time Systems and Programming Languages: Ada, Real-Time Java and C/Real-Time POSIX by Alan Burns and Andy Wellings.
>At the practical level, I would suggest the Redhat Realtime linux tuning guide. It covers practical ways to identify and remove latency and jitter from your system.
Agreed, but it deals with configuring the system rather than explicit coding. I listed it in another comment in this thread - https://access.redhat.com/documentation/en-us/red_hat_enterp...
While there quite a few hiccups along the way - you will be able to bring down jitter or OS noise to around 1 us. Of course a microkernel based OS like QNX can take you down to around 1 ns - but then the point of using Linux is that you are able to utilize the ecosystem around it.
Look into isolation, real-time patch and high performance computing.
As for Linux, your first stop should be the bootlin materials [1]. They're fairly comprehensive and regularly updated.
What is your goal as this is a broad field?
If you wanna just start with it, I would try to read up on cars, can Bus and how all of that works.
In embedded the trend is heading toward heterogenous systems, where you have an application processor running Linux and a coprocessor (sometimes on the same die) that runs an RTOS.
1) Do i need to configure "isolcpus" if i use "pthread_setaffinity" in my code directly ?
2) How do you do "interrupt affinity" in code ?
PS: I found Red Hat's documentation for "real-time" useful: https://access.redhat.com/documentation/en-us/red_hat_enterp...
yes: isolcpus is there to tell the kernel : "never schedule anything on this CPU" ; pthread_setaffinity is then there to move your real-time process/thread on the now-isolated CPU. Maybe if you control the entire user space you could get the same result by manually calling pthread_setaffinity for every single thread, but that's very likley not what you want (and I'd guess the kernel would still do some periodic polling in this case which they won't on isolated cpus).
But most the information I have comes from reading this exact guide which is very, very good and comprehensive :)
You can set up a timer interrupts in Arduino, There are web-JavaScript tutorials to set up callback function to execute every 3000ms, but you won't be doing RPC over network with timestamps and expiration, without going neck deep in something specialized and chaotic as ROS2.
I'm picturing some sort of distributed, networked, timestamped system that can schedule remote executions and construct time correlated observations, something obvious to designers/architects of original SNMP spec and NIST 4D/RCS project, and I'm predicting we'll have an industry standard framework just casually appearing by the end of this decade. It's weird we don't have one.
- Traditional Unix optimises for sharing resources and using them efficiently - 'multiprocessing', 'time slicing', 'resource sharing', 'garbage collecting', etc.
- Realtime: optimises for deterministic low latency. SCHED_FIFO processes that use a logical CPU and do not yield during the trading day, use money to buy more memory or crash rather than allow the GC to destroy your latency during the trading day.
https://access.redhat.com/documentation/en-us/red_hat_enterp... is RHEL RT focused but the kernel optimisations discussed are all OSS licensed.
Linux is too complex to provide any sort of guarantee; real-time Linux is just soft realtime.
Look at an actual RTOS instead, such as seL4[0].
This however may give you a nice point to dive in from:
https://ubuntu.com/engage/an-introduction-to-real-time-linux...
for more advanced projects consider getting preempt-rt going in a yocto install.
Apparently a malicious or poorly coded rt process could also completely lock the machine on rt kernel.
https://help.ubuntu.com/community/UbuntuStudio/RealTimeKerne...
This is false by default. The kernel reserves 5% (configurable) of CPU cycles for non-RT tasks, meaning that no RT task can lock the machine unless it also blocks all IRQs; this could be done by a non-RT task too, so it is not an RT-related hazard.
See
/proc/sys/kernel/sched_rt_period_us
/proc/sys/kernel/sched_rt_runtime_us
It is true that if you misconfigure these values, things can go wrong, but that's true of a lot of kernel parameters.Code compiles to assembly instructions which typically appear atomic to the author, however, such instructions may take variable numbers of cycles to execute.
2. use hwlatdetect
3. give up when you realize you can't buy commodity hardware with documented NMIs or open-source firmware