FreeRTOS Lecture 5 – RTOS vs GPOS: Priority inversion

  • Post author:
  • Post category:Blog

 

RTOS vs GPOS: Priority inversion

 

 

RTOS vs GPOS: Priority Inversion and Key Features

Priority Inversion: An Analogy

Examining the differences between Real-Time Operating Systems (RTOS) and General-Purpose Operating Systems (GPOS) in relation to priority inversion.

Imagine you’re driving your car and considering that as a lower priority vehicle, enters the busy traffic intersection (Figure 1), and you may be thinking that you can easily cross the intersection.

Now let’s say, unfortunately, all the vehicles come to a sudden stop, and you are stuck right in the middle of the intersection of the roads, as shown in Figure 2.

Suddenly you hear the siren of an ambulance (Figure 3), which is heading to a hospital over this line. The ambulance is, of course, a higher priority vehicle. Now the ambulance cannot cross the intersection because, unfortunately, you cannot move since you are stuck in the middle. The ambulance now has to wait (Figure 4) until you move out of its way.

This situation illustrates priority inversion – where a higher priority entity waits on a lower priority one, contrary to their intended priorities.

The higher priority vehicle behaving like it is a lower priority, and a lower priority vehicle is behaving like a higher priority. This is the case of priority inversion.

 

RTOS vs GPOS: Priority inversion
Figure 1. Lower priority vehicle entering the busy traffic intersection.

 

RTOS vs GPOS: Priority inversion
Figure 2. Low priority vehicle struck in the middle of the intersection of the roads.

 

RTOS vs GPOS: Priority inversion
Figure 3. Ambulance coming towards the intersection.

 

RTOS vs GPOS: Priority inversion
Figure 4. Ambulance waits for the low-priority vehicle to move out of its way.

 

 

Now, let’s apply this to the computing world. Let’s say your car is a lower priority task, the taxies  are medium priority, and the ambulance is a higher priority task. And the intersection area marked in Figure 5 is a shared resource because this is common for both roads.

Figure 5. Example for priority inversion
Figure 5. Example for priority inversion.

 

Now let’s say the lower priority task has acquired the key to access this shared area. But it is not allowed to run on the CPU because lots of medium priority tasks are running on the CPU, which won’t allow lower priority tasks to take the CPU.

Now when the higher priority task enters, it cannot access this shared area because the key is taken by the lower priority task, but the lower priority task is not allowed to run. It can only give up the key once it is allowed to run. So, until the lower priority task runs, the key will be locked for this shared resource, and the higher priority task cannot access it. Therefore, the higher priority task has to wait until the lower priority task releases the key, causing the inversion in priority.

In GPOS, this is not at all a major issue. But in RTOS, it will definitely lead to issues because you are blocking the higher priority task to execute.

Most of the real-time kernels use some techniques to solve this issue. An RTOS can create paths on the fly, which allows the higher priority task to bypass a lower priority task, as shown in Figure 6. That we call as rescheduling, or there could be other techniques like temporarily making lower priority task (car) as a higher priority task and medium priority task (a group of taxies) as a lower priority task as shown in Figure 7, giving a chance for the lowest priority task to run and release the key.

An RTOS uses all these techniques to minimize the priority inversion problem.

 

Figure 6. On the fly path creation or Re-Scheduling.
Figure 6. On the fly path creation or Re-Scheduling.

 

Figure 7. Temporarily changing the priories.
Figure 7. Temporarily changing the priories.

Priority inversion is not at all a problem in general-purpose OS. But this will surely cause a problem in the Real-Time Operating System.

 

RTOS vs GPOS Features:

1.Priority-Based Preemptive Scheduling:

RTOS employs a priority-based preemptive scheduling mechanism, That means it always favors the highest priority task in the system. But a GPOS cannot act like this. If it does, then it will kill the throughput of the system. So, GPOS usually goes for those scheduling techniques which increase the throughput of the system.

 

2. Critical Section Code Handling:

You will not find very long critical section code segments where the interrupt, as well as the preemption of the system, is disabled in order to protect the critical section. But in the case of GPOS, this may not be the case.

 

3. Priority Inversion Handling:

RTOS must address and prevent priority inversion issues, as they can lead to system failure. GPOS doesn’t encounter this problem to the same degree.

 

4. Interrupt and Scheduling Latency:

RTOS maintains bounded interrupt and scheduling latency. In GPOS, these latencies can vary significantly due to system complexity and increasing load over time.

 

In the following article, let’s learn about Multitasking.

 

FastBit Embedded Brain Academy Courses

click here: https://fastbitlab.com/course1

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.

Leave a Reply