---
title: What is real-time Linux? Part III
description: Real-time Ubuntu Linux will power the next generation of embedded innovations
  by providing a deterministic response time to their low-latency requirements.
url: https://canonical.com/blog/what-is-real-time-linux-part-iii?format=md
---

1. [Blog](https://canonical.com/blog)
2. Article

---

[Edoardo Barbieri](https://canonical.com/blog/author/edoardo-barbieri "More about Edoardo Barbieri")

7 March 2023

# What is real-time Linux? Part III

[Embedded](https://canonical.com/blog/tag/embedded)
[Industrial](https://canonical.com/blog/tag/industrial)

---

Share the article

[Real-time Ubuntu is now generally available](https://ubuntu.com/blog/real-time-ubuntu-is-now-generally-available)

Welcome to the final post of this three-part series on real-time Linux. As market adoption of real-time computing continues to rise, [real-time in the Linux kernel](https://www.brighttalk.com/webcast/6793/571067) is emerging as a valuable solution on the software side.

A real-time Linux kernel on its own, however, will not necessarily make a system real-time.   We clarified this point in [Part I](https://ubuntu.com/blog/what-is-real-time-linux-i) and listed the common misconceptions and stack components. We then concluded [Part I](https://ubuntu.com/blog/what-is-real-time-linux-i) by discussing the role of real-time Linux in target verticals and applications, from industrial factories and telco workloads to automotive and healthcare.

[Part II](https://ubuntu.com/blog/what-is-real-time-linux-ii) tackled how to achieve real-time in the kernel by introducing User Space to Kernel Space transitions and preemption. This is the final chapter of the series, where we will start by discussing the challenges to bringing preemption into the Linux kernel and the key benefits of the PREEMPT\_RT real-time patches.

## Challenges to implementing preemption

The challenge in making a preemptible kernel lies in identifying all the locations where preemption must not occur. These are critical sections where kernel developers must disable preemption.

In the example scenario in Figure 1 below, two processes with different priority levels operate on shared variables and make decisions based on their values. Process A is accessing and working on some shared data in the kernel. At this point, a higher-priority Process B preempts the running, lower-priority Process A. Process B then changes the value of the shared data structure. A process switch then occurs, with Process A resuming its operations after the prior interruption. Once Process A gets to run again, however, it will make a decision based on a value determined by Process B. In such a scenario, where two processes access the same data structures in critical sections, kernel preemption must be disabled.

**Figure 1**: *Two processes operating on common variables in a preemptible kernel.*

The difficult tradeoff is that developers must make the Linux kernel preemptible to reduce latency and achieve real-time computing capabilities. At the same time, they must disable preemption around critical sections to avoid resulting in corrupted data.

Such a balance is hard to strike, and it involves poring over the entire kernel source code base to assess which data to protect from concurrency. For [real-time processing in Linux](https://www.brighttalk.com/webcast/6793/571067) to be a reality, the kernel must be able to preempt the current thread of execution while placing checks at strategic locations. How do Linux developers overcome this riddle?

## Preemption options in the Linux kernel

A few preemption models are available in the [mainline Linux](https://www.kernel.org/) kernel’s scheduler. In this section, we’ll go over the key features and target applications for each [[1]](https://github.com/torvalds/linux/blob/master/kernel/Kconfig.preempt).

### PREEMPT\_NONE

The traditional Linux preemption model maximises the kernel’s raw processing power, irrespective of scheduling latencies.

As the default behaviour in standard kernels, the no-preemption case for server workloads is optimised for overall throughput for systems making intense computations like a server. Whereas PREEMPT\_NONE can still provide decent latencies, there are no guarantees, and occasional longer delays can occur, as interrupts, exceptions, and system calls in the kernel code are never preempted.

### PREEMPT\_VOLUNTARY

The PREEMPT\_VOLUNTARY preemption mode provides quicker application reactions to user input and targets desktop use.

A low-priority process can voluntarily preempt itself even when executing a system call in kernel code. By enabling voluntary preemption points in kernel code, PREEMPT\_VOLUNTARY reduces the maximum latency of rescheduling at the price of slightly lower throughput. As a result, faster application reactions, even when under load, are perceived to run more smoothly.

### PREEMPT

Just like PREEMPT\_VOLUNTARY, PREEMPT enables voluntary preemption points in the Linux kernel, but it further makes kernel code preemptible when not executing in a critical section.

By adding non-critical-section preemption, PREEMPT enables kernel code to be preempted involuntarily. Higher-priority processes can interrupt execution threads in low-priority processes even when executing a system call in kernel mode and when not about to reach a natural preemption point.

The reduced kernel latencies are suitable for desktop or embedded systems with latency requirements in the milliseconds range and they result in slightly lower throughput and runtime overhead to kernel code.

As per the screen capture, my Linux machine is running the 22.04 LTS release of Ubuntu Desktop with version 5.19 of the Linux kernel. PREEMPT\_VOLUNTARY is the default preemption model selected, as the kernel is for a desktop system, whereas CONFIG\_PREEMPT is not set.

From the above, PREEMPT is a configuration flavour of mainline, with the highest preemption level available in the kernel. Is that all we can do to achieve [real-time in Linux](https://www.brighttalk.com/webcast/6793/571067)?

### PREEMPT\_RT

[PREEMPT\_RT](https://wiki.linuxfoundation.org/realtime/start) is the name of the patchset hosted at the Linux Foundation to implement a priority scheduler and other supporting real-time mechanisms. Whereas the patches are slowly being mainlined, they are not yet fully upstream in the mainline Linux kernel. The PREEMPT\_RT locking code, representing a bulk of the outstanding real-time patches, was merged in Linux 5.15, but there is still more work to be upstreamed. PREEMPT\_RT is nowadays the de-facto Linux real-time implementation, despite various mechanisms to bring real-time compute into the Linux kernel having been attempted through the years, like Xenomai and RTAI.

Other approaches to bringing real-time in Linux often implement a ‘co-kernel’ running concurrently with a soft Linux kernel, whereas PREEMPT\_RT differs by affecting the kernel itself. The [PREEMPT\_RT](https://wiki.linuxfoundation.org/realtime/start) patchset strives for full preemption in the Linux kernel, including in critical sections and except for very low-level and critical code paths like entry code and low-level interrupt handling.

The goal with PREEMPT\_RT is to make all code running in kernel mode involuntarily preempted at any time by bringing most execution contexts under scheduler control.

PREEMPT\_RT does so by replacing locking primitives like spinlocks with variants aware of [priority inheritance](https://www.brighttalk.com/webcast/6793/571067), enforcing interrupt threading and introducing mechanisms to break up long non-preemptible sections. Other mechanisms the PREEMPT\_RT patch adopts to make the kernel deterministic involve replacing mutexes in the mainline Linux kernel with rt\_mutexes, to implement priority inheritance and avoid priority inversion [[2]](https://lwn.net/Articles/146861/).

Whereas PREEMPT\_RT doesn’t strive for the lowest latencies possible, an unbounded latency would represent a bug, as PREEMPT\_RT makes the Linux kernel preemptible by providing deterministic response times.

## Real-time Ubuntu

Ubuntu 22.04 LTS with the out-of-tree PREEMPT\_RT patches [entered general availability](https://ubuntu.com/blog/real-time-ubuntu-is-now-generally-available) last February. [Real-time Ubuntu](https://ubuntu.com/real-time) is more preemptive than mainline Linux. It reduces the kernel latencies as required by the most exacting workloads, and helps ensure a time-predictable task execution. Device manufacturers can focus on their business drivers, shortening time-to-market by relying on an enterprise-grade, real-time Linux kernel supported over 10+ years.

Enterprise customers can access the real-time kernel via [Ubuntu Core](https://ubuntu.com/core), the secure, application-centric IoT OS for embedded devices. [Ubuntu Core](https://ubuntu.com/core) is Ubuntu for IoT and embedded environments, delivering the resiliency and security that developers around the world expect from Ubuntu. It is an OS with a minimal footprint and a modular and simple architecture, built on [snaps](https://snapcraft.io/docs/getting-started), the universal Linux packaging format.

Alternatively, end-users can deploy [Ubuntu Server 22.04 LTS](https://ubuntu.com/server) with the real-time kernel, available via [Ubuntu Pro](https://ubuntu.com/pro), Canonical’s comprehensive enterprise security and compliance subscription, covering all aspects of open infrastructure. A [free tier](https://ubuntu.com/pro/dashboard) is available for personal and small-scale commercial use, in line with the company’s community commitment and mission to ease open-source access and consumption.

Canonical’s enterprise-grade software support and long-term maintenance for the [Real-time Ubuntu](https://ubuntu.com/real-time) kernel ensure product longevity.

#### Do you want to run real-time Ubuntu Linux in production?

[Get in touch](https://ubuntu.com/kernel/real-time/contact-us)

## Further reading

As the processing of time-sensitive workloads depends upon the capacity of the Linux system to respond within a bounded interval of time, real-time at the kernel level denotes a deterministic response to an external event. The [Real-time Ubuntu](https://ubuntu.com/real-time) kernel will power the next generation of robotics, IoT, and telco innovations by providing a known response time to their stringent low-latency requirements. By minimising the non-preemptible critical sections in kernel code, Ubuntu with the PREEMPT\_RT patches makes the kernel more preemptive than mainline.

[How real-time Linux accelerates industrial transformation](https://register.gotowebinar.com/register/8712572348523284318?source=Canonical)

[Embedded Linux: Yocto or Ubuntu Core?](https://ubuntu.com/engage/embedded-linux-yocto-ubuntu-core-whitepaper)

[Technical deep-dive into a real-time kernel](https://ubuntu.com/blog/real-time-kernel-technical)

[Get in touch

Interested in running Ubuntu in your organization?](https://ubuntu.com/about/contact-us/form)

## Sign up for our newsletter

Get the latest Canonical news and updates in your inbox.

Work email:

\*I agree to receive information about Canonical's
products and services.

By submitting this form, I confirm that I have read and agree to [Canonical's Privacy Policy](https://canonical.com/legal/dataprivacy).

Sign up

## Share on

---

## Related posts

[### Industrial cybersecurity: the journey towards IEC 62443 compliance](https://canonical.com/blog/industrial-cybersecurity-iec-62443-compliance)

Industrial cybersecurity is on every CISO’s mind as manufacturers strive to integrate their IT and OT operations to drive efficiency and productivity. However, with increased...

[Edoardo Barbieri](https://canonical.com/blog/author/edoardo-barbieri)

2 December 2024

[### Is a real-time OS right for your business?](https://canonical.com/blog/is-a-real-time-os-right-for-your-business)

With automation spanning virtually every sector of society, real-time capable operating systems (OS) are becoming critical across industries, from automotive and...

[Edoardo Barbieri](https://canonical.com/blog/author/edoardo-barbieri)

26 November 2024

[### Meet Canonical at SPS 2024](https://canonical.com/blog/canonical-sps-2024-industrial)

SPS (Smart Production Solutions) 2024 is almost here! With over 1,200 national and international exhibitors, SPS is the main gathering of industrial manufacturing to experience...

[Edoardo Barbieri](https://canonical.com/blog/author/edoardo-barbieri)

29 October 2024

[### Canonical releases Real-time Ubuntu 24.04 LTS](https://canonical.com/blog/real-time-24-04)

London, 30 May 2024. Today Canonical announced the availability of Real-time Ubuntu 24.04 LTS. By ensuring high-priority processes are executed first, with deterministic...

[Edoardo Barbieri](https://canonical.com/blog/author/edoardo-barbieri)

30 May 2024
