Real-time embedded Linux for Multimedia Applications

Source: Internet
Author: User
First, the real-time machine of Linux is analyzed. Then, based on the characteristics of multimedia applications, the embedded Linux System for multimedia applications is constructed by improving the real-time performance of Linux systems. Experimental results show that the system can fully meet the needs of multimedia applications in real time.

In today's information society, the development and application of information technology and information industry, characterized by multimedia, have increasingly become more and more important to human society. The development of multimedia technology depends largely on the level of multimedia software development. At present, both system software supporting multimedia and application software are unable to meet the needs of rapid multimedia development in terms of capabilities and quantity. In particular, the lack of multimedia system software has always been one of the bottlenecks restricting the development of the multimedia industry.

Linux has developed into a powerful and well-designed operating system for more than a decade since its birth in 1991. In the field of embedded systems, Linux has also achieved rapid development. Linux has the following features:

(1) The open source code of the Linux operating system is easy to customize and cut, making it price-competitive;

(2) the Linux operating system has a small kernel, powerful functions, stable operation, strong system, and high efficiency;

(3) Linux not only supports x86 CPU, but also supports dozens of other CPU chips;

(4) Linux supports all standard Internet protocols, and almost all protocols and network interfaces are customized.

Therefore, Linux is the first choice for multimedia terminal operating systems.

1. Real-time analysis of general Linux and its shortcomings in real-time performance

Although the Linux kernel has enhanced real-time performance, but because the Linux system itself is a desktop-oriented system, when it is applied to multimedia terminals, there are still some problems in real-time performance.

1.1 Scheduling Policies for general Linux systems

Common Linux systems support real-time and non-real-time processes. Real-time processes have absolute priority over common processes. Correspondingly, real-time processes adopt sched_fifo or sched_rr scheduling policies, while common processes adopt sched_ottier scheduling policies.

Sched_other scheduling policy is essentially a proportional-sharing scheduling policy, which can be designed to ensure the fairness of process scheduling: A low-priority process also gets the CPU execution time that it deserves in each epoch. In addition, it also differentiates the priorities of different processes, processes with a high priority value can get more execution time.

For real-time processes, they use a priority scheduling policy based on the real-time priority rt_pnonty, but according to different scheduling policies, the scheduling methods for processes with the same real-time priority are different.

During Linux scheduling, You need to traverse the running queue and calculate the goodness value for each process in the queue. The process with the largest goodness will be selected for running. Depending on the scheduling policy, the goodness value of the process must be calculated differently. The gooclness value of a common process is slightly floating Based on the Count value of the process counter, and its range is O ~ 999. The goodness value of a real-time process is to add the real-time priority rt_priority of the process to 1000. Therefore, the goodness of real-time processes is always greater than that of non-real-time processes, thus ensuring the priority of real-time process scheduling. The goodness () function is as follows:

From the soodness () function, we can see that the process scheduling algorithm of the common Linux kernel is soft and real-time, not hard and real-time.

1.2 defects in real-time performance of general Linux

(1) The scheduling unit in Linux is loms, so it cannot provide accurate timing;

(2) When a process calls a system call and runs in kernel mode, it cannot be preemptible;

(3) the Linux kernel may cause loss of interruptions when a large number of interrupted sealing operations are implemented;

(4) due to the use of virtual memory technology, when a page error occurs, you need to read and exchange data from the hard disk. However, random read/write time may occur due to Random storage locations, in some cases, the deadline for some real-time tasks may be affected;

(5) Although linu ~ Process Scheduling also supports real-time priority, but lacks effective real-time task Scheduling Mechanisms and scheduling algorithms; the protocol processing of the network subsystem and the interrupt processing of other devices are not associated with the scheduling of the corresponding process, and there is no clear scheduling mechanism.

2. Real-Time Linux improvement for Multimedia Applications

There are two methods to improve the real-time performance of Linux: one is to modify the data structure, scheduling function, and interrupt mode of the common Linux kernel so that it can process real-time processes. The other is real-time extension outside the Linux kernel. That is, on the basis of common Linux, design a kernel dedicated to processing Real-Time Processes. In order to improve the real-time performance of Linux and better meet the needs of multimedia application systems, this paper uses the first method to improve the real-time performance of the system.

2.1 improve the clock accuracy supported by the system

To improve the real-time features of Linux, the clock accuracy supported by the system must be improved. However, simply increasing the clock frequency will increase the scheduling load, seriously reducing the system performance. To solve this problem, this article sets the clock chip to a single trigger state, that is, each time a timeout time is set for the clock chip, then, when the time-out event occurs, set a time-out period for the clock chip in the clock interrupt handler as needed. The basic idea is: a precise timing means that the clock interruption occurs at a relatively precise time, but it does not necessarily require the system clock frequency to reach this precision. It uses the CPU clock Counter to provide the time precision that can reach the CPU clock speed.

2.2 preemptible kernel design

(1) The preemptible kernel adds a data item preempt_count to the task struct data structure. This data item is used by macros preempt_disable (), pro-empt_enable (), and preempt_enable_no_resched. Preempt_disable increases the preempt_count count, and preempt _

Enable: decrease preempt_count. The preempt_enable macro is used to view the contents of the preempt_count and need_resched domains of the current process. If preempt_count is O and need_resched is 1, The pre-empt_schedule () function is called. This function will add a large value to the preempt_count item of the current process, then call the process scheduling function 8 chedule (), and subtract the value from the process preempt_count after returning the scheduhj function, in this way, the kernel can be preemptible.

(2) modify the schedule function to check whether the preempt_co-unter of the process is large (this is to shield some common Scheduling Flow for preemptible scheduling is redundant operations ), then execute preemptible scheduling. Modify the code of the spinlock at the same time. Added the call to preempt_disable in spin_lock () and spin_try_lock, and added the call to preempt_enable in spin _ un-lock. Modify the code returned by the interrupt and add a call to preempt_enable.

From the above, we can see that the kernel preemptible scheduling occurs in the following situations: when the spinlock is released, or when the interrupt returns, if the need_resched of the currently executed process is marked, The preemptible scheduling is performed.

2.3 Implementation of real-time task scheduling

In terms of task switching, Linux cannot enter RTOS because the kernel cannot schedule the process in time, that is, the schedule () function of the Task Scheduler cannot be executed in time; when the interrupt is returned to the kernel state, the Linux kernel prohibits process scheduling. the Linux kernel allows process scheduling only when the interrupt is returned to the user State. The Linux kernel functions are modified as follows:


In this way, process scheduling is prohibited in the Linux Kernel when the interrupt is returned to the kernel state. process scheduling is allowed in the Linux Kernel only when the interrupt is returned to the user State, this enhances the timeliness of task scheduling.

3 embedded Linux real-time performance test results

Test Tool: Linux trace ToolKit-0.8
Test environment: Intel celon 1.2 GHz CPU, 256 mb sdram, General ljnux is red hat9.0, RT-linnx is 3.0, and media-Linux is the embedded linnx implemented in this article.
The test results are shown in table L.

We can see that the task response time of the Linux system built in this article is at 10 microseconds, which can fully meet the real-time requirements of multimedia application terminals.

Based on the characteristics of multimedia applications, while ensuring system performance as much as possible, this article improves the real-time performance of General linnux by improving the clock precision supported by the system, designing preemptible kernels, and enhancing real-time task scheduling (the key part is the source code and data structure ). Experimental results show that the system can fully meet the needs of multimedia terminal applications in real time and has good application prospects.

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.