Analysis and research of real-time Linux based on Xenomai

Source: Internet
Author: User

Turn from: http://blog.csdn.net/cyberlabs/article/details/6967192 introduction


With the rapid development of embedded devices, the function and flexibility of embedded devices are more and more high, and many embedded devices start to use the operating system. Due to the particularity of the work, many embedded devices require that the system's interrupt response to external events must be completed within a predetermined time frame, making the system predictable, and that the general desktop operating system is mostly non-real-time or soft real-time, and cannot meet the requirements, so it must use a real-time operating system (real-time Operating System,rtos).
A real-time operating system is an information system that can process and output asynchronous inputs for a limited amount of time. A high-performance, real-time operating system should have good comprehensive capabilities, including system architecture, basic system function support (such as memory and interrupt management), APL support, and stability.
Real-time systems also have soft real-time systems (soft real-time system) and hard real-time systems. Soft real-time systems are those systems that allow missed time limits (deadline) when the system is heavily loaded and do not cause too much harm, such as videoconferencing systems, while hard-time systems are those systems that require very strict scheduling times for each task, and if they do not meet the time limit requirements, will have devastating consequences for the system. For example, the feed control system of CNC machine tools, in the specified time, the feed system must reach the predetermined position, otherwise it can not guarantee the accuracy of the processing parts, or even can not complete processing.
In the field of embedded systems, real-time system is the core of realtime systems. At present, there are many commercial real-time operating systems, famous WindRiver Company's VxWorks, others have QNX, psos+ and so on. Their advantages are very good stability, reliability and real-time, but the general price is expensive and incompatible, and the source code as a trade secret and not public. In contrast, the Linux operating system under the GPL provides the possibility for developers to do more in-depth research based on their predecessors. At present, the typical real-time research project of Linux kernel is rt-linux, RTAI, Xenomai and so on.

1 Linux 2. Real-time analysis of the 6 kernel


Linux 2, relative to the old kernel version. The kernel structure of version 6 has changed greatly, and the developer has rewritten the code of many functional modules. The most significant improvement is in the process scheduling that affects the real-time system, including the use of the preemptive kernel and the new 0 (1) scheduler.
But Linux in the original design is used as a personal PC or small server operating system, due to the design requirements of the targeted, resulting in Linux can not provide a hard real-time environment, directly affect its hard real-time performance. This is mainly manifested in two ways:
(1) Process scheduling mode
The process scheduling of Linux is based on the time slice rotation scheduling strategy. Regardless of the priority of the process, Linux is assigned to a time slice of the process during a certain period of time, i.e. its design pays more attention to the fairness of task scheduling. In this case, a high-priority process is forced to abandon the processor due to the exhaustion of its time slices, and the processor is not consumed by the low-priority process that runs out of time slices. This is obviously not suitable for systems with high real-time requirements.
(2) Coarse clock granularity
In Linux 2. In the 6 version of the kernel, the clock interrupt occurs in the frequency range of 50~1 200Hz, with a period of not less than 0. 8 MS, and many industrial interruptions are within dozens of μs.
There are 2 main solutions to the problems that are mentioned above that affect the real-time nature of Linux:
The ① is a real-time transformation of the Linux kernel, which directly modifies the data structure of the Linux kernel, the scheduling method, and the interrupt mode (mainly clock interrupts).
Using this method, real-time transformation of the system in real-time, but the workload is large, and may cause system instability. The biggest drawback is that device drivers and applications that were originally running on Linux cannot run directly on the improved kernel. Typical Representative has kurt-linux.
② the external real-time extension of the Linux kernel, this approach is usually a dual-core approach. Specifically, a hardware abstraction layer (Hardware abstract layer,hal) is added between the Linux kernel and hardware, and all the hardware interrupts of the system are controlled by this abstraction layer. The newly created kernel is dedicated to scheduling real-time processes, while normal processes are dispatched through the original Linux kernel. The biggest benefit of this approach is that the kernel changes to Linux are minimal, and that device drivers and applications on the original Linux can run smoothly on this real-time system. Its representatives are rt-linux, Rtai and Xenomai.

2 Xenomai principle and application 2. 1 Xenomai Introduction and its ADEOS realization

