Tag Archive for: canonical-ubuntu

Logo FreeRTOS con TUX de fondo

Real-time Linux (RTOS) – Now part of your kernel

Did you know that while you have opened the browser to read this… your computer has decided to prioritize that process leaving many others in the queue?🤯 Do you want to know how it does it? What does it mean when Linux becomes an RTOS? Well, read on and I’ll show you. And watch out, because if you are interested in the world of the penguin OS, we are going to tell you more than one fact that you may not know...💥

How does the Linux Kernel scheduler work?

The Linux scheduler works as in the previous example: Basically, it decides in which state to put the processes (running, interruptible, non-interruptible, zombie or stopped) and their execution order to improve your experience. For their execution order, each process has a priority level. Let’s say you have a background process running and you open the browser. The scheduler will interrupt that background process and focus resources on opening the browser, ensuring it runs quickly and efficiently.

The concept of expropriation (preemption)

Expropriation on Linux🐧? It’s not what you’re thinking of…. Expropriation is a fundamental feature, as it allows processes to be interrupted if a higher priority one breaks in. In Linux version 2.6, the ability to expropriate processeswas added to the kernel, that is, the kernel can interrupt processes. Systems that are not preemptible must terminate the running task in order to get to the next one.

In the case of Linux, since version 2.6.24, the Completely Fair Scheduler (CFS) is used as a scheduler. This scheduler is governed by ensuring “fair” access to the CPU.

Completely Fair Scheduler: how do you decide which process should run at which time in order to have fair access to the CPU?

There are two types of priorities: static and dynamic.

  • Static (Niceness): Can be adjusted by the user. The lower the value, the more important the program is and the more CPU time it consumes.
  • Dynamic: It is set according to the behavior of the program. They can be I/O Bound (programs that need a lot of CPU time because they are usually waiting) or CPU Bound programs (that require less CPU time, since they usually perform intensive tasks that could collapse other processes).

How does the planner prioritize?

The operating system maintains two lists of programs:

  • List 1: Programs that still have time to use.
  • List 2: Programs that have used your time.

When a program uses its time, the system calculates how much time it should have next time and moves it to the second list. When the first list becomes empty, the two lists are swapped. This helps the system work efficiently. Linux 2.6, with the fully preemptible kernel, greatly improved the responsiveness of the system. Now, the kernel can be interrupted on low-priority tasks to respond to priority events.

 

PREEMPT_RT inside the Linux Kernel

With a new kernel update, Linux can be controlled with pinpoint accuracy. An RTOS implies that the system will be accurate for critical tasks, such as in medical centers. However, since Linux was not intended for that, the fact that it is now part of the kernel brings certain features, even if they do not make it an RTOS.

Feature Enhancement
Straightforward integration and simplified maintenance
  • Less dependence on external patching: Direct access to upgrades without managing patches.
  • Easier maintenance: Easier upgrades and fewer compatibility issues.
Improved stability and performance
  • Testing and validation: Increased stability and performance through rigorous testing.
  • Continuous development: Continuous improvements in functionality and performance.
Accessibility for developers
  • Ease of use: Enabling more accessible real-time functionalities.
  • Documentation and support: Increased documentation and support in the community.
Competition with dedicated systems
  • Increased competitiveness: Positioning Linux as an alternative to dedicated RTOS.
Extended use cases
  • Critical applications: Adoption of Linux in critical systems where accuracy is essential.

Why has PREEMPT_RT taken so long to become part of the kernel?

In addition to financial problems and the community’s lack of interest in taking a real-time approach to Linux, a technical problem arose: the printk. Printk es una función que imprime mensajes en el búfer de registro del kernel. El problema con esta función es que producía retrasos cada vez que se llamaba. Este retraso interrumpía el flujo normal del sistema, y alejado este problema, PREEMPT_RT se pudo incorporar al kernel.

How does Linux becoming a Real-Time Operating System affect you?

For the average user: nothing. However, if you are a developer, this innovation in the Linux core will be a breakthrough to take into account. Until now, developers who need real-time precision opted for other operating systems designed for it. With the new PREEMPT_RT function integrated into the Linux kernel, this will no longer be necessary. The feature allows Linux to stop any task to prioritize a request in real time, which is essential for applications that demand low latency.

Use case: home security

Imagine you are using a voice assistant at home that controls both the lighting and the security system. If it detects an intrusion while you are at home, it should prioritize the activation of alarms and notify you immediately. In this case, the lights or music can wait; what really matters is your safety. This ability to respond immediately in critical situations can make all the difference.

Why is Real Time necessary?

As we have seen in the use case, RTOSs can complete unforeseen tasks, moreover, in specific and predictable times. In workloads that require precision, RTOSs play a critical role. In this case, RTOSs are often seen in IoT applications:

  • Vehicles: Pioneering cars like Tesla can brake immediately if they detect an obstacle.
  • Critical systems: In aircraft or medicine, systems must operate on tight schedules.
  • Industry: In industrial processes, a slight delay can cause failures.
The role of AI and machine learning

AI and machine learning also play a key role in RTOS and IoT. They could predict events and support fast and effective decision making.

Conclusion

In short, Linux Real Time will finally become a reality. The integration of Linux as a real-time operating system marks a turning point and opens up new opportunities for critical tasks in sectors such as healthcare, robotics and IoT. With the PREEMPT_RT function integrated into the kernel, Ubuntu Linux guarantees greater accuracy. However, we should not fail to keep in mind that the penguin🐧 operating system is not 100% an RTOS, it was not designed for it. So, we will see if companies will adapt Canonical’s solution to their real-time needs, or will continue to opt for other solutions such as FreeRTOS or Zephyr. Do you want to continue learning about Linux? We offer you official certifications. And if you don’t have enough… we adapt to you with tailor-made training 👇

Intensive training on Linux systems

Linux is the order of the day… if you don’t want to be left out of the latest technological demands, we recommend our Canonical Ubuntu courses 👇

Official SIXE training at Canonical, creators of Ubuntu

SiXe Ingeniería
×