14

I understand what priority inheritance is. I also understand, from the Mars Pathfinder's system reset issue, that most of the time, depending upon the criticality of the operation, it is good to enable/implement priority inheritance.

However, are there any cases where priority inheritance is not desirable and may actually cause problems if enabled/implemented? If so, could you please provide an example while preferably describing a problem?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Anish Ramaswamy
  • 2,326
  • 3
  • 32
  • 63

1 Answers1

5

OP gives an example where priority inheritance is desirable. There we have a short mutex-protected transaction between threads of highest and lowest priorities and a long-running thread with medium priority which could block the transaction if priority inheritance is not used. Also in this example high-priority thread is more important for the application than medium-priority thread.

To get priority inheritance not desirable, we could make an application where all these assumptions are opposite to the above example. Let's make transaction between threads of highest and lowest priorities longer than time available for medium-priority thread to perform its task. And let's assume that the results of this medium-priority thread are more important than the results of high-priority thread.

Imagine an application which should serve 100 interrupts per second with its high-priority thread. And 10 interrupts per second with its medium-priority thread (where each interrupt needs 30 ms to be processed). Low-priority thread could lock some resource (used together with high-priority thread). And sometimes (very rarely) it could lock it for a long time (1 sec). With priority inheritance first access to this resource by high-priority thread boosts priority of background thread for up to 1 sec. So that medium-priority thread would miss 10 interrupts. At the same time high-priority thread could miss 100 interrupts. Without priority inheritance medium-priority thread serves all interrupts but high-priority thread misses up to 130 interrupts. If interrupts served by medium-priority thread are more valuable, we should prefer to disable priority inheritance.

I never seen a real-life application like this. So I invented one to illustrate this case. Let it be a video capture application with some computer vision task in background and (as additional bonus) sound recording. Video frames are captured by medium-priority thread. Sound is captured by high-priority thread (because otherwise video capturing process could block significant portion of sound interrupts). Video is captured to pre-allocated buffer. Audio is captured with silence suppression (no memory is needed to capture silence). So audio thread needs dynamically allocated memory blocks (this is our shared resource). Computer vision task also sometimes allocates memory blocks. When we are out-of-memory, garbage collector thread blocks memory allocation and does some work. Here without priority inheritance video capture works flawlessly. But with priority inheritance audio thread sometimes blocks video capture (which is considered bad for this application).


Also there are applications where priority inheritance does not give any benefits:

  • When there are (1) several background threads and (2) several short-living priority threads. Each group of threads shares resources only inside its own group.
  • When one resource is shared by threads with priorities 1 & 2, other one - by threads with priorities 3 & 4, etc.
  • When processor has more cores than there are time-critical threads in application.
  • In many other cases.

If priority inheritance is enabled in such cases, we could only get some performance (or power efficiency) degradation because priority inheritance implementation in kernel most likely needs some additional resources.

Evgeny Kluev
  • 24,287
  • 7
  • 55
  • 98
  • Thank you for your answer! I'm still not convinced though. If the results of thread 'X' are more important than the results of thread 'Y', wouldn't we assign thread 'X' to be of higher priority? In your example, why does the video frame capturing thread have only medium priority? I'm a bit confused by that. – Anish Ramaswamy Apr 07 '14 at 21:33
  • @AnishRamaswamy: In this example we have audio interrupts coming more frequently than video interrupts, so if video capturing thread had higher priority, it would prevent lower-priority audio thread from processing interrupts (for example, each 30 of 100 ms), so every 3 of 10 audio interrupts stay not processed, every 3 of 10 audio frames not captured, and such audio is useless. Even if audio thread is less important for this application, it should have higher priority. – Evgeny Kluev Apr 08 '14 at 05:18
  • So what would happen if we assign the audio thread to have lower priority and enable priority inheritance? Wouldn't that prevent the problem you proposed? Or am I completely missing the point here? – Anish Ramaswamy Apr 08 '14 at 17:48
  • @AnishRamaswamy: audio thread would still miss 30% interrupts. Priority inheritance cannot prevent this problem because neither shared resource nor mutex is involved here. – Evgeny Kluev Apr 08 '14 at 17:57
  • +1 Ah I think I understand now. One more question though. You mentioned in your answer, _"But with priority inheritance audio thread sometimes blocks video capture"_. But, in your previous comment (and in your answer) you seemed to imply that priority inheritance will not affect anything since each thread group only shares resources within the group. So this is a bit confusing again. Thanks for your patience! – Anish Ramaswamy Apr 08 '14 at 21:13
  • @AnishRamaswamy: in previous comment we discussed the case when resource was shared between mid- and low-priority threads while high-priority thread did not share resources with others. In second half of the answer there are more examples where resources are shared only within separate groups. But first half of the answer is completely different: there resource is shared between high- and low-priority threads with mid-priority thread in between. That's exactly the case where priority inheritance changes things (and here it changes them in a bad way). – Evgeny Kluev Apr 09 '14 at 07:31