Low priority task executes while a high priority task waits (blocked) due to resource contentions. Priority Inversion happens because in poorly designed real time embedded systems,
There can be two types of inversion, bounded and unbounded.
- If the inversion will get over in a fixed time boundary, it is Bounded inversion.
- If the time for which priorities will not be bounded, then it is called Unbounded inversion.
Solutions for priority inversion:
1. Priority ceiling
- One way to solve priority inversion is to use Priority ceiling protocol, which gives each shared resource a refined priority ceiling.
- When a task acquires a shared resource, the task priority is temporarily raised to the priority ceiling of that resource.
- The priority ceiling must be higher than the highest priority of all tasks thereby ensuring that a task running a shared resource won’t be preempted by any other task attempting to access the same resource.
- When the task whose priority is raised, releases the resource, it gains its original priority level.
- Lower priority task has the resource due to which higher priority task enters blocked state, is temporarily given higher priority of all tasks.
- This ensures that no lower or other task will be able to acquire the resource in between, since it has become highest priority task.
- This ensures no priority inversion takes place.
2. Priority Inheritance
- When a low priority task acquires a shared resource, the task continues running at its original priority level.
- If a higher priority task requests ownership of the shared resource, then the low priority task’s priority is raised above the requesting task.
- The low priority task continues its operation and once when resource is released, the task is dropped back to its original priority permitting higher priority task to execute.