Real Time Mutexes

Real-time mutexes (RT-mutexes) are another form of mutex supported by the kernel. They need to be explicitly enabled at compile time by selecting the configuration option config_rt_mutex. In contrast to regular mutexes, they implement priority inheritance, which, in turn, allows for solving (or, at least, attenuating) the effects of priority inversion. Both are well-known effects, respectively, methods and are discussed in most operating systems textbooks.

Consider a situation in which two processes run on a system: A has high priority, and C has low priority. Assume the C has acquired a mutex and is happily operating in the protected region, with no intention of leaving it sometime in the near future. However, shortly after C has entered the protected region, A also tries to obtain the mutex that protects it — and has to wait, because C has already acquired the mutex. This causes the higher-priority process A to wait for the lower-priority process C.

Things can get worse when a third process B with a priority between A and C enters the field. Suppose that C still holds the lock, and A is waiting for it. Now B gets ready to run. Because it has a higher priority than C, it can preempt C. But it has also effectively preempted A, although this process has a higher priority than B. If B continues to stay runnable, it can prevent A from running for a long time, because C will finish its operation only slowly. B therefore acts as if it had a higher priority than A. This unfortunate situation is referred to as unbounded priority inversion.

This problem can be solved by priority inheritance: When a high-priority process blocks on a mutex that is currently held by a low-priority process, the priority of C (in our example) is temporarily boosted to the priority of A. If B starts to run now, it will only get as much CPU time as if it were competing with A, thus setting priorities straight again.

The definition of a RT-mutex is tantalizingly close to the definition of a regular mutex:

Continue reading here: Info

Was this article helpful?

0 0