Xenomai is a free software project that provides a real-time solution based on Linux. It provides the performance of an industrial-grade RTOS and is fully compliant with the Gnu/linux Free software protocol. The latest stable version is now 2. 4. 5.
The Xenomai project started in 2001. Since the summer of 2003, Xenomai and Rtai have been cooperating for more than two years, during which a well-known Rtai/fusion project branch was developed. By 2005, the Xenomai project was again independent. and from 2. 0. Beginning with version 0, the porting of Xenomai on the hardware platform has been based on the ADEOS architecture.
In a ADEOS-based system, it is divided into multiple domains. Each domain is run independently of an operating system (or a program module that implements some functionality), and each domain can have a separate address space and a software abstraction layer similar to process, virtual memory, and so on. There is a adeos on the lower level of each domain to dispatch the above domains by means of virtual interrupts. In ADEOS-based systems, there are four types of interactions in a, B, C, and D, as shown in 1.

Class A interaction is the direct operation of hardware devices in each domain, including access to memory, etc. b-type interaction means that when the ADEOS received a hardware interrupt, the corresponding domain will be interrupted according to the interrupt service; Class C interaction means that the operating system within the current domain actively requests some services to ADEOS Class D interaction refers to interrupts and exceptions generated by the ADEOS receiving hardware, as well as direct control of the hardware. Among them, the function that Adeos realizes mainly includes interrupt pipeline mechanism (I-PIPE), domain management module and domain dispatch module function.

2. 2 Xenomai Real-time implementation of user layer

Xenomai In addition to the kernel layer using ADEOS to achieve hard real-time, it in the user space also has a good real-time. On the s3c2410 platform, in order to realize the real-time of the user layer, Xenomai implements a hardware counter--decrementer. This hardware counter can be used to simulate the TSC (time Stamp Counter, timestamp counter) well in the user's empty question.

At the same time, Xenomai has added a new data structure to the Linux kernel __ipipe_tscinfo, which can be used to store the user layer's needs. The data structure is composed of the following:

At the user level, applications can quickly get the data in the Struct_ipipe_tscinfo structure through system calls. And to avoid being affected by the cache, Xenomai this struct variable in a vector page of Linux.

The kernel fills the contents of the Struct_ipipe_tscinfo struct variable with the function _ipipe_mach_get_tscinfo:

Among them, info one >typte shows that TSC is based on Decrementer hardware counting method on s3c2410 platform; info one >u. Dec The counter is used to set the physical address of the Decrementer counter to 0x51000038;info a >u. Dec Mask mask is used to indicate the use of dec-rementet. Special positioning in the counter; info one >u. Dec TSC points to the area where the 64-bit TSC value is stored.
When the real-time program of the Xenomai user layer runs, the program will get the kernel-filled struct_ipipe_tscinfo structure variables through the system call. The concrete implementation can refer to compiling the user layer real-time program used, by Xenomai the header file/usr/xenomai/include/asm/syscall. H.

2. 3 Xenomai multi-API architecture

In addition to providing Linux hard, Xenomai's other purpose is to enable Linux-based RTOs to provide the same API as traditional industrial-grade real-time operating systems (including VxWorks, psos+, Vrtx, or Uitron). This allows applications under these operating systems to be easily ported to the GNU/LINUX environment while maintaining good real-time capability.
Xenomai's core technology is the use of a real-time microkernel (real-time nucleus) to build these real-time APIs, also known as "skins." On the basis of real-time kernel multiplexing, a skin can simulate a real-time operating system API very well. Its structure diagram can be referenced in Figure 2.

In Figure 2, native is Xenomai's own API, with all types of APIs having the same status, independently based on the same real-time microkernel. Doing so allows the kernel's benefits to be well inherited by all the APIs in the outer layer. More importantly, the services provided by the real-time microkernel are represented in different ways by the various layers of APIs, thereby enhancing the robustness of the entire system.
When compiling the real-time program, it can only be implemented on the kernel layer in many real-time operating systems, while the real-time kernel module is limited by the kernel, for example, some real-time kernels do not support floating-point arithmetic, and the whole system hangs when error occurs, and the debugging of kernel module is more difficult. Xenomai can support a good real-time user layer, which provides an effective way for compiling real-time programs that are not very high in real-time requirements. The following user layer real-time routines use the native API provided by Xenomai:

From the program can be seen, Xenomai user layer real-time program cycle can be easily set to the μs level, so it can be applied to the general real-time requirements of engineering applications.

3 Summary

In this paper, the real-time operating system is introduced briefly, and Linux 2 is analyzed. 6 The kernel real-time performance is insufficient, then emphatically introduced a Linux real-time solution--xenomai, analyzed the Xenomai ADEOS Framework Foundation, briefly explained Xenomai user layer real-time realization, And the new features of the API that Xenomai supports a variety of real-time operating systems. The Xenomai user layer real-time routines presented in this paper have been successfully run on multiple platforms, indicating that the Xenomai user program has a good portability on a variety of hardware platforms.

Analysis and research of real-time Linux based on Xenomai

Related Article

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.