Priority Ceiling for SMP?
Hi!
I'm thinking about adding the priority ceiling protocol to -rt (implemented in a way so that you can select between priority inheritance and priority ceiling with the kernel configurator).
Since this mechanism inherently avoids dead-locks, it could be helpful for applications that need high safety integrity levels!?
The priority ceiling protocol is basically no rocket science and implemented for other OSes for a while, so it should be a no-brainer get it going with Linux. However. I'm struggling at the point where it comes to SMP: it seems like when a task acquires a lock, it is necessary to un-schedule any active tasks on other cores sharing the same lock. This would be very inefficient, of course, because tasks sharing a lock couldn't run in parallel on different CPUs.
Does anybody know of any other priority inversion and dead-lock avoidance mechanism that would efficiently work on SMP?
Feedback is highly appreciated!
regards
Bernhard
Hi!
Quoted 22 lines · you
Hi!
I'm thinking about adding the priority ceiling protocol to -rt (implemented in a way so that you can select between priority inheritance and priority ceiling with the kernel configurator).
Since this mechanism inherently avoids dead-locks, it could be helpful for applications that need high safety integrity levels!?
The priority ceiling protocol is basically no rocket science and implemented for other OSes for a while, so it should be a no-brainer get it going with Linux. However. I'm struggling at the point where it comes to SMP: it seems like when a task acquires a lock, it is necessary to un-schedule any active tasks on other cores sharing the same lock. This would be very inefficient, of course, because tasks sharing a lock couldn't run in parallel on different CPUs.
Does anybody know of any other priority inversion and dead-lock avoidance mechanism that would efficiently work on SMP?
Quoted 5 lines
Feedback is highly appreciated!
regards
Bernhard
Maybe I didn't completely understood your question, but... if there is a problem with SMP efficiency (I do not really know, but believe you :) ) with priority ceiling (PC) implementation, this problem should have been already identified (and possibly solved) in the current PI implementation, right?
As far as I know (and I might be wrong), the PC is very similar to the PI. Main difference is that for the PC, the priority burst is to the lock ceiling value instead of the higher priority task that accesses the lock.
(BTW, what do you think that should be the kernel behaviour when the ceiling value is violated? Typical solution in RTOS is to have a fatal error)
Best regards
Signature · 1 line
Luís Henriques
Quoted 1 line · Luís Henriques
Maybe I didn't completely understood your question, but... if there is a problem with SMP efficiency (I do not really know, but believe you :) ) with priority ceiling (PC) implementation, this problem should have been already identified (and possibly solved) in the current PI implementation, right?
To make it clear: I'm not aware of any efficiency issues with the current PI implementation :-)
The (potential) efficiency issue with PC on SMP derives from the dead-lock avoidance mechanism that you mentioned: If a task locks a resource, then it's priority is raised to the ceiling (which is typically the highest priority of all task sharing that resource). Once that happens, no other task (sharing the same resource) could then lock another resource that potentially leads to a dead-lock situation.
Example:
* A low priority Task A shall share resources X and Y with a high priority Task B.
* Task A shall execute the following fraction of code:
1. lock(X)
2. lock(Y)
* Task B shall execute the following fraction of code:
1. lock(Y)
2. lock(X)
With PI, this could easily lead to a race condition resulting in a dead-lock. But with PC, no dead-lock is possible: the very moment Task A locks X, Task B won't be scheduled any more (assuming a FIFO scheduling policy), because A would now run at the same priority as B. If B takes Y, then lower priority A wouldn't be scheduled anyway, because in a single CPU system, only the highest priority task will actually run!
On SMP systems, the situation is completely different, because you can have two CPUs to run the tasks on: even if Task A running on CPU 1 is boosted to the ceiling when it takes X, then Task B on CPU 2 is not affected and could easily lock Y -> deadlock!
The only solution (i'm aware of) would be that when Task A locks Y, then CPU 1 needs to inform CPU 2 to un-schedule Task B (if it's currently running) or to mark Task-B as un-schedulable (if it's not currently running), respectively. This way, Task B can't take any shared resources (X or Y) while Task A holds X or Y. When Task A frees the lock, CPU 1 has to tell CPU 2 to kick Task B again (if it was put asleep) or to mark it as schedulable, respectivly.
Effectivly, all Tasks using PC and sharing the same resources do
not perform any better than on a single CPU system because they
can't run in parallel on different CPUs. Even worse the notable notification overhead could reduce performance dramatically for heavyly contended locks!
Now my actual question was if there is any other resource locking mechanism that inherently (by design) avoids dead-locks and is proven to work on SMP?
Quoted 1 line
(BTW, what do you think that should be the kernel behaviour when the ceiling value is violated? Typical solution in RTOS is to have a fatal error)
Here's where i'm not exactly sure what you mean:
You mean, if in the example above, a new yet higher priority Task C would come in (sharing X or Y) and thus the ceiling value would need to be (dynamically) changed? I don't think that would have any implications for the case, above.
regards
Bernhard
Quoted 34 lines · you
Quoted 5 lines · Luís Henriques
Maybe I didn't completely understood your question, but... if there is a problem with SMP efficiency (I do not really know, but believe you :) ) with priority ceiling (PC) implementation, this problem should have been already identified (and possibly solved) in the current PI implementation, right?
To make it clear: I'm not aware of any efficiency issues with the current PI implementation :-)
The (potential) efficiency issue with PC on SMP derives from the dead-lock avoidance mechanism that you mentioned: If a task locks a resource, then it's priority is raised to the ceiling (which is typically the highest priority of all task sharing that resource). Once that happens, no other task (sharing the same resource) could then lock another resource that potentially leads to a dead-lock situation.
Example:
* A low priority Task A shall share resources X and Y with a high priority Task B.
* Task A shall execute the following fraction of code:
1. lock(X)
2. lock(Y)* Task B shall execute the following fraction of code:
1. lock(Y)
2. lock(X)
Quoted 7 lines
With PI, this could easily lead to a race condition resulting in a dead-lock. But with PC, no dead-lock is possible: the very moment Task A locks X, Task B won't be scheduled any more (assuming a FIFO scheduling policy), because A would now run at the same priority as B. If B takes Y, then lower priority A wouldn't be scheduled anyway, because in a single CPU system, only the highest priority task will actually run!
Fully agree! Single CPU systems are great :)
Quoted 4 lines
On SMP systems, the situation is completely different, because you can have two CPUs to run the tasks on: even if Task A running on CPU 1 is boosted to the ceiling when it takes X, then Task B on CPU 2 is not affected and could easily lock Y -> deadlock!
Now I see what you mean. However, I guess the problem here is that, in the example you provide you are using nested locks and this is _always_ an issue. It is a known problem with the PI protocol. Good practices in RT applications development say you should never do this. Anyway, the main goal of PI and PC protocols is to avoid priority inversion, not dead-locks.
Quoted 7 lines
The only solution (i'm aware of) would be that when Task A locks Y, then CPU 1 needs to inform CPU 2 to un-schedule Task B (if it's currently running) or to mark Task-B as un-schedulable (if it's not currently running), respectively. This way, Task B can't take any shared resources (X or Y) while Task A holds X or Y. When Task A frees the lock, CPU 1 has to tell CPU 2 to kick Task B again (if it was put asleep) or to mark it as schedulable, respectivly.
I believe this could actually be implemented _but_ it might not be desirable to do it. An in-deep analysis would be required to check this, but I believe the determinism of the system would suffer with this.
Quoted 9 lines
Effectivly, all Tasks using PC and sharing the same resources do not perform any better than on a single CPU system because they can't run in parallel on different CPUs. Even worse the notable notification overhead could reduce performance dramatically for heavyly contended locks!
Now my actual question was if there is any other resource locking mechanism that inherently (by design) avoids dead-locks and is proven to work on SMP?
Well... apart for good RT applications design and some schedulabity analysis, no, I don't know anything else. I know there are several academic research (probably some implementations too, of course) on distributed systems locking mechanisms that deal with this issues but I am not familiar with those.
Note once again that the main goal of PI and PC protocols is not dead-locks avoidance but to prevent priority inversion.
Quoted 5 lines
Quoted 3 lines
(BTW, what do you think that should be the kernel behaviour when the ceiling value is violated? Typical solution in RTOS is to have a fatal error)
Here's where i'm not exactly sure what you mean:
When you have a some kind of locking mechanism (a mutex, for example) that implements the PC protocol, you need to define a ceiling value for it. This ceiling value is defined according to an analysis of your system and correspond to the highest priority task that can access this locking mechanism. My question was: sometimes it may not be easy to define this value and, in runtime, the ceiling may be violated by a task that accesses this mutex.
Quoted 4 lines
You mean, if in the example above, a new yet higher priority Task C would come in (sharing X or Y) and thus the ceiling value would need to be (dynamically) changed? I don't think that would have any implications for the case, above.
Well, but if you dynamically change the ceiling value, then we are talking about PI, right? :)
Best regards
Signature · 1 line
Luís Henriques
Quoted 4 lines · Luís Henriques
Quoted 2 lines
[...] because in a single CPU system,
only the highest priority task will actually run!Fully agree! Single CPU systems are great :)
Basically agreed, but the situation is that the industry is going multi-core because you get more bang for the buck - so it is necessary to somehow scope with it ...
Quoted 3 lines
Quoted 1 line
The only solution (i'm aware of) would be [...]
I believe this could actually be implemented _but_ it might not be desirable to do it. An in-deep analysis would be required to check this, but I believe the determinism of the system would suffer with this.
I came to the same conclusion - hence the question if there is a better way to do it :-)
Quoted 3 lines
I know there are several academic research (probably some implementations too, of course) on distributed systems locking mechanisms that deal with this issues
Can you please give me hint where to find papers on that topic? A Google research didn't helped very much - i guess i didn't used the right keywords ...
Quoted 1 line
the main goal of PI and PC protocols is not dead-locks avoidance but to prevent priority inversion.
In respect to prevent priority inversion, i think PI is superior to PC, but i have recently learned that a dead-lock avoidance mechanism can be very helpful if it comes to SIL
certification: stating "we follow good programming practices" is certainly a weaker justification for a high safety integrity level rather then telling "our OS avoids dead-locks by design".
Quoted 1 line
When you have a some kind of locking mechanism (a mutex, for example) that implements the PC protocol, you need to define a ceiling value for it. This ceiling value is defined according to an analysis of your system and correspond to the highest priority task that can access this locking mechanism. My question was: sometimes it may not be easy to define this value and, in runtime, the ceiling may be violated by a task that accesses this mutex.
Now i see the problem: i.e.. if the *topmost* priority task *rarely* accesses a *highly* contended lock, you may decide to lower the ceiling because otherwise the lock pretty much acts like a giant lock. (causing in-determinism). However, when lowering the ceiling, then dead-locks may happen, again, and the only potential advantage of PC over PI is gone ...
Quoted 1 line
Well, but if you dynamically change the ceiling value, then we are talking about PI, right? :)
Not necessarily: lets assume that we stick to the rule that the ceiling value for a lock should always be equal to the highest priority amongst all tasks using the lock. Now the situation is that the ceiling value may change when new high priority tasks are created or old high priority tasks get killed. If each task provides a list of locks it uses to the OS, then the OS could easily decide the new ceiling value for each lock when a tasks is created or killed (from what i understand, this might be tricky to implement for -rt). Change the ceiling value during runtime is IMHO no problem: either no task is currently accessing a lock, so the new task can simple run at it's priority, or the the lock is in use by another task so it's priority will be temporarily raised to the new ceiling value. Did i missed anything?
regards
Bernhard
On Friday 09 November 2007, Bernhard Kuhn wrote:
[...]
Quoted 3 lines
Can you please give me hint where to find papers on that topic? A Google research didn't helped very much - i guess i didn't used the right keywords ...
Actually, I do not have any links on my bookmarks on this topic, but, after a very quick search, I guess I found something that you might take a look at:
http://www-md.e-technik.uni-rostock.de/ma/gol/rtsys/articulos/YCS159.pdf
And talking about articles, there is one on this topic that you probably already know: "Against priority inheritance". It is a very light article... well... against priority inheritance :)
Quoted 9 lines
Quoted 2 lines
the main goal of PI and PC protocols is not dead-locks avoidance but to prevent priority inversion.
In respect to prevent priority inversion, i think PI is superior to PC, but i have recently learned that a dead-lock avoidance mechanism can be very helpful if it comes to SIL
certification: stating "we follow good programming practices" is certainly a weaker justification for a high safety integrity level rather then telling "our OS avoids dead-locks by design".
Yes, fully agree with you this.
I would like, however, to add that telling "our OS avoids dead-locks by design" is also not enough for SIL certification -- you need to prove this, which might be as difficult as implementing your system without these mechanisms (they tend to add high complexity to the kernel).
BTW and just for curiosity: anyone's aware of any application running on top of a Linux kernel that has been SIL (or similar) certified? I guess that you need a fully qualified kernel for SIL, right?
Quoted 18 lines
Quoted 7 lines
When you have a some kind of locking mechanism (a mutex, for example) that implements the PC protocol, you need to define a ceiling value for it. This ceiling value is defined according to an analysis of your system and correspond to the highest priority task that can access this locking mechanism. My question was: sometimes it may not be easy to define this value and, in runtime, the ceiling may be violated by a task that accesses this mutex.
Now i see the problem: i.e.. if the *topmost* priority task *rarely* accesses a *highly* contended lock, you may decide to lower the ceiling because otherwise the lock pretty much acts like a giant lock. (causing in-determinism). However, when lowering the ceiling, then dead-locks may happen, again, and the only potential advantage of PC over PI is gone ...
Quoted 2 lines
Well, but if you dynamically change the ceiling value, then we are talking about PI, right? :)
Quoted 12 lines
Not necessarily: lets assume that we stick to the rule that the ceiling value for a lock should always be equal to the highest priority amongst all tasks using the lock. Now the situation is that the ceiling value may change when new high priority tasks are created or old high priority tasks get killed. If each task provides a list of locks it uses to the OS, then the OS could easily decide the new ceiling value for each lock when a tasks is created or killed (from what i understand, this might be tricky to implement for -rt). Change the ceiling value during runtime is IMHO no problem: either no task is currently accessing a lock, so the new task can simple run at it's priority, or the the lock is in use by another task so it's priority will be temporarily raised to the new ceiling value. Did i missed anything?
You're right, I heard about this variation on the PC protocol. If I remember correctly, it is called "dynamic priority ceiling protocol".
To sum up: most of the priority-inversion/dead-lock avoidance mechanisms (we've been discussing PI and PC but probably there are much more...) have advantages and disadventages which are widely known and documented. The conclusion, I guess, is that no "magic" solution exists and the applications system architects will need to choose one or more (or none!) of the available mechanisms.
My personal opinion is that, no matter what mechanism you select, if your developing critical software you will _always_ need to perform static schedulability analysis of your system and never rely on PI or PC. Been there... ;)
Signature · 1 line
Luís Henriques
Quoted 1 line · Luís Henriques
http://www-md.e-technik.uni-rostock.de/ma/gol/rtsys/articulos/YCS159.pdf
Thanks for this link. This paper teached me the right keywords to feed Google and i stumbled over this one:
https://drum.umd.edu/dspace/bitstream/1903/630/1/CS-TR-3252.ps
However, it seems like this "Multiprocessor Priority Ceiling Protocol" doesn't allow nested locking and thus is not applicable to -rt :-(
Quoted 1 line
I would like, however, to add that telling "our OS avoids dead-locks by design" is also not enough for SIL certification -- you need to prove this,
True, but you only need to do it once for the OS and not for all applications developed on top of it, afterwards
Quoted 1 line
which might be as difficult as implementing your system without these mechanisms (they tend to add high complexity to the kernel).
This depends into which level of detail the SIL certifier likes to dig :-)
Quoted 1 line
BTW and just for curiosity: anyone's aware of any application running on top of a Linux kernel that has been SIL (or similar) certified? I guess that you need a fully qualified kernel for SIL, right?
IIRC, you can claim yourself that your system reaches SIL1 or SIL2. (it's a little bit like the "CE" sign). The fun starts at SIL3 and SIL4, where you get your system certified by somebody else.
Quoted 1 line
To sum up: most of the priority-inversion/dead-lock avoidance mechanisms (we've been discussing PI and PC but probably there are much more...) have advantages and disadventages which are widely known and documented. The conclusion, I guess, is that no "magic" solution exists and the applications system architects will need to choose one or more (or none!) of the available mechanisms.
Agreed.
Quoted 1 line
My personal opinion is that, no matter what mechanism you select, if your developing critical software you will _always_ need to perform static schedulability analysis of your system and never rely on PI or PC.
Basically agreed, however, this can be a very challenging activity for a highly dynamic system like Linux :-)
regards
Bernhard
Quoted 26 lines · Bernhard Kuhn
Quoted 4 lines · Luís Henriques
Maybe I didn't completely understood your question, but... if there is a problem with SMP efficiency (I do not really know, but believe you :) ) with priority ceiling (PC) implementation, this problem should have been already identified (and possibly solved) in the current PI implementation, right?
To make it clear: I'm not aware of any efficiency issues with the current PI implementation :-)
The (potential) efficiency issue with PC on SMP derives from the dead-lock avoidance mechanism that you mentioned: If a task locks a resource, then it's priority is raised to the ceiling (which is typically the highest priority of all task sharing that resource). Once that happens, no other task (sharing the same resource) could then lock another resource that potentially leads to a dead-lock situation.
Example:
* A low priority Task A shall share resources X and Y with a high priority Task B.
* Task A shall execute the following fraction of code:
Quoted 7 lines
1. lock(X)
2. lock(Y)* Task B shall execute the following fraction of code:
1. lock(Y)
2. lock(X)
Classic ABBA deadlock :) Priority ceiling is not designed to allow that. It's just a coincidence that it does not lead to a deadlock on UP, but thats not a semantical property.
Thanks,
tglx