Linux task response model-general Linux technology-Linux programming and kernel information. The following is a detailed description. From the defects inherent in the real-time nature of Linux, we can see that the ultimate goal of Linux real-time is to meet the requirements of real-time task rapid response time. A real-time task is triggered by an external interrupt. When the interrupt occurs, the CPU receives the interrupt signal, if the CPU is currently allowed to be interrupted (if not, the interruption will not be handled until the interruption is allowed), save the currently running task and jump to the interrupted service program, execute the interrupt service program (wake up real-time tasks in the interrupt service program), and then execute the interrupt and return. If the current system allows process scheduling, the Scheduled real-time task starts to run (assuming that the real-time task has the highest priority ). To better understand the basic principles of Real-Time Linux, we need to analyze the Linux task response model in detail, as shown in the image in the attachment, and provide a simplified Linux task response model.
(400) {this. resized = true; this. width = 400; this. alt = 'click here to open new window';} "onmouseover =" if (this. resized) this. style. cursor = 'hand'; "onclick =" window. open ('HTTP: // response); ">
In the task response model, Task 2 (which can be viewed as a soft real-time task in Linux) has a higher priority than Task 1. Task 1 is running at t0 time, and task 2 is sleep, waiting for interruption to wake up; Task 1 is requesting system services to complete some operations (for example, by reading () the file interface reads files on the disk.) At this time, the system starts to run in the kernel state. At the time of t2, an interruption occurs (wake up the task in the interrupted service program 2 ), however, because the system does not want to interrupt some operations in the kernel state and the CPU processing interruption is disabled, the interrupt signal does not respond immediately, but continues to execute system services in the kernel state; at the time of T3. kernel-State Code enable interrupt response (the Linux kernel exits from the critical section). At this time, the CPU starts to respond to the interrupt at the time of T2. the interrupt service program is executed from the time of T4; after the interrupted service program is executed (Task 2 is awakened in the interrupted service program), the interrupted code is returned, because the system is running in the kernel state (the system service request for Task 1 is executed), Task 2 cannot control task 1, so the system service request for Task 1 is executed; at the time of t7, after the system call of Task 1 is completed or the system service is executed Task 2 is the highest priority task in the system ).
The Time range from Time t2 to Time t8 is what we call the Task Response Time. The figure shows that, the task response latency can be divided into the following parts:
1) Interrupt Latency or interruption Latency, which refers to the period from the interruption generation to the time when the CPU starts to respond to the interruption, that is, the period from t2 to t3 in the figure. The interrupt latency is caused by the kernel disabling the interrupt response of the CPU before entering the critical section. During this period, although the external device makes the interrupt request line of the CPU valid, however, the CPU does not immediately respond to the interruption, but continues to execute the kernel code in the critical section until the critical section is exited and the request can be interrupted. Of course, it should be noted that the interrupt latency actually includes the interruption delay time produced by the hardware. We generally study how to minimize the latency caused by the software, therefore, unless otherwise stated, we do not consider the delay caused by hardware (but in fact, in engineering applications, when the software optimization cannot meet the real-time requirements of the system, the only way is to increase the processing speed of the hardware ).
2) the interruption Distribution phase (the interruption preparation phase) refers to the period between the CPU starts to respond to the interrupt request and the execution of the interrupt service program, that is, the period from t3 to t4 in the figure. During this period, the system mainly performs operations such as finding the interrupt number, saving the Register, and locating the interrupt service program. The length of this time period is generally deterministic for a specific platform, that is, the time length is fixed. In addition, the Time period between the interruption generation and the execution of the Interrupt service program is called the Interrupt Response Time, which corresponds to the Time period between t2 and t4 in the figure.
3) in the service interruption phase, this refers to the period from when the system executes the interrupted service program to when the interrupted service program is executed, that is, the period from t4 to t5 in the figure. The length of this time period depends on the specific interruption or application, that is, the length of this time period can be controlled.
4) In the return interruption phase, this refers to the period from the execution of the interrupted service program to the start of the Code to be interrupted, that is, the period from t5 to t6 in the figure. During this period, the system will mainly perform operations to restore the register value. The length of this period is usually fixed.
5) Schedule Latency or scheduling Latency, which refers to the process scheduling from the system (the value of need_resched in the process structure of the current process is 1) the actual start time period, that is, the time period from t6 to t7 in the figure. Because Linux2.4 kernel cannot be preemptible, when the system runs in the kernel space, even if a process with a higher priority needs to run, unless the request is scheduled, otherwise, a high-priority process cannot seize the current process to run. Therefore, the process can be scheduled only when the system call of the low-priority process is completed or the scheduling is actively requested.
6) process scheduling time, which refers to the time period from System Scheduling to scheduling of the process with the highest priority, that is, the time period from t7 to t8 in the figure. During this period, the system selects appropriate processes for scheduling based on the utilization of system resources, the priority of processes, and the running status of processes.
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