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.
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.
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.
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