Based on the upstream v6.8 kernel, the 24.04 release of Real-time Ubuntu includes optimised support for Raspberry Pi hardware. Discover the possibilities of optimised real-time compute with enhanced performance on Raspberry Pi 4 and 5:
Depending on your background knowledge, you may wish to start with the basics of preemption and a real-time system. In that case, this introductory webinar or our blog series on what is real-time Linux, is for you.
The present blog post highlights two primary test suites for Real-time Ubuntu, followed by an explanation of the components and processes involved, from the scheduler role and its different policies, to blocking spinning locks.
If you are already familiar with a real-time Linux kernel and do not wish to refresh your memory, jump to the tuning guide. There, we will go through the three primary metrics to monitor when tuning a real-time kernel, some key configs set at compile time, and a tuning example.
The scheduler is a key component of a real-time system. In the Linux kernel, a few scheduling classes, like Early Deadline First, Real-Time, and the Completely Fair Scheduler, are available, with different scheduling policies within each class, as per the table below:
The runqueue contains per-processor scheduling information and is the basic data structure in the scheduler. It lists the runnable processes for a given processor and is defined as a struct in kernel/sched.c.
The scheduler can be run via a call to the schedule() function. The Linux kernel will then sequentially check the EDF, RT and CFS runqueue for waiting tasks. Alternatively, the system will do an idle loop if no tasks ready to run are present.
The unintended consequence and potential issue with the SCHED_DEADLINE policy is that in case a task was to miss its deadline, it would keep on running, causing a domino effect with the follow-on tasks also missing their deadlines. When using SCHED_DEADLINE, one must pay close attention to the system and application requirements.
The SCHED_DEADLINE policy of the EDF class specifies three vital parameters for a system, the runtime, deadline and period. The runtime denotes how long a thread will run on a processor. The deadline is the specific period of time during which a task has to complete its operation, usually measured in μs. The period states how often it will run.
Real-time Ubuntu relies on the RT class, a POSIX fixed-priority scheduler, which provides the FIFO and RR scheduling policies, first-in-first-out and round-robin, respectively. In particular, real-time Ubuntu uses the SCHED_RR policy. SCHED_RR and SCHED_FIFO are both priority-based: the higher priority task will run on the processor by preempting the lower priority ones.
The difference between the FIFO and RR schedulers is evident when two tasks share the same priority. In the FIFO scheduler, the task that arrived first will receive the processor, running until it goes to sleep. On the other hand, in the RR scheduler, the tasks with the same priority will share the processor in a round-robin fashion.
The danger with the round-robin scheduling policy is that the CPU may spend too much time in context switching because the scheduler assigns an equal amount of runtime to each task. One can remediate such downsides by properly tuning a real-time kernel and focusing on how long tasks will run and the type of work they will do.
An application should never run at priority 90 or higher, as that is where critical kernel threads run. Similarly, watchdogs and migration run at priority 99. Running a task at priority 99 will likely result in the overall system locking up. Hence, one should strive to set a priority below the range of 50-99 when writing a program.
The primary characteristic of blocking locks is that the tasks holding them can be put to sleep. Among examples of blocking locks there are counting semaphores, (per-CPU) Reader/Writer semaphores, mutexes and WW-mutexes and RT-mutexes. Of those, RT-Mutex is the only blocking lock that will not lead to priority inversion, covered in the following section.
In a real-time kernel, classical spin locks convert to sleepable spinlocks and are renamed raw_spinlocks. Hence, a developer may have to recode their applications and drivers to use raw spinlocks in a kernel with PREMPT_RT, depending on whether or not a spin lock is allowed to sleep.
Among spinning locks, reader/writer locks are also available. In particular, rwlock_t is a multiple reader and single writer lock mechanism. Non-PREEMPT_RT kernels implement rwlock_t as a spinning lock, with the suffix rules of spinlock_t applying accordingly.
Among the reasons why PREEMPT_RT is not in mainline yet is that much of the locking within the kernel has to be updated to prevent priority inversion from occurring in a real-time environment. The present and the following section will introduce unbounded priority inversion and the need for priority inheritance.
Priority inversion occurred on the Mars Rover, and it is a critical challenge for developers and engineers working with real-time systems. With unbounded priority inversion, the need for priority inheritance becomes clear.
The diagram below helps illustrate the mechanism. As before, the low-priority task L starts running and acquires the lock. Similarly to the previous scenario, task H wakes up and starts running, but it is soon blocked while attempting to get the lock.
Once task L finishes its critical section work, task H acquires the lock, where the red bar turns orange. Whenever task H completes, it will, in turn, release the lock. Only now can the medium-priority task M come along and start running. If needed, the higher-priority task H could further preempt task M to finish its processing. Priority inheritance in a real-time kernel solves the issue of task M starting to run between tasks H and L, which would give rise to unbounded latencies and priority inversion.
Real-time Ubuntu brings end-to-end security and reliability to the time-bound workloads of modern enterprises. With support for real-time compute, Canonical furthers its commitment to providing a best-in-class experience for open-source software consumption.
14 February 2023, London: Canonical today announced the general availability of Real-time Ubuntu 22.04 LTS. Real-time Ubuntu provides a deterministic response to an external event, aiming to minimise the response time guarantee within a specified deadline. The new enterprise-grade real-time kernel is ideal for stringent low-latency requirements. Enterprises in industrial, telecommunications, automotive, aerospace and defence, as well as public sector and retail, can now run their most demanding workloads and develop a wide range of time-sensitive applications on the open-source operating system (OS).
Based on the 5.15 version of the Linux kernel, Ubuntu 22.04 LTS integrates the out-of-tree PREEMPT_RT patches for x86 and Arm architectures. The PREEMPT_RT patchset reduces the kernel latencies as required by the most exacting workloads, helping to ensure time-predictable task execution. Meeting stringent determinism requirements and upper-bounding execution time, Ubuntu with PREEMPT_RT makes the kernel more preemptive than mainline Linux.
By collaborating with a world-leading ecosystem of partners, from silicon providers to OEMs and ODMs, Canonical is raising the bar of what is possible in the software world, unleashing a new wave of creativity and innovation with Real-time Ubuntu.
Real-time Ubuntu is designed to deliver performance, ultra-low latency and security for critical telco infrastructure. As workloads requiring quality of service and low latency steadily migrate to Ubuntu, Canonical designed the real-time kernel to meet telco network transformation needs for 5G.
Canonical is the publisher of Ubuntu, the operating system for most public cloud workloads as well as the emerging categories of smart gateways, self-driving cars and advanced robots. Canonical provides enterprise security, support and services to commercial users of Ubuntu. Established in 2004, Canonical is a privately held company.
I am trying to install Real time patch on ubuntu 20.04 I followed many steps and for each trial it took about 4 hours to complete. Unfortunately none of these trials worked (in the links below).I really appreciate if you could advice me with exact steps to follow as I am new guy in using Linux.Thank you very much.
Ubuntu 22.04 now includes a real-time Linux kernel based on kernel v5.15 with the PREEMPT-RT patch. We take a look at how easy it is to add this real-time Linux kernel, and then test the performance for EtherCAT applications.
In order to install the real-time kernel on Ubuntu 22.04, just follow the instructions from Ubuntu's website: -time-ubuntu-released. Previously in beta, recently Canonical made the 22.04 release generally available: -time-ubuntu-is-now-generally-available. In order to enable the real-time kernel, two options are available; Ubuntu Server 22.04 LTS via Ubuntu Pro, and Ubuntu Core 22 with an App Store. A subscription to Ubuntu Pro is free for personal use, but for your specific needs we recommend you contact Canonical about your licensing options.
Further optimizations can be done with kernel parameters. The kernel parameters provide a lot of ptions for fine-tuning the OS. A full list of the kernel command line parameters can be found here: -guide/kernel-parameters.html.
I am working on a Dell Precision 5770 laptop which has Ubuntu Jammy 20.04.3. I was able to install the realtime kernel using ubuntu pro sudo pro enable realtime-kernel and it worked fine. However, upon rebooting, I lose my wifi adapter. I've checked and disabled secure boot, as one guide suggested to do so, but it was not helpful in getting it to work. I also have tried backporting the driver but it was unsuccessful. I can go into more detail about that if anyone is curious or can help me successfully do that, if that's the solution. Running the following commands shows me the following:
d3342ee215