Analysis of Priority Reversal in Embedded Systems

VxWorks is a real-time operating system launched by Wind River System Inc. (ie, WRS Corporation) in the United States. It has excellent reliability and excellent real-time performance. The system adopts a priority-based preemptive scheduling strategy. The system assigns a priority to each task. The scheduler ensures that the currently running task is the highest priority task. However, in actual development, due to the sharing of resources among tasks, the introduction of semaphores and interrupts, there often occurs a phenomenon in which high-priority tasks are blocked or blocked for a long period of time by low-priority tasks. Priority Inversion. Priority inversion can cause task scheduling uncertainty, which can lead to system crashes. On the basis of references [1, 2], this paper discusses the causes of the priority reversal and the solutions to it, combining the priority reversal issues encountered during the actual project development process.
Priority Inversion General Description
Priority reversal occurs when a high-priority task is forced to wait for an indefinite period of time waiting for a low-priority task to complete first. The three tasks in Figure 1 are task1, task2, and task3, respectively, and their priorities are from high to low. It can be seen from FIG. 1 that when task3 occupies a certain shared resource protected by a semaphore and enters a critical region to execute, task1 is ready, and because the system can preemptively schedule a PBP (Priority Based Preemptive) scheduling policy, task1 preempts task3 execution. After task1 is executed for a period of time, it enters the critical zone, but task3 still occupies the semaphore of this critical resource. Task1 is blocked and waits for task3 to release the semaphore. After such a period of time, task2 is already in the ready state, so the system schedules task2 execution. If task3 has not been scheduled to execute during the execution of task2, then task1 and task3 will wait until task2 is executed. Task1 will wait until task3 releases the semaphore it occupies to execute; if this time exceeds task1 There was a problem with the scheduling of Deadline and task1. At this time, the task was blocked for a long time, and the system crash was caused. The reason for the priority inversion can be summarized as follows: the high-priority task task1 is blocked by task2 due to waiting for the critical resource occupied by the low-priority task task3, and the task task2 with medium-priority task preempts the CPU time of task3. Causes task2 to execute before task1. There are roughly two solutions to this kind of priority reversal problem: one is called priority inheritance; the other is called priority ceilings. The following describes the priority inversion problem encountered in this article.
Example of Priority Reversal
The previous section described the phenomenon of priority reversal in the general sense. The priority reversal involved in this section is more complex than the above, and it is more subtle.
This article uses the embedded microprocessor S3C2510, CPU core Arm940T, SAMSUNG company. According to the needs of the project, task 1 and task 2 are required to call microsecond and millisecond timer functions respectively. Because of the S3C2510 processor's five 32-bit timers, two of them can be used. Among them, the code architecture implemented by the ms-level timer is as follows:
1) Interrupt handler:
LOCAL void Timer1_Int_Handle(void)
{
*S3C2510_TIC |= S3C2510_TIC_T1;/*Clear interrupt*/
...
semGive(TelID4_Stop);/* Release binary semaphore*/
...
}
2) Millisecond-level timing function
Void ms_Delay(int ms)
{
...
semTake(TelID4_Stop,WAIT_FOREVER);
...
}
3) Clock initialization function
Void msTimer_Init()
TelID4_Stop=semCCreate(SEM_Q_FIFO,SEM_EMPTY);/*Initialize binary semaphore*/
Assert(TelID4_Stop);
...
}
The code implemented by the us level timer function is similar to the above, and no corresponding code is given here. Function call description: Initialize first, then the task can call the timer function function at will. When a task calls a timer function, the task is blocked by the semaphore and the timer starts to count down. When the counter is reduced to 0, an interrupt request signal is generated. At this time, the system will call the interrupt handler function. The semaphore is released when the interrupt handler function is released. At this time, the semaphore becomes available and the task continues to execute.
When two different priority tasks task1, task2 (set priorities 93 and 94 respectively) operate simultaneously and call the us and ms-level timing function functions respectively, the priority reversal occurs, and task1 is blocked for a long time. Among them, the calls to task1 and task2 are as follows:
Void task1(void)
{
...
FOREVER
{
...
us_Delay();
...
taskDelay(4);
}
Void Task2(void)
{
...
FOREVER
{
ms_Delay();
...
}
The resources between the above two tasks are independent, but when the two tasks are run together, the high-priority task task1 will be blocked for a long time after a period of time.
The method to solve the above problem is relatively simple, as long as the task priority of task1 is adjusted to be lower than task2, and the value of 95 is selected here, then the two tasks can run in parallel for a long time.
Due to the addition of interrupts and semaphores, the task scheduling of the system becomes complex, resulting in two tasks task1 and task2 that seem to be independent and cannot run in parallel. The analysis of the causes of such phenomena is extremely complex and can be regarded as a blind spot of system application. However, such problems can be effectively solved by summing up the rules. For example, in the above problem, if the timing function of the timer function called by task1 is shorter than the timing time in task2, the corresponding task priority should also be task1PriorityTASK2PRIORITY, so that the high-priority task will not be blocked.
4 Conclusion
In this paper, the priority inversion problem in Vxworks is discussed with practical examples, and the solution to this problem is described. The discussion of this article will enable embedded system developers to better understand the issue of priority reversal. At the end of the article, we summarize the priority reversal issues as follows:
1) General conditions: introduction of semaphores;
2) Time of occurrence: High-priority tasks are forced to wait for an indefinite period of time, waiting for a low-priority task to complete;
3) Causes: different;
4) Manifestation: High-priority tasks are blocked for long periods of time.
references
1. Liu Hui, Meng Fanrong, Xi Jingke. 'Priority inversion of embedded real-time systems', Embedded System Application, 2003.3
2. Dang Jihong, Li Dongming, Yuan Xiaonan. “Research and Analysis of Real-time Kernel Scheduling in Vxworks”, Applied Science and Technology, 2003.2

Inflatable Swimming Pools

At the heart of our manufacturing process is a dedication to creating products that not only meet but exceed industry standards. We leverage cutting-edge technology and pvc materials to ensure the durability and longevity of our inflatable pool. Whether it's for family fun in residential settings or large-scale commercial installations, our pools are designed to cater to diverse needs.

What sets us apart is our unwavering commitment to customer satisfaction. We prioritize safety features in every design, implementing rigorous quality control measures to guarantee a secure and enjoyable experience for users of all ages. Our team of skilled artisans and engineers works tirelessly to bring forth inflatable swimming pools that not only meet but exceed expectations.

Beyond functionality, we understand the importance of aesthetics. Our designs encompass a wide array of shapes, sizes, and styles, catering to various preferences and spaces. From vibrant and playful designs for children to sleek and modern options for adults, our inflatable pools add a touch of joy to any environment.

With a global footprint, we take pride in being a trusted partner for clients worldwide. Our commitment to environmental sustainability is reflected in our manufacturing processes, ensuring that our products not only bring joy but also contribute to a greener future.

Choose P&D Plastic Manufacture Co., Ltd for inflatable swimming pools that redefine recreation – where quality, safety, and innovation converge to create an unmatched aquatic experience. Dive into a world of possibilities with our exceptional inflatable pools, crafted with passion and precision.

inflatable swimming pool for kids and adults, outdoor inflatable swimming pool, adult inflatable swimming pool, large inflatable swimming pools, kids inflatable swimming pool

P&D Plastic Manufacture Co., Ltd , https://www.jmInflatableboat.com