0
8.9kviews
What is Priority Inversion? How can it be avoided?
1 Answer
0
540views

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,

  • Consider 3 tasks viz. task A with high priority, task B with medium priority and task C with low priority.
  • Task A and task C share a variable ‘X’ and access to this variable is synchronous with use of semaphore.
  • Task C is ready and picked up by scheduler for execution and acquires shared variable.
  • Task A is blocked due to unavailability of resource and waiting for resource being used by task B which has itself preempted the task C.
  • Therefore, task A which has higher priority is effectively inverted to lower priority.

    Priority Inversion

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.

Priority Ceiling

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.

Priority Inheritance

Please log in to add an answer.