VxWorks is a real-time operating system of Wind River, USA, with good reliability and real-time performance. The system uses a priority-based preemptive scheduling strategy. The system assigns a priority to each task. The scheduler guarantees that the tasks that are running at the highest priority are currently running. However, in actual development, due to the sharing of resources among tasks, the introduction of semaphores and interrupts, there is often a phenomenon in which high-priority tasks are blocked or blocked for an indefinite period of time by low-priority tasks, that is, so-called priority reversal ( Priority Inversion). Priority inversion can cause task scheduling uncertainty, which can lead to system crashes. Based on the references and the priority reversal problems encountered in the actual project development process, this article discusses the causes of the priority reversal and its solutions.
Priority inversion general description
Priority reversal occurs when a high-priority task is forced to wait for an indefinite period of time. In Figure 1, the three tasks are task1, task2, and task3, and their priorities are high to low. As can be seen from FIG. 1, when task3 occupies a shared resource protected by a semaphore and enters a critical region to execute, task1 is ready. Due to the preemptive scheduling policy of the system, 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 In the deadline, there was a problem with the scheduling of 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 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 ceilings. The following describes the priority inversion problem encountered in this article.
Figure 1 Priority Inversion Diagram
Priority inversion example
The previous section described the phenomenon of priority reversal in a general sense. The priority reversal involved in this section is more complex and more subtle than the above. The embedded microprocessor used in this paper is S3C2510 from SAMSUNG and the ARM940T is the CPU core. The task functions task1 and task2 are called to perform microsecond and millisecond timer function functions respectively. Since the S3C2510 processor has five 32-bit timers, only two of them can be used. Here, the code structure implemented by the ms-level timer is as follows:
1) Interrupt handlers
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=semCreate (SEM_Q_FI FO, 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 freely call the timer function. When a task calls the 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 handling function. When the function is interrupted, the semaphore is released and the semaphore becomes available. The task continues to execute.
When two different priority tasks task1, task2 (set priorities 93 and 94 respectively) are running at the same time, and the us and ms-level timing functions are called 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 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 more complicated, resulting in two originally seemingly independent tasks task1 and task2, which 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 bypassed 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 timer time in task2, the corresponding task priority should also be provided with task1Priority< task2Priority, so that the high-priority task will not be blocked.
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.
references:
1. Liu Hui, Meng Fanrong, Xi Jingke, 'Priority reversal 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.
Whaylan On/Off Grid Solar Inverter
Pure sine wave output
The electrical waveform output of PH1800 is pure sine wave, which has the same quality as practical power supply or household power supply. This waveform is suitable for most electrical equipment, appliances and tools. This pure sine wave unit provides more functions than an improved sine wave inverter because it has a cleaner form of power. Pure sine wave can also reduce the noise generated when applying electrical appliances to a limited extent.
On/Off Grid Solar Inverter,Hybrid Inverter With Mppt Charge,pure sine wave solar inverter
suzhou whaylan new energy technology co., ltd , https://www.whaylanenergy.com