Summary of Linux real-time learning

Source: Internet
Author: User

I. Basic concepts of real-time systems

POSIX defines what a real-time system is: a system that provides the required level of service within a limited response time. Another definition proposed by Donald Gillies is: a real-time system means that the correctness of computing depends not only on the logic correctness of the program, but also on the time when the results are generated, if the system's time constraints are not met, a system error occurs. The real-time system has strict requirements on response time.

Real-time Operating System (RTOS) is an operating System that can correctly respond to internal or external exception events before a given deadline. In a real-time operating system, whether the execution result of a process is correct is not only related to the correctness of the logical operation or mathematical calculation result, but also the time when the process ends, that is, if the calculation result of a process is correct, but its completion time has exceeded the deadline specified by the system, this result is meaningless in the real-time system.

Based on the strength of the System's response Time constraints, real-Time operating systems can be divided into two categories: hard real-Time systems (RPS, HardReal-Time System) and soft real-Time systems (SRT, softReal-Time System ).

  • Soft Real-time Operating System: the soft real-time operating system is not very harsh on the time limit, the response time can be relatively delayed, that is, not within the range of the last defined time, the results are acceptable and will not cause serious consequences.
  • Hard real-time operating system: For a hard real-time operating system, not only must each task be run to obtain the correct results, but also must be completed within a limited time, this time is determined by the system itself, which is much stricter than the time constraints of the soft real-time operating system. For example, in an embedded real-time operating system in the aerospace field, if the expected calculation result is not obtained within the specified time, the consequences will be very serious.

Ii. Real-Time Linux operating system

1. Linux System Framework
On a macro scale, Linux framework 1:

Figure 1 Linux framework

To be more intuitive and easy to understand, the Linux framework 1 can be abstracted into 2.

Figure 2

2. Factors Restricting the real-time performance of the standard Linux Kernel

  • Linux has a large number of areas that cannot be preemptible

In Linux2.6, the kernel can be preemptible, so the real-time performance is enhanced. "However, there are still a large number of unpreemptible regions in the kernel, such as the critical zone protected by the spin lock.

  • Rough clock Granularity

Although the Linux 1000 kernel increases the clock frequency to Hz and the timing precision to 1 ms, it is far from meeting the requirements of the Real-Time System in microsecond-level timing precision. For example, the numerical control system requires the timing precision of 50 US.

  • Disable interruption

In system calls and service interruption programs, to protect critical zone resources, Linux will shut down interrupts for a long time. "Some systems call and interrupt service programs for a long time, which will increase the interruption delay.

  • Lack of effective real-time task Scheduling Mechanisms and Scheduling Algorithms

The Linux system is designed according to the objective of the time-sharing system to achieve better average performance of the system. It emphasizes balancing the response time between processes to ensure fair CPU time consumption. Generally, the time-based scheduling algorithm with a fixed time slice is used, and the kernel cannot be preemptible. The behavior of the real-time system depends more on the complicated unpredictable situation. These principles cannot meet the short response time and definite execution behavior requirements of the real-time system.

  • Priority inversion

When a low-priority process occupies a certain resource, the advanced process that also needs this resource cannot run, and a ready process with a priority between them obtains control of the CPU, in this way, high-level tasks need to wait for tasks that are lower than their priorities. This phenomenon is called priority inversion. In Linux, priority inversion may occur because resources cannot be preemptible and Priority Inheritance policies are not supported. This affects the system's real-time performance.

3. Improvement of Linux real-time performance

From the past, we can see that there are many factors restricting the real-time performance of the standard Linux kernel. To use the Linux system in a real-time environment, we must improve it. Currently, there are two solutions to improve the real-time performance of Linux: Direct kernel modification and dual-kernel modification.

Directly modify the kernel method. By analyzing the Linux principle and source code, you can modify and optimize the kernel process scheduling, interrupt service programs, and other code to improve the system's real-time performance, to ensure the versatility of the system, the POSIX
. This method can improve the performance, and has good compatibility because it uses the same application interface as the standard Linux kernel. Currently, many products use kernel modification methods to improve Linux real-time performance, such as Kurt-Linux, TimesysLinux, and Ingo's RT patch.

By adding a preemptive Real-Time Kernel Between the Linux kernel and hardware interruption, the standard Linux kernel is scheduled as the process with the lowest priority of the real-time kernel, it can be disconnected by real-time processes.
Linux processes can still run on the Linux kernel. This allows you to use a standard time-based operating system (Linux) for various services and provides a low-latency real-time environment. RT-Linux is a typical example of Linux real-time transformation using a dual-kernel approach.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